Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
lib/Fuzzer/test/CMakeLists.txt | ||
---|---|---|
41 ↗ | (On Diff #81816) | sounds wrong. |
lib/Fuzzer/test/CMakeLists.txt | ||
---|---|---|
41 ↗ | (On Diff #81816) | We can't have it in the clang driver because the clang driver isn't called to perform links on Windows, as explained in this comment. This CL seems to do what you're suggesting: call the driver and keep the logic to find sanitizer runtimes there. |
lib/Fuzzer/test/CMakeLists.txt | ||
---|---|---|
41 ↗ | (On Diff #81816) | @kcc |
Try passing -fuse-ld=lld to clang-cl. We basically whitelist certain gcc-style options, and this is one of them. That's why -g doesn't work, but certain other options do. It's kind of a hodgepodge and there's no clearly defined pattern for which ones we accept and which ones we don't.
In any way, in this case -fuse-ld=lld should force it to use lld.
I greatly dislike the need for such a change.
What is the command line with just clang-cl (no cmake) to build libFuzzer.lib?
To build an executable using libFuzzer, or to build the static archive libFuzzer.lib?
I was asking about "build the static archive libFuzzer.lib" but actually I'd like to see both.
LLVMFuzzer.lib is basically this command:
link.exe /lib /nologo /machine:x64 /out:lib\LLVMFuzzer.lib lib\Fuzzer\CMakeFiles\LLVMFuzzerNoMainObjects.dir\*.obj lib\Fuzzer\CMakeFiles\LLVMFuzzer.dir\FuzzerMain.cpp.obj
LLVMFuzzer-NullDerefTest links like this:
link.exe /nologo lib\Fuzzer\test\CMakeFiles\LLVMFuzzer-NullDerefTest.dir\NullDerefTest.cpp.obj /out:lib\Fuzzer\test\LLVMFuzzer-NullDerefTest.exe /implib:lib\LLVMFuzzer-NullDerefTest.lib /pdb:lib\Fuzzer\test\LLVMFuzzer-NullDerefTest.pdb /version:0.0 /machine:x64 /MANIFEST:NO /STACK:10000000 -debug /INCREMENTAL:NO /subsystem:console lib\LLVMFuzzer.lib kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib
Many of those arguments are unnecessary, and would maybe not be present without cmake, but the important point is that executables are not linked by calling the clang driver on Windows. This is true in every Windows build system I've ever encountered that wasn't ported from Unix.
The link step above fails because the ASan RTL is not listed on the link line. We can solve this problem in either of these ways:
- Break convention as Marcos is doing here and call clang-cl to do the link manually.
- Duplicate the clang driver logic to pass the appropriate asan runtimes into LLVM cmake. Chromium already duplicates this logic itself.
@kcc
To build libFuzer.lib this changes are not needed, they are only needed when compiling the code to be fuzzed with cmake, which means, it is only necessary for the tests. Because of that, I include this changes in the CMake file in the test folder only.
If we want to compile the tests on command line with clang-cl, it would be:
clang-cl -fsanitize-coverage=trace-pc-guard,.... -fsanitize=address Test.cpp LLVMFuzzer.lib /MD /link /SUBSYSTEM:CONSOLE
Cmake split this command in 2 steps, compiling and linking:
clang-cl -fsanitize-coverage=trace-pc-guard -fsanitize=address /c Test.cpp link.exe /MD Test.obj LLVMFuzzer.lib /SUBSYSTEM:CONSOLE
The last command fails, because we don't provide compiler-rt libraries to the linker.
So, basically, I change the link command, so cmake execute this:
clang-cl -fsanitize-coverage=trace-pc-guard -fsanitize=address /c Test.cpp clang-cl -fsanitize-coverage=trace-pc-guard -fsanitize=address /MD Test.obj LLVMFuzzer.lib /link /SUBSYSTEM:CONSOLE
Now, clang-cl will include compiler-rt libraries.
The ASan lit tests? They invoke clang directly to perform the link, so the driver logic does it for us:
// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
The "unit" tests I think also invoke clang directly.
LGTM
Ok, (I think) I understand now.
Please leave a TODO saying that once we have a monorepo we should simply require the just-built clang.
@kcc @rnk I am looking at this change now, as it makes porting to compiler-rt more difficult.
In all other tests (asan/tsan/etc) test runtime is linked together with the executable instead, which contains all the libraries injected by the driver.
If we do that, would it be possible to not apply this change?
AFAICT, libFuzzer on Windows has no active users or contributors.
If you ask me, I would prefer to
a) disable check-fuzzer on the windows bot b) complete the migration from llvm to compiler-rt, while preserving the status quo only on Linux and Mac c) let anyone who cares about windows (if anyone left) fix it once the dust settles.
The same also applies to our recent discussion around r309646 where the windows part is blocking me.
Reid, Zack, WDYT?
@kcc I strongly agree with your idea of dropping the support, at least until someone is prepared to heavily invest into this (and invest using good code style, without writing scary CMake hacks)