This avoids unnecessary instrumentation.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
The analysis should not run at -O0.
Otherwise, LGTM.
What kind of code size improvement do you see?
clang/test/CodeGen/hwasan-stack-safety-analysis-asm.c | ||
---|---|---|
5 | this patch mostly change code under llvm/ so tests should be also there, as IR tests | |
llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h | ||
32 | Why not from M.getTargetTriple() ? | |
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
200 | Could you please extract these function in a separate patch? | |
392 | why we need to check TargetTriple for that? | |
1278 | Instead of // clang-format off # comment1 if (...) return false; # comment2 if (...) return false; ... in a separate patch? |
Addressed inline comments.
clang/test/CodeGen/hwasan-stack-safety-analysis-asm.c | ||
---|---|---|
5 | I don't have strong feelings, but clang/test/CodeGen/lifetime-sanitizer.c is a very similar test, so I think we should either move all of these to llvm/ or add the new ones here to clang/. What do you think? | |
llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h | ||
32 | Mostly for consistency with the legacy pass. Either way is fine for me though, what do you prefer? | |
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
392 | Because we only need the stack safety analysis if we instrument the stack, which we do not do on x86_64 (see shouldInstrumentStack). | |
1278 | OK, will do in a followup (or see how I can get clang-tidy to do the right thing here). |
Other than missing llvm test is LGTM
clang/test/CodeGen/hwasan-stack-safety-analysis-asm.c | ||
---|---|---|
5 | That lifetime tests how clang inserts lifetime markers. So it must be in clang/ this is from https://reviews.llvm.org/D20759 which is clang only patch. | |
llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h | ||
32 | I don't know if will cause any issues, but usually most passes get triple from the module. | |
39 | !IsOptNull -> Optimize | |
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
392 | I see, I forgot about this limitation. | |
433 | we usually don't use {} for single line |
Thanks!
clang/test/CodeGen/hwasan-stack-safety-analysis-asm.c | ||
---|---|---|
5 | Thanks for the explanation. Moved to llvm/. | |
llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h | ||
32 | I'll leave it as is, for consistency within this file, as we need to do it this way for the new pass manager. | |
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
392 | I am not sure we will ever add it for non-LAM x86_64. | |
433 | I think this would make a bit of a long tenary expression. |
llvm/test/CodeGen/hwasan-stack-safety-analysis-asm.c | ||
---|---|---|
1 ↗ | (On Diff #358885) | You can't use %clang in LLVM tests. There may be no clang. Use opt to invoke the hwasan pass in isolation, see the tests under test/Instrumentation/HWAddressSanitizer/. The reason I did not say anything about the tests was because only in clang we can test this thing end-to-end. |
llvm/test/CodeGen/hwasan-stack-safety-analysis-asm.c | ||
---|---|---|
8 ↗ | (On Diff #358885) | these tests do not work because %clang is not defined here, in LLVM my request was to add new tests in llvm-project/llvm/test/Instrumentation/HWAddressSanitizer/ Also try to generated CHECK statements with llvm/utils/update_test_checks.py, often result is quite useful. |
llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h | ||
---|---|---|
32 | OK, no strong feelings but now we addRequire the pass even if we don't need it, so there isn't much point turning it off anymore, no? |
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
---|---|---|
402 | No need to pass this down, just look at OptimizeNone function attribute. |
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
---|---|---|
402 | Interesting, the Aarch64StackTagging code does pass this down, do you know why? |
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
---|---|---|
402 | Also we really should be using this at least in the getAnalysisUsage, which Vitaly's change made unconditional. Correct? |
Btw Vitaly, will this work with LTO out of the box? I think we used to add pre-LTO StackSafety pass explicitly for memtag only, but it looks like that code is gone.
What do you mean gone? Can you show me the patch?
We probably needs something to add analysis for HWASAN as well.
llvm/include/llvm/Transforms/Instrumentation/HWAddressSanitizer.h | ||
---|---|---|
32 | In case of legacy pass? Correct. I don't think we need to over optimize this deprecated case which is going to be removed at some point anyway. For new PM it's irrelevant as it's does not declare requirements in advance. | |
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
421 | @eugenis unrelated to the patch, but why do we this args if then we assert(!CompileKernel || Recover); | |
llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll | ||
5 ↗ | (On Diff #359376) | you don't need to hardcode local path here |
10 ↗ | (On Diff #359376) | would be nice to have also function which have __hwasan_generate_tag in either case to make sure |
27 ↗ | (On Diff #359376) | usually we remove irrelevant attributes #* and module flags !* to make test simpler |
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
---|---|---|
421 | why not? This forbids CompileKernel && !Recover, how else would you represent the 3 remaining combinations? |
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
---|---|---|
421 |
Thanks. I've misread the expression. |
update
llvm/test/Instrumentation/HWAddressSanitizer/stack-safety-analysis.ll | ||
---|---|---|
27 ↗ | (On Diff #359376) | Removed all sorts of unneeded stuff. Thanks. |
I removed the stack-safety-analysis-asm.c test because I don't think it really adds anything and it caused problems. SGTY?
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
---|---|---|
394 | I like this even less than "plumbing", if you need shouldUseStackSafetyAnalysis please just pass Triple as in earlier versions. Why do you need to avoid loading analysis? Revert does not explain what is broken. |
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
---|---|---|
394 | I am still looking at the breakage. But if you looked at the logic before, there was the case DisableOptimization BUT ClUseStackAnalysis being explicitly set, which made us try to getAnalysis without having required it here. I also like the plumbing more than this, but changed to this to see what you think. |
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
---|---|---|
398 | Why not just: if (!DisableOptimization || ClUseStackSafety) AU.addRequired<StackSafetyGlobalInfoWrapperPass>(); |
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
---|---|---|
398 | Because ClUseStackSafety defaults to true, so this will be quite useless except if the user explicitly sets it to false. So then you end up duplicating the logic in shouldUseStackSafetyAnalysis, which is why I went for the Dummy (thinking about it, we don't actually need to setArch on it). |
more flag parsing.
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
---|---|---|
398 | How about this (mightUseStackSafetyAnalysis)? This seems like a nice tradeoff without duplication of the logic. |
Sorry. broke a buildbot again: https://lab.llvm.org/buildbot/#/builders/139/builds/7613/steps/6/logs/FAIL__Clang__asan_c
I am not sure why I cannot reproduce this locally.
Pass 'HWAddressSanitizer' is not initialized. Verify if there is a pass dependency cycle. Required Passes: clang: /home/buildbot/buildbot-root/llvm-clang-x86_64-sie-ubuntu-fast/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:715: void llvm::PMTopLevelManager::schedulePass(llvm::Pass*): Assertion `PI && "Expected required passes to be initialized"' failed. PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace, preprocessed source, and associated run script.
llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp | ||
---|---|---|
409 | To fix that revert you need to add INITIALIZE_PASS_DEPENDENCY(StackSafetyGlobalInfoWrapperPass) |
weird, my config with -DLLVM_ENABLE_ASSERTIONS=ON does not reproduce, however exact cmake from bot does
DisableOptimization=