[cfe-dev] Windows runtimes and compiler-rt and ASAN libraries

Milian Wolff via cfe-dev cfe-dev at lists.llvm.org
Tue Jan 9 06:20:04 PST 2018


Hey all,

I recently tried to use ASAN on Windows again. I noticed some issues regarding 
Windows runtimes and would like to get some insight on that:

a) The compiler-rt ASAN libs as provided for Windows from [1] are linked 
against the static Windows runtime (/MT). Would it be possible to also include 
versions for the compiler-rt libs linked against the dynamic runtime (/MD)? 
This would greatly simplify getting ASAN up and running for projects that use 
e.g. Qt which is usually consumed as a dynamic library.

[1]: http://releases.llvm.org/download.html 

b) I notice that it's impossible to compile compiler-rt against the debug 
variants (/MTd or /MDd), cf. [2]. Is this a conceptual limitation that cannot 
ever be implemented? I.e. are features in the debug runtime negatively 
influencing the functionality of ASAN, making this impossible to work? Or is 
it "simply" a matter of work that needs to be done, i.e. adding the 
corresponding interceptors for the debug runtime?

[2]: https://github.com/llvm-mirror/compiler-rt/blob/master/lib/asan/
asan_win.cc#L214

c) Using ASAN via `clang.exe` or `clang-cl.exe` on single-file demo 
applications is straight forward, as the linker will be fed with the correct 
arguments when enabling `-fsanitize=address`. But when trying to use ASAN on 
Windows for real-world applications that use e.g. CMake or QMake, I am running 
into the following issue: These build systems separate the object file 
creation and linking phase. Then, when using the Visual Studio linker 
(`link.exe`) for linking, that tool of course does not (yet?) know anything 
about the sanitizers and compiler-rt. So while I can simply add the `-
fsanitize=address` argument to the invocation of `clang-cl.exe`, one needs to 
find and specify the correct arguments to pass to `link.exe` too. This latter 
step is not straight forward at all. How do people cope with this? Is there 
something I'm missing, like a `clang-link.exe` that understands `-
fsanitize=address`?

Right now, I have to hardcode these arguments manually:

  /LIBPATH:C:/tools/clang/lib/clang/6.0.0/lib/windows/
  -lclang_rt.asan_dynamic-x86_64
  -lclang_rt.asan_dynamic_runtime_thunk-x86_64

The path could probably be obtained automatically by joining `llvm-config --
lib`, `llvm-config --version` and some hard coded strings. But could we maybe 
get an `llvm-config --asan-ldflags` or similar?

Thanks

-- 
Milian Wolff
mail at milianw.de
http://milianw.de
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180109/31e6f73a/attachment.sig>


More information about the cfe-dev mailing list