Skip to content

Allow ASan container annotations to activate piecemeal#6211

Open
amyw-msft wants to merge 2 commits intomicrosoft:mainfrom
amyw-msft:partial-asan-annotation
Open

Allow ASan container annotations to activate piecemeal#6211
amyw-msft wants to merge 2 commits intomicrosoft:mainfrom
amyw-msft:partial-asan-annotation

Conversation

@amyw-msft
Copy link
Copy Markdown
Member

Fix addressing #6186.

Previously, ASan annotations for string, vector, and optional were activated by linking with stl_asan.lib which set each activation variable to true, leading to ODR violations if some TUs were built with annotations inserted but partially activated.

This change removes the stl_asan.lib dependency and allows each option to set the activation variable individually.

I've retained stl_asan.lib and modified the definitions with __declspec(selectany) to match those in the headers, and also to ensure compatibility if linking with a static library from a previous version of the toolset.

The test I've included just ensures the annotations can be targeted individually instead of constructing an ASan error. I did this for simplicity (esp as new annotations are added) while still covering every scenario. I limited it to one disabled out of the set instead of exhaustive validation to not devote too much test time to this.

I've verified the scenario from #6186 locally, as well as ensuring it is backwards compatible with old versions of the headers (meaning, I built the annotated_lib.lib with an old toolset and test.obj with a toolset with this change and manually tried out every combination). Building a static library with the new toolset and linking with an old toolset produces a link error (the old stl_asan.lib does not contain __declspec(selectany), so clashes with the definition added in __msvc_sanitizer_annotate_container.hpp), but my understanding is that this isn't a supported scenario.

…ted piecemeal. The lib is retained for compatibility with static libraries built with old headers.
@amyw-msft amyw-msft added the bug Something isn't working label Apr 3, 2026
@amyw-msft amyw-msft requested a review from a team as a code owner April 3, 2026 22:15
@amyw-msft amyw-msft added the ASan Address Sanitizer label Apr 3, 2026
@github-project-automation github-project-automation bot moved this to Initial Review in STL Code Reviews Apr 3, 2026
@StephanTLavavej StephanTLavavej self-assigned this Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ASan Address Sanitizer bug Something isn't working

Projects

Status: Initial Review

Development

Successfully merging this pull request may close these issues.

2 participants