Index: lib/Driver/Tools.cpp =================================================================== --- lib/Driver/Tools.cpp +++ lib/Driver/Tools.cpp @@ -4389,6 +4389,17 @@ return EH; } +static void addSanitizerRTDependentLib(const ToolChain &TC, const ArgList &Args, + ArgStringList &CmdArgs, + const StringRef RTName) { + SmallString<128> LibSanitizer(getCompilerRTLibDir(TC)); + llvm::sys::path::append(LibSanitizer, + Twine("clang_rt.") + RTName + ".lib"); + SmallString<128> ArgStr("--dependent-lib="); + ArgStr.append(LibSanitizer); + CmdArgs.push_back(Args.MakeArgString(ArgStr)); +} + void Clang::AddClangCLArgs(const ArgList &Args, ArgStringList &CmdArgs) const { unsigned RTOptionID = options::OPT__SLASH_MT; @@ -4400,6 +4411,17 @@ if (Arg *A = Args.getLastArg(options::OPT__SLASH_M_Group)) RTOptionID = A->getOption().getID(); + if (getToolChain().getSanitizerArgs().needsAsanRt()) { + // FIXME: Handle 64-bit. + bool DLL = Args.hasArg(options::OPT__SLASH_LD, options::OPT__SLASH_LDd); + if (DLL) { + addSanitizerRTDependentLib(getToolChain(), Args, CmdArgs, "asan_dll_thunk-i386"); + } else { + addSanitizerRTDependentLib(getToolChain(), Args, CmdArgs, "asan-i386"); + addSanitizerRTDependentLib(getToolChain(), Args, CmdArgs, "asan_cxx-i386"); + } + } + switch(RTOptionID) { case options::OPT__SLASH_MD: if (Args.hasArg(options::OPT__SLASH_LDd)) @@ -7557,15 +7579,6 @@ C.addCommand(new Command(JA, *this, Exec, CmdArgs)); } -static void addSanitizerRTWindows(const ToolChain &TC, const ArgList &Args, - ArgStringList &CmdArgs, - const StringRef RTName) { - SmallString<128> LibSanitizer(getCompilerRTLibDir(TC)); - llvm::sys::path::append(LibSanitizer, - Twine("clang_rt.") + RTName + ".lib"); - CmdArgs.push_back(Args.MakeArgString(LibSanitizer)); -} - void visualstudio::Link::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, @@ -7606,14 +7619,6 @@ if (getToolChain().getSanitizerArgs().needsAsanRt()) { CmdArgs.push_back(Args.MakeArgString("-debug")); CmdArgs.push_back(Args.MakeArgString("-incremental:no")); - // FIXME: Handle 64-bit. - if (DLL) { - addSanitizerRTWindows(getToolChain(), Args, CmdArgs, - "asan_dll_thunk-i386"); - } else { - addSanitizerRTWindows(getToolChain(), Args, CmdArgs, "asan-i386"); - addSanitizerRTWindows(getToolChain(), Args, CmdArgs, "asan_cxx-i386"); - } } Args.AddAllArgValues(CmdArgs, options::OPT_l); Index: test/Driver/cl-link.c =================================================================== --- test/Driver/cl-link.c +++ test/Driver/cl-link.c @@ -12,11 +12,12 @@ // LINK: "baz" // RUN: %clang_cl /Tc%s -### -fsanitize=address 2>&1 | FileCheck --check-prefix=ASAN %s +// ASAN: "--dependent-lib={{.*}}clang_rt.asan-i386.lib" +// ASAN: "--dependent-lib={{.*}}clang_rt.asan_cxx-i386.lib" // ASAN: link.exe // ASAN: "-debug" // ASAN: "-incremental:no" -// ASAN: "{{.*}}clang_rt.asan-i386.lib" -// ASAN: "{{.*}}clang_rt.asan_cxx-i386.lib" +// ASAN-NOT: .lib // ASAN: "{{.*}}cl-link{{.*}}.obj" // RUN: %clang_cl /LD -### /Tc%s 2>&1 | FileCheck --check-prefix=DLL %s @@ -26,11 +27,12 @@ // RUN: %clang_cl /LD /Tc%s -### -fsanitize=address 2>&1 | FileCheck --check-prefix=ASAN-DLL %s // RUN: %clang_cl /LDd /Tc%s -### -fsanitize=address 2>&1 | FileCheck --check-prefix=ASAN-DLL %s +// ASAN-DLL: "--dependent-lib={{.*}}clang_rt.asan_dll_thunk-i386.lib" // ASAN-DLL: link.exe // ASAN-DLL: "-dll" // ASAN-DLL: "-debug" // ASAN-DLL: "-incremental:no" -// ASAN-DLL: "{{.*}}clang_rt.asan_dll_thunk-i386.lib" +// ASAN-DLL-NOT: .lib // ASAN-DLL: "{{.*}}cl-link{{.*}}.obj" // RUN: %clang_cl /Zi /Tc%s -### 2>&1 | FileCheck --check-prefix=DEBUG %s