Skip to content

Commit 78f0991

Browse files
authored
[hwasan] Workaround unsupported AssignmentTrackingPass (llvm#76547)
Temporarily fix for issue llvm#76545 Hwasan does not attach tags to @llvm.dbg.assign. It's not clear if we can attach tags to @llvm.dbg.assign. For now we just disable the path replacing llvm.dbg.declare with llvm.dbg.assign. It may reduce the quality of interactive debugging with HWASAN, but usually it's a smaller priority for sanitizers than the quality if reports.
1 parent c0345b4 commit 78f0991

File tree

5 files changed

+45
-3
lines changed

5 files changed

+45
-3
lines changed

compiler-rt/test/hwasan/TestCases/stack-overflow.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %clang_hwasan -g %s -o %t && not %run %t 2>&1 | FileCheck %s
1+
// RUN: %clang_hwasan -O0 -g %s -o %t && not %run %t 2>&1 | FileCheck %s
2+
// RUN: %clang_hwasan -O3 -g %s -o %t && not %run %t 2>&1 | FileCheck %s
23

34
// Stack histories currently are not recorded on x86.
45
// XFAIL: target=x86_64{{.*}}

compiler-rt/test/hwasan/TestCases/stack-uar.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Tests use-after-return detection and reporting.
2-
// RUN: %clang_hwasan -g %s -o %t && not %run %t 2>&1 | FileCheck %s
2+
// RUN: %clang_hwasan -O0 -g %s -o %t && not %run %t 2>&1 | FileCheck %s
3+
// RUN: %clang_hwasan -O3 -g %s -o %t && not %run %t 2>&1 | FileCheck %s
34
// RUN: %clang_hwasan -g %s -o %t && not %env_hwasan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM
45

56
// Run the same test as above, but using the __hwasan_add_frame_record libcall.

compiler-rt/test/hwasan/TestCases/stack-uas.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Tests use-after-scope detection and reporting.
2-
// RUN: %clang_hwasan -g %s -o %t && not %run %t 2>&1 | FileCheck %s
2+
// RUN: %clang_hwasan -O0 -g %s -o %t && not %run %t 2>&1 | FileCheck %s
3+
// RUN: %clang_hwasan -O2 -g %s -o %t && not %run %t 2>&1 | FileCheck %s
34
// RUN: %clang_hwasan -g %s -o %t && not %env_hwasan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM
45

56
// RUN: %clang_hwasan -mllvm -hwasan-use-after-scope=false -g %s -o %t && %run %t 2>&1

llvm/lib/IR/DebugInfo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2115,6 +2115,10 @@ bool AssignmentTrackingPass::runOnFunction(Function &F) {
21152115
if (F.hasFnAttribute(Attribute::OptimizeNone))
21162116
return /*Changed*/ false;
21172117

2118+
// FIXME: https://github.com/llvm/llvm-project/issues/76545
2119+
if (F.hasFnAttribute(Attribute::SanitizeHWAddress))
2120+
return /*Changed*/ false;
2121+
21182122
bool Changed = false;
21192123
auto *DL = &F.getParent()->getDataLayout();
21202124
// Collect a map of {backing storage : dbg.declares} (currently "backing
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
; RUN: opt %s -S -passes=declare-to-assign -o - | FileCheck %s
2+
3+
; CHECK: call void @llvm.dbg.declare
4+
5+
define dso_local void @f() sanitize_hwaddress !dbg !9 {
6+
entry:
7+
%a = alloca i32, align 4
8+
call void @llvm.dbg.declare(metadata ptr %a, metadata !13, metadata !DIExpression()), !dbg !16
9+
ret void, !dbg !17
10+
}
11+
12+
declare void @llvm.dbg.declare(metadata, metadata, metadata)
13+
14+
!llvm.dbg.cu = !{!0}
15+
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
16+
!llvm.ident = !{!8}
17+
18+
!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 17.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
19+
!1 = !DIFile(filename: "test.c", directory: "/")
20+
!2 = !{i32 7, !"Dwarf Version", i32 5}
21+
!3 = !{i32 2, !"Debug Info Version", i32 3}
22+
!4 = !{i32 1, !"wchar_size", i32 4}
23+
!5 = !{i32 8, !"PIC Level", i32 2}
24+
!6 = !{i32 7, !"PIE Level", i32 2}
25+
!7 = !{i32 7, !"uwtable", i32 2}
26+
!8 = !{!"clang version 17.0.0"}
27+
!9 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !10, scopeLine: 1, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !12)
28+
!10 = !DISubroutineType(types: !11)
29+
!11 = !{null}
30+
!12 = !{!13}
31+
!13 = !DILocalVariable(name: "a", scope: !9, file: !1, line: 1, type: !14)
32+
!14 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
33+
!15 = !DILocation(line: 1, column: 12, scope: !9)
34+
!16 = !DILocation(line: 1, column: 16, scope: !9)
35+
!17 = !DILocation(line: 1, column: 19, scope: !9)

0 commit comments

Comments
 (0)