Skip to content

Commit 5a9ef6c

Browse files
committed
[DWARF] Support 64-bit DWARF in .debug_pubnames and similar tables.
Differential Revision: https://reviews.llvm.org/D73103
1 parent 0e3ae35 commit 5a9ef6c

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

llvm/include/llvm/DebugInfo/DWARF/DWARFDebugPubTable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class DWARFDebugPubTable {
4242
struct Set {
4343
/// The total length of the entries for that set, not including the length
4444
/// field itself.
45-
uint32_t Length;
45+
uint64_t Length;
4646

4747
/// This number is specific to the name lookup table and is independent of
4848
/// the DWARF version number.
@@ -54,7 +54,7 @@ class DWARFDebugPubTable {
5454

5555
/// The size in bytes of the contents of the .debug_info section generated
5656
/// to represent that compilation unit.
57-
uint32_t Size;
57+
uint64_t Size;
5858

5959
std::vector<Entry> Entries;
6060
};

llvm/lib/DebugInfo/DWARF/DWARFDebugPubTable.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,20 @@ DWARFDebugPubTable::DWARFDebugPubTable(const DWARFObject &Obj,
2828
Sets.push_back({});
2929
Set &SetData = Sets.back();
3030

31+
dwarf::DwarfFormat Format = dwarf::DWARF32;
3132
SetData.Length = PubNames.getU32(&Offset);
33+
if (SetData.Length == dwarf::DW_LENGTH_DWARF64) {
34+
Format = dwarf::DWARF64;
35+
SetData.Length = PubNames.getU64(&Offset);
36+
}
37+
const unsigned OffsetSize = dwarf::getDwarfOffsetByteSize(Format);
38+
3239
SetData.Version = PubNames.getU16(&Offset);
33-
SetData.Offset = PubNames.getRelocatedValue(4, &Offset);
34-
SetData.Size = PubNames.getU32(&Offset);
40+
SetData.Offset = PubNames.getRelocatedValue(OffsetSize, &Offset);
41+
SetData.Size = PubNames.getUnsigned(&Offset, OffsetSize);
3542

3643
while (Offset < Sec.Data.size()) {
37-
uint32_t DieRef = PubNames.getU32(&Offset);
44+
uint64_t DieRef = PubNames.getUnsigned(&Offset, OffsetSize);
3845
if (DieRef == 0)
3946
break;
4047
uint8_t IndexEntryValue = GnuStyle ? PubNames.getU8(&Offset) : 0;
@@ -47,10 +54,10 @@ DWARFDebugPubTable::DWARFDebugPubTable(const DWARFObject &Obj,
4754

4855
void DWARFDebugPubTable::dump(raw_ostream &OS) const {
4956
for (const Set &S : Sets) {
50-
OS << "length = " << format("0x%08x", S.Length);
57+
OS << "length = " << format("0x%08" PRIx64, S.Length);
5158
OS << " version = " << format("0x%04x", S.Version);
5259
OS << " unit_offset = " << format("0x%08" PRIx64, S.Offset);
53-
OS << " unit_size = " << format("0x%08x", S.Size) << '\n';
60+
OS << " unit_size = " << format("0x%08" PRIx64, S.Size) << '\n';
5461
OS << (GnuStyle ? "Offset Linkage Kind Name\n"
5562
: "Offset Name\n");
5663

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# RUN: llvm-mc -triple x86_64-unknown-linux %s -filetype=obj -o - | \
2+
# RUN: llvm-dwarfdump -debug-pubnames - | \
3+
# RUN: FileCheck %s
4+
5+
# CHECK: .debug_pubnames contents:
6+
# CHECK-NEXT: length = 0x00000032
7+
# CHECK-SAME: version = 0x0002
8+
# CHECK-SAME: unit_offset = 0x1122334455667788
9+
# CHECK-SAME: unit_size = 0x1100220033004400
10+
# CHECK-NEXT: Offset Name
11+
# CHECK-NEXT: 0xaa01aaaabbbbbbbb "foo"
12+
# CHECK-NEXT: 0xaa02aaaabbbbbbbb "bar"
13+
14+
.section .debug_pubnames,"",@progbits
15+
.long 0xffffffff # DWARF64 mark
16+
.quad .Lend - .Lversion # Unit Length
17+
.Lversion:
18+
.short 2 # Version
19+
.quad 0x1122334455667788 # Debug Info Offset
20+
.quad 0x1100220033004400 # Debug Info Length
21+
.quad 0xaa01aaaabbbbbbbb # Tuple0: Offset
22+
.asciz "foo" # Name
23+
.quad 0xaa02aaaabbbbbbbb # Tuple1: Offset
24+
.asciz "bar" # Name
25+
.quad 0 # Terminator
26+
.Lend:

0 commit comments

Comments
 (0)