Skip to content

Commit 9c1f518

Browse files
rastogishubhamadrian-prantl
authored andcommitted
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 (cherry picked from commit b66b176)
1 parent 9004c0e commit 9c1f518

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
@@ -137,10 +137,9 @@ class DwarfEmitter {
137137
virtual MCSymbol *emitDwarfDebugRangeListHeader(const CompileUnit &Unit) = 0;
138138

139139
/// Emit debug ranges (.debug_ranges, .debug_rnglists) fragment.
140-
virtual void
141-
emitDwarfDebugRangeListFragment(const CompileUnit &Unit,
142-
const AddressRanges &LinkedRanges,
143-
PatchLocation Patch) = 0;
140+
virtual void emitDwarfDebugRangeListFragment(
141+
const CompileUnit &Unit, const AddressRanges &LinkedRanges,
142+
PatchLocation Patch, DebugAddrPool &AddrPool) = 0;
144143

145144
/// Emit debug ranges (.debug_ranges, .debug_rnglists) footer.
146145
virtual void emitDwarfDebugRangeListFooter(const CompileUnit &Unit,
@@ -821,7 +820,8 @@ class DWARFLinker {
821820

822821
/// Compute and emit debug ranges(.debug_aranges, .debug_ranges,
823822
/// .debug_rnglists) for \p Unit, patch the attributes referencing it.
824-
void generateUnitRanges(CompileUnit &Unit, const DWARFFile &File) const;
823+
void generateUnitRanges(CompileUnit &Unit, const DWARFFile &File,
824+
DebugAddrPool &AddrPool) const;
825825

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

llvm/include/llvm/DWARFLinker/DWARFStreamer.h

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

100101
/// Emit debug ranges(.debug_ranges, .debug_rnglists) footer.
101102
void emitDwarfDebugRangeListFooter(const CompileUnit &Unit,
@@ -217,7 +218,8 @@ class DwarfStreamer : public DwarfEmitter {
217218
/// Emit piece of .debug_rnglists for \p LinkedRanges.
218219
void emitDwarfDebugRngListsTableFragment(const CompileUnit &Unit,
219220
const AddressRanges &LinkedRanges,
220-
PatchLocation Patch);
221+
PatchLocation Patch,
222+
DebugAddrPool &AddrPool);
221223

222224
/// Emit piece of .debug_loc for \p LinkedRanges.
223225
void emitDwarfDebugLocTableFragment(

llvm/lib/DWARFLinker/DWARFLinker.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,8 +1812,8 @@ DIE *DWARFLinker::DIECloner::cloneDIE(const DWARFDie &InputDIE,
18121812
/// Patch the input object file relevant debug_ranges or debug_rnglists
18131813
/// entries and emit them in the output file. Update the relevant attributes
18141814
/// to point at the new entries.
1815-
void DWARFLinker::generateUnitRanges(CompileUnit &Unit,
1816-
const DWARFFile &File) const {
1815+
void DWARFLinker::generateUnitRanges(CompileUnit &Unit, const DWARFFile &File,
1816+
DebugAddrPool &AddrPool) const {
18171817
if (LLVM_UNLIKELY(Options.Update))
18181818
return;
18191819

@@ -1866,14 +1866,14 @@ void DWARFLinker::generateUnitRanges(CompileUnit &Unit,
18661866
}
18671867

18681868
// Emit linked ranges.
1869-
TheDwarfEmitter->emitDwarfDebugRangeListFragment(Unit, LinkedRanges,
1870-
AttributePatch);
1869+
TheDwarfEmitter->emitDwarfDebugRangeListFragment(
1870+
Unit, LinkedRanges, AttributePatch, AddrPool);
18711871
}
18721872

18731873
// Emit ranges for Unit AT_ranges attribute.
18741874
if (UnitRngListAttribute.has_value())
18751875
TheDwarfEmitter->emitDwarfDebugRangeListFragment(
1876-
Unit, LinkedFunctionRanges, *UnitRngListAttribute);
1876+
Unit, LinkedFunctionRanges, *UnitRngListAttribute, AddrPool);
18771877

18781878
// Emit ranges footer.
18791879
TheDwarfEmitter->emitDwarfDebugRangeListFooter(Unit, EndLabel);
@@ -2515,7 +2515,7 @@ uint64_t DWARFLinker::DIECloner::cloneAllCompileUnits(
25152515
if (LLVM_UNLIKELY(Linker.Options.Update))
25162516
continue;
25172517

2518-
Linker.generateUnitRanges(*CurrentUnit, File);
2518+
Linker.generateUnitRanges(*CurrentUnit, File, AddrPool);
25192519

25202520
auto ProcessExpr = [&](SmallVectorImpl<uint8_t> &SrcBytes,
25212521
SmallVectorImpl<uint8_t> &OutBytes,

llvm/lib/DWARFLinker/DWARFStreamer.cpp

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

444444
void DwarfStreamer::emitDwarfDebugRangeListFragment(
445445
const CompileUnit &Unit, const AddressRanges &LinkedRanges,
446-
PatchLocation Patch) {
446+
PatchLocation Patch, DebugAddrPool &AddrPool) {
447447
if (Unit.getOrigUnit().getVersion() < 5) {
448448
emitDwarfDebugRangesTableFragment(Unit, LinkedRanges, Patch);
449449
return;
450450
}
451451

452-
emitDwarfDebugRngListsTableFragment(Unit, LinkedRanges, Patch);
452+
emitDwarfDebugRngListsTableFragment(Unit, LinkedRanges, Patch, AddrPool);
453453
}
454454

455455
void DwarfStreamer::emitDwarfDebugRangeListFooter(const CompileUnit &Unit,
@@ -466,25 +466,35 @@ void DwarfStreamer::emitDwarfDebugRangeListFooter(const CompileUnit &Unit,
466466

467467
void DwarfStreamer::emitDwarfDebugRngListsTableFragment(
468468
const CompileUnit &Unit, const AddressRanges &LinkedRanges,
469-
PatchLocation Patch) {
469+
PatchLocation Patch, DebugAddrPool &AddrPool) {
470470
Patch.set(RngListsSectionSize);
471471

472472
// Make .debug_rnglists to be current section.
473473
MS->switchSection(MC->getObjectFileInfo()->getDwarfRnglistsSection());
474-
475-
unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
474+
std::optional<uint64_t> BaseAddress;
476475

477476
for (const AddressRange &Range : LinkedRanges) {
477+
478+
if (!BaseAddress) {
479+
BaseAddress = Range.start();
480+
481+
// Emit base address.
482+
MS->emitInt8(dwarf::DW_RLE_base_addressx);
483+
RngListsSectionSize += 1;
484+
RngListsSectionSize +=
485+
MS->emitULEB128IntValue(AddrPool.getAddrIndex(*BaseAddress));
486+
}
487+
478488
// Emit type of entry.
479-
MS->emitInt8(dwarf::DW_RLE_start_length);
489+
MS->emitInt8(dwarf::DW_RLE_offset_pair);
480490
RngListsSectionSize += 1;
481491

482-
// Emit start address.
483-
MS->emitIntValue(Range.start(), AddressSize);
484-
RngListsSectionSize += AddressSize;
492+
// Emit start offset relative to base address.
493+
RngListsSectionSize +=
494+
MS->emitULEB128IntValue(Range.start() - *BaseAddress);
485495

486-
// Emit length of the range.
487-
RngListsSectionSize += MS->emitULEB128IntValue(Range.end() - Range.start());
496+
// Emit end offset relative to base address.
497+
RngListsSectionSize += MS->emitULEB128IntValue(Range.end() - *BaseAddress);
488498
}
489499

490500
// 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)