-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Reapply^2 "[HWASan] remove incorrectly inferred attributes" (#106622) #106816
Reapply^2 "[HWASan] remove incorrectly inferred attributes" (#106622) #106816
Conversation
Created using spr 1.3.4
@llvm/pr-subscribers-compiler-rt-sanitizer @llvm/pr-subscribers-llvm-transforms Author: Florian Mayer (fmayer) ChangesThis reverts commit 66927fb. Filter functions this applies to, which I initially wanted to do in a Full diff: https://github.com/llvm/llvm-project/pull/106816.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index 69e5835bee8a5e..1cd8e2e41a536c 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -591,6 +591,12 @@ void HWAddressSanitizer::createHwasanCtorComdat() {
appendToCompilerUsed(M, Dummy);
}
+static bool onlyReadsArgMemory(const Function &F) {
+ return F.onlyAccessesArgMemory() && llvm::all_of(F.args(), [](const auto &A) {
+ return A.onlyReadsMemory();
+ });
+}
+
/// Module-level initialization.
///
/// inserts a call to __hwasan_init to the module's constructor list.
@@ -598,6 +604,28 @@ void HWAddressSanitizer::initializeModule() {
LLVM_DEBUG(dbgs() << "Init " << M.getName() << "\n");
TargetTriple = Triple(M.getTargetTriple());
+ for (auto &F : M.functions()) {
+ // Remove memory attributes that are invalid with HWASan.
+ // HWASan checks read from shadow, which invalidates memory(argmem: *)
+ // Short granule checks on function arguments read from the argument memory
+ // (last byte of the granule), which invalidates writeonly.
+ //
+ // This is not only true for sanitized functions, because AttrInfer can
+ // infer those attributes on libc functions, which is not true if those
+ // are instrumented (Android) or intercepted.
+
+ // nobuiltin makes sure later passes don't restore assumptions about
+ // the function.
+ if (F.doesNotAccessMemory() || F.onlyReadsMemory() || onlyReadsArgMemory(F))
+ continue;
+ F.addFnAttr(llvm::Attribute::NoBuiltin);
+ F.removeFnAttr(llvm::Attribute::Memory);
+ // F.setMemoryEffects(F.getMemoryEffects() | MemoryEffects::writeOnly() |
+ // MemoryEffects::readOnly());
+ for (auto &A : F.args())
+ A.removeAttr(llvm::Attribute::WriteOnly);
+ }
+
// x86_64 currently has two modes:
// - Intel LAM (default)
// - pointer aliasing (heap only)
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Scheduled 3 stage hwasan build: https://lab.llvm.org/buildbot/#/buildrequests/1084424?redirect_to_build=true |
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/123/builds/4914 Here is the relevant piece of the build log for the reference
|
Looks like a flake, next build is green: https://lab.llvm.org/buildbot/#/builders/123/builds/4915 |
) This reverts commit 66927fb. Filter functions this applies to, which I initially wanted to do in a follow up to make reverts easier, but turns out without that it gets really slow Fleetbench proto: no significant movement Fleetbench hashing: no significant movement Fleetbench libc: no significant movement 2nd stage LLVM build: https://lab.llvm.org/buildbot/#/builders/55/builds/1765/steps/9/logs/stdio after this change: 80833.56user 3303.04system previous build: 78430.21user 3258.04system Pull Request: llvm#106816
This reverts commit 66927fb.
Filter functions this applies to, which I initially wanted to do in a
follow up to make reverts easier, but turns out without that it gets
really slow
Fleetbench proto: no significant movement
Fleetbench hashing: no significant movement
Fleetbench libc: no significant movement
2nd stage LLVM build: https://lab.llvm.org/buildbot/#/builders/55/builds/1765/steps/9/logs/stdio
after this change: 80833.56user 3303.04system
previous build: 78430.21user 3258.04system