]> granicus.if.org Git - clang/commitdiff
[ASan] Do not imply -undefined dynamic_lookup when linking dylibs with -fsanitize...
authorAlexander Potapenko <glider@google.com>
Fri, 20 Sep 2013 08:09:51 +0000 (08:09 +0000)
committerAlexander Potapenko <glider@google.com>
Fri, 20 Sep 2013 08:09:51 +0000 (08:09 +0000)
Instead add the ASan runtime to the linker command line so that only the ASan API functions can be undefined in the target library.

Fixes http://llvm.org/bugs/show_bug.cgi?id=17275

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@191076 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains.cpp
lib/Driver/Tools.cpp

index 18b4a0f01eab81f3f36f36782cb22ade186fa159..a006b52c5dee853458573e9334dc04d21afcbd7b 100644 (file)
@@ -314,15 +314,13 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList &Args,
       getDriver().Diag(diag::err_drv_clang_unsupported_per_platform)
         << "-fsanitize=address";
     } else {
-      if (Args.hasArg(options::OPT_dynamiclib) ||
-          Args.hasArg(options::OPT_bundle)) {
-        // Assume the binary will provide the ASan runtime.
-      } else {
-        AddLinkRuntimeLib(Args, CmdArgs,
-                          "libclang_rt.asan_osx_dynamic.dylib", true);
+      if (!Args.hasArg(options::OPT_dynamiclib) &&
+          !Args.hasArg(options::OPT_bundle)) {
         // The ASAN runtime library requires C++.
         AddCXXStdlibLibArgs(Args, CmdArgs);
       }
+      AddLinkRuntimeLib(Args, CmdArgs,
+                        "libclang_rt.asan_osx_dynamic.dylib", true);
     }
   }
 
index a9d3acc2da4b69e71a2cca9285da6d6aeb420897..c2ba2e93afd2660bdc1fdaaa129ad92e096e2a80 100644 (file)
@@ -4817,20 +4817,6 @@ void darwin::Link::ConstructJob(Compilation &C, const JobAction &JA,
 
   Args.AddAllArgs(CmdArgs, options::OPT_L);
 
-  const SanitizerArgs &Sanitize =
-      getToolChain().getDriver().getOrParseSanitizerArgs(Args);
-  // If we're building a dynamic lib with -fsanitize=address,
-  // unresolved symbols may appear. Mark all
-  // of them as dynamic_lookup. Linking executables is handled in
-  // lib/Driver/ToolChains.cpp.
-  if (Sanitize.needsAsanRt()) {
-    if (Args.hasArg(options::OPT_dynamiclib) ||
-        Args.hasArg(options::OPT_bundle)) {
-      CmdArgs.push_back("-undefined");
-      CmdArgs.push_back("dynamic_lookup");
-    }
-  }
-
   if (Args.hasArg(options::OPT_fopenmp))
     // This is more complicated in gcc...
     CmdArgs.push_back("-lgomp");