[PATCH] D28600: [compiler-rt] [Sanitizer Coverage] Use interception to access to sanitizer coverage's strong functions defined in the main executable (for MD on Windows.)

Marcos Pividori via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 12 00:58:57 PST 2017


mpividori created this revision.
mpividori added reviewers: kcc, rnk, aizatsky, zturner.
mpividori added a subscriber: llvm-commits.
mpividori set the repository for this revision to rL LLVM.
Herald added subscribers: mgorny, dberris, kubabrecka.

When considering MD, asan is implemented as an external dll: `clang-rt_asan_dynamic-arch.dll`
We provide default implementation for sanitizer coverage's weak functions like: `__sanitizer_cov_trace_pc_guard`, `__sanitizer_cov_trace_cmp` , etc, imported from asan dll as: `__sanitizer_cov_trace_pc_guard__def`, `__sanitizer_cov_trace_cmp__def` , etc.

But clients can redefine and export a new definition in the main executable, like:

  extern "C" __declspec(dllexport) void __sanitizer_cov_trace_pc_guard(u32* guard) {
    // Diferent implementation provided by the client.
  }

However, other client's dlls, will continue using the default implementation imported from asan dll: `__sanitizer_cov_trace_pc_guard__def`.

So, with the implementation in this diff, when asan dll is initialized, it will check if the main executable exports the definition of some weak function (for example `__sanitizer_cov_trace_pc_guard`). If it finds that function, then it will override the default function in the dll (`__sanitizer_cov_trace_pc_guard__def`) with that pointer. So, all the client's dlls with instrumentation that import `__sanitizer_cov_trace_pc_guard__def()` from asan dll, will be using the function provided by the main executable.

After this diff, sanitizer coverage is fixed for MD on Windows. In particular `libFuzzer` can provide custom implementation for all sanitizer coverage's weak functions, and they will be considered by asan dll.


Repository:
  rL LLVM

https://reviews.llvm.org/D28600

Files:
  lib/asan/CMakeLists.txt
  lib/asan/asan_win_coverage_interception.cc

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28600.84084.patch
Type: text/x-patch
Size: 4024 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170112/a0e44645/attachment.bin>


More information about the llvm-commits mailing list