[cfe-commits] r145955 - in /cfe/trunk/lib/Driver: ToolChains.cpp Tools.cpp
Kostya Serebryany
kcc at google.com
Tue Dec 6 11:18:44 PST 2011
Author: kcc
Date: Tue Dec 6 13:18:44 2011
New Revision: 145955
URL: http://llvm.org/viewvc/llvm-project?rev=145955&view=rev
Log:
[asan] Mac: do not link dynamic libs with the asan-rt, use -undefined dynamic_lookup for dynamic libs. Style fixes. Patch by glider at google.com
Modified:
cfe/trunk/lib/Driver/ToolChains.cpp
cfe/trunk/lib/Driver/Tools.cpp
Modified: cfe/trunk/lib/Driver/ToolChains.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=145955&r1=145954&r2=145955&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChains.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChains.cpp Tue Dec 6 13:18:44 2011
@@ -467,9 +467,12 @@
}
}
- // Add ASAN runtime library, if required.
+ // Add ASAN runtime library, if required. Dynamic libraries and bundles
+ // should not be linked with the runtime library.
if (Args.hasFlag(options::OPT_faddress_sanitizer,
options::OPT_fno_address_sanitizer, false)) {
+ if (Args.hasArg(options::OPT_dynamiclib) ||
+ Args.hasArg(options::OPT_bundle)) return;
if (isTargetIPhoneOS()) {
getDriver().Diag(diag::err_drv_clang_unsupported_per_platform)
<< "-faddress-sanitizer";
Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=145955&r1=145954&r2=145955&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Dec 6 13:18:44 2011
@@ -1103,13 +1103,13 @@
/// If AddressSanitizer is enabled, add appropriate linker flags (Linux).
/// This needs to be called before we add the C run-time (malloc, etc).
static void addAsanRTLinux(const ToolChain &TC, const ArgList &Args,
- ArgStringList &CmdArgs) {
+ ArgStringList &CmdArgs) {
// Add asan linker flags when linking an executable, but not a shared object.
if (Args.hasArg(options::OPT_shared) ||
!Args.hasFlag(options::OPT_faddress_sanitizer,
options::OPT_fno_address_sanitizer, false))
return;
- // LibAsan is "../lib/clang/linux/ArchName/libclang_rt.asan.a
+ // LibAsan is "../lib/clang/linux/ArchName/libclang_rt.asan.a"
llvm::SmallString<128> LibAsan =
llvm::sys::path::parent_path(StringRef(TC.getDriver().Dir));
llvm::sys::path::append(LibAsan, "lib", "clang", "linux", TC.getArchName());
@@ -3586,6 +3586,18 @@
Args.AddAllArgs(CmdArgs, options::OPT_L);
+ // If we're building a dynamic lib with -faddress-sanitizer, unresolved
+ // symbols may appear. Mark all of them as dynamic_lookup.
+ // Linking executables is handled in lib/Driver/ToolChains.cpp.
+ if (Args.hasFlag(options::OPT_faddress_sanitizer,
+ options::OPT_fno_address_sanitizer, false)) {
+ 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");
More information about the cfe-commits
mailing list