Skip to content

Commit b66b176

Browse files
Emit DW_RLE_base_addressx + DW_RLE_offset_pairs
instead of DW_ELE_start_length in debug_rnglists section This patch tries to reduce the size of the debug_rnglist section by replacing the DW_RLE_start_length opcodes currently emitted by dsymutil in favor of using DW_RLE_base_addressx + DW_RLE_offset_pair instead. The DW_RLE_start_length is one AddressSize followed by a ULEB per entry, whereas, the DW_RLE_base_addressx + DW_RLE_offset_pair will use one ULEB for the base address, and then the DW_RLE_offset_pair is a pair of ULEBs. This will be more efficient. Differential Revision: https://reviews.llvm.org/D156166
1 parent 8ccc8b1 commit b66b176

File tree

8 files changed

+65
-43
lines changed

8 files changed

+65
-43
lines changed

llvm/include/llvm/DWARFLinker/DWARFLinker.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,9 @@ class DwarfEmitter {
140140
virtual MCSymbol *emitDwarfDebugRangeListHeader(const CompileUnit &Unit) = 0;
141141

142142
/// Emit debug ranges (.debug_ranges, .debug_rnglists) fragment.
143-
virtual void
144-
emitDwarfDebugRangeListFragment(const CompileUnit &Unit,
145-
const AddressRanges &LinkedRanges,
146-
PatchLocation Patch) = 0;
143+
virtual void emitDwarfDebugRangeListFragment(
144+
const CompileUnit &Unit, const AddressRanges &LinkedRanges,
145+
PatchLocation Patch, DebugAddrPool &AddrPool) = 0;
147146

148147
/// Emit debug ranges (.debug_ranges, .debug_rnglists) footer.
149148
virtual void emitDwarfDebugRangeListFooter(const CompileUnit &Unit,
@@ -825,7 +824,8 @@ class DWARFLinker {
825824

826825
/// Compute and emit debug ranges(.debug_aranges, .debug_ranges,
827826
/// .debug_rnglists) for \p Unit, patch the attributes referencing it.
828-
void generateUnitRanges(CompileUnit &Unit, const DWARFFile &File) const;
827+
void generateUnitRanges(CompileUnit &Unit, const DWARFFile &File,
828+
DebugAddrPool &AddrPool) const;
829829

830830
/// Emit the accelerator entries for \p Unit.
831831
void emitAcceleratorEntriesForUnit(CompileUnit &Unit);

llvm/include/llvm/DWARFLinker/DWARFStreamer.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ class DwarfStreamer : public DwarfEmitter {
9898
/// Emit debug ranges(.debug_ranges, .debug_rnglists) fragment.
9999
void emitDwarfDebugRangeListFragment(const CompileUnit &Unit,
100100
const AddressRanges &LinkedRanges,
101-
PatchLocation Patch) override;
101+
PatchLocation Patch,
102+
DebugAddrPool &AddrPool) override;
102103

103104
/// Emit debug ranges(.debug_ranges, .debug_rnglists) footer.
104105
void emitDwarfDebugRangeListFooter(const CompileUnit &Unit,
@@ -220,7 +221,8 @@ class DwarfStreamer : public DwarfEmitter {
220221
/// Emit piece of .debug_rnglists for \p LinkedRanges.
221222
void emitDwarfDebugRngListsTableFragment(const CompileUnit &Unit,
222223
const AddressRanges &LinkedRanges,
223-
PatchLocation Patch);
224+
PatchLocation Patch,
225+
DebugAddrPool &AddrPool);
224226

225227
/// Emit piece of .debug_loc for \p LinkedRanges.
226228
void emitDwarfDebugLocTableFragment(

llvm/lib/DWARFLinker/DWARFLinker.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1868,8 +1868,8 @@ DIE *DWARFLinker::DIECloner::cloneDIE(const DWARFDie &InputDIE,
18681868
/// Patch the input object file relevant debug_ranges or debug_rnglists
18691869
/// entries and emit them in the output file. Update the relevant attributes
18701870
/// to point at the new entries.
1871-
void DWARFLinker::generateUnitRanges(CompileUnit &Unit,
1872-
const DWARFFile &File) const {
1871+
void DWARFLinker::generateUnitRanges(CompileUnit &Unit, const DWARFFile &File,
1872+
DebugAddrPool &AddrPool) const {
18731873
if (LLVM_UNLIKELY(Options.Update))
18741874
return;
18751875

@@ -1922,14 +1922,14 @@ void DWARFLinker::generateUnitRanges(CompileUnit &Unit,
19221922
}
19231923

19241924
// Emit linked ranges.
1925-
TheDwarfEmitter->emitDwarfDebugRangeListFragment(Unit, LinkedRanges,
1926-
AttributePatch);
1925+
TheDwarfEmitter->emitDwarfDebugRangeListFragment(
1926+
Unit, LinkedRanges, AttributePatch, AddrPool);
19271927
}
19281928

19291929
// Emit ranges for Unit AT_ranges attribute.
19301930
if (UnitRngListAttribute.has_value())
19311931
TheDwarfEmitter->emitDwarfDebugRangeListFragment(
1932-
Unit, LinkedFunctionRanges, *UnitRngListAttribute);
1932+
Unit, LinkedFunctionRanges, *UnitRngListAttribute, AddrPool);
19331933

19341934
// Emit ranges footer.
19351935
TheDwarfEmitter->emitDwarfDebugRangeListFooter(Unit, EndLabel);
@@ -2571,7 +2571,7 @@ uint64_t DWARFLinker::DIECloner::cloneAllCompileUnits(
25712571
if (LLVM_UNLIKELY(Linker.Options.Update))
25722572
continue;
25732573

2574-
Linker.generateUnitRanges(*CurrentUnit, File);
2574+
Linker.generateUnitRanges(*CurrentUnit, File, AddrPool);
25752575

25762576
auto ProcessExpr = [&](SmallVectorImpl<uint8_t> &SrcBytes,
25772577
SmallVectorImpl<uint8_t> &OutBytes,

llvm/lib/DWARFLinker/DWARFStreamer.cpp

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -455,13 +455,13 @@ DwarfStreamer::emitDwarfDebugRangeListHeader(const CompileUnit &Unit) {
455455

456456
void DwarfStreamer::emitDwarfDebugRangeListFragment(
457457
const CompileUnit &Unit, const AddressRanges &LinkedRanges,
458-
PatchLocation Patch) {
458+
PatchLocation Patch, DebugAddrPool &AddrPool) {
459459
if (Unit.getOrigUnit().getVersion() < 5) {
460460
emitDwarfDebugRangesTableFragment(Unit, LinkedRanges, Patch);
461461
return;
462462
}
463463

464-
emitDwarfDebugRngListsTableFragment(Unit, LinkedRanges, Patch);
464+
emitDwarfDebugRngListsTableFragment(Unit, LinkedRanges, Patch, AddrPool);
465465
}
466466

467467
void DwarfStreamer::emitDwarfDebugRangeListFooter(const CompileUnit &Unit,
@@ -478,25 +478,35 @@ void DwarfStreamer::emitDwarfDebugRangeListFooter(const CompileUnit &Unit,
478478

479479
void DwarfStreamer::emitDwarfDebugRngListsTableFragment(
480480
const CompileUnit &Unit, const AddressRanges &LinkedRanges,
481-
PatchLocation Patch) {
481+
PatchLocation Patch, DebugAddrPool &AddrPool) {
482482
Patch.set(RngListsSectionSize);
483483

484484
// Make .debug_rnglists to be current section.
485485
MS->switchSection(MC->getObjectFileInfo()->getDwarfRnglistsSection());
486-
487-
unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
486+
std::optional<uint64_t> BaseAddress;
488487

489488
for (const AddressRange &Range : LinkedRanges) {
489+
490+
if (!BaseAddress) {
491+
BaseAddress = Range.start();
492+
493+
// Emit base address.
494+
MS->emitInt8(dwarf::DW_RLE_base_addressx);
495+
RngListsSectionSize += 1;
496+
RngListsSectionSize +=
497+
MS->emitULEB128IntValue(AddrPool.getAddrIndex(*BaseAddress));
498+
}
499+
490500
// Emit type of entry.
491-
MS->emitInt8(dwarf::DW_RLE_start_length);
501+
MS->emitInt8(dwarf::DW_RLE_offset_pair);
492502
RngListsSectionSize += 1;
493503

494-
// Emit start address.
495-
MS->emitIntValue(Range.start(), AddressSize);
496-
RngListsSectionSize += AddressSize;
504+
// Emit start offset relative to base address.
505+
RngListsSectionSize +=
506+
MS->emitULEB128IntValue(Range.start() - *BaseAddress);
497507

498-
// Emit length of the range.
499-
RngListsSectionSize += MS->emitULEB128IntValue(Range.end() - Range.start());
508+
// Emit end offset relative to base address.
509+
RngListsSectionSize += MS->emitULEB128IntValue(Range.end() - *BaseAddress);
500510
}
501511

502512
// Emit the terminator entry.

llvm/test/tools/dsymutil/ARM/dwarf5-dwarf4-combination-macho.test

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ CHECK: .debug_ranges contents:
146146
CHECK-NEXT: 00000000 [[#sub(RANGE_START,RANGE_LOWPC)]] [[#sub(RANGE_END,RANGE_LOWPC)]]
147147

148148
CHECK: .debug_rnglists contents:
149-
CHECK-NEXT: 0x00000000: range list header: length = 0x00000013, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
149+
CHECK-NEXT: 0x00000000: range list header: length = 0x0000000e, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
150150
CHECK-NEXT: ranges:
151-
CHECK-NEXT: [[RANGELIST_OFFSET]]: [DW_RLE_start_length]: {{.*}}[0x[[RANGELIST_OFFSET_START]], 0x[[RANGELIST_OFFSET_END]])
151+
CHECK-NEXT: [[RANGELIST_OFFSET]]: [DW_RLE_base_addressx]: 0x0000000000000000
152+
CHECK-NEXT: 0x0000000e: [DW_RLE_offset_pair ]: {{.*}}[0x[[RANGELIST_OFFSET_START]], 0x[[RANGELIST_OFFSET_END]])
153+
CHECK-NEXT: 0x00000011: [DW_RLE_end_of_list ]
152154

153155
CHECK: .debug_names contents:
154156
CHECK-NEXT: Name Index @ 0x0 {

llvm/test/tools/dsymutil/ARM/dwarf5-macho.test

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ CHECK-NEXT: 0x00000000: "/Users/shubham/Development/test109275485"
8484
CHECK-NEXT: 0x00000029: "a.cpp"
8585

8686
CHECK: .debug_rnglists contents:
87-
CHECK-NEXT: 0x00000000: range list header: length = 0x00000013, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
87+
CHECK-NEXT: 0x00000000: range list header: length = 0x0000000e, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
8888
CHECK-NEXT: ranges:
89-
CHECK-NEXT: [[RANGELIST_OFFSET]]: [DW_RLE_start_length]: {{.*}}[0x[[RANGELIST_OFFSET_START]], 0x[[RANGELIST_OFFSET_END]])
89+
CHECK-NEXT: [[RANGELIST_OFFSET]]: [DW_RLE_base_addressx]: 0x0000000000000000
90+
CHECK-NEXT: 0x0000000e: [DW_RLE_offset_pair ]: {{.*}}[0x[[RANGELIST_OFFSET_START]], 0x[[RANGELIST_OFFSET_END]])
91+
CHECK-NEXT: 0x00000011: [DW_RLE_end_of_list ]
9092

9193
CHECK: .debug_names contents:
9294
CHECK-NEX:T Name Index @ 0x0 {

llvm/test/tools/dsymutil/X86/dwarf5-rnglists.test

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@
4646
#DWARF-CHECK: [0x0000000100000f79, 0x0000000100000f96)
4747
#DWARF-CHECK: [0x0000000100000fad, 0x0000000100000fb4))
4848
#DWARF-CHECK: .debug_rnglists contents:
49-
#DWARF-CHECK: 0x00000000: range list header: length = 0x0000001d, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
49+
#DWARF-CHECK: 0x00000000: range list header: length = 0x00000011, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
5050
#DWARF-CHECK: ranges:
51-
#DWARF-CHECK: 0x0000000c: [DW_RLE_start_length]: 0x0000000100000f79, 0x000000000000001d => [0x0000000100000f79, 0x0000000100000f96)
52-
#DWARF-CHECK: 0x00000016: [DW_RLE_start_length]: 0x0000000100000fad, 0x0000000000000007 => [0x0000000100000fad, 0x0000000100000fb4)
53-
#DWARF-CHECK: 0x00000020: [DW_RLE_end_of_list ]
51+
#DWARF-CHECK: 0x0000000c: [DW_RLE_base_addressx]: 0x0000000000000003
52+
#DWARF-CHECK: 0x0000000e: [DW_RLE_offset_pair ]: 0x0000000000000000, 0x000000000000001d => [0x0000000100000f79, 0x0000000100000f96)
53+
#DWARF-CHECK: 0x00000011: [DW_RLE_offset_pair ]: 0x0000000000000034, 0x000000000000003b => [0x0000000100000fad, 0x0000000100000fb4)
54+
#DWARF-CHECK: 0x00000014: [DW_RLE_end_of_list ]
5455
#
5556
#UPD-DWARF-CHECK: DW_TAG_compile_unit
5657
#UPD-DWARF-CHECK: DW_AT_addr_base [DW_FORM_sec_offset] (0x00000008)

llvm/test/tools/llvm-dwarfutil/ELF/X86/dwarf5-rnglists.test

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,23 @@
6363
#DWARF-CHECK: 0x0000000000001160
6464
#DWARF-CHECK: ]
6565
#DWARF-CHECK: .debug_rnglists contents:
66-
#DWARF-CHECK: 0x00000000: range list header: length = 0x0000003f, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
66+
#DWARF-CHECK: 0x00000000: range list header: length = 0x00000026, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00, offset_entry_count = 0x00000000
6767
#DWARF-CHECK: ranges:
68-
#DWARF-CHECK: 0x[[F1RANGE_OFF]]: [DW_RLE_start_length]: 0x0000000000001130, 0x0000000000000010 => [0x0000000000001130, 0x0000000000001140)
69-
#DWARF-CHECK: {{.*}} [DW_RLE_end_of_list ]
70-
#DWARF-CHECK: 0x[[F2RANGE_OFF]]: [DW_RLE_start_length]: 0x0000000000001140, 0x0000000000000010 => [0x0000000000001140, 0x0000000000001150)
71-
#DWARF-CHECK: {{.*}} [DW_RLE_end_of_list ]
72-
#DWARF-CHECK: 0x[[F3RANGE_OFF]]: [DW_RLE_start_length]: 0x0000000000001150, 0x0000000000000010 => [0x0000000000001150, 0x0000000000001160)
73-
#DWARF-CHECK: {{.*}} [DW_RLE_end_of_list ]
74-
#DWARF-CHECK: 0x[[F4RANGE_OFF]]: [DW_RLE_start_length]: 0x0000000000001160, 0x0000000000000010 => [0x0000000000001160, 0x0000000000001170)
75-
#DWARF-CHECK: {{.*}} [DW_RLE_end_of_list ]
76-
#DWARF-CHECK: 0x[[CURANGE_OFF]]: [DW_RLE_start_length]: 0x0000000000001130, 0x0000000000000040 => [0x0000000000001130, 0x0000000000001170)
77-
#DWARF-CHECK: {{.*}} [DW_RLE_end_of_list ]
68+
#DWARF-CHECK: 0x[[F1RANGE_OFF]]: [DW_RLE_base_addressx]: 0x0000000000000000
69+
#DWARF-CHECK: {{.}}: [DW_RLE_offset_pair ]: 0x0000000000000000, 0x0000000000000010 => [0x0000000000001130, 0x0000000000001140)
70+
#DWARF-CHECK: {{.}}: [DW_RLE_end_of_list ]
71+
#DWARF-CHECK: 0x[[F2RANGE_OFF]]: [DW_RLE_base_addressx]: 0x0000000000000001
72+
#DWARF-CHECK: {{.}}: [DW_RLE_offset_pair ]: 0x0000000000000000, 0x0000000000000010 => [0x0000000000001140, 0x0000000000001150)
73+
#DWARF-CHECK: {{.}}: [DW_RLE_end_of_list ]
74+
#DWARF-CHECK: 0x[[F3RANGE_OFF]]: [DW_RLE_base_addressx]: 0x0000000000000002
75+
#DWARF-CHECK: {{.}}: [DW_RLE_offset_pair ]: 0x0000000000000000, 0x0000000000000010 => [0x0000000000001150, 0x0000000000001160)
76+
#DWARF-CHECK: {{.}}: [DW_RLE_end_of_list ]
77+
#DWARF-CHECK: 0x[[F4RANGE_OFF]]: [DW_RLE_base_addressx]: 0x0000000000000003
78+
#DWARF-CHECK: {{.}}: [DW_RLE_offset_pair ]: 0x0000000000000000, 0x0000000000000010 => [0x0000000000001160, 0x0000000000001170)
79+
#DWARF-CHECK: {{.}}: [DW_RLE_end_of_list ]
80+
#DWARF-CHECK 0x[[CURANGE_OFF]]: [DW_RLE_base_addressx]: 0x0000000000000000
81+
#DWARF-CHECK: {{.}}: [DW_RLE_offset_pair ]: 0x0000000000000000, 0x0000000000000040 => [0x0000000000001130, 0x0000000000001170)
82+
#DWARF-CHECK: {{.}}: [DW_RLE_end_of_list ]
7883

7984
#UPD-DWARF-CHECK: DW_TAG_compile_unit
8085
#UPD-DWARF-CHECK: DW_AT_name {{.*}}"CU1"

0 commit comments

Comments
 (0)