Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSVC 14.37.32822 does not ship with stl_asan.lib for arm64 #4035

Closed
farzonl opened this issue Sep 17, 2023 · 8 comments · Fixed by #4058
Closed

MSVC 14.37.32822 does not ship with stl_asan.lib for arm64 #4035

farzonl opened this issue Sep 17, 2023 · 8 comments · Fixed by #4058
Labels
ARM64 Related to the ARM64 architecture ASan Address Sanitizer bug Something isn't working fixed Something works now, yay!

Comments

@farzonl
Copy link

farzonl commented Sep 17, 2023

Describe the bug

When trying to build compiler rt test cases on windows I am getting the following linker error:

LINK : fatal error LNK1104: cannot open file 'stl_asan.lib'

I reported the bug to llvm, but the fix likely needs to come from MSVC to provide a stl_asan.lib for arm64.
llvm/llvm-project#66600

Without stl_asan.lib you can't build compiler_rt test cases using COMPILER_RT_INCLUDE_TESTS.

These test cases are important to validate a port of sanitzers for winodws arm64.

Command-line test case

cmake -GNinja -DLLVM_ENABLE_PROJECTS=llvm;compiler-rt -DCMAKE_BUILD_TYPE=Release \
 -DLLVM_ENABLE_PDB=ON -DLLVM_ENABLE_ASSERTIONS=ON -DLLVM_TARGETS_TO_BUILD=AArch64 \
-DCMAKE_C_COMPILER=clang-cl.exe -DCMAKE_CXX_COMPILER=clang-cl.exe \
 -DCOMPILER_RT_INCLUDE_TESTS=TRUE -DCMAKE_LINKER=lld-link.exe  \
-S llvm-project\llvm -B compiler-rt_build
cd llvm_build
ninja 
ninja check-all

Possible solutions
for arm64 set: _DISABLE_STRING_ANNOTATION and _DISABLE_VECTOR_ANNOTATION

#if !defined(_M_CEE_PURE) && !(defined(_DISABLE_STRING_ANNOTATION) && defined(_DISABLE_VECTOR_ANNOTATION))

or remove defined(_M_ARM64) so that we don't try to invoke the linker for asan on windows arm64
#elif defined(_M_X64) || defined(_M_ARM) || defined(_M_ARM64)

@StephanTLavavej StephanTLavavej added ARM64 Related to the ARM64 architecture ASan Address Sanitizer labels Sep 20, 2023
@StephanTLavavej
Copy link
Member

Thanks for reporting this issue. This is a known limitation - MSVC's ASAN doesn't yet work on ARM64, which is why the .lib is not part of the install. We'll keep this issue open because we eventually intend to support this scenario, but that won't happen for some time.

@farzonl
Copy link
Author

farzonl commented Sep 21, 2023

So I'm looking for a work around so I can test some arm64 asan improvements I am making for WOA. The next step for me is to standup the compiler-rt tests cases via COMPILER_RT_INCLUDE_TESTS.

How can I remove the stl_asan.lib depedency? At this early stage I don't need string or vector annotations. I'm still working on trying to get function hooking working.

@farzonl
Copy link
Author

farzonl commented Sep 21, 2023

@StephanTLavavej Re-reading my response and your response I don't think I'm conveying the problem properly. To be more clear I think what is going on here is the STL is telling the linker to look for stl_asan.lib. And since that file doesn't exist for arm64 my suggestion was to disable asan type annotations for arm64 by changing one of the preprocessor definitions Iink-ed.

My work around right now is to use visual studio 2019. I'm not entirely sure why 2019 works, but I think the issue I'm running into is related to the /INFERASANLIBS flag since that seems to be something new.

@StephanTLavavej
Copy link
Member

I see - yes, there does seem to be a bug here. I'll bring it up at the next maintainer meeting on Wednesday (as I am not personally an ASAN expert).

@strega-nil-ms
Copy link
Contributor

Oh, this is absolutely a bug in our headers; it makes the assumption that the only ASan you'll be using is ours. This should be reasonably quick to fix; I think the correct thing for now is to remove support on ARM64 for ASan/STL integration without some kind of flag to re-enable.

@strega-nil-ms
Copy link
Contributor

strega-nil-ms commented Sep 27, 2023

Alright, I've done some figuring out; I think there are two things here you can do.

  1. Define _DISABLE_STRING_ANNOTATION and _DISABLE_VECTOR_ANNOTATION. This will disable all of the STL's support for ASan, but when you're just spinning up ARM64 support for ASan, entirely reasonable.
  2. (the more fun option) Just create your own stl_asan.lib. The entirety of it is a single object file consisting of the following C++:
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

namespace std {
    extern "C" {
    extern const bool _Asan_string_should_annotate = true;
    extern const bool _Asan_vector_should_annotate = true;
    }
} // namespace std

We need stl_asan.lib to exist for us to support ASan in the STL, so doing this is your best bet 😄

I don't believe this is a bug, though. We will ship stl_asan.lib as soon as we support ASan on ARM64 with out runtime.

@farzonl
Copy link
Author

farzonl commented Sep 27, 2023

So I actually tried 1 but the llvm cmake keeps ignoring the defines I try to do. But I might try to just add in a cmakefile.txt instead of via the cli.

  1. I also considered, given how little code is involved here. I guess my concern is more that 2 isn't something I could upstream into the llvm repo.

@strega-nil-ms
Copy link
Contributor

@farzonl I believe that #4058 should give you the changes you need to do this work.

@CaseyCarter CaseyCarter added the bug Something isn't working label Sep 28, 2023
@StephanTLavavej StephanTLavavej added the fixed Something works now, yay! label Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ARM64 Related to the ARM64 architecture ASan Address Sanitizer bug Something isn't working fixed Something works now, yay!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants