Skip to content

Commit e74197b

Browse files
committed
[Reland][Debuginfo][llvm-dwarfutil] Add check for unsupported debug sections.
Current DWARFLinker implementation does not support some debug sections (mainly DWARF v5 sections). This patch adds diagnostic for such sections. The warning would be displayed for critical(such that could not be removed) sections and the source file would be skipped. Other unsupported sections would be removed and warning message should be displayed. The zero exit status would be returned for both cases. Reviewed By: JDevlieghere Differential Revision: https://reviews.llvm.org/D123623
1 parent 0f93a45 commit e74197b

19 files changed

+716
-20
lines changed

llvm/include/llvm/DWARFLinker/DWARFLinker.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class DWARFLinker {
245245

246246
/// Link debug info for added objFiles. Object
247247
/// files are linked all together.
248-
bool link();
248+
Error link();
249249

250250
/// A number of methods setting various linking options:
251251

llvm/lib/DWARFLinker/DWARFLinker.cpp

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2343,7 +2343,7 @@ void DWARFLinker::addObjectFile(DWARFFile &File) {
23432343
updateAccelKind(*ObjectContexts.back().File.Dwarf);
23442344
}
23452345

2346-
bool DWARFLinker::link() {
2346+
Error DWARFLinker::link() {
23472347
assert(Options.NoOutput || TheDwarfEmitter);
23482348

23492349
// A unique ID that identifies each compile unit.
@@ -2410,6 +2410,58 @@ bool DWARFLinker::link() {
24102410
if (!OptContext.File.Dwarf)
24112411
continue;
24122412

2413+
// Check whether type units are presented.
2414+
if (!OptContext.File.Dwarf->types_section_units().empty()) {
2415+
reportWarning("type units are not currently supported: file will "
2416+
"be skipped",
2417+
OptContext.File);
2418+
OptContext.Skip = true;
2419+
continue;
2420+
}
2421+
2422+
// Check for unsupported sections. Following sections can be referenced
2423+
// from .debug_info section. Current DWARFLinker implementation does not
2424+
// support or update references to these tables. Thus we report warning
2425+
// and skip corresponding object file.
2426+
if (!OptContext.File.Dwarf->getDWARFObj()
2427+
.getRnglistsSection()
2428+
.Data.empty()) {
2429+
reportWarning("'.debug_rnglists' is not currently supported: file "
2430+
"will be skipped",
2431+
OptContext.File);
2432+
OptContext.Skip = true;
2433+
continue;
2434+
}
2435+
2436+
if (!OptContext.File.Dwarf->getDWARFObj()
2437+
.getLoclistsSection()
2438+
.Data.empty()) {
2439+
reportWarning("'.debug_loclists' is not currently supported: file "
2440+
"will be skipped",
2441+
OptContext.File);
2442+
OptContext.Skip = true;
2443+
continue;
2444+
}
2445+
2446+
if (!OptContext.File.Dwarf->getDWARFObj().getMacroSection().Data.empty()) {
2447+
reportWarning("'.debug_macro' is not currently supported: file "
2448+
"will be skipped",
2449+
OptContext.File);
2450+
OptContext.Skip = true;
2451+
continue;
2452+
}
2453+
2454+
if (OptContext.File.Dwarf->getDWARFObj().getMacinfoSection().size() > 0) {
2455+
if (OptContext.File.Dwarf->getDWARFObj().getMacinfoSection().find_if(
2456+
[](char Sym) { return Sym != 0; }) != StringRef::npos) {
2457+
reportWarning("'.debug_macinfo' is not currently supported: file "
2458+
"will be skipped",
2459+
OptContext.File);
2460+
OptContext.Skip = true;
2461+
continue;
2462+
}
2463+
}
2464+
24132465
// In a first phase, just read in the debug info and load all clang modules.
24142466
OptContext.CompileUnits.reserve(
24152467
OptContext.File.Dwarf->getNumCompileUnits());
@@ -2660,7 +2712,7 @@ bool DWARFLinker::link() {
26602712
"---------------\n\n";
26612713
}
26622714

2663-
return true;
2715+
return Error::success();
26642716
}
26652717

26662718
bool DWARFLinker::verify(const DWARFFile &File) {
Binary file not shown.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## This test checks the warning message displayed if input file
2+
## contains .debug_cu_index section.
3+
4+
# RUN: yaml2obj %s -o %t.o
5+
6+
# RUN: llvm-dwarfutil --garbage-collection %t.o %t1 2>&1 | FileCheck %s -DFILE=%t.o
7+
8+
# CHECK: [[FILE]]: warning: '.debug_cu_index' is not currently supported: section will be skipped
9+
10+
--- !ELF
11+
FileHeader:
12+
Class: ELFCLASS64
13+
Data: ELFDATA2LSB
14+
Type: ET_REL
15+
Machine: EM_X86_64
16+
Sections:
17+
- Name: .text
18+
Type: SHT_PROGBITS
19+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
20+
Address: 0x1000
21+
AddressAlign: 0x0000000000000010
22+
Content: "FFFFFFFF"
23+
- Name: .debug_cu_index
24+
Type: SHT_PROGBITS
25+
Flags: [ ]
26+
Content: "0000"
27+
DWARF:
28+
debug_abbrev:
29+
- Table:
30+
- Tag: DW_TAG_compile_unit
31+
Children: DW_CHILDREN_yes
32+
Attributes:
33+
- Attribute: DW_AT_producer
34+
Form: DW_FORM_string
35+
- Attribute: DW_AT_language
36+
Form: DW_FORM_data2
37+
- Attribute: DW_AT_name
38+
Form: DW_FORM_string
39+
- Attribute: DW_AT_low_pc
40+
Form: DW_FORM_addr
41+
- Attribute: DW_AT_high_pc
42+
Form: DW_FORM_data8
43+
debug_info:
44+
- Version: 4
45+
Entries:
46+
- AbbrCode: 1
47+
Values:
48+
- CStr: by_hand
49+
- Value: 0x04
50+
- CStr: CU1
51+
- Value: 0x1000
52+
- Value: 0x4
53+
- AbbrCode: 0
54+
...
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## This test checks the warning message displayed if input file
2+
## contains .gdb_index section.
3+
4+
# RUN: yaml2obj %s -o %t.o
5+
6+
# RUN: llvm-dwarfutil --garbage-collection %t.o %t1 2>&1 | FileCheck %s -DFILE=%t.o
7+
8+
# CHECK: [[FILE]]: warning: '.gdb_index' is not currently supported: section will be skipped
9+
10+
--- !ELF
11+
FileHeader:
12+
Class: ELFCLASS64
13+
Data: ELFDATA2LSB
14+
Type: ET_REL
15+
Machine: EM_X86_64
16+
Sections:
17+
- Name: .text
18+
Type: SHT_PROGBITS
19+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
20+
Address: 0x1000
21+
AddressAlign: 0x0000000000000010
22+
Content: "FFFFFFFF"
23+
- Name: .gdb_index
24+
Type: SHT_PROGBITS
25+
Flags: [ ]
26+
Content: "0000"
27+
DWARF:
28+
debug_abbrev:
29+
- Table:
30+
- Tag: DW_TAG_compile_unit
31+
Children: DW_CHILDREN_yes
32+
Attributes:
33+
- Attribute: DW_AT_producer
34+
Form: DW_FORM_string
35+
- Attribute: DW_AT_language
36+
Form: DW_FORM_data2
37+
- Attribute: DW_AT_name
38+
Form: DW_FORM_string
39+
- Attribute: DW_AT_low_pc
40+
Form: DW_FORM_addr
41+
- Attribute: DW_AT_high_pc
42+
Form: DW_FORM_data8
43+
debug_info:
44+
- Version: 4
45+
Entries:
46+
- AbbrCode: 1
47+
Values:
48+
- CStr: by_hand
49+
- Value: 0x04
50+
- CStr: CU1
51+
- Value: 0x1000
52+
- Value: 0x4
53+
- AbbrCode: 0
54+
...
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## This test checks the warning message displayed if input file
2+
## contains .debug_pubnames section.
3+
4+
# RUN: yaml2obj %s -o %t.o
5+
6+
# RUN: llvm-dwarfutil --garbage-collection %t.o %t1 2>&1 | FileCheck %s -DFILE=%t.o
7+
8+
# CHECK: [[FILE]]: warning: '.debug_gnu_pubnames' is not currently supported: section will be skipped
9+
10+
--- !ELF
11+
FileHeader:
12+
Class: ELFCLASS64
13+
Data: ELFDATA2LSB
14+
Type: ET_REL
15+
Machine: EM_X86_64
16+
Sections:
17+
- Name: .text
18+
Type: SHT_PROGBITS
19+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
20+
Address: 0x1000
21+
AddressAlign: 0x0000000000000010
22+
Content: "FFFFFFFF"
23+
- Name: .debug_gnu_pubnames
24+
Type: SHT_PROGBITS
25+
Flags: [ ]
26+
Content: "0000"
27+
DWARF:
28+
debug_abbrev:
29+
- Table:
30+
- Tag: DW_TAG_compile_unit
31+
Children: DW_CHILDREN_yes
32+
Attributes:
33+
- Attribute: DW_AT_producer
34+
Form: DW_FORM_string
35+
- Attribute: DW_AT_language
36+
Form: DW_FORM_data2
37+
- Attribute: DW_AT_name
38+
Form: DW_FORM_string
39+
- Attribute: DW_AT_low_pc
40+
Form: DW_FORM_addr
41+
- Attribute: DW_AT_high_pc
42+
Form: DW_FORM_data8
43+
debug_info:
44+
- Version: 4
45+
Entries:
46+
- AbbrCode: 1
47+
Values:
48+
- CStr: by_hand
49+
- Value: 0x04
50+
- CStr: CU1
51+
- Value: 0x1000
52+
- Value: 0x4
53+
- AbbrCode: 0
54+
...
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## This test checks the warning message displayed if input file
2+
## contains .debug_gnu_pubtypes section.
3+
4+
# RUN: yaml2obj %s -o %t.o
5+
6+
# RUN: llvm-dwarfutil --garbage-collection %t.o %t1 2>&1 | FileCheck %s -DFILE=%t.o
7+
8+
# CHECK: [[FILE]]: warning: '.debug_gnu_pubtypes' is not currently supported: section will be skipped
9+
10+
--- !ELF
11+
FileHeader:
12+
Class: ELFCLASS64
13+
Data: ELFDATA2LSB
14+
Type: ET_REL
15+
Machine: EM_X86_64
16+
Sections:
17+
- Name: .text
18+
Type: SHT_PROGBITS
19+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
20+
Address: 0x1000
21+
AddressAlign: 0x0000000000000010
22+
Content: "FFFFFFFF"
23+
- Name: .debug_gnu_pubtypes
24+
Type: SHT_PROGBITS
25+
Flags: [ ]
26+
Content: "0000"
27+
DWARF:
28+
debug_abbrev:
29+
- Table:
30+
- Tag: DW_TAG_compile_unit
31+
Children: DW_CHILDREN_yes
32+
Attributes:
33+
- Attribute: DW_AT_producer
34+
Form: DW_FORM_string
35+
- Attribute: DW_AT_language
36+
Form: DW_FORM_data2
37+
- Attribute: DW_AT_name
38+
Form: DW_FORM_string
39+
- Attribute: DW_AT_low_pc
40+
Form: DW_FORM_addr
41+
- Attribute: DW_AT_high_pc
42+
Form: DW_FORM_data8
43+
debug_info:
44+
- Version: 4
45+
Entries:
46+
- AbbrCode: 1
47+
Values:
48+
- CStr: by_hand
49+
- Value: 0x04
50+
- CStr: CU1
51+
- Value: 0x1000
52+
- Value: 0x4
53+
- AbbrCode: 0
54+
...
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## This test checks the warning message displayed if input file
2+
## contains .debug_loclists section.
3+
4+
# RUN: yaml2obj %s -o %t.o
5+
6+
# RUN: llvm-dwarfutil --garbage-collection %t.o %t1 2>&1 | FileCheck %s -DFILE=%t.o
7+
8+
# CHECK: [[FILE]]: warning: '.debug_loclists' is not currently supported: file will be skipped
9+
10+
--- !ELF
11+
FileHeader:
12+
Class: ELFCLASS64
13+
Data: ELFDATA2LSB
14+
Type: ET_REL
15+
Machine: EM_X86_64
16+
Sections:
17+
- Name: .text
18+
Type: SHT_PROGBITS
19+
Flags: [ SHF_ALLOC, SHF_EXECINSTR ]
20+
Address: 0x1000
21+
AddressAlign: 0x0000000000000010
22+
Content: "FFFFFFFF"
23+
- Name: .debug_loclists
24+
Type: SHT_PROGBITS
25+
Flags: [ ]
26+
Content: "0000000000000000000000"
27+
DWARF:
28+
debug_abbrev:
29+
- Table:
30+
- Tag: DW_TAG_compile_unit
31+
Children: DW_CHILDREN_yes
32+
Attributes:
33+
- Attribute: DW_AT_producer
34+
Form: DW_FORM_string
35+
- Attribute: DW_AT_language
36+
Form: DW_FORM_data2
37+
- Attribute: DW_AT_name
38+
Form: DW_FORM_string
39+
- Attribute: DW_AT_low_pc
40+
Form: DW_FORM_addr
41+
- Attribute: DW_AT_high_pc
42+
Form: DW_FORM_data8
43+
debug_info:
44+
- Version: 4
45+
Entries:
46+
- AbbrCode: 1
47+
Values:
48+
- CStr: by_hand
49+
- Value: 0x04
50+
- CStr: CU1
51+
- Value: 0x1000
52+
- Value: 0x4
53+
- AbbrCode: 0
54+
...

0 commit comments

Comments
 (0)