From: Alexander Potapenko Date: Fri, 20 Sep 2013 08:09:51 +0000 (+0000) Subject: [ASan] Do not imply -undefined dynamic_lookup when linking dylibs with -fsanitize... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4123b92f915fb27855ddaa294b0c7de7aa6c6274;p=clang [ASan] Do not imply -undefined dynamic_lookup when linking dylibs with -fsanitize=address. 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 --- diff --git a/lib/Driver/ToolChains.cpp b/lib/Driver/ToolChains.cpp index 18b4a0f01e..a006b52c5d 100644 --- a/lib/Driver/ToolChains.cpp +++ b/lib/Driver/ToolChains.cpp @@ -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); } } diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index a9d3acc2da..c2ba2e93af 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -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");