Skip to content

Commit 88ce4e8

Browse files
rorthtru
authored andcommitted
[Driver] Link shared asan runtime lib with -z now on Solaris/x86
As detailed in Issue #64126, several asan tests `FAIL` due to a cycle in `AsanInitInternal`. This can by avoided by disabling lazy binding with `ld -z now`. Tested on `amd64-pc-solaris2.11` and `x86_64-pc-linux-gnu`. Differential Revision: https://reviews.llvm.org/D156325 (cherry picked from commit 6b5149a)
1 parent 6614571 commit 88ce4e8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

clang/lib/Driver/ToolChains/Solaris.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,22 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA,
151151
CmdArgs.push_back("-lgcc");
152152
CmdArgs.push_back("-lm");
153153
}
154+
const SanitizerArgs &SA = getToolChain().getSanitizerArgs(Args);
154155
if (NeedsSanitizerDeps) {
155156
linkSanitizerRuntimeDeps(getToolChain(), CmdArgs);
156157

157158
// Work around Solaris/amd64 ld bug when calling __tls_get_addr directly.
158159
// However, ld -z relax=transtls is available since Solaris 11.2, but not
159160
// in Illumos.
160-
const SanitizerArgs &SA = getToolChain().getSanitizerArgs(Args);
161161
if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 &&
162162
(SA.needsAsanRt() || SA.needsStatsRt() ||
163163
(SA.needsUbsanRt() && !SA.requiresMinimalRuntime())))
164164
CmdArgs.push_back("-zrelax=transtls");
165165
}
166+
// Avoid AsanInitInternal cycle, Issue #64126.
167+
if (getToolChain().getTriple().isX86() && SA.needsSharedRt() &&
168+
SA.needsAsanRt())
169+
CmdArgs.push_back("-znow");
166170
}
167171

168172
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,

clang/test/Driver/solaris-ld-sanitizer.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,19 @@
4949
// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
5050
// RUN: | FileCheck --check-prefix=CHECK-LD-X64-UBSAN %s
5151
// CHECK-LD-X64-UBSAN: -zrelax=transtls
52+
53+
/// General tests that the ld -z now workaround is only applied on
54+
/// Solaris/i386 with shared libclang_rt.asan.. Note that we use sysroot to
55+
/// make these tests independent of the host system.
56+
57+
/// Check i386-pc-solaris2.11, 32bit, shared libclang_rt.asan
58+
// RUN: %clang -fsanitize=address -shared-libasan --target=i386-pc-solaris2.11 %s -### 2>&1 \
59+
// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
60+
// RUN: | FileCheck --check-prefix=CHECK-LD-X32-ASAN-SHARED %s
61+
// CHECK-LD-X32-ASAN-SHARED: -znow
62+
63+
/// Check i386-pc-solaris2.11, 32bit, static libclang_rt.asan
64+
// RUN: %clang -fsanitize=address --target=i386-pc-solaris2.11 %s -### 2>&1 \
65+
// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \
66+
// RUN: | FileCheck --check-prefix=CHECK-LD-X32-ASAN %s
67+
// CHECK-LD-X32-ASAN-NOT: -znow

0 commit comments

Comments
 (0)