aboutsummaryrefslogtreecommitdiff
path: root/runtime/compiler-rt
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2012-10-09 16:03:52 +0000
committerAlexey Samsonov <samsonov@google.com>2012-10-09 16:03:52 +0000
commitf288d223a44fb2fa0de69b225dcdbc5f7669defd (patch)
tree296214b50cda8fd59bca7e7ab9f7d20d9ee4b8fc /runtime/compiler-rt
parent3644d970095d9c638c658cfd17f8e19fc333aadc (diff)
Fixup for r165097: build 32-bit ASan compiler-rt library on 64-bit Linux only if just-built clang can build simple 32-bit executables
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165503 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'runtime/compiler-rt')
-rw-r--r--runtime/compiler-rt/Makefile22
-rw-r--r--runtime/compiler-rt/clang_linux_test_input.c4
2 files changed, 23 insertions, 3 deletions
diff --git a/runtime/compiler-rt/Makefile b/runtime/compiler-rt/Makefile
index 58cb7fdaaf..0336c01d03 100644
--- a/runtime/compiler-rt/Makefile
+++ b/runtime/compiler-rt/Makefile
@@ -84,19 +84,35 @@ 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.a profile-i386.a asan-i386.a
endif
+
ifeq ($(ARCH),x86_64)
RuntimeLibrary.linux.Configs += \
full-x86_64.a profile-x86_64.a asan-x86_64.a tsan-x86_64.a
-# We assume that 32-bit ASan library can be built by Clang on 64-bit platform,
-# and add it to the list of runtime libraries so that
-# "clang -faddress-sanitizer -m32" would work.
+# 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
+endif
endif
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 0000000000..e65ce9860a
--- /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(){}