This is an archive of the discontinued LLVM Phabricator instance.

[CMake][MSVC] Add include path to crt headers when enabling sanitizers.
AbandonedPublic

Authored by pgousseau on Jan 25 2022, 9:24 AM.

Details

Reviewers
rnk
vitalybuka
kcc
Summary

This change is to fix build errors “Cannot open include file: 'sanitizer/asan_interface.h'” when building LLVM with MSVC and LLVM_USE_SANITIZER=Address.

I have used the VCToolsInstallDir environment variable to generate the path, let me know if there is a better alternative.

Tested with visual studio 2019 v16.9.6

Diff Detail

Event Timeline

pgousseau created this revision.Jan 25 2022, 9:24 AM
pgousseau requested review of this revision.Jan 25 2022, 9:24 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2022, 9:24 AM
thakis removed a reviewer: thakis.Jan 25 2022, 10:09 AM
thakis added a subscriber: thakis.

(removing myself as reviewer; i don't know anything about using address sanitizer with msvc's cl.exe)

rnk added a comment.Jan 25 2022, 12:19 PM

Can we use __has_include instead? I think that would be simpler, which I'd prefer. MSVC claims to support it:
https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=msvc-170

rnk added a subscriber: cbezault.Jan 25 2022, 12:26 PM
rnk added inline comments.
llvm/cmake/modules/HandleLLVMOptions.cmake
818

I sent the previous comment too early, I see this now.

@cbezault , is there a reason MSVC doesn't ship asan_interface.h with the other includes? I imagine there could be some bad interaction if clang-cl finds the wrong asan_interface.h (MSVC's instead its own from compiler-rt), but clang puts its resource directory onto the search path first, so this should work.

If the usage if asan_interface.h is to call the LSan APIs, I think it would be reasonable to still use __has_include, since LSan support is new and somewhat optional. I would rather not add all internal crt sources to the header search paths used for all compiles in LLVM.

cbezault added inline comments.
llvm/cmake/modules/HandleLLVMOptions.cmake
818

This is not something that I've looked at. @stwish_msft if you want to comment.

pgousseau added inline comments.Jan 26 2022, 3:58 AM
llvm/cmake/modules/HandleLLVMOptions.cmake
818

Thank you for reviewing!
We seem to include asan_interface.h to use asan manual poisoning in Allocator.h

So, it seems we would lose some Asan coverage if not including asan_interface.h

With this change I mean to only affect cl.exe builds and not clang-cl, let me know if this is not the case.

I have a separate patch for an lsan api msvc issue at https://reviews.llvm.org/D118162

I have made an alternative patch at https://reviews.llvm.org/D118624 to avoid adding all internal crt sources to the header search paths. Not ideal either, let me know what you think, thanks!