Skip to content

Commit be5ae06

Browse files
author
Alexey Samsonov
committed
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
llvm-svn: 165503
1 parent 8cb1746 commit be5ae06

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

clang/runtime/compiler-rt/Makefile

+19-3
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,35 @@ ifeq ($(OS),Linux)
8484
RuntimeDirs += linux
8585
RuntimeLibrary.linux.Configs :=
8686

87+
# TryCompile compiler source flags
88+
# Returns exit code of running a compiler invocation.
89+
TryCompile = \
90+
$(shell \
91+
cflags=""; \
92+
for flag in $(3); do \
93+
cflags="$$cflags $$flag"; \
94+
done; \
95+
$(1) $$cflags $(2) -o /dev/null > /dev/null 2> /dev/null ; \
96+
echo $$?)
97+
8798
# We currently only try to generate runtime libraries on x86.
8899
ifeq ($(ARCH),x86)
89100
RuntimeLibrary.linux.Configs += \
90101
full-i386.a profile-i386.a asan-i386.a
91102
endif
103+
92104
ifeq ($(ARCH),x86_64)
93105
RuntimeLibrary.linux.Configs += \
94106
full-x86_64.a profile-x86_64.a asan-x86_64.a tsan-x86_64.a
95-
# We assume that 32-bit ASan library can be built by Clang on 64-bit platform,
96-
# and add it to the list of runtime libraries so that
97-
# "clang -faddress-sanitizer -m32" would work.
107+
# We need to build 32-bit ASan library on 64-bit platform, and add it to the
108+
# list of runtime libraries to make "clang -faddress-sanitizer -m32" work.
109+
# We check that Clang can produce working 32-bit binaries by compiling a simple
110+
# executable.
111+
test_source = $(LLVM_SRC_ROOT)/tools/clang/runtime/compiler-rt/clang_linux_test_input.c
112+
ifeq ($(call TryCompile,$(ToolDir)/clang,$(test_source),-m32),0)
98113
RuntimeLibrary.linux.Configs += asan-i386.a
99114
endif
115+
endif
100116

101117
endif
102118

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This file is used to check if we can produce working executables
2+
// for i386 and x86_64 archs on Linux.
3+
#include <stdlib.h>
4+
int main(){}

0 commit comments

Comments
 (0)