diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp b/clang/lib/Driver/ToolChains/CommonArgs.cpp --- a/clang/lib/Driver/ToolChains/CommonArgs.cpp +++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp @@ -630,6 +630,14 @@ return false; } +static const char *getAsNeededOption(const ToolChain &TC, bool ignore) { + // FIXME: Need to handle GNU ld on Solaris. + if (TC.getTriple().isOSSolaris()) + return ignore ? "-zignore" : "-zrecord"; + else + return ignore ? "--as-needed" : "--no-as-needed"; +} + void tools::linkSanitizerRuntimeDeps(const ToolChain &TC, ArgStringList &CmdArgs) { // Fuchsia never needs these. Any sanitizer runtimes with system @@ -639,7 +647,7 @@ // Force linking against the system libraries sanitizers depends on // (see PR15823 why this is necessary). - CmdArgs.push_back("--no-as-needed"); + CmdArgs.push_back(getAsNeededOption(TC, false)); // There's no libpthread or librt on RTEMS & Android. if (TC.getTriple().getOS() != llvm::Triple::RTEMS && !TC.getTriple().isAndroid()) { @@ -833,7 +841,7 @@ } void tools::linkXRayRuntimeDeps(const ToolChain &TC, ArgStringList &CmdArgs) { - CmdArgs.push_back("--no-as-needed"); + CmdArgs.push_back(getAsNeededOption(TC, false)); CmdArgs.push_back("-lpthread"); if (!TC.getTriple().isOSOpenBSD()) CmdArgs.push_back("-lrt"); @@ -1258,7 +1266,7 @@ bool AsNeeded = LGT == LibGccType::UnspecifiedLibGcc && !TC.getTriple().isAndroid() && !TC.getTriple().isOSCygMing(); if (AsNeeded) - CmdArgs.push_back("--as-needed"); + CmdArgs.push_back(getAsNeededOption(TC, true)); switch (UNW) { case ToolChain::UNW_None: @@ -1286,7 +1294,7 @@ } if (AsNeeded) - CmdArgs.push_back("--no-as-needed"); + CmdArgs.push_back(getAsNeededOption(TC, false)); } static void AddLibgcc(const ToolChain &TC, const Driver &D,