r293668 - [windows] [asan] Add wholearchive flag when including static lib asan.

Marcos Pividori via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 31 10:31:38 PST 2017

Author: mpividori
Date: Tue Jan 31 12:31:38 2017
New Revision: 293668

URL: http://llvm.org/viewvc/llvm-project?rev=293668&view=rev
[windows] [asan] Add wholearchive flag when including static lib asan.

In Windows, when the sanitizer is implemented as a static library, we use
auxiliary static library dll_thunk that will be linked to the dlls that have
instrumentation, so they can refer to the runtime in the main executable.
It uses interception to get a pointer the function in the main executable and
override its function with that pointer.
Because of that, we need to ensure that the main executable exports all the
sanitizers' interface, otherwise the initialization in dll_thunk will fail.

In this commit we add the flag -wholearchive to clang driver to ensure that
the linker does not omit any object files from asan library.

Differential Revision: https://reviews.llvm.org/D29334


Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=293668&r1=293667&r2=293668&view=diff
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Tue Jan 31 12:31:38 2017
@@ -11002,6 +11002,11 @@ void visualstudio::Linker::ConstructJob(
     } else {
       for (const auto &Lib : {"asan", "asan_cxx"})
         CmdArgs.push_back(TC.getCompilerRTArgString(Args, Lib));
+      // Make sure the linker consider all object files from the static library.
+      // This is necessary because instrumented dlls need access to all the
+      // interface exported by the static lib in the main executable.
+      CmdArgs.push_back(Args.MakeArgString(std::string("-wholearchive:") +
+          TC.getCompilerRT(Args, "asan")));

More information about the cfe-commits mailing list