1Description := Static runtime libraries for clang/Linux. 2 3### 4 5CC := clang 6Arch := unknown 7Configs := 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. 13CompilerTargetTriple := $(shell \ 14 LANG=C $(CC) -v 2>&1 | grep 'Target:' | cut -d' ' -f2) 15ifeq ($(CompilerTargetTriple),) 16$(error "unable to infer compiler target triple for $(CC)") 17endif 18 19# Only define configs if we detected a linux target. 20ifneq ($(findstring -linux-,$(CompilerTargetTriple)),) 21 22# Define configs only if arch in triple is i386 or x86_64 23CompilerTargetArch := $(firstword $(subst -, ,$(CompilerTargetTriple))) 24ifeq ($(call contains,i386 x86_64,$(CompilerTargetArch)),true) 25 26# TryCompile compiler source flags 27# Returns exit code of running a compiler invocation. 28TryCompile = \ 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 37test_source = $(ProjSrcRoot)/make/platform/clang_linux_test_input.c 38ifeq ($(CompilerTargetArch),i386) 39 SupportedArches := i386 40 ifeq ($(call TryCompile,$(CC),$(test_source),-m64),0) 41 SupportedArches += x86_64 42 endif 43else 44 SupportedArches := x86_64 45 ifeq ($(call TryCompile,$(CC),$(test_source),-m32),0) 46 SupportedArches += i386 47 endif 48endif 49 50# Build runtime libraries for i386. 51ifeq ($(call contains,$(SupportedArches),i386),true) 52Configs += builtins-i386 profile-i386 san-i386 asan-i386 asan_cxx-i386 \ 53 ubsan-i386 ubsan_cxx-i386 54Arch.builtins-i386 := i386 55Arch.profile-i386 := i386 56Arch.san-i386 := i386 57Arch.asan-i386 := i386 58Arch.asan_cxx-i386 := i386 59Arch.ubsan-i386 := i386 60Arch.ubsan_cxx-i386 := i386 61endif 62 63# Build runtime libraries for x86_64. 64ifeq ($(call contains,$(SupportedArches),x86_64),true) 65Configs += 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 68Arch.builtins-x86_64 := x86_64 69Arch.profile-x86_64 := x86_64 70Arch.san-x86_64 := x86_64 71Arch.asan-x86_64 := x86_64 72Arch.asan_cxx-x86_64 := x86_64 73Arch.tsan-x86_64 := x86_64 74Arch.msan-x86_64 := x86_64 75Arch.ubsan-x86_64 := x86_64 76Arch.ubsan_cxx-x86_64 := x86_64 77Arch.dfsan-x86_64 := x86_64 78Arch.lsan-x86_64 := x86_64 79endif 80 81endif 82 83ifneq ($(LLVM_ANDROID_TOOLCHAIN_DIR),) 84Configs += asan-arm-android 85Arch.asan-arm-android := arm-android 86endif 87 88endif 89 90### 91 92CFLAGS := -Wall -Werror -O3 -fomit-frame-pointer 93SANITIZER_CFLAGS := -fPIE -fno-builtin -gline-tables-only 94 95CFLAGS.builtins-i386 := $(CFLAGS) -m32 96CFLAGS.builtins-x86_64 := $(CFLAGS) -m64 97CFLAGS.profile-i386 := $(CFLAGS) -m32 98CFLAGS.profile-x86_64 := $(CFLAGS) -m64 99CFLAGS.san-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti 100CFLAGS.san-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti 101CFLAGS.asan-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti 102CFLAGS.asan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti 103CFLAGS.asan_cxx-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti 104CFLAGS.asan_cxx-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti 105CFLAGS.tsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti 106CFLAGS.msan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti 107CFLAGS.ubsan-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti 108CFLAGS.ubsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti 109CFLAGS.ubsan_cxx-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) 110CFLAGS.ubsan_cxx-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) 111CFLAGS.dfsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti 112CFLAGS.lsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti 113 114SHARED_LIBRARY.asan-arm-android := 1 115ANDROID_COMMON_FLAGS := -target arm-linux-androideabi \ 116 --sysroot=$(LLVM_ANDROID_TOOLCHAIN_DIR)/sysroot \ 117 -B$(LLVM_ANDROID_TOOLCHAIN_DIR) 118CFLAGS.asan-arm-android := $(CFLAGS) $(SANITIZER_CFLAGS) \ 119 $(ANDROID_COMMON_FLAGS) -fno-rtti \ 120 -I$(ProjSrcRoot)/android/include 121LDFLAGS.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. 127CFLAGS.builtins-i386 += --sysroot=$(ProjSrcRoot)/SDKs/linux 128CFLAGS.builtins-x86_64 += --sysroot=$(ProjSrcRoot)/SDKs/linux 129 130FUNCTIONS.builtins-i386 := $(CommonFunctions) $(ArchFunctions.i386) 131FUNCTIONS.builtins-x86_64 := $(CommonFunctions) $(ArchFunctions.x86_64) 132FUNCTIONS.profile-i386 := GCDAProfiling InstrProfiling InstrProfilingBuffer \ 133 InstrProfilingFile InstrProfilingPlatformOther \ 134 InstrProfilingRuntime 135FUNCTIONS.profile-x86_64 := $(FUNCTIONS.profile-i386) 136FUNCTIONS.san-i386 := $(SanitizerCommonFunctions) 137FUNCTIONS.san-x86_64 := $(SanitizerCommonFunctions) 138FUNCTIONS.asan-i386 := $(AsanFunctions) $(InterceptionFunctions) \ 139 $(SanitizerCommonFunctions) 140FUNCTIONS.asan-x86_64 := $(AsanFunctions) $(InterceptionFunctions) \ 141 $(SanitizerCommonFunctions) $(LsanCommonFunctions) 142FUNCTIONS.asan_cxx-i386 := $(AsanCXXFunctions) 143FUNCTIONS.asan_cxx-x86_64 := $(AsanCXXFunctions) 144FUNCTIONS.asan-arm-android := $(AsanFunctions) $(AsanCXXFunctions) \ 145 $(InterceptionFunctions) \ 146 $(SanitizerCommonFunctions) 147FUNCTIONS.tsan-x86_64 := $(TsanFunctions) $(InterceptionFunctions) \ 148 $(SanitizerCommonFunctions) 149FUNCTIONS.msan-x86_64 := $(MsanFunctions) $(InterceptionFunctions) \ 150 $(SanitizerCommonFunctions) 151FUNCTIONS.ubsan-i386 := $(UbsanFunctions) 152FUNCTIONS.ubsan-x86_64 := $(UbsanFunctions) 153FUNCTIONS.ubsan_cxx-i386 := $(UbsanCXXFunctions) 154FUNCTIONS.ubsan_cxx-x86_64 := $(UbsanCXXFunctions) 155FUNCTIONS.dfsan-x86_64 := $(DfsanFunctions) $(InterceptionFunctions) \ 156 $(SanitizerCommonFunctions) 157FUNCTIONS.lsan-x86_64 := $(LsanFunctions) $(InterceptionFunctions) \ 158 $(SanitizerCommonFunctions) 159 160# Always use optimized variants. 161OPTIMIZED := 1 162 163# We don't need to use visibility hidden on Linux. 164VISIBILITY_HIDDEN := 0 165 166SHARED_LIBRARY_SUFFIX := so 167