-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
ASAN Instrumentation removed when using optimizations #51724
Comments
Ok, I think I found the underlying issue. So asan (under the new PM) isn't instrumenting the load in main because it considers it incorrectly considers it a "safe access". For my explanation, I've been compiling:
with So the hood, it looks like asan extends the size of Now asan (for both legacy and new PM) is composed of 2 passes: a function pass that loops over functions searching for interesting accesses, and a module pass that instruments globals. The module pass is in charge of changing globals to allocate for the redzone. We only see this error for the new PM because the module pass is run BEFORE the function pass:
Under the legacy PM, the module pass runs AFTER the function pass:
So the function pass in the legacy PM operates on the global before it gets instrumented. It looks like the right solution might be somehow ensuring the module pass runs after the function pass in the new PM. I think this is doable in the legacy PM but I'm not entirely sure how this is done in the new PM. CC'ing Arthur who has done a lot of new PM work and may know the correct solution. |
Should be a fairly easy fix in BackendUtil.cpp by swapping the order we add the function/module pass. llvm-project/clang/lib/CodeGen/BackendUtil.cpp Line 1188 in 3de3ca3
|
Looks like https://reviews.llvm.org/D112732 already fixed this by removing the function pass entirely and just keeping the module pass, but ensuring function instrumentation happens before module instrumentation within that pass. I have https://reviews.llvm.org/D113143 up which adds a regression test. |
This is broken in clang 13. |
Oh yeah, we'll want to cherry pick this. CCing tstellar@. Would you be able to cherry pick a55c4ec which contains this fix? |
I afraid simple cherry-pick is not possible. This is the minimal relevant patch https://reviews.llvm.org/D113529 |
I don't see this commit in tree, is there a typo? |
|
Typo again :( |
Extended Description
The following code does not emit clang instrumentation when compiling with optimizations:
Code generated with
-fsanitize=address -O -g
Shouldn't the code have asan instrumentation? When compiling with
-O0
the instrumentation is there, as well as compiling with-flegacy-pass-manager
The text was updated successfully, but these errors were encountered: