1d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel DunbarDescription := Static runtime libraries for clang/Linux.
2d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar
3d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar###
4d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar
5d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel DunbarCC := clang
6d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel DunbarArch := unknown
7d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel DunbarConfigs :=
8d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar
9d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar# We don't currently have any general purpose way to target architectures other
10d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar# than the compiler defaults (because there is no generalized way to invoke
11b63dba903c29fe6ed1bfcb67e78f72beb832d01bSylvestre Ledru# cross compilers). For now, we just find the target architecture of the
12b63dba903c29fe6ed1bfcb67e78f72beb832d01bSylvestre Ledru# compiler and only define configurations we know that compiler can generate.
13d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel DunbarCompilerTargetTriple := $(shell \
142d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines	LANG=C $(CC) -v 2>&1 | grep 'Target:' | cut -d' ' -f2)
15d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbarifeq ($(CompilerTargetTriple),)
16d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar$(error "unable to infer compiler target triple for $(CC)")
17d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbarendif
18d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar
19d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar# Only define configs if we detected a linux target.
20d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbarifneq ($(findstring -linux-,$(CompilerTargetTriple)),)
21d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar
2248154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov# Define configs only if arch in triple is i386 or x86_64
2348154ece07a13072d2ee72d6796e2604cf40545eAlexey SamsonovCompilerTargetArch := $(firstword $(subst -, ,$(CompilerTargetTriple)))
244fd6b1c8d9ffba56fb5151a7beae487160e0903dDaniel Dunbarifeq ($(call contains,i386 x86_64,$(CompilerTargetArch)),true)
25d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar
2648154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov# TryCompile compiler source flags
2748154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov# Returns exit code of running a compiler invocation.
2848154ece07a13072d2ee72d6796e2604cf40545eAlexey SamsonovTryCompile = \
2948154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov  $(shell \
3048154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov    cflags=""; \
3148154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov    for flag in $(3); do \
3248154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov      cflags="$$cflags $$flag"; \
3348154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov    done; \
3448154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov    $(1) $$cflags $(2) -o /dev/null > /dev/null 2> /dev/null ; \
3548154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov    echo $$?)
365f9ee2809fff2459fd13374834e16d22893bad45Daniel Dunbar
3748154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonovtest_source = $(ProjSrcRoot)/make/platform/clang_linux_test_input.c
38dd01c883c20f4ef5bed6e8fbde452a0ac9191c90Alexey Samsonovifeq ($(CompilerTargetArch),i386)
3948154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov  SupportedArches := i386
4048154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov  ifeq ($(call TryCompile,$(CC),$(test_source),-m64),0)
4148154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov    SupportedArches += x86_64
4248154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov  endif
4348154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonovelse
4448154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov  SupportedArches := x86_64
4548154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov  ifeq ($(call TryCompile,$(CC),$(test_source),-m32),0)
4648154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov    SupportedArches += i386
4748154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov  endif
48dd01c883c20f4ef5bed6e8fbde452a0ac9191c90Alexey Samsonovendif
4948154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov
5048154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov# Build runtime libraries for i386.
5148154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonovifeq ($(call contains,$(SupportedArches),i386),true)
522d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesConfigs += builtins-i386 profile-i386 san-i386 asan-i386 asan_cxx-i386 \
532d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines	   ubsan-i386 ubsan_cxx-i386
542d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesArch.builtins-i386 := i386
5548154ece07a13072d2ee72d6796e2604cf40545eAlexey SamsonovArch.profile-i386 := i386
563e587a4f631c1b7338d4f2a29df74b704b8bb1caRichard SmithArch.san-i386 := i386
575f9ee2809fff2459fd13374834e16d22893bad45Daniel DunbarArch.asan-i386 := i386
582d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesArch.asan_cxx-i386 := i386
599db0aed8558aff3cd5413b5c21a90918efae8986Alexey SamsonovArch.ubsan-i386 := i386
603e587a4f631c1b7338d4f2a29df74b704b8bb1caRichard SmithArch.ubsan_cxx-i386 := i386
615f9ee2809fff2459fd13374834e16d22893bad45Daniel Dunbarendif
625f9ee2809fff2459fd13374834e16d22893bad45Daniel Dunbar
6348154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonov# Build runtime libraries for x86_64.
6448154ece07a13072d2ee72d6796e2604cf40545eAlexey Samsonovifeq ($(call contains,$(SupportedArches),x86_64),true)
652d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesConfigs += builtins-x86_64 profile-x86_64 san-x86_64 asan-x86_64 asan_cxx-x86_64 \
662d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines	   tsan-x86_64 msan-x86_64 ubsan-x86_64 ubsan_cxx-x86_64 dfsan-x86_64 \
672d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines	   lsan-x86_64
682d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesArch.builtins-x86_64 := x86_64
6948154ece07a13072d2ee72d6796e2604cf40545eAlexey SamsonovArch.profile-x86_64 := x86_64
703e587a4f631c1b7338d4f2a29df74b704b8bb1caRichard SmithArch.san-x86_64 := x86_64
7148154ece07a13072d2ee72d6796e2604cf40545eAlexey SamsonovArch.asan-x86_64 := x86_64
722d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesArch.asan_cxx-x86_64 := x86_64
734026c2c28927b90a97cda2a713c761f633bb1422Kostya SerebryanyArch.tsan-x86_64 := x86_64
74372b267fadcaf73b9d9cee5c8050d3c10e94f74dEvgeniy StepanovArch.msan-x86_64 := x86_64
759db0aed8558aff3cd5413b5c21a90918efae8986Alexey SamsonovArch.ubsan-x86_64 := x86_64
763e587a4f631c1b7338d4f2a29df74b704b8bb1caRichard SmithArch.ubsan_cxx-x86_64 := x86_64
77eee71ae5c1f4ce71612fac359463a54bc867abd6Peter CollingbourneArch.dfsan-x86_64 := x86_64
78ebc0484ebbd1b7ed142b2851e3308559dabe79f7Alexey SamsonovArch.lsan-x86_64 := x86_64
794026c2c28927b90a97cda2a713c761f633bb1422Kostya Serebryanyendif
804026c2c28927b90a97cda2a713c761f633bb1422Kostya Serebryany
81984930932ac6d85af5b07294a91b203ce822dc68Evgeniy Stepanovendif
82984930932ac6d85af5b07294a91b203ce822dc68Evgeniy Stepanov
83a69eb9a1a0b111a4776a9bd727f4d551ec308261Evgeniy Stepanovifneq ($(LLVM_ANDROID_TOOLCHAIN_DIR),)
84a69eb9a1a0b111a4776a9bd727f4d551ec308261Evgeniy StepanovConfigs += asan-arm-android
85a69eb9a1a0b111a4776a9bd727f4d551ec308261Evgeniy StepanovArch.asan-arm-android := arm-android
86a69eb9a1a0b111a4776a9bd727f4d551ec308261Evgeniy Stepanovendif
87a69eb9a1a0b111a4776a9bd727f4d551ec308261Evgeniy Stepanov
88d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbarendif
89d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar
90d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar###
91d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar
92d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel DunbarCFLAGS := -Wall -Werror -O3 -fomit-frame-pointer
93a225736903b1bef1a232067429368e536f610266Alexey SamsonovSANITIZER_CFLAGS := -fPIE -fno-builtin -gline-tables-only
94d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar
952d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesCFLAGS.builtins-i386 := $(CFLAGS) -m32
962d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesCFLAGS.builtins-x86_64 := $(CFLAGS) -m64
975f9ee2809fff2459fd13374834e16d22893bad45Daniel DunbarCFLAGS.profile-i386 := $(CFLAGS) -m32
985f9ee2809fff2459fd13374834e16d22893bad45Daniel DunbarCFLAGS.profile-x86_64 := $(CFLAGS) -m64
99a225736903b1bef1a232067429368e536f610266Alexey SamsonovCFLAGS.san-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti
100a225736903b1bef1a232067429368e536f610266Alexey SamsonovCFLAGS.san-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
1012d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesCFLAGS.asan-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti
1022d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesCFLAGS.asan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
1032d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesCFLAGS.asan_cxx-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti
1042d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesCFLAGS.asan_cxx-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
105a225736903b1bef1a232067429368e536f610266Alexey SamsonovCFLAGS.tsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
106a225736903b1bef1a232067429368e536f610266Alexey SamsonovCFLAGS.msan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
107a225736903b1bef1a232067429368e536f610266Alexey SamsonovCFLAGS.ubsan-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS) -fno-rtti
108a225736903b1bef1a232067429368e536f610266Alexey SamsonovCFLAGS.ubsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
109a225736903b1bef1a232067429368e536f610266Alexey SamsonovCFLAGS.ubsan_cxx-i386 := $(CFLAGS) -m32 $(SANITIZER_CFLAGS)
110a225736903b1bef1a232067429368e536f610266Alexey SamsonovCFLAGS.ubsan_cxx-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS)
1112d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesCFLAGS.dfsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
112cf637373d5e6c0f2ba6381a944818f3a73ca7946Sergey MatveevCFLAGS.lsan-x86_64 := $(CFLAGS) -m64 $(SANITIZER_CFLAGS) -fno-rtti
113d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar
114a69eb9a1a0b111a4776a9bd727f4d551ec308261Evgeniy StepanovSHARED_LIBRARY.asan-arm-android := 1
115a69eb9a1a0b111a4776a9bd727f4d551ec308261Evgeniy StepanovANDROID_COMMON_FLAGS := -target arm-linux-androideabi \
116a69eb9a1a0b111a4776a9bd727f4d551ec308261Evgeniy Stepanov	--sysroot=$(LLVM_ANDROID_TOOLCHAIN_DIR)/sysroot \
117a69eb9a1a0b111a4776a9bd727f4d551ec308261Evgeniy Stepanov	-B$(LLVM_ANDROID_TOOLCHAIN_DIR)
1182d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesCFLAGS.asan-arm-android := $(CFLAGS) $(SANITIZER_CFLAGS) \
1192d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines	$(ANDROID_COMMON_FLAGS) -fno-rtti \
1202d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines	-I$(ProjSrcRoot)/android/include
1212d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesLDFLAGS.asan-arm-android := $(LDFLAGS) $(ANDROID_COMMON_FLAGS) -ldl -lm -llog \
1222d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines	-lstdc++ -Wl,-soname=libclang_rt.asan-arm-android.so -Wl,-z,defs
123a69eb9a1a0b111a4776a9bd727f4d551ec308261Evgeniy Stepanov
1244fd6b1c8d9ffba56fb5151a7beae487160e0903dDaniel Dunbar# Use our stub SDK as the sysroot to support more portable building. For now we
1253515fb60c6edb50c3e4c0928100fefdf7bb495bcChandler Carruth# just do this for the core module, because the stub SDK doesn't have
1263515fb60c6edb50c3e4c0928100fefdf7bb495bcChandler Carruth# enough support to build the sanitizers or profile runtimes.
1272d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesCFLAGS.builtins-i386 += --sysroot=$(ProjSrcRoot)/SDKs/linux
1282d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesCFLAGS.builtins-x86_64 += --sysroot=$(ProjSrcRoot)/SDKs/linux
1294fd6b1c8d9ffba56fb5151a7beae487160e0903dDaniel Dunbar
1302d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesFUNCTIONS.builtins-i386 := $(CommonFunctions) $(ArchFunctions.i386)
1312d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesFUNCTIONS.builtins-x86_64 := $(CommonFunctions) $(ArchFunctions.x86_64)
1325d71de26cedae3dafc17449fe0182045c0bd20e8Stephen HinesFUNCTIONS.profile-i386 := GCDAProfiling InstrProfiling InstrProfilingBuffer \
1335d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hines                          InstrProfilingFile InstrProfilingPlatformOther \
1345d71de26cedae3dafc17449fe0182045c0bd20e8Stephen Hines                          InstrProfilingRuntime
1355d71de26cedae3dafc17449fe0182045c0bd20e8Stephen HinesFUNCTIONS.profile-x86_64 := $(FUNCTIONS.profile-i386)
1363e587a4f631c1b7338d4f2a29df74b704b8bb1caRichard SmithFUNCTIONS.san-i386 := $(SanitizerCommonFunctions)
1373e587a4f631c1b7338d4f2a29df74b704b8bb1caRichard SmithFUNCTIONS.san-x86_64 := $(SanitizerCommonFunctions)
138b3cedf98a3c8545da2234c2d35cb5d687984035fKostya SerebryanyFUNCTIONS.asan-i386 := $(AsanFunctions) $(InterceptionFunctions) \
139b3cedf98a3c8545da2234c2d35cb5d687984035fKostya Serebryany                                        $(SanitizerCommonFunctions)
140b3cedf98a3c8545da2234c2d35cb5d687984035fKostya SerebryanyFUNCTIONS.asan-x86_64 := $(AsanFunctions) $(InterceptionFunctions) \
141975a3294d9baf6bbbcfdb3c3a0e0a24714cde7cbAlexey Samsonov                         $(SanitizerCommonFunctions) $(LsanCommonFunctions)
1422d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesFUNCTIONS.asan_cxx-i386 := $(AsanCXXFunctions)
1432d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesFUNCTIONS.asan_cxx-x86_64 := $(AsanCXXFunctions)
1442d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesFUNCTIONS.asan-arm-android := $(AsanFunctions) $(AsanCXXFunctions) \
1452d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines                              $(InterceptionFunctions) \
1462d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines                              $(SanitizerCommonFunctions)
147b3cedf98a3c8545da2234c2d35cb5d687984035fKostya SerebryanyFUNCTIONS.tsan-x86_64 := $(TsanFunctions) $(InterceptionFunctions) \
1489db0aed8558aff3cd5413b5c21a90918efae8986Alexey Samsonov                                          $(SanitizerCommonFunctions)
149372b267fadcaf73b9d9cee5c8050d3c10e94f74dEvgeniy StepanovFUNCTIONS.msan-x86_64 := $(MsanFunctions) $(InterceptionFunctions) \
150372b267fadcaf73b9d9cee5c8050d3c10e94f74dEvgeniy Stepanov                                          $(SanitizerCommonFunctions)
1513e587a4f631c1b7338d4f2a29df74b704b8bb1caRichard SmithFUNCTIONS.ubsan-i386 := $(UbsanFunctions)
1523e587a4f631c1b7338d4f2a29df74b704b8bb1caRichard SmithFUNCTIONS.ubsan-x86_64 := $(UbsanFunctions)
1533e587a4f631c1b7338d4f2a29df74b704b8bb1caRichard SmithFUNCTIONS.ubsan_cxx-i386 := $(UbsanCXXFunctions)
1543e587a4f631c1b7338d4f2a29df74b704b8bb1caRichard SmithFUNCTIONS.ubsan_cxx-x86_64 := $(UbsanCXXFunctions)
1552d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen HinesFUNCTIONS.dfsan-x86_64 := $(DfsanFunctions) $(InterceptionFunctions) \
1562d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines                                            $(SanitizerCommonFunctions)
157ebc0484ebbd1b7ed142b2851e3308559dabe79f7Alexey SamsonovFUNCTIONS.lsan-x86_64 := $(LsanFunctions) $(InterceptionFunctions) \
158ebc0484ebbd1b7ed142b2851e3308559dabe79f7Alexey Samsonov                                          $(SanitizerCommonFunctions)
159d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar
160d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar# Always use optimized variants.
161d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel DunbarOPTIMIZED := 1
162d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar
163d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel Dunbar# We don't need to use visibility hidden on Linux.
164d25fa8d63f05aae6fd13ed8ed0d71040caf95e5cDaniel DunbarVISIBILITY_HIDDEN := 0
165a69eb9a1a0b111a4776a9bd727f4d551ec308261Evgeniy Stepanov
166a69eb9a1a0b111a4776a9bd727f4d551ec308261Evgeniy StepanovSHARED_LIBRARY_SUFFIX := so
167