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 archicture of the compiler 12 # and only define configurations we know that compiler can generate. 13 CompilerTargetTriple := $(shell \ 14 $(CC) -v 2>&1 | grep 'Target:' | cut -d' ' -f2) 15 ifneq ($(DEBUGMAKE),) 16 ifeq ($(CompilerTargetTriple),) 17 $(error "unable to infer compiler target triple for $(CC)") 18 endif 19 endif 20 21 # Only define configs if we detected a linux target. 22 ifneq ($(findstring -linux-,$(CompilerTargetTriple)),) 23 24 # Define configs only if arch in triple is i386 or x86_64 25 CompilerTargetArch := $(firstword $(subst -, ,$(CompilerTargetTriple))) 26 ifeq ($(call contains,i386 x86_64,$(CompilerTargetArch)),true) 27 28 # TryCompile compiler source flags 29 # Returns exit code of running a compiler invocation. 30 TryCompile = \ 31 $(shell \ 32 cflags=""; \ 33 for flag in $(3); do \ 34 cflags="$$cflags $$flag"; \ 35 done; \ 36 $(1) $$cflags $(2) -o /dev/null > /dev/null 2> /dev/null ; \ 37 echo $$?) 38 39 test_source = $(ProjSrcRoot)/make/platform/clang_linux_test_input.c 40 ifeq ($(CompilerTargetArch),i386) 41 SupportedArches := i386 42 ifeq ($(call TryCompile,$(CC),$(test_source),-m64),0) 43 SupportedArches += x86_64 44 endif 45 else 46 SupportedArches := x86_64 47 ifeq ($(call TryCompile,$(CC),$(test_source),-m32),0) 48 SupportedArches += i386 49 endif 50 endif 51 52 # Build runtime libraries for i386. 53 ifeq ($(call contains,$(SupportedArches),i386),true) 54 Configs += full-i386 profile-i386 asan-i386 ubsan-i386 55 Arch.full-i386 := i386 56 Arch.profile-i386 := i386 57 Arch.asan-i386 := i386 58 Arch.ubsan-i386 := i386 59 endif 60 61 # Build runtime libraries for x86_64. 62 ifeq ($(call contains,$(SupportedArches),x86_64),true) 63 Configs += full-x86_64 profile-x86_64 asan-x86_64 tsan-x86_64 msan-x86_64 \ 64 ubsan-x86_64 65 Arch.full-x86_64 := x86_64 66 Arch.profile-x86_64 := x86_64 67 Arch.asan-x86_64 := x86_64 68 Arch.tsan-x86_64 := x86_64 69 Arch.msan-x86_64 := x86_64 70 Arch.ubsan-x86_64 := x86_64 71 endif 72 73 ifneq ($(LLVM_ANDROID_TOOLCHAIN_DIR),) 74 Configs += asan-arm-android 75 Arch.asan-arm-android := arm-android 76 endif 77 78 endif 79 endif 80 81 ### 82 83 CFLAGS := -Wall -Werror -O3 -fomit-frame-pointer 84 85 CFLAGS.full-i386 := $(CFLAGS) -m32 86 CFLAGS.full-x86_64 := $(CFLAGS) -m64 87 CFLAGS.profile-i386 := $(CFLAGS) -m32 88 CFLAGS.profile-x86_64 := $(CFLAGS) -m64 89 CFLAGS.asan-i386 := $(CFLAGS) -m32 -fPIE -fno-builtin -fno-rtti \ 90 -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=1 91 CFLAGS.asan-x86_64 := $(CFLAGS) -m64 -fPIE -fno-builtin -fno-rtti \ 92 -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=1 93 CFLAGS.tsan-x86_64 := $(CFLAGS) -m64 -fPIE -fno-builtin -fno-rtti 94 CFLAGS.msan-x86_64 := $(CFLAGS) -m64 -fPIE -fno-builtin -fno-rtti 95 CFLAGS.ubsan-i386 := $(CFLAGS) -m32 -fPIE -fno-builtin 96 CFLAGS.ubsan-x86_64 := $(CFLAGS) -m64 -fPIE -fno-builtin 97 98 SHARED_LIBRARY.asan-arm-android := 1 99 ANDROID_COMMON_FLAGS := -target arm-linux-androideabi \ 100 --sysroot=$(LLVM_ANDROID_TOOLCHAIN_DIR)/sysroot \ 101 -B$(LLVM_ANDROID_TOOLCHAIN_DIR) 102 CFLAGS.asan-arm-android := $(CFLAGS) -fPIC -fno-builtin \ 103 $(ANDROID_COMMON_FLAGS) -mllvm -arm-enable-ehabi 104 LDFLAGS.asan-arm-android := $(LDFLAGS) $(ANDROID_COMMON_FLAGS) -ldl \ 105 -Wl,-soname=libclang_rt.asan-arm-android.so 106 107 # Use our stub SDK as the sysroot to support more portable building. For now we 108 # just do this for the non-ASAN modules, because the stub SDK doesn't have 109 # enough support to build ASAN. 110 CFLAGS.full-i386 += --sysroot=$(ProjSrcRoot)/SDKs/linux 111 CFLAGS.full-x86_64 += --sysroot=$(ProjSrcRoot)/SDKs/linux 112 CFLAGS.profile-i386 += --sysroot=$(ProjSrcRoot)/SDKs/linux 113 CFLAGS.profile-x86_64 += --sysroot=$(ProjSrcRoot)/SDKs/linux 114 115 FUNCTIONS.full-i386 := $(CommonFunctions) $(ArchFunctions.i386) 116 FUNCTIONS.full-x86_64 := $(CommonFunctions) $(ArchFunctions.x86_64) 117 FUNCTIONS.profile-i386 := GCDAProfiling 118 FUNCTIONS.profile-x86_64 := GCDAProfiling 119 FUNCTIONS.asan-i386 := $(AsanFunctions) $(InterceptionFunctions) \ 120 $(SanitizerCommonFunctions) 121 FUNCTIONS.asan-x86_64 := $(AsanFunctions) $(InterceptionFunctions) \ 122 $(SanitizerCommonFunctions) 123 FUNCTIONS.asan-arm-android := $(AsanFunctions) $(InterceptionFunctions) \ 124 $(SanitizerCommonFunctions) 125 FUNCTIONS.tsan-x86_64 := $(TsanFunctions) $(InterceptionFunctions) \ 126 $(SanitizerCommonFunctions) 127 FUNCTIONS.msan-x86_64 := $(MsanFunctions) $(InterceptionFunctions) \ 128 $(SanitizerCommonFunctions) 129 FUNCTIONS.ubsan-i386 := $(UbsanFunctions) $(SanitizerCommonFunctions) 130 FUNCTIONS.ubsan-x86_64 := $(UbsanFunctions) $(SanitizerCommonFunctions) 131 132 # Always use optimized variants. 133 OPTIMIZED := 1 134 135 # We don't need to use visibility hidden on Linux. 136 VISIBILITY_HIDDEN := 0 137 138 SHARED_LIBRARY_SUFFIX := so 139