Hi,
I modified Sanitizer Coverage Instrumentation's code, to work on Windows.
In Windows, the symbols "___stop___sancov_guards" and "___start___sancov_guards" are not defined automatically.
So, we need to take a different approach.
As suggested in: https://msdn.microsoft.com/en-us/library/7977wcck.aspx
I define 3 sections: ".SCOV$A", ".SCOV$M" and ".SCOV$Z".
- Section ".SCOV$A" will only hold a variable ___start___sancov_guard.
- Section ".SCOV$M" will hold the main data.
- Section ".SCOV$Z" will only hold a variable ___stop___sancov_guards.
When linking, they will be merged sorted by the characters after the $, so we can use the pointers of the variables ___[start|stop]___sancov_guard to know the actual range of addresses of that section.
___[start|stop]___sancov_guard should be defined only once per module, because of that, I include them inside the static asan runtime: "clang_rt.asan_dynamic_runtime_thunk", that will be included in both, dlls and executables (that changes are in a different diff).
In this diff, I updated the instrumentation to include all the guard arrays in section ".SCOV$M".
I don't think we need this dynamic initialization in every TU on Windows. If ___start___sancov_guard is linked statically into every DLL, we can add code to that object file to call __sanitizer_cov_trace_pc_guard_init on Windows.