[PATCH] D29334: [asan] Ensure we export all the interface when considering the static library.

Marcos Pividori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 31 10:00:24 PST 2017


mpividori created this revision.

In Windows, when the sanitizer is implemented as a static library and is included in the main executable, 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.

To ensure that the main executable exports all the sanitizers' interface, all object files from the static library should be linked to the main executable, so we need to add the flag `-wholearchive` to clang driver, when including the static version of asan.

If we don't include `-wholearchive` , the linker could omit some object files when they don't resolve any symbol for the main executable.

But instrumented dlls will try to access to all the interface exposed by the main executable. If we omit part of it, the initialization in `dll_thunk` will fail.


https://reviews.llvm.org/D29334

Files:
  lib/Driver/Tools.cpp


Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -10999,6 +10999,11 @@
     } 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")));
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29334.86449.patch
Type: text/x-patch
Size: 668 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170131/5516497e/attachment.bin>


More information about the llvm-commits mailing list