clang_linux.mk revision cf637373d5e6c0f2ba6381a944818f3a73ca7946
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 $(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 += full-i386 profile-i386 san-i386 asan-i386 ubsan-i386 ubsan_cxx-i386 53Arch.full-i386 := i386 54Arch.profile-i386 := i386 55Arch.san-i386 := i386 56Arch.asan-i386 := i386 57Arch.ubsan-i386 := i386 58Arch.ubsan_cxx-i386 := i386 59endif 60 61# Build runtime libraries for x86_64. 62ifeq ($(call contains,$(SupportedArches),x86_64),true) 63Configs += full-x86_64 profile-x86_64 san-x86_64 asan-x86_64 tsan-x86_64 \ 64 msan-x86_64 ubsan-x86_64 ubsan_cxx-x86_64 dfsan-x86_64 lsan-x86_64 65Arch.full-x86_64 := x86_64 66Arch.profile-x86_64 := x86_64 67Arch.san-x86_64 := x86_64 68Arch.asan-x86_64 := x86_64 69Arch.tsan-x86_64 := x86_64 70Arch.msan-x86_64 := x86_64 71Arch.ubsan-x86_64 := x86_64 72Arch.ubsan_cxx-x86_64 := x86_64 73Arch.dfsan-x86_64 := x86_64 74Arch.lsan-x86_64 := x86_64 75endif 76 77ifneq ($(LLVM_ANDROID_TOOLCHAIN_DIR),) 78Configs += asan-arm-android 79Arch.asan-arm-android := arm-android 80endif 81 82endif 83endif 84 85### 86 87CFLAGS := -Wall -Werror -O3 -fomit-frame-pointer 88SANITIZER_CFLAGS := -fPIE -fno-builtin -gline-tables-only 89 90CFLAGS.full-i386 := $(CFLAGS) -m32 91CFLAGS.full-x86_64 := $(CFLAGS) -m64 92CFLAGS.profile-i386 := $(CFLAGS) -m32 93CFLAGS.profile-x86_64 := $(CFLAGS) -m64 94CFLAGS.san-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti 95CFLAGS.san-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti 96CFLAGS.asan-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti \ 97 -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=1 98CFLAGS.asan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti \ 99 -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=1 100CFLAGS.tsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti 101CFLAGS.msan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti 102CFLAGS.ubsan-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti 103CFLAGS.ubsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti 104CFLAGS.ubsan_cxx-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) 105CFLAGS.ubsan_cxx-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) 106CFLAGS.dfsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) 107CFLAGS.lsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti 108 109SHARED_LIBRARY.asan-arm-android := 1 110ANDROID_COMMON_FLAGS := -target arm-linux-androideabi \ 111 --sysroot=$(LLVM_ANDROID_TOOLCHAIN_DIR)/sysroot \ 112 -B$(LLVM_ANDROID_TOOLCHAIN_DIR) 113CFLAGS.asan-arm-android := $(CFLAGS) -fPIC -fno-builtin \ 114 $(ANDROID_COMMON_FLAGS) -mllvm -arm-enable-ehabi -fno-rtti 115LDFLAGS.asan-arm-android := $(LDFLAGS) $(ANDROID_COMMON_FLAGS) -ldl \ 116 -Wl,-soname=libclang_rt.asan-arm-android.so 117 118# Use our stub SDK as the sysroot to support more portable building. For now we 119# just do this for the core module, because the stub SDK doesn't have 120# enough support to build the sanitizers or profile runtimes. 121CFLAGS.full-i386 += --sysroot=$(ProjSrcRoot)/SDKs/linux 122CFLAGS.full-x86_64 += --sysroot=$(ProjSrcRoot)/SDKs/linux 123 124FUNCTIONS.full-i386 := $(CommonFunctions) $(ArchFunctions.i386) 125FUNCTIONS.full-x86_64 := $(CommonFunctions) $(ArchFunctions.x86_64) 126FUNCTIONS.profile-i386 := GCDAProfiling 127FUNCTIONS.profile-x86_64 := GCDAProfiling 128FUNCTIONS.san-i386 := $(SanitizerCommonFunctions) 129FUNCTIONS.san-x86_64 := $(SanitizerCommonFunctions) 130FUNCTIONS.asan-i386 := $(AsanFunctions) $(InterceptionFunctions) \ 131 $(SanitizerCommonFunctions) 132FUNCTIONS.asan-x86_64 := $(AsanFunctions) $(InterceptionFunctions) \ 133 $(SanitizerCommonFunctions) $(LsanCommonFunctions) 134FUNCTIONS.asan-arm-android := $(AsanFunctions) $(InterceptionFunctions) \ 135 $(SanitizerCommonFunctions) 136FUNCTIONS.tsan-x86_64 := $(TsanFunctions) $(InterceptionFunctions) \ 137 $(SanitizerCommonFunctions) 138FUNCTIONS.msan-x86_64 := $(MsanFunctions) $(InterceptionFunctions) \ 139 $(SanitizerCommonFunctions) 140FUNCTIONS.ubsan-i386 := $(UbsanFunctions) 141FUNCTIONS.ubsan-x86_64 := $(UbsanFunctions) 142FUNCTIONS.ubsan_cxx-i386 := $(UbsanCXXFunctions) 143FUNCTIONS.ubsan_cxx-x86_64 := $(UbsanCXXFunctions) 144FUNCTIONS.dfsan-x86_64 := $(DfsanFunctions) $(SanitizerCommonFunctions) 145FUNCTIONS.lsan-x86_64 := $(LsanFunctions) $(InterceptionFunctions) \ 146 $(SanitizerCommonFunctions) 147 148# Always use optimized variants. 149OPTIMIZED := 1 150 151# We don't need to use visibility hidden on Linux. 152VISIBILITY_HIDDEN := 0 153 154SHARED_LIBRARY_SUFFIX := so 155