Don't link in sanitizer runtimes if -nostdlib/-nodefaultlibs is provided.
It makes no sense to link in sanitizer runtimes in this case: the user
probably doesn't want to see any system/toolchain libs in his link if he
provides these flags, and the link will most likely fail anyway - as sanitizer
runtimes depend on libpthread, libdl, libc etc.
Also, see discussion in https://code.google.com/p/address-sanitizer/issues/detail?id=344
llvm-svn: 218541
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index 8d9af96..20c88ae 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -2243,6 +2243,10 @@
// C runtime, etc). Returns true if sanitizer system deps need to be linked in.
static bool addSanitizerRuntimes(const ToolChain &TC, const ArgList &Args,
ArgStringList &CmdArgs) {
+ // Don't link in any sanitizer runtimes if we have no system libraries.
+ if (Args.hasArg(options::OPT_nostdlib) ||
+ Args.hasArg(options::OPT_nodefaultlibs))
+ return false;
SmallVector<StringRef, 4> SharedRuntimes, StaticRuntimes,
HelperStaticRuntimes;
collectSanitizerRuntimes(TC, Args, SharedRuntimes, StaticRuntimes,