diff options
author | Vitaly Buka <vitalybuka@google.com> | 2024-03-27 13:43:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-27 13:43:18 -0700 |
commit | 70e8cf0c31493071c50c8112c6e0c7903abf6ca6 (patch) | |
tree | 2946904a791eb086395011387977a41f6fbea848 | |
parent | 453a63caebc35378bcdb31da9d0f358a3998e51b (diff) | |
download | llvm-70e8cf0c31493071c50c8112c6e0c7903abf6ca6.zip llvm-70e8cf0c31493071c50c8112c6e0c7903abf6ca6.tar.gz llvm-70e8cf0c31493071c50c8112c6e0c7903abf6ca6.tar.bz2 |
[HWASAN] Don't instrument loads from global if globals are not tagged (#86774)
3 files changed, 7 insertions, 17 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp index 96fd530..f7d4803 100644 --- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp @@ -790,6 +790,13 @@ bool HWAddressSanitizer::ignoreAccess(Instruction *Inst, Value *Ptr) { if (SSI && SSI->stackAccessIsSafe(*Inst)) return true; } + + if (isa<GlobalVariable>(getUnderlyingObject(Ptr))) { + if (!InstrumentGlobals) + return true; + // TODO: Optimize inbound global accesses, like Asan `instrumentMop`. + } + return false; } diff --git a/llvm/test/Instrumentation/HWAddressSanitizer/globals-access.ll b/llvm/test/Instrumentation/HWAddressSanitizer/globals-access.ll index f8d13fc..f9040af 100644 --- a/llvm/test/Instrumentation/HWAddressSanitizer/globals-access.ll +++ b/llvm/test/Instrumentation/HWAddressSanitizer/globals-access.ll @@ -15,22 +15,6 @@ define dso_local noundef i32 @_Z3tmpv() sanitize_hwaddress { ; NOGLOB-LABEL: define dso_local noundef i32 @_Z3tmpv( ; NOGLOB-SAME: ) #[[ATTR0:[0-9]+]] { ; NOGLOB-NEXT: entry: -; NOGLOB-NEXT: [[TMP12:%.*]] = load i64, ptr @__hwasan_tls, align 8 -; NOGLOB-NEXT: [[TMP1:%.*]] = or i64 [[TMP12]], 4294967295 -; NOGLOB-NEXT: [[HWASAN_SHADOW:%.*]] = add i64 [[TMP1]], 1 -; NOGLOB-NEXT: [[TMP2:%.*]] = inttoptr i64 [[HWASAN_SHADOW]] to ptr -; NOGLOB-NEXT: [[TMP3:%.*]] = lshr i64 ptrtoint (ptr @x to i64), 56 -; NOGLOB-NEXT: [[TMP4:%.*]] = trunc i64 [[TMP3]] to i8 -; NOGLOB-NEXT: [[TMP5:%.*]] = and i64 ptrtoint (ptr @x to i64), 72057594037927935 -; NOGLOB-NEXT: [[TMP6:%.*]] = lshr i64 [[TMP5]], 4 -; NOGLOB-NEXT: [[TMP7:%.*]] = getelementptr i8, ptr [[TMP2]], i64 [[TMP6]] -; NOGLOB-NEXT: [[TMP8:%.*]] = load i8, ptr [[TMP7]], align 1 -; NOGLOB-NEXT: [[TMP9:%.*]] = icmp ne i8 [[TMP4]], [[TMP8]] -; NOGLOB-NEXT: br i1 [[TMP9]], label [[TMP10:%.*]], label [[TMP11:%.*]], !prof [[PROF1:![0-9]+]] -; NOGLOB: 10: -; NOGLOB-NEXT: call void @llvm.hwasan.check.memaccess.shortgranules(ptr [[TMP2]], ptr @x, i32 2) -; NOGLOB-NEXT: br label [[TMP11]] -; NOGLOB: 11: ; NOGLOB-NEXT: [[TMP0:%.*]] = load i32, ptr @x, align 4 ; NOGLOB-NEXT: ret i32 [[TMP0]] ; diff --git a/llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope-setjmp.ll b/llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope-setjmp.ll index 079d722..62fd7a1 100644 --- a/llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope-setjmp.ll +++ b/llvm/test/Instrumentation/HWAddressSanitizer/use-after-scope-setjmp.ll @@ -54,7 +54,6 @@ define dso_local noundef i1 @_Z6targetv() sanitize_hwaddress { ; CHECK: sw.bb1: ; CHECK-NEXT: br label [[RETURN]] ; CHECK: while.body: -; CHECK-NEXT: call void @llvm.hwasan.check.memaccess(ptr [[TMP16]], ptr @stackbuf, i32 19) ; CHECK-NEXT: store ptr [[BUF_HWASAN]], ptr @stackbuf, align 8 ; CHECK-NEXT: call void @may_jump() ; CHECK-NEXT: br label [[RETURN]] |