}
}
- // 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";
/// 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());
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");