Skip to content

Commit 3a7a5bf

Browse files
committed
[dsymutil] Support and relocate base address selection entries for debug_loc
Since r374600 clang emits base address selection entries. Currently dsymutil does not support these entries and incorrectly interprets them as location list entries. This patch adds support for base address selection entries in dsymutil and makes sure they are relocated correctly. Thanks to Dave for coming up with the test case! Differential revision: https://reviews.llvm.org/D69005 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@374957 91177308-0d34-0410-b5e6-96231b3b80d8 (cherry picked from commit cd6834c109a8d99666ab4471b6f275bd32e09766) apple-llvm-split-commit: bbec568f9f7aae5c3af01d7b1d2698ed842e011d apple-llvm-split-dir: llvm/
1 parent 7807353 commit 3a7a5bf

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed
Binary file not shown.
Binary file not shown.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
RUN: dsymutil -oso-prepend-path %p/../Inputs %p/../Inputs/private/tmp/baseaddr/loc1.x86_64 -f -o - | llvm-dwarfdump -debug-loc - | FileCheck %s
2+
3+
The test was compiled from a single source:
4+
$ cat loc1.cpp
5+
int f1(int i, int j) {
6+
int x = 5;
7+
int y = 3;
8+
int r = i + j;
9+
int undef;
10+
x = undef;
11+
y = 4;
12+
return r;
13+
}
14+
__attribute__((nodebug)) void f2() {
15+
}
16+
int main() {
17+
return 0;
18+
}
19+
20+
CHECK: .debug_loc contents:
21+
CHECK: [0xffffffffffffffff, 0x0000000100000f90):
22+
CHECK: [0x0000000000000004, 0x0000000000000007): DW_OP_consts +3, DW_OP_stack_value
23+
CHECK: [0x0000000000000007, 0x0000000000000009): DW_OP_consts +4, DW_OP_stack_value
24+
25+
CHECK: [0xffffffffffffffff, 0x0000000100000f90):
26+
CHECK: [0x0000000000000004, 0x0000000000000007): DW_OP_consts +5, DW_OP_stack_value
27+
28+
CHECK: [0xffffffffffffffff, 0x0000000100000f90):
29+
CHECK: [0x0000000000000007, 0x0000000000000009): DW_OP_reg0 RAX

llvm/tools/dsymutil/DwarfStreamer.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ void DwarfStreamer::emitLocationsForUnit(
395395
MS->SwitchSection(MC->getObjectFileInfo()->getDwarfLocSection());
396396

397397
unsigned AddressSize = Unit.getOrigUnit().getAddressByteSize();
398+
uint64_t BaseAddressMarker = (AddressSize == 8)
399+
? std::numeric_limits<uint64_t>::max()
400+
: std::numeric_limits<uint32_t>::max();
398401
const DWARFSection &InputSec = Dwarf.getDWARFObj().getLocSection();
399402
DataExtractor Data(InputSec.Data, Dwarf.isLittleEndian(), AddressSize);
400403
DWARFUnit &OrigUnit = Unit.getOrigUnit();
@@ -414,11 +417,20 @@ void DwarfStreamer::emitLocationsForUnit(
414417
uint64_t Low = Data.getUnsigned(&Offset, AddressSize);
415418
uint64_t High = Data.getUnsigned(&Offset, AddressSize);
416419
LocSectionSize += 2 * AddressSize;
420+
// End of list entry.
417421
if (Low == 0 && High == 0) {
418422
Asm->OutStreamer->EmitIntValue(0, AddressSize);
419423
Asm->OutStreamer->EmitIntValue(0, AddressSize);
420424
break;
421425
}
426+
// Base address selection entry.
427+
if (Low == BaseAddressMarker) {
428+
Asm->OutStreamer->EmitIntValue(BaseAddressMarker, AddressSize);
429+
Asm->OutStreamer->EmitIntValue(High + Attr.second, AddressSize);
430+
LocPcOffset = 0;
431+
continue;
432+
}
433+
// Location list entry.
422434
Asm->OutStreamer->EmitIntValue(Low + LocPcOffset, AddressSize);
423435
Asm->OutStreamer->EmitIntValue(High + LocPcOffset, AddressSize);
424436
uint64_t Length = Data.getU16(&Offset);

0 commit comments

Comments
 (0)