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
why is this in asan and not in a common dir?