[cfe-dev] lld-link and fsanitize

Markus Haberlander via cfe-dev cfe-dev at lists.llvm.org
Wed May 15 08:57:36 PDT 2019


Hello,

I would like to use ASan/UBsan on Windows together with clang-cl and
lld-link.

Is it nowadays possible to somehow pass the sanitizer flags to lld-link in
order to get automatic linking?


The following commands ...
__________________________
echo int main() { return 0;} > test.cpp
clang-cl test.cpp /c -fsanitize=address
lld-link *.obj /OUT:"test.exe" -fsanitize=address
__________________________


... just give me the following errors:
___________________________
lld-link.exe: warning: ignoring unknown argument: -fsanitize=address
lld-link.exe: error: undefined symbol: ___asan_init
>>> referenced by test.obj:(_asan.module_ctor)
lld-link.exe: error: undefined symbol: ___asan_version_mismatch_check_v8
>>> referenced by test.obj:(_asan.module_ctor)
___________________________


I know there is the following possibility to find the parameters to
"manually" add everything to the lld-link (or link.exe) call:
___________________________
clang-cl -v -fsanitize=address test.cpp 2>&1 | find "link.exe"
 "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\VC\\bin\\link.exe"
-out:test.exe -nologo -debug -incremental:no "C:\\Program Files
(x86)\\LLVM\\lib\\clang\\7.0.1\\lib\\windows\\clang_rt.asan-i386.lib"
"-wholearchive:C:\\Program Files
(x86)\\LLVM\\lib\\clang\\7.0.1\\lib\\windows\\clang_rt.asan-i386.lib"
"C:\\Program Files
(x86)\\LLVM\\lib\\clang\\7.0.1\\lib\\windows\\clang_rt.asan_cxx-i386.lib"
"-wholearchive:C:\\Program Files
(x86)\\LLVM\\lib\\clang\\7.0.1\\lib\\windows\\clang_rt.asan_cxx-i386.lib"
"C:\\Users\\markus\\AppData\\Local\\Temp\\test-941b84.obj"
___________________________


But adopting these paths for every minor version change of clang sounds
like an awful idea. The idea of writing a script that automates finding
these paths in a build system just feels very wrong, too ...


Is there any mechanism to pass the -fsanitize=... flags on to lld-link like
it is done for non-MSVC builds?

Best regards
Markus Haberlander
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190515/bb086e3f/attachment.html>


More information about the cfe-dev mailing list