Skip to content

Commit 59c9a48

Browse files
authored
[llvm-gsymutil] Fix assert failure on FileEntry.Dir empty (#79926)
Summary: FileEntry.Dir can be empty if debug info only contains relative path. This caused an assertion failure when gsym segmentation is trying to copy a file entry with empty dir. As the fitst entry of StringTable is always empty (and is preserved), `StringOffsetMap` doesn't have key 0. Hence, `find(0)` returns `End` and `operator->()` fails the assertion Test Plan: ./bin/llvm-lit -sv llvm/test/tools/llvm-gsymutil/X86/elf-empty-dir.yaml
1 parent 3d11570 commit 59c9a48

File tree

2 files changed

+112
-1
lines changed

2 files changed

+112
-1
lines changed

llvm/lib/DebugInfo/GSYM/GsymCreator.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ uint32_t GsymCreator::copyFile(const GsymCreator &SrcGC, uint32_t FileIdx) {
5555
return 0;
5656
const FileEntry SrcFE = SrcGC.Files[FileIdx];
5757
// Copy the strings for the file and then add the newly converted file entry.
58-
uint32_t Dir = StrTab.add(SrcGC.StringOffsetMap.find(SrcFE.Dir)->second);
58+
uint32_t Dir =
59+
SrcFE.Dir == 0
60+
? 0
61+
: StrTab.add(SrcGC.StringOffsetMap.find(SrcFE.Dir)->second);
5962
uint32_t Base = StrTab.add(SrcGC.StringOffsetMap.find(SrcFE.Base)->second);
6063
FileEntry DstFE(Dir, Base);
6164
return insertFileEntry(DstFE);
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
## Test converting DWARF using relative path
2+
3+
# RUN: yaml2obj %s -o %t
4+
# RUN: llvm-gsymutil --convert %t -o %t.gsym --segment-size=100000 --num-threads=80 --quiet 2>&1 | FileCheck %s --check-prefix=CONVERT
5+
6+
# CONVERT: Input file: {{.*\.yaml\.tmp}}
7+
# CONVERT: Output file (x86_64): {{.*\.yaml\.tmp\.gsym}}
8+
# CONVERT: Pruned 0 functions, ended with 1 total
9+
10+
--- !ELF
11+
FileHeader:
12+
Class: ELFCLASS64
13+
Data: ELFDATA2LSB
14+
Type: ET_EXEC
15+
Machine: EM_X86_64
16+
DWARF:
17+
debug_str:
18+
- ''
19+
- main.cpp
20+
- foo
21+
debug_abbrev:
22+
- ID: 0
23+
Table:
24+
- Code: 0x1
25+
Tag: DW_TAG_compile_unit
26+
Children: DW_CHILDREN_yes
27+
Attributes:
28+
- Attribute: DW_AT_name
29+
Form: DW_FORM_strp
30+
- Attribute: DW_AT_language
31+
Form: DW_FORM_udata
32+
- Attribute: DW_AT_stmt_list
33+
Form: DW_FORM_sec_offset
34+
- Code: 0x2
35+
Tag: DW_TAG_subprogram
36+
Children: DW_CHILDREN_no
37+
Attributes:
38+
- Attribute: DW_AT_name
39+
Form: DW_FORM_strp
40+
- Attribute: DW_AT_low_pc
41+
Form: DW_FORM_addr
42+
- Attribute: DW_AT_high_pc
43+
Form: DW_FORM_addr
44+
debug_info:
45+
- Length: 0x27
46+
Version: 4
47+
AbbrevTableID: 0
48+
AbbrOffset: 0x0
49+
AddrSize: 8
50+
Entries:
51+
- AbbrCode: 0x1
52+
Values:
53+
- Value: 0x1
54+
- Value: 0x2
55+
- Value: 0x0
56+
- AbbrCode: 0x2
57+
Values:
58+
- Value: 0xA
59+
- Value: 0x1000
60+
- Value: 0x1050
61+
- AbbrCode: 0x0
62+
debug_line:
63+
- Length: 66
64+
Version: 2
65+
PrologueLength: 31
66+
MinInstLength: 1
67+
DefaultIsStmt: 1
68+
LineBase: 251
69+
LineRange: 14
70+
OpcodeBase: 13
71+
StandardOpcodeLengths: [ 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1 ]
72+
Files:
73+
- Name: main.cpp
74+
DirIdx: 0
75+
ModTime: 0
76+
Length: 0
77+
Opcodes:
78+
- Opcode: DW_LNS_extended_op
79+
ExtLen: 9
80+
SubOpcode: DW_LNE_set_address
81+
Data: 4096
82+
- Opcode: DW_LNS_advance_line
83+
SData: 9
84+
Data: 0
85+
- Opcode: DW_LNS_copy
86+
Data: 0
87+
- Opcode: DW_LNS_advance_pc
88+
Data: 16
89+
- Opcode: DW_LNS_advance_line
90+
SData: 1
91+
Data: 0
92+
- Opcode: DW_LNS_copy
93+
Data: 0
94+
- Opcode: DW_LNS_advance_line
95+
SData: 1
96+
Data: 0
97+
- Opcode: DW_LNS_copy
98+
Data: 0
99+
- Opcode: DW_LNS_advance_pc
100+
Data: 64
101+
- Opcode: DW_LNS_advance_line
102+
SData: 1
103+
Data: 0
104+
- Opcode: DW_LNS_extended_op
105+
ExtLen: 1
106+
SubOpcode: DW_LNE_end_sequence
107+
Data: 0
108+
...

0 commit comments

Comments
 (0)