diff options
author | Rainer Orth <ro@gcc.gnu.org> | 2023-07-27 11:32:48 +0200 |
---|---|---|
committer | Tobias Hieta <tobias@hieta.se> | 2023-07-28 09:08:02 +0200 |
commit | 88ce4e85f21201344f6820556760d4477ccb97f4 (patch) | |
tree | 2b949a9e0eb6f0a9336df5164a0c84212e688484 | |
parent | 66145712c823a5cce91bc3b7a655a59edd1a57da (diff) | |
download | llvm-88ce4e85f21201344f6820556760d4477ccb97f4.zip llvm-88ce4e85f21201344f6820556760d4477ccb97f4.tar.gz llvm-88ce4e85f21201344f6820556760d4477ccb97f4.tar.bz2 |
[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 6b5149aa442efc10afa00e8864e58a24a9cf5c9f)
-rw-r--r-- | clang/lib/Driver/ToolChains/Solaris.cpp | 6 | ||||
-rw-r--r-- | clang/test/Driver/solaris-ld-sanitizer.c | 16 |
2 files changed, 21 insertions, 1 deletions
diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp index 335a5a8..86c789f 100644 --- a/clang/lib/Driver/ToolChains/Solaris.cpp +++ b/clang/lib/Driver/ToolChains/Solaris.cpp @@ -151,18 +151,22 @@ void solaris::Linker::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-lgcc"); CmdArgs.push_back("-lm"); } + const SanitizerArgs &SA = getToolChain().getSanitizerArgs(Args); if (NeedsSanitizerDeps) { linkSanitizerRuntimeDeps(getToolChain(), CmdArgs); // Work around Solaris/amd64 ld bug when calling __tls_get_addr directly. // However, ld -z relax=transtls is available since Solaris 11.2, but not // in Illumos. - const SanitizerArgs &SA = getToolChain().getSanitizerArgs(Args); if (getToolChain().getTriple().getArch() == llvm::Triple::x86_64 && (SA.needsAsanRt() || SA.needsStatsRt() || (SA.needsUbsanRt() && !SA.requiresMinimalRuntime()))) CmdArgs.push_back("-zrelax=transtls"); } + // Avoid AsanInitInternal cycle, Issue #64126. + if (getToolChain().getTriple().isX86() && SA.needsSharedRt() && + SA.needsAsanRt()) + CmdArgs.push_back("-znow"); } if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles, diff --git a/clang/test/Driver/solaris-ld-sanitizer.c b/clang/test/Driver/solaris-ld-sanitizer.c index caf0191..d4fe62b 100644 --- a/clang/test/Driver/solaris-ld-sanitizer.c +++ b/clang/test/Driver/solaris-ld-sanitizer.c @@ -49,3 +49,19 @@ // RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \ // RUN: | FileCheck --check-prefix=CHECK-LD-X64-UBSAN %s // CHECK-LD-X64-UBSAN: -zrelax=transtls + +/// General tests that the ld -z now workaround is only applied on +/// Solaris/i386 with shared libclang_rt.asan.. Note that we use sysroot to +/// make these tests independent of the host system. + +/// Check i386-pc-solaris2.11, 32bit, shared libclang_rt.asan +// RUN: %clang -fsanitize=address -shared-libasan --target=i386-pc-solaris2.11 %s -### 2>&1 \ +// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \ +// RUN: | FileCheck --check-prefix=CHECK-LD-X32-ASAN-SHARED %s +// CHECK-LD-X32-ASAN-SHARED: -znow + +/// Check i386-pc-solaris2.11, 32bit, static libclang_rt.asan +// RUN: %clang -fsanitize=address --target=i386-pc-solaris2.11 %s -### 2>&1 \ +// RUN: --gcc-toolchain="" --sysroot=%S/Inputs/solaris_x86_tree \ +// RUN: | FileCheck --check-prefix=CHECK-LD-X32-ASAN %s +// CHECK-LD-X32-ASAN-NOT: -znow |