diff options
Diffstat (limited to 'runtime/compiler-rt')
-rw-r--r-- | runtime/compiler-rt/Makefile | 61 | ||||
-rw-r--r-- | runtime/compiler-rt/clang_linux_test_input.c | 4 |
2 files changed, 59 insertions, 6 deletions
diff --git a/runtime/compiler-rt/Makefile b/runtime/compiler-rt/Makefile index f133591..68b2941 100644 --- a/runtime/compiler-rt/Makefile +++ b/runtime/compiler-rt/Makefile @@ -74,8 +74,9 @@ RuntimeDirs := ifeq ($(OS),Darwin) RuntimeDirs += darwin RuntimeLibrary.darwin.Configs := \ - eprintf 10.4 osx cc_kext \ - asan_osx profile_osx + eprintf.a 10.4.a osx.a ios.a cc_kext.a cc_kext_ios5.a \ + asan_osx.a asan_osx_dynamic.dylib \ + profile_osx.a profile_ios.a endif # On Linux, include a library which has all the runtime functions. @@ -83,14 +84,37 @@ ifeq ($(OS),Linux) RuntimeDirs += linux RuntimeLibrary.linux.Configs := +# TryCompile compiler source flags +# Returns exit code of running a compiler invocation. +TryCompile = \ + $(shell \ + cflags=""; \ + for flag in $(3); do \ + cflags="$$cflags $$flag"; \ + done; \ + $(1) $$cflags $(2) -o /dev/null > /dev/null 2> /dev/null ; \ + echo $$?) + # We currently only try to generate runtime libraries on x86. ifeq ($(ARCH),x86) RuntimeLibrary.linux.Configs += \ - full-i386 profile-i386 asan-i386 + full-i386.a profile-i386.a asan-i386.a endif + ifeq ($(ARCH),x86_64) RuntimeLibrary.linux.Configs += \ - full-x86_64 profile-x86_64 asan-x86_64 tsan-x86_64 + full-x86_64.a profile-x86_64.a asan-x86_64.a tsan-x86_64.a +# We need to build 32-bit ASan library on 64-bit platform, and add it to the +# list of runtime libraries to make "clang -faddress-sanitizer -m32" work. +# We check that Clang can produce working 32-bit binaries by compiling a simple +# executable. +test_source = $(LLVM_SRC_ROOT)/tools/clang/runtime/compiler-rt/clang_linux_test_input.c +ifeq ($(call TryCompile,$(ToolDir)/clang,$(test_source),-m32),0) +RuntimeLibrary.linux.Configs += asan-i386.a +endif +ifneq ($(LLVM_ANDROID_TOOLCHAIN_DIR),) +RuntimeLibrary.linux.Configs += asan-arm-android.so +endif endif endif @@ -109,6 +133,7 @@ BuildRuntimeLibraries: ProjSrcRoot=$(COMPILERRT_SRC_ROOT) \ ProjObjRoot=$(PROJ_OBJ_DIR) \ CC="$(ToolDir)/clang" \ + LLVM_ANDROID_TOOLCHAIN_DIR="$(LLVM_ANDROID_TOOLCHAIN_DIR)" \ $(RuntimeDirs:%=clang_%) .PHONY: BuildRuntimeLibraries CleanRuntimeLibraries: @@ -126,6 +151,10 @@ $(PROJ_resources_lib): define RuntimeLibraryTemplate $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a: BuildRuntimeLibraries @true +$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.so: BuildRuntimeLibraries + @true +$(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.dylib: BuildRuntimeLibraries + @true .PRECIOUS: $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.a # Rule to copy the libraries to their resource directory location. @@ -134,8 +163,20 @@ $(ResourceLibDir)/$1/libclang_rt.%.a: \ $(ResourceLibDir)/$1/.dir $(Echo) Copying runtime library $1/$$* to build dir $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.a $$@ +$(ResourceLibDir)/$1/libclang_rt.%.so: \ + $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.so \ + $(ResourceLibDir)/$1/.dir + $(Echo) Copying runtime library $1/$$* to build dir + $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.so $$@ +$(ResourceLibDir)/$1/libclang_rt.%.dylib: \ + $(PROJ_OBJ_DIR)/clang_$1/%/libcompiler_rt.dylib \ + $(ResourceLibDir)/$1/.dir + $(Echo) Copying runtime library $1/$$* to build dir + $(Verb) cp $(PROJ_OBJ_DIR)/clang_$1/$$*/libcompiler_rt.dylib $$@ + $(Echo) Fixing LC_ID_DYLIB of $$@ + $(Verb) install_name_tool $$@ -id $$@ RuntimeLibrary.$1: \ - $(RuntimeLibrary.$1.Configs:%=$(ResourceLibDir)/$1/libclang_rt.%.a) + $(RuntimeLibrary.$1.Configs:%=$(ResourceLibDir)/$1/libclang_rt.%) .PHONY: RuntimeLibrary.$1 $(PROJ_resources_lib)/$1: $(PROJ_resources_lib) @@ -145,10 +186,18 @@ $(PROJ_resources_lib)/$1/libclang_rt.%.a: \ $(ResourceLibDir)/$1/libclang_rt.%.a | $(PROJ_resources_lib)/$1 $(Echo) Installing compiler runtime library: $1/$$* $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1 +$(PROJ_resources_lib)/$1/libclang_rt.%.so: \ + $(ResourceLibDir)/$1/libclang_rt.%.so | $(PROJ_resources_lib)/$1 + $(Echo) Installing compiler runtime library: $1/$$* + $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1 +$(PROJ_resources_lib)/$1/libclang_rt.%.dylib: \ + $(ResourceLibDir)/$1/libclang_rt.%.dylib | $(PROJ_resources_lib)/$1 + $(Echo) Installing compiler runtime library: $1/$$* + $(Verb) $(DataInstall) $$< $(PROJ_resources_lib)/$1 # Rule to install runtime libraries. RuntimeLibraryInstall.$1: \ - $(RuntimeLibrary.$1.Configs:%=$(PROJ_resources_lib)/$1/libclang_rt.%.a) + $(RuntimeLibrary.$1.Configs:%=$(PROJ_resources_lib)/$1/libclang_rt.%) .PHONY: RuntimeLibraryInstall.$1 endef $(foreach lib,$(RuntimeDirs), $(eval $(call RuntimeLibraryTemplate,$(lib)))) diff --git a/runtime/compiler-rt/clang_linux_test_input.c b/runtime/compiler-rt/clang_linux_test_input.c new file mode 100644 index 0000000..e65ce98 --- /dev/null +++ b/runtime/compiler-rt/clang_linux_test_input.c @@ -0,0 +1,4 @@ +// This file is used to check if we can produce working executables +// for i386 and x86_64 archs on Linux. +#include <stdlib.h> +int main(){} |