Skip to content

[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

Merged
merged 1 commit into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1589,6 +1589,14 @@ void HWAddressSanitizer::sanitizeFunction(Function &F,

assert(!ShadowBase);

// Remove memory attributes that are about to become invalid.
// 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.
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,
Expand Down
15 changes: 15 additions & 0 deletions llvm/test/Instrumentation/HWAddressSanitizer/mem-attr.ll
Original file line number Diff line number Diff line change
@@ -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 }
Loading