-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[hwasan] Remove memory attrs from instrumented functions. #92974
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
Conversation
@llvm/pr-subscribers-compiler-rt-sanitizer @llvm/pr-subscribers-llvm-transforms Author: Evgenii Stepanov (eugenis) ChangesHWASan instrumentation makes writeonly attribute on function parameters, as well as most memory(*) attributes invalid. This causes miscompilations with LTO, when more optimizations are run after the HWASan pass. Full diff: https://github.com/llvm/llvm-project/pull/92974.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index 8d39217992c71..3b1a5fce85137 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -1589,6 +1589,10 @@ void HWAddressSanitizer::sanitizeFunction(Function &F,
assert(!ShadowBase);
+ F.removeFnAttr(llvm::Attribute::Memory);
+ for (auto& A : F.args())
+ A.removeAttr(llvm::Attribute::WriteOnly);
+
BasicBlock::iterator InsertPt = F.getEntryBlock().begin();
IRBuilder<> EntryIRB(&F.getEntryBlock(), InsertPt);
emitPrologue(EntryIRB,
diff --git a/llvm/test/Instrumentation/HWAddressSanitizer/mem-attr.ll b/llvm/test/Instrumentation/HWAddressSanitizer/mem-attr.ll
new file mode 100644
index 0000000000000..c0e370f20213a
--- /dev/null
+++ b/llvm/test/Instrumentation/HWAddressSanitizer/mem-attr.ll
@@ -0,0 +1,15 @@
+; Test that HWASan remove writeonly and memory(*) attributes from instrumented functions.
+; RUN: opt -S -passes=hwasan %s | FileCheck %s
+
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32"
+target triple = "aarch64-unknown-linux-android30"
+
+; CHECK: define dso_local void @test_writeonly(ptr nocapture noundef %p) local_unnamed_addr #0
+define dso_local void @test_writeonly(ptr nocapture noundef writeonly %p) local_unnamed_addr #0 {
+entry:
+ store i32 42, ptr %p, align 4
+ ret void
+}
+
+; CHECK: attributes #0 = { sanitize_hwaddress uwtable }
+attributes #0 = { sanitize_hwaddress memory(argmem: write) uwtable }
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Do we need to do the same thing for call sites? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please run clang-format
1c9ee47
to
0f4004a
Compare
I do not think call site attributes are possible before hwasan - at I least I'm not sure how to cause them. |
HWASan instrumentation makes writeonly attribute on function parameters, as well as most memory(*) attributes invalid. This causes miscompilations with LTO, when more optimizations are run after the HWASan pass.
more comments |
…80328586e Local branch amd-gfx aaa8032 Merged main:0012b1ea84e671a9e0c9f7f2d1564315ed9cbcca into amd-gfx:b8aa986939d6 Remote branch main 79a3260 [hwasan] Remove memory attrs from instrumented functions. (llvm#92974)
HWASan instrumentation makes writeonly attribute on function parameters, as well as most memory(*) attributes invalid. This causes miscompilations with LTO, when more optimizations are run after the HWASan pass.