Skip to content

Commit 0baa360

Browse files
CarlosAlbertoEncisoGroverkss
authored andcommitted
[llvm-debuginfo-analyzer] Fix crash with thread local storage. (llvm#113904)
The DW_OP_GNU_push_tls_address, DW_OP_form_tls_address DWARF location forms generated for thread local storage variables, caused a crash in the DWARFReader, due to incorrect number of operands.
1 parent fedebe6 commit 0baa360

File tree

3 files changed

+95
-2
lines changed

3 files changed

+95
-2
lines changed

llvm/lib/DebugInfo/LogicalView/Core/LVLocation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ std::string LVOperation::getOperandsDWARFInfo() {
156156
Stream << "push_object_address";
157157
break;
158158
case dwarf::DW_OP_form_tls_address:
159-
Stream << "form_tls_address " << hexString(Operands[0]);
159+
Stream << "form_tls_address";
160160
break;
161161
case dwarf::DW_OP_call_frame_cfa:
162162
Stream << "call_frame_cfa";
@@ -308,7 +308,7 @@ std::string LVOperation::getOperandsDWARFInfo() {
308308
PrintRegisterInfo(dwarf::DW_OP_reg0);
309309
break;
310310
case dwarf::DW_OP_GNU_push_tls_address:
311-
Stream << "gnu_push_tls_address " << hexString(Operands[0]);
311+
Stream << "gnu_push_tls_address";
312312
break;
313313
case dwarf::DW_OP_GNU_addr_index:
314314
Stream << "gnu_addr_index " << unsigned(Operands[0]);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
source_filename = "ThreadLocalStorage.cpp"
2+
target triple = "x86_64-pc-linux-gnu"
3+
4+
@TGlobal = dso_local thread_local global i32 0, align 4, !dbg !0
5+
@NGlobal = dso_local global i32 1, align 4, !dbg !5
6+
@_ZZ4testvE6TLocal = internal thread_local global i32 0, align 4, !dbg !8
7+
8+
define dso_local void @_Z4testv() !dbg !10 {
9+
entry:
10+
%NLocal = alloca i32, align 4
11+
%0 = call align 4 ptr @llvm.threadlocal.address.p0(ptr align 4 @TGlobal), !dbg !22
12+
store i32 1, ptr %0, align 4
13+
#dbg_declare(ptr %NLocal, !24, !DIExpression(), !25)
14+
store i32 0, ptr %NLocal, align 4, !dbg !25
15+
store i32 2, ptr @NGlobal, align 4
16+
ret void
17+
}
18+
19+
declare nonnull ptr @llvm.threadlocal.address.p0(ptr nonnull)
20+
21+
!llvm.dbg.cu = !{!2}
22+
!llvm.module.flags = !{!14, !15}
23+
24+
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
25+
!1 = distinct !DIGlobalVariable(name: "TGlobal", scope: !2, file: !3, line: 1, type: !7, isLocal: false, isDefinition: true)
26+
!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, emissionKind: FullDebug, globals: !4)
27+
!3 = !DIFile(filename: "ThreadLocalStorage.cpp", directory: "")
28+
!4 = !{!0, !5, !8}
29+
!5 = !DIGlobalVariableExpression(var: !6, expr: !DIExpression())
30+
!6 = distinct !DIGlobalVariable(name: "NGlobal", scope: !2, file: !3, line: 2, type: !7, isLocal: false, isDefinition: true)
31+
!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
32+
!8 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression())
33+
!9 = distinct !DIGlobalVariable(name: "TLocal", scope: !10, file: !3, line: 4, type: !7, isLocal: true, isDefinition: true)
34+
!10 = distinct !DISubprogram(name: "test", scope: !3, file: !3, line: 3, type: !11, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !13)
35+
!11 = !DISubroutineType(types: !12)
36+
!12 = !{null}
37+
!13 = !{}
38+
!14 = !{i32 7, !"Dwarf Version", i32 5}
39+
!15 = !{i32 2, !"Debug Info Version", i32 3}
40+
!22 = !DILocation(line: 5, scope: !10)
41+
!24 = !DILocalVariable(name: "NLocal", scope: !10, file: !3, line: 7, type: !7)
42+
!25 = !DILocation(line: 7, scope: !10)
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
; REQUIRES: x86-registered-target
2+
3+
; For the given test case:
4+
5+
; // ThreadLocalStorage.cpp
6+
; 1 thread_local int TGlobal = 0;
7+
; 2 int NGlobal = 1;
8+
; 3 void test() {
9+
; 4 thread_local int TLocal = 0;
10+
; 5 TGlobal = 1;
11+
; 6
12+
; 7 int NLocal = 0;
13+
; 8 NGlobal = 2;
14+
; 9 }
15+
16+
; The llvm-debuginfo-analyzer crashes when producing a logical view for
17+
; the object file generated using the following commands:
18+
;
19+
; clang++ -Xclang -disable-O0-optnone -Xclang -disable-llvm-passes
20+
; -fno-discard-value-names -emit-llvm -S -g -O0
21+
; ThreadLocalStorage.cpp -o ThreadLocalStorage.ll
22+
; llc --filetype=obj ThreadLocalStorage.ll -o ThreadLocalStorage.o
23+
;
24+
; llvm-debuginfo-analyzer --attribute=location --print=symbols
25+
; ThreadLocalStorage.o
26+
27+
; RUN: llc --filetype=obj \
28+
; RUN: %p/Inputs/ThreadLocalStorage.ll -o %t.ThreadLocalStorage.o
29+
30+
; RUN: llvm-debuginfo-analyzer --attribute=location \
31+
; RUN: --print=symbols \
32+
; RUN: %t.ThreadLocalStorage.o 2>&1 | \
33+
; RUN: FileCheck --strict-whitespace %s
34+
35+
; CHECK: Logical View:
36+
; CHECK: {File} '{{.*}}threadlocalstorage.o'
37+
; CHECK-EMPTY:
38+
; CHECK: {CompileUnit} 'threadlocalstorage.cpp'
39+
; CHECK: 1 {Variable} extern 'TGlobal' -> 'int'
40+
; CHECK: {Location}
41+
; CHECK: {Entry} const_u 0, gnu_push_tls_address
42+
; CHECK: 2 {Variable} extern 'NGlobal' -> 'int'
43+
; CHECK: {Location}
44+
; CHECK: {Entry} addrx 0
45+
; CHECK: 3 {Function} extern not_inlined 'test' -> 'void'
46+
; CHECK: 4 {Variable} 'TLocal' -> 'int'
47+
; CHECK: {Location}
48+
; CHECK: {Entry} const_u 0, gnu_push_tls_address
49+
; CHECK: 7 {Variable} 'NLocal' -> 'int'
50+
; CHECK: {Location}
51+
; CHECK: {Entry} fbreg -4

0 commit comments

Comments
 (0)