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