[TSan] remove artifacts from gotsan build in 'make clean' command
[blocksruntime.git] / make / platform / clang_linux.mk
blobce763ad96a3e37221a3eeccde98b10d5bfcaee4c
1 Description := Static runtime libraries for clang/Linux.
3 ###
5 CC := clang
6 Arch := unknown
7 Configs :=
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
21 # Only define configs if we detected a linux target.
22 ifneq ($(findstring -linux-,$(CompilerTargetTriple)),)
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)
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 $$?)
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
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
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 ubsan-x86_64
64 Arch.full-x86_64 := x86_64
65 Arch.profile-x86_64 := x86_64
66 Arch.asan-x86_64 := x86_64
67 Arch.tsan-x86_64 := x86_64
68 Arch.ubsan-x86_64 := x86_64
69 endif
71 ifneq ($(LLVM_ANDROID_TOOLCHAIN_DIR),)
72 Configs += asan-arm-android
73 Arch.asan-arm-android := arm-android
74 endif
76 endif
77 endif
79 ###
81 CFLAGS := -Wall -Werror -O3 -fomit-frame-pointer
83 CFLAGS.full-i386 := $(CFLAGS) -m32
84 CFLAGS.full-x86_64 := $(CFLAGS) -m64
85 CFLAGS.profile-i386 := $(CFLAGS) -m32
86 CFLAGS.profile-x86_64 := $(CFLAGS) -m64
87 CFLAGS.asan-i386 := $(CFLAGS) -m32 -fPIE -fno-builtin \
88 -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=1
89 CFLAGS.asan-x86_64 := $(CFLAGS) -m64 -fPIE -fno-builtin \
90 -DASAN_FLEXIBLE_MAPPING_AND_OFFSET=1
91 CFLAGS.tsan-x86_64 := $(CFLAGS) -m64 -fPIE -fno-builtin
92 CFLAGS.ubsan-i386 := $(CFLAGS) -m32 -fPIE -fno-builtin
93 CFLAGS.ubsan-x86_64 := $(CFLAGS) -m64 -fPIE -fno-builtin
95 SHARED_LIBRARY.asan-arm-android := 1
96 ANDROID_COMMON_FLAGS := -target arm-linux-androideabi \
97 --sysroot=$(LLVM_ANDROID_TOOLCHAIN_DIR)/sysroot \
98 -B$(LLVM_ANDROID_TOOLCHAIN_DIR)
99 CFLAGS.asan-arm-android := $(CFLAGS) -fPIC -fno-builtin \
100 $(ANDROID_COMMON_FLAGS) -mllvm -arm-enable-ehabi
101 LDFLAGS.asan-arm-android := $(LDFLAGS) $(ANDROID_COMMON_FLAGS) -ldl \
102 -Wl,-soname=libclang_rt.asan-arm-android.so
104 # Use our stub SDK as the sysroot to support more portable building. For now we
105 # just do this for the non-ASAN modules, because the stub SDK doesn't have
106 # enough support to build ASAN.
107 CFLAGS.full-i386 += --sysroot=$(ProjSrcRoot)/SDKs/linux
108 CFLAGS.full-x86_64 += --sysroot=$(ProjSrcRoot)/SDKs/linux
109 CFLAGS.profile-i386 += --sysroot=$(ProjSrcRoot)/SDKs/linux
110 CFLAGS.profile-x86_64 += --sysroot=$(ProjSrcRoot)/SDKs/linux
112 FUNCTIONS.full-i386 := $(CommonFunctions) $(ArchFunctions.i386)
113 FUNCTIONS.full-x86_64 := $(CommonFunctions) $(ArchFunctions.x86_64)
114 FUNCTIONS.profile-i386 := GCDAProfiling
115 FUNCTIONS.profile-x86_64 := GCDAProfiling
116 FUNCTIONS.asan-i386 := $(AsanFunctions) $(InterceptionFunctions) \
117 $(SanitizerCommonFunctions)
118 FUNCTIONS.asan-x86_64 := $(AsanFunctions) $(InterceptionFunctions) \
119 $(SanitizerCommonFunctions)
120 FUNCTIONS.asan-arm-android := $(AsanFunctions) $(InterceptionFunctions) \
121 $(SanitizerCommonFunctions)
122 FUNCTIONS.tsan-x86_64 := $(TsanFunctions) $(InterceptionFunctions) \
123 $(SanitizerCommonFunctions)
124 FUNCTIONS.ubsan-i386 := $(UbsanFunctions) $(SanitizerCommonFunctions)
125 FUNCTIONS.ubsan-x86_64 := $(UbsanFunctions) $(SanitizerCommonFunctions)
127 # Always use optimized variants.
128 OPTIMIZED := 1
130 # We don't need to use visibility hidden on Linux.
131 VISIBILITY_HIDDEN := 0
133 SHARED_LIBRARY_SUFFIX := so