[PATCH] D28432: [compiler-rt] Fix Sanitizer Coverage for Windows.

Marcos Pividori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 6 19:18:15 PST 2017


mpividori created this revision.
mpividori added reviewers: kcc, aizatsky, zturner, rnk.
mpividori added a subscriber: llvm-commits.
Herald added subscribers: mgorny, dberris, kubabrecka.

Hi,

In this diff, I fix Sanitizer Coverage for Windows, when using a shared run time for asan, which means, when compiling for MD.

I needed to update the code, since currently it doesn't work because it relies on weak symbols.
This works fine for Linux, since weak symbols work in both cases, when using a static asan rt or when considering a shared asan rt.
In Windows, we have something similar to weak symbols, using "pragma"(/alternatename...". This works for static libraries but this doesn't work for dlls.
For MD, asan is implemented in a separate dll, and the linker will fails because we can not set "__sanitizer_cov_trace_*" functions as optional in "clang-rt_asan_dynamic-arch.dll".

So, for example, for "__sanitizer_cov_trace_pc_guard", we include the default implementation in asan dll.
When initialized, asan dll will try to find an implementation of "__sanitizer_cov_trace_pc_guard_impl" in the main executable, (I can't use the same name, so I decided to add a suffix "_impl" for user provided implementations). If it finds it, it will override its own "__sanitizer_cov_trace_pc_guard"  with that function, to use the user provided implementation.
So, users that don't want to use the default implementation, can change it, defining "__sanitizer_cov_trace_pc_guard_impl" with dllexport.

So, for example, for libFuzzer:

+ libFuzzer.lib defines "__sanitizer_cov_trace_pc_guard_impl" (non default implementation), and exports it with dllexport.
 + asan.dll exports  "__sanitizer_cov_trace_pc_guard"  with default implementation.
 + All user's code, for example: "main.cc", "someUserLib.dll", etc,  is instrumented with calls to "__sanitizer_cov_trace_pc_guard", which the linker resolves to point to the asan.dll's implementation.

When asan dll is initialized, it will look for an implementation of "__sanitizer_cov_trace_pc_guard_impl" in the main executable, and it will find the implementation from libFuzzer.lib.  Then, it will override "__sanitizer_cov_trace_pc_guard" function pointer in asan.dll to point to  "__sanitizer_cov_trace_pc_guard_impl"  implementation.

Thanks,
Marcos


https://reviews.llvm.org/D28432

Files:
  lib/asan/CMakeLists.txt
  lib/asan/asan_win_coverage.cc
  lib/sanitizer_common/sanitizer_coverage_libcdep.cc
  lib/sanitizer_common/sanitizer_interface_internal.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28432.83486.patch
Type: text/x-patch
Size: 7981 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170107/c8da9c07/attachment.bin>


More information about the llvm-commits mailing list