@@ -23,7 +23,9 @@ ResourceDir := $(PROJ_OBJ_ROOT)/$(BuildMode)/lib/clang/$(CLANG_VERSION)
2323PROJ_resources := $(DESTDIR )$(PROJ_prefix ) /lib/clang/$(CLANG_VERSION )
2424
2525ResourceLibDir := $(ResourceDir ) /lib
26+ ResourceIncludeDir := $(ResourceDir ) /include
2627PROJ_resources_lib := $(PROJ_resources ) /lib
28+ PROJ_resources_include := $(PROJ_resources ) /include
2729
2830# Expect compiler-rt to be in llvm/projects/compiler-rt
2931COMPILERRT_SRC_ROOT := $(LLVM_SRC_ROOT ) /projects/compiler-rt
@@ -75,7 +77,9 @@ ifeq ($(OS),Darwin)
7577RuntimeDirs += darwin macho_embedded
7678RuntimeLibrary.darwin.Configs := \
7779 eprintf.a 10.4.a osx.a cc_kext.a \
78- profile_osx.a
80+ asan_osx_dynamic.dylib \
81+ profile_osx.a \
82+ ubsan_osx.a
7983
8084IOS_SDK := $(shell xcrun --show-sdk-path -sdk iphoneos 2> /dev/null)
8185IOSSIM_SDK := $(shell xcrun --show-sdk-path -sdk iphonesimulator 2> /dev/null)
@@ -88,6 +92,10 @@ ifneq ($(IOS_SDK),)
8892RuntimeLibrary.darwin.Configs += cc_kext_ios5.a
8993endif
9094
95+ ifneq ($(IOSSIM_SDK ) ,)
96+ RuntimeLibrary.darwin.Configs += asan_iossim_dynamic.dylib
97+ endif
98+
9199RuntimeLibrary.macho_embedded.Configs := \
92100 hard_static.a hard_pic.a
93101ifneq (,$(findstring ARM,$(TARGETS_TO_BUILD ) ) )
@@ -114,7 +122,8 @@ TryCompile = \
114122
115123# We try to build 32-bit runtimes both on 32-bit hosts and 64-bit hosts.
116124Runtime32BitConfigs = \
117- builtins-i386.a profile-i386.a
125+ builtins-i386.a profile-i386.a san-i386.a asan-i386.a asan_cxx-i386.a \
126+ ubsan-i386.a ubsan_cxx-i386.a
118127
119128# We currently only try to generate runtime libraries on x86.
120129ifeq ($(ARCH ) ,x86)
@@ -123,15 +132,21 @@ endif
123132
124133ifeq ($(ARCH ) ,x86_64)
125134RuntimeLibrary.linux.Configs += \
126- builtins-x86_64.a profile-x86_64.a
127- # We need to build 32-bit libraries on 64-bit platform, and add them
128- # to the list of runtime libraries to make "clang -m32" work.
135+ builtins-x86_64.a profile-x86_64.a san-x86_64.a asan-x86_64.a \
136+ asan_cxx-x86_64.a tsan-x86_64.a msan-x86_64.a ubsan-x86_64.a \
137+ ubsan_cxx-x86_64.a dfsan-x86_64.a lsan-x86_64.a
138+ # We need to build 32-bit ASan/UBsan libraries on 64-bit platform, and add them
139+ # to the list of runtime libraries to make
140+ # "clang -fsanitize=(address|undefined) -m32" work.
129141# We check that Clang can produce working 32-bit binaries by compiling a simple
130142# executable.
131143test_source = $(LLVM_SRC_ROOT ) /tools/clang/runtime/compiler-rt/clang_linux_test_input.c
132144ifeq ($(call TryCompile,$(ToolDir ) /clang,$(test_source ) ,-m32) ,0)
133145RuntimeLibrary.linux.Configs += $(Runtime32BitConfigs )
134146endif
147+ ifneq ($(LLVM_ANDROID_TOOLCHAIN_DIR ) ,)
148+ RuntimeLibrary.linux.Configs += asan-arm-android.so
149+ endif
135150endif
136151
137152endif
@@ -151,6 +166,7 @@ BuildRuntimeLibraries:
151166 ProjObjRoot=$(PROJ_OBJ_DIR ) \
152167 CC=" $( ToolDir) /clang" \
153168 VERBOSE=$(VERBOSE ) \
169+ LLVM_ANDROID_TOOLCHAIN_DIR=" $( LLVM_ANDROID_TOOLCHAIN_DIR) " \
154170 $(RuntimeDirs:%=clang_% )
155171.PHONY : BuildRuntimeLibraries
156172CleanRuntimeLibraries :
@@ -160,10 +176,18 @@ CleanRuntimeLibraries:
160176 VERBOSE=$(VERBOSE ) \
161177 clean
162178.PHONY : CleanRuntimeLibraries
179+ RuntimeHeader : $(ResourceIncludeDir ) /sanitizer
163180
164181$(PROJ_resources_lib ) :
165182 $(Verb ) $(MKDIR ) $@
166183
184+ $(ResourceIncludeDir ) :
185+ $(Verb ) $(MKDIR ) $@
186+
187+ $(ResourceIncludeDir ) /sanitizer : $(ResourceIncludeDir )
188+ $(Verb ) $(MKDIR ) $@
189+ $(Verb ) cp $(COMPILERRT_SRC_ROOT ) /include/sanitizer/* .h $@
190+
167191# Expand rules for copying/installing each individual library. We can't use
168192# implicit rules here because we need to match against multiple things.
169193define RuntimeLibraryTemplate
@@ -218,9 +242,21 @@ RuntimeLibraryInstall.$1: \
218242endef
219243$(foreach lib,$(RuntimeDirs), $(eval $(call RuntimeLibraryTemplate,$(lib))))
220244
245+ $(PROJ_resources_include ) :
246+ $(Verb ) $(MKDIR ) $@
247+
248+ $(PROJ_resources_include ) /sanitizer : $(ResourceIncludeDir ) /sanitizer $(PROJ_resources_include )
249+ $(Verb ) $(MKDIR ) $@
250+ $(Echo ) Installing compiler runtime headers
251+ $(Verb ) $(DataInstall ) $(ResourceIncludeDir ) /sanitizer/* \
252+ $(PROJ_resources_include)/sanitizer
253+
254+ RuntimeHeaderInstall : $(PROJ_resources_include ) /sanitizer
255+ .PHONY : RuntimeHeaderInstall
256+
221257# Hook into the standard Makefile rules.
222- all-local :: $(RuntimeDirs:%=RuntimeLibrary.% )
223- install-local :: $(RuntimeDirs:%=RuntimeLibraryInstall.% )
258+ all-local :: $(RuntimeDirs:%=RuntimeLibrary.% ) RuntimeHeader
259+ install-local :: $(RuntimeDirs:%=RuntimeLibraryInstall.% ) RuntimeHeaderInstall
224260clean-local :: CleanRuntimeLibraries
225261
226262endif
0 commit comments