From 8e6a25fecaad6888d915bfc0c68ddd6debb2a147 Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Tue, 7 Feb 2017 03:21:57 +0000 Subject: [PATCH] Driver: Do not link safestack with --whole-archive. This allows it to be used with the other sanitizers. Differential Revision: https://reviews.llvm.org/D29545 llvm-svn: 294274 --- clang/lib/Driver/Tools.cpp | 8 +++++--- clang/test/Driver/sanitizer-ld.c | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 1cefce6848c4..1eddefd4f03a 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/lib/Driver/Tools.cpp @@ -3365,8 +3365,10 @@ collectSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, if (SanArgs.linkCXXRuntimes()) StaticRuntimes.push_back("ubsan_standalone_cxx"); } - if (SanArgs.needsSafeStackRt()) - StaticRuntimes.push_back("safestack"); + if (SanArgs.needsSafeStackRt()) { + NonWholeStaticRuntimes.push_back("safestack"); + RequiredSymbols.push_back("__safestack_init"); + } if (SanArgs.needsCfiRt()) StaticRuntimes.push_back("cfi"); if (SanArgs.needsCfiDiagRt()) { @@ -3417,7 +3419,7 @@ static bool addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args, if (SanArgs.hasCrossDsoCfi() && !AddExportDynamic) CmdArgs.push_back("-export-dynamic-symbol=__cfi_check"); - return !StaticRuntimes.empty(); + return !StaticRuntimes.empty() || !NonWholeStaticRuntimes.empty(); } static bool addXRayRuntime(const ToolChain &TC, const ArgList &Args, diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c index c98ce8a0c4c7..c4a6f4377b89 100644 --- a/clang/test/Driver/sanitizer-ld.c +++ b/clang/test/Driver/sanitizer-ld.c @@ -416,7 +416,9 @@ // // CHECK-SAFESTACK-LINUX: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}" // CHECK-SAFESTACK-LINUX-NOT: "-lc" +// CHECK-SAFESTACK-LINUX-NOT: whole-archive // CHECK-SAFESTACK-LINUX: libclang_rt.safestack-x86_64.a" +// CHECK-SAFESTACK-LINUX: "-u" "__safestack_init" // CHECK-SAFESTACK-LINUX: "-lpthread" // CHECK-SAFESTACK-LINUX: "-ldl"