From 8cbe53b5d9fe86c465e4a1c72c35b43e3734e5ed 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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@294274 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Driver/Tools.cpp | 8 +++++--- test/Driver/sanitizer-ld.c | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 1cefce6848..1eddefd4f0 100644 --- a/lib/Driver/Tools.cpp +++ b/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/test/Driver/sanitizer-ld.c b/test/Driver/sanitizer-ld.c index c98ce8a0c4..c4a6f4377b 100644 --- a/test/Driver/sanitizer-ld.c +++ b/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" -- 2.50.1