Home | History | Annotate | Download | only in platform
      1 Description := Static runtime libraries for clang/Linux.
      2 
      3 ###
      4 
      5 CC := clang
      6 Arch := unknown
      7 Configs :=
      8 
      9 # We don't currently have any general purpose way to target architectures other
     10 # than the compiler defaults (because there is no generalized way to invoke
     11 # cross compilers). For now, we just find the target architecture of the
     12 # compiler and only define configurations we know that compiler can generate.
     13 CompilerTargetTriple := $(shell \
     14 	LANG=C $(CC) -v 2>&1 | grep 'Target:' | cut -d' ' -f2)
     15 ifeq ($(CompilerTargetTriple),)
     16 $(error "unable to infer compiler target triple for $(CC)")
     17 endif
     18 
     19 # Only define configs if we detected a linux target.
     20 ifneq ($(findstring -linux-,$(CompilerTargetTriple)),)
     21 
     22 # Define configs only if arch in triple is i386 or x86_64
     23 CompilerTargetArch := $(firstword $(subst -, ,$(CompilerTargetTriple)))
     24 ifeq ($(call contains,i386 x86_64,$(CompilerTargetArch)),true)
     25 
     26 # TryCompile compiler source flags
     27 # Returns exit code of running a compiler invocation.
     28 TryCompile = \
     29   $(shell \
     30     cflags=""; \
     31     for flag in $(3); do \
     32       cflags="$$cflags $$flag"; \
     33     done; \
     34     $(1) $$cflags $(2) -o /dev/null > /dev/null 2> /dev/null ; \
     35     echo $$?)
     36 
     37 test_source = $(ProjSrcRoot)/make/platform/clang_linux_test_input.c
     38 ifeq ($(CompilerTargetArch),i386)
     39   SupportedArches := i386
     40   ifeq ($(call TryCompile,$(CC),$(test_source),-m64),0)
     41     SupportedArches += x86_64
     42   endif
     43 else
     44   SupportedArches := x86_64
     45   ifeq ($(call TryCompile,$(CC),$(test_source),-m32),0)
     46     SupportedArches += i386
     47   endif
     48 endif
     49 
     50 # Build runtime libraries for i386.
     51 ifeq ($(call contains,$(SupportedArches),i386),true)
     52 Configs += builtins-i386 profile-i386 san-i386 asan-i386 asan_cxx-i386 \
     53 	   ubsan-i386 ubsan_cxx-i386
     54 Arch.builtins-i386 := i386
     55 Arch.profile-i386 := i386
     56 Arch.san-i386 := i386
     57 Arch.asan-i386 := i386
     58 Arch.asan_cxx-i386 := i386
     59 Arch.ubsan-i386 := i386
     60 Arch.ubsan_cxx-i386 := i386
     61 endif
     62 
     63 # Build runtime libraries for x86_64.
     64 ifeq ($(call contains,$(SupportedArches),x86_64),true)
     65 Configs += builtins-x86_64 profile-x86_64 san-x86_64 asan-x86_64 asan_cxx-x86_64 \
     66 	   tsan-x86_64 msan-x86_64 ubsan-x86_64 ubsan_cxx-x86_64 dfsan-x86_64 \
     67 	   lsan-x86_64
     68 Arch.builtins-x86_64 := x86_64
     69 Arch.profile-x86_64 := x86_64
     70 Arch.san-x86_64 := x86_64
     71 Arch.asan-x86_64 := x86_64
     72 Arch.asan_cxx-x86_64 := x86_64
     73 Arch.tsan-x86_64 := x86_64
     74 Arch.msan-x86_64 := x86_64
     75 Arch.ubsan-x86_64 := x86_64
     76 Arch.ubsan_cxx-x86_64 := x86_64
     77 Arch.dfsan-x86_64 := x86_64
     78 Arch.lsan-x86_64 := x86_64
     79 endif
     80 
     81 endif
     82 
     83 ifneq ($(LLVM_ANDROID_TOOLCHAIN_DIR),)
     84 Configs += asan-arm-android
     85 Arch.asan-arm-android := arm-android
     86 endif
     87 
     88 endif
     89 
     90 ###
     91 
     92 CFLAGS := -Wall -Werror -O3 -fomit-frame-pointer
     93 SANITIZER_CFLAGS := -fPIE -fno-builtin -gline-tables-only
     94 
     95 CFLAGS.builtins-i386 := $(CFLAGS) -m32
     96 CFLAGS.builtins-x86_64 := $(CFLAGS) -m64
     97 CFLAGS.profile-i386 := $(CFLAGS) -m32
     98 CFLAGS.profile-x86_64 := $(CFLAGS) -m64
     99 CFLAGS.san-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti
    100 CFLAGS.san-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
    101 CFLAGS.asan-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti
    102 CFLAGS.asan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
    103 CFLAGS.asan_cxx-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti
    104 CFLAGS.asan_cxx-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
    105 CFLAGS.tsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
    106 CFLAGS.msan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
    107 CFLAGS.ubsan-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti
    108 CFLAGS.ubsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
    109 CFLAGS.ubsan_cxx-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS)
    110 CFLAGS.ubsan_cxx-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS)
    111 CFLAGS.dfsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
    112 CFLAGS.lsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
    113 
    114 SHARED_LIBRARY.asan-arm-android := 1
    115 ANDROID_COMMON_FLAGS := -target arm-linux-androideabi \
    116 	--sysroot=$(LLVM_ANDROID_TOOLCHAIN_DIR)/sysroot \
    117 	-B$(LLVM_ANDROID_TOOLCHAIN_DIR)
    118 CFLAGS.asan-arm-android := $(CFLAGS) $(SANITIZER_CFLAGS) \
    119 	$(ANDROID_COMMON_FLAGS) -fno-rtti \
    120 	-I$(ProjSrcRoot)/android/include
    121 LDFLAGS.asan-arm-android := $(LDFLAGS) $(ANDROID_COMMON_FLAGS) -ldl -lm -llog \
    122 	-lstdc++ -Wl,-soname=libclang_rt.asan-arm-android.so -Wl,-z,defs
    123 
    124 # Use our stub SDK as the sysroot to support more portable building. For now we
    125 # just do this for the core module, because the stub SDK doesn't have
    126 # enough support to build the sanitizers or profile runtimes.
    127 CFLAGS.builtins-i386 += --sysroot=$(ProjSrcRoot)/SDKs/linux
    128 CFLAGS.builtins-x86_64 += --sysroot=$(ProjSrcRoot)/SDKs/linux
    129 
    130 FUNCTIONS.builtins-i386 := $(CommonFunctions) $(ArchFunctions.i386)
    131 FUNCTIONS.builtins-x86_64 := $(CommonFunctions) $(ArchFunctions.x86_64)
    132 FUNCTIONS.profile-i386 := GCDAProfiling InstrProfiling InstrProfilingBuffer \
    133                           InstrProfilingFile InstrProfilingPlatformOther \
    134                           InstrProfilingRuntime
    135 FUNCTIONS.profile-x86_64 := $(FUNCTIONS.profile-i386)
    136 FUNCTIONS.san-i386 := $(SanitizerCommonFunctions)
    137 FUNCTIONS.san-x86_64 := $(SanitizerCommonFunctions)
    138 FUNCTIONS.asan-i386 := $(AsanFunctions) $(InterceptionFunctions) \
    139                                         $(SanitizerCommonFunctions)
    140 FUNCTIONS.asan-x86_64 := $(AsanFunctions) $(InterceptionFunctions) \
    141                          $(SanitizerCommonFunctions) $(LsanCommonFunctions)
    142 FUNCTIONS.asan_cxx-i386 := $(AsanCXXFunctions)
    143 FUNCTIONS.asan_cxx-x86_64 := $(AsanCXXFunctions)
    144 FUNCTIONS.asan-arm-android := $(AsanFunctions) $(AsanCXXFunctions) \
    145                               $(InterceptionFunctions) \
    146                               $(SanitizerCommonFunctions)
    147 FUNCTIONS.tsan-x86_64 := $(TsanFunctions) $(InterceptionFunctions) \
    148                                           $(SanitizerCommonFunctions)
    149 FUNCTIONS.msan-x86_64 := $(MsanFunctions) $(InterceptionFunctions) \
    150                                           $(SanitizerCommonFunctions)
    151 FUNCTIONS.ubsan-i386 := $(UbsanFunctions)
    152 FUNCTIONS.ubsan-x86_64 := $(UbsanFunctions)
    153 FUNCTIONS.ubsan_cxx-i386 := $(UbsanCXXFunctions)
    154 FUNCTIONS.ubsan_cxx-x86_64 := $(UbsanCXXFunctions)
    155 FUNCTIONS.dfsan-x86_64 := $(DfsanFunctions) $(InterceptionFunctions) \
    156                                             $(SanitizerCommonFunctions)
    157 FUNCTIONS.lsan-x86_64 := $(LsanFunctions) $(InterceptionFunctions) \
    158                                           $(SanitizerCommonFunctions)
    159 
    160 # Always use optimized variants.
    161 OPTIMIZED := 1
    162 
    163 # We don't need to use visibility hidden on Linux.
    164 VISIBILITY_HIDDEN := 0
    165 
    166 SHARED_LIBRARY_SUFFIX := so
    167