Author: Rainer Orth Date: 2023-07-27T11:32:48+02:00 New Revision: 6b5149aa442efc10afa00e8864e58a24a9cf5c9f
URL: https://github.com/llvm/llvm-project/commit/6b5149aa442efc10afa00e8864e58a24a9cf5c9f DIFF: https://github.com/llvm/llvm-project/commit/6b5149aa442efc10afa00e8864e58a24a9cf5c9f.diff LOG: [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 Added: Modified: clang/lib/Driver/ToolChains/Solaris.cpp clang/test/Driver/solaris-ld-sanitizer.c Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/Solaris.cpp b/clang/lib/Driver/ToolChains/Solaris.cpp index 335a5a88cdfac6..86c789f5fcef5c 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 caf01919d4671e..d4fe62b5e14943 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits