This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Improve support for ASAN on Windows with MSVC cl & clang-cl
ClosedPublic

Authored by andrewng on May 31 2022, 8:32 AM.

Details

Summary

Tested with MSVC 2019 (19.29) and LLVM 14.0.4.

Diff Detail

Event Timeline

andrewng created this revision.May 31 2022, 8:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2022, 8:32 AM
Herald added a subscriber: mgorny. · View Herald Transcript
andrewng requested review of this revision.May 31 2022, 8:32 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 31 2022, 8:32 AM
rnk added inline comments.May 31 2022, 2:24 PM
llvm/cmake/modules/HandleLLVMOptions.cmake
827

This isn't clang-specific, it's x86_32-specific.

897

This assumes x86_64, while i386 is also a possibility.

I wish we hadn't embedded the architecture into our library names. =/

zero9178 added inline comments.
llvm/cmake/modules/HandleLLVMOptions.cmake
897

They may even possibly not have a suffix at all if the clang toolchain has per target runtime directories. In that case it is eg. called just clang_rt.asan.lib on my machine.

So this seems like if we want it to actually handle all possible options we'll have to loop and check for the existence of those files.
One can use either clang-cl /clang:-print-runtime-dir to get the directory of the runtime files if the clang version is new enough or otherwise clang-cl /clang:-print-libgcc-file-name /clang:--rtlib=compiler-rt to get the (likely non existent) builtins file to extract the directory from. The latter is quite a hack however that has worked well for me so far.

andrewng added inline comments.May 31 2022, 4:44 PM
llvm/cmake/modules/HandleLLVMOptions.cmake
827

I just kept this the same as it was but you're right it is x86_32 specific. Do you want me to address this?

897

Thanks for the comments.

I have assumed x86_64 as I believe that's the most commonly used. I deliberately titled this patch "improve" as my goal wasn't really to attempt to cope with every possible configuration. Is this acceptable? Perhaps it can be improved incrementally for other desired configurations.

zero9178 added inline comments.Jun 1 2022, 2:12 AM
llvm/cmake/modules/HandleLLVMOptions.cmake
897

Doing it incrementally sounds good to me, but in the current state it would break existing configurations, so it wouldn't just be an improvement but an regression as well.

andrewng added inline comments.Jun 1 2022, 5:24 AM
llvm/cmake/modules/HandleLLVMOptions.cmake
897

The addition of the ASAN libraries was never setup before when lld-link is being used. Are you saying that there are configurations that don't require this and therefore by adding these libraries, it would break those configurations? Could you shed some light on such configurations? If there's another way to make ASAN work without modifying the CMake, then perhaps that's the way to go.

andrewng updated this revision to Diff 433382.Jun 1 2022, 7:01 AM

I've added support for x86_32/i686.

rnk accepted this revision.Jun 2 2022, 2:52 PM

lgtm

llvm/cmake/modules/HandleLLVMOptions.cmake
827

There's probably a better way to check the architecture, but I'm not sure what it is and this seems good enough.

This revision is now accepted and ready to land.Jun 2 2022, 2:52 PM
This revision was landed with ongoing or failed builds.Jun 8 2022, 3:18 AM
This revision was automatically updated to reflect the committed changes.