Skip to content

Commit 057b612

Browse files
clayborggithub-actions[bot]
authored andcommitted
Automerge: Add the ability to load DWARF64 .debug_str_offsets tables for DWARF32 DWARF units in .dwp files. (#167986)
This path is updating the reading capabilities of the LLVM DWARF parser for a llvm-dwp patch llvm/llvm-project#167457 that will emit .dwp files where the compile units are DWARF32 and the .debug_str_offsets tables will be emitted as DWARF64 to allow .debug_str sections that exceed 4GB in size.
2 parents 6d55c84 + 8b59622 commit 057b612

File tree

2 files changed

+96
-2
lines changed

2 files changed

+96
-2
lines changed

llvm/lib/DebugInfo/DWARF/DWARFUnit.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,9 +1187,15 @@ DWARFUnit::determineStringOffsetsTableContributionDWO(DWARFDataExtractor &DA) {
11871187
if (getVersion() >= 5) {
11881188
if (DA.getData().data() == nullptr)
11891189
return std::nullopt;
1190-
Offset += Header.getFormat() == dwarf::DwarfFormat::DWARF32 ? 8 : 16;
1190+
// FYI: The .debug_str_offsets.dwo section may use DWARF64 even when the
1191+
// rest of the file uses DWARF32, so respect whichever encoding the
1192+
// header/length uses.
1193+
uint64_t Length = 0;
1194+
DwarfFormat Format = dwarf::DwarfFormat::DWARF32;
1195+
std::tie(Length, Format) = DA.getInitialLength(&Offset);
1196+
Offset += 4; // Skip the DWARF version uint16_t and the uint16_t padding.
11911197
// Look for a valid contribution at the given offset.
1192-
auto DescOrError = parseDWARFStringOffsetsTableHeader(DA, Header.getFormat(), Offset);
1198+
auto DescOrError = parseDWARFStringOffsetsTableHeader(DA, Format, Offset);
11931199
if (!DescOrError)
11941200
return DescOrError.takeError();
11951201
return *DescOrError;
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# This YAML file will create a .dwp file that has a DWARF32 compile unit whose
2+
# .debug_str_offsets.dwo is in DWARF64 format. This test verifies that
3+
# llvm-dwarfdump can read the strings correctly and dump the
4+
# .debug_str_offsets.dwo info correctly. This paves the way for llvm-dwp to
5+
# promote some .debug_str_offsets tables for .dwo files to be DWARF64 and will
6+
# allow the .debug_str section to be larger than UINT32_MAX size in bytes
7+
# without losing data.
8+
9+
# RUN: yaml2obj %s -o %t.dwp
10+
# RUN: llvm-dwarfdump --debug-str-offsets --debug-info %t.dwp | FileCheck %s
11+
12+
# CHECK: 0x00000000: Compile Unit: length = 0x0000002a, format = DWARF32, version = 0x0005, unit_type = DW_UT_split_compile, abbr_offset = 0x0000, addr_size = 0x08, DWO_id = 0x1158980a3c2f811b (next unit at 0x0000002e)
13+
14+
# CHECK: 0x00000014: DW_TAG_compile_unit
15+
# CHECK-NEXT: DW_AT_producer ("Apple clang version 17.0.0 (clang-1700.4.4.1)")
16+
# CHECK-NEXT: DW_AT_language (DW_LANG_C_plus_plus_14)
17+
# CHECK-NEXT: DW_AT_name ("main.minimal.cpp")
18+
# CHECK-NEXT: DW_AT_dwo_name ("main.minimal.dwo")
19+
20+
# CHECK: 0x0000001a: DW_TAG_subprogram
21+
# CHECK-NEXT: DW_AT_low_pc (indexed (00000000) address = <unresolved>)
22+
# CHECK-NEXT: DW_AT_high_pc (0x0000000f)
23+
# CHECK-NEXT: DW_AT_frame_base (DW_OP_reg6 RBP)
24+
# CHECK-NEXT: DW_AT_name ("main")
25+
# CHECK-NEXT: DW_AT_decl_file (0x00)
26+
# CHECK-NEXT: DW_AT_decl_line (1)
27+
# CHECK-NEXT: DW_AT_type (0x00000029 "int")
28+
# CHECK-NEXT: DW_AT_external (true)
29+
30+
# CHECK: 0x00000029: DW_TAG_base_type
31+
# CHECK-NEXT: DW_AT_name ("int")
32+
# CHECK-NEXT: DW_AT_encoding (DW_ATE_signed)
33+
# CHECK-NEXT: DW_AT_byte_size (0x04)
34+
35+
# CHECK: 0x0000002d: NULL
36+
37+
# CHECK: .debug_str_offsets.dwo contents:
38+
# CHECK-NEXT: 0x00000000: Contribution size = 44, Format = DWARF64, Version = 5
39+
# CHECK-NEXT: 0x00000010: 0000000000000000 "main"
40+
# CHECK-NEXT: 0x00000018: 0000000000000005 "int"
41+
# CHECK-NEXT: 0x00000020: 0000000000000009 "Apple clang version 17.0.0 (clang-1700.4.4.1)"
42+
# CHECK-NEXT: 0x00000028: 0000000000000037 "main.minimal.cpp"
43+
# CHECK-NEXT: 0x00000030: 0000000000000048 "main.minimal.dwo"
44+
45+
--- !ELF
46+
FileHeader:
47+
Class: ELFCLASS64
48+
Data: ELFDATA2LSB
49+
Type: ET_REL
50+
Machine: EM_X86_64
51+
SectionHeaderStringTable: .strtab
52+
Sections:
53+
- Name: .debug_abbrev.dwo
54+
Type: SHT_PROGBITS
55+
Flags: [ SHF_EXCLUDE ]
56+
AddressAlign: 0x1
57+
Content: 01110125251305032576250000022E00111B1206401803253A0B3B0B49133F19000003240003253E0B0B0B000000
58+
- Name: .debug_str.dwo
59+
Type: SHT_PROGBITS
60+
Flags: [ SHF_EXCLUDE, SHF_MERGE, SHF_STRINGS ]
61+
AddressAlign: 0x1
62+
EntSize: 0x1
63+
Content: 6D61696E00696E74004170706C6520636C616E672076657273696F6E2031372E302E302028636C616E672D313730302E342E342E3129006D61696E2E6D696E696D616C2E637070006D61696E2E6D696E696D616C2E64776F00
64+
- Name: .debug_str_offsets.dwo
65+
Type: SHT_PROGBITS
66+
Flags: [ SHF_EXCLUDE ]
67+
AddressAlign: 0x1
68+
Content: 'FFFFFFFF2C000000000000000500000000000000000000000500000000000000090000000000000037000000000000004800000000000000'
69+
- Name: .debug_info.dwo
70+
Type: SHT_PROGBITS
71+
Flags: [ SHF_EXCLUDE ]
72+
AddressAlign: 0x1
73+
Content: 2A00000005000508000000001B812F3C0A98581101022100030402000F0000000156000001290000000301050400
74+
- Name: .debug_cu_index
75+
Type: SHT_PROGBITS
76+
AddressAlign: 0x1
77+
Content: 0500000003000000010000000200000000000000000000001B812F3C0A98581100000000010000000100000003000000060000000000000000000000000000002E0000002E0000001C000000
78+
- Type: SectionHeaderTable
79+
Sections:
80+
- Name: .strtab
81+
- Name: .debug_abbrev.dwo
82+
- Name: .debug_str.dwo
83+
- Name: .debug_str_offsets.dwo
84+
- Name: .debug_info.dwo
85+
- Name: .debug_cu_index
86+
- Name: .symtab
87+
Symbols: []
88+
...

0 commit comments

Comments
 (0)