Skip to content

Commit 0ce5fa2

Browse files
daniilavdeevgithub-actions[bot]
authored andcommitted
Automerge: [dwarf] make dwarf fission compatible with RISCV relaxations 2/2 (#164813)
This patch makes DWARF fission compatible with RISC-V relaxations by using indirect addressing for the DW_AT_high_pc attribute. This eliminates the remaining relocations in .dwo files.
2 parents a444c88 + cc1c417 commit 0ce5fa2

File tree

2 files changed

+38
-23
lines changed

2 files changed

+38
-23
lines changed

llvm/lib/CodeGen/AsmPrinter/DwarfCompileUnit.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -493,10 +493,12 @@ void DwarfCompileUnit::attachLowHighPC(DIE &D, const MCSymbol *Begin,
493493
assert(End->isDefined() && "Invalid end label");
494494

495495
addLabelAddress(D, dwarf::DW_AT_low_pc, Begin);
496-
if (DD->getDwarfVersion() < 4)
497-
addLabelAddress(D, dwarf::DW_AT_high_pc, End);
498-
else
496+
if (DD->getDwarfVersion() >= 4 &&
497+
(!isDwoUnit() || !llvm::isRangeRelaxable(Begin, End))) {
499498
addLabelDelta(D, dwarf::DW_AT_high_pc, End, Begin);
499+
return;
500+
}
501+
addLabelAddress(D, dwarf::DW_AT_high_pc, End);
500502
}
501503

502504
// Add info for Wasm-global-based relocation.

llvm/test/DebugInfo/RISCV/relax_dwo_ranges.ll

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,68 +20,81 @@
2020

2121
; RUN: llc -dwarf-version=5 -split-dwarf-file=foo.dwo -O0 -mtriple=riscv64-unknown-linux-gnu -filetype=obj relax_dwo_ranges.ll -o %t.o
2222
; RUN: llvm-dwarfdump -v %t.o | FileCheck --check-prefix=DWARF5 %s
23-
; RUN: llvm-dwarfdump --debug-info %t.o 2> %t.txt
24-
; RUN: FileCheck --input-file=%t.txt %s --check-prefix=RELOCS --implicit-check-not=warning:
23+
; RUN: llvm-dwarfdump --debug-info %t.o > /dev/null 2>&1 | count 0
24+
; RUN: llvm-objdump -h %t.o | FileCheck --check-prefix=HDR %s
2525

2626
; RUN: llc -dwarf-version=4 -split-dwarf-file=foo.dwo -O0 -mtriple=riscv64-unknown-linux-gnu -filetype=obj relax_dwo_ranges.ll -o %t.o
2727
; RUN: llvm-dwarfdump -v %t.o | FileCheck --check-prefix=DWARF4 %s
28-
; RUN: llvm-dwarfdump --debug-info %t.o 2> %t.txt
29-
; RUN: FileCheck --input-file=%t.txt %s --check-prefix=RELOCS --implicit-check-not=warning:
28+
; RUN: llvm-dwarfdump --debug-info %t.o > /dev/null 2>&1 | count 0
29+
; RUN: llvm-objdump -h %t.o | FileCheck --check-prefix=HDR %s
3030

31-
; Currently, square() still uses an offset to represent the function's end address,
32-
; which requires a relocation here.
33-
; RELOCS: warning: unexpected relocations for dwo section '.debug_info.dwo'
31+
; Make sure we don't produce any relocations in any .dwo section
32+
; HDR-NOT: .rela.{{.*}}.dwo
3433

34+
; Ensure that 'square()' function uses indexed start and end addresses
3535
; DWARF5: .debug_info.dwo contents:
3636
; DWARF5: DW_TAG_subprogram
37-
; DWARF5-NEXT: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000000) address = 0x0000000000000000 ".text")
38-
; DWARF5-NEXT: DW_AT_high_pc [DW_FORM_data4] (0x00000000)
39-
; DWARF5: DW_AT_name {{.*}} "square")
37+
; DWARF5-NEXT: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000000) address = 0x0000000000000000 ".text")
38+
; DWARF5-NEXT: DW_AT_high_pc [DW_FORM_addrx] (indexed (00000001) address = 0x000000000000002c ".text")
39+
; DWARF5: DW_AT_name {{.*}} "square")
4040
; DWARF5: DW_TAG_formal_parameter
4141

42+
; HDR-NOT: .rela.{{.*}}.dwo
43+
4244
; Ensure there is no unnecessary addresses in .o file
4345
; DWARF5: .debug_addr contents:
4446
; DWARF5: Addrs: [
4547
; DWARF5-NEXT: 0x0000000000000000
4648
; DWARF5-NEXT: 0x000000000000002c
49+
; DWARF5-NEXT: 0x000000000000002c
4750
; DWARF5-NEXT: 0x000000000000003e
4851
; DWARF5-NEXT: 0x000000000000006e
4952
; DWARF5-NEXT: ]
5053

54+
; HDR-NOT: .rela.{{.*}}.dwo
55+
5156
; Ensure that 'boo()' and 'main()' use DW_RLE_startx_length and DW_RLE_startx_endx
5257
; entries respectively
5358
; DWARF5: .debug_rnglists.dwo contents:
5459
; DWARF5: ranges:
55-
; DWARF5-NEXT: 0x00000014: [DW_RLE_startx_length]: 0x0000000000000001, 0x0000000000000012 => [0x000000000000002c, 0x000000000000003e)
60+
; DWARF5-NEXT: 0x00000014: [DW_RLE_startx_length]: 0x0000000000000002, 0x0000000000000012 => [0x000000000000002c, 0x000000000000003e)
5661
; DWARF5-NEXT: 0x00000017: [DW_RLE_end_of_list ]
57-
; DWARF5-NEXT: 0x00000018: [DW_RLE_startx_endx ]: 0x0000000000000002, 0x0000000000000003 => [0x000000000000003e, 0x000000000000006e)
62+
; DWARF5-NEXT: 0x00000018: [DW_RLE_startx_endx ]: 0x0000000000000003, 0x0000000000000004 => [0x000000000000003e, 0x000000000000006e)
5863
; DWARF5-NEXT: 0x0000001b: [DW_RLE_end_of_list ]
5964
; DWARF5-EMPTY:
6065

66+
; HDR-NOT: .rela.{{.*}}.dwo
67+
6168
; DWARF4: .debug_info.dwo contents:
6269
; DWARF4: DW_TAG_subprogram
63-
; DWARF4-NEXT: DW_AT_low_pc [DW_FORM_GNU_addr_index] (indexed (00000000) address = 0x0000000000000000 ".text")
64-
; DWARF4-NEXT: DW_AT_high_pc [DW_FORM_data4] (0x00000000)
65-
; DWARF4: DW_AT_name {{.*}} "square")
70+
; DWARF4-NEXT: DW_AT_low_pc [DW_FORM_GNU_addr_index] (indexed (00000000) address = 0x0000000000000000 ".text")
71+
; DWARF4-NEXT: DW_AT_high_pc [DW_FORM_GNU_addr_index] (indexed (00000001) address = 0x000000000000002c ".text")
72+
; DWARF4: DW_AT_name {{.*}} "square")
6673

6774
; DWARF4: DW_TAG_subprogram
68-
; DWARF4-NEXT: DW_AT_low_pc [DW_FORM_GNU_addr_index] (indexed (00000001) address = 0x000000000000002c ".text")
75+
; DWARF4-NEXT: DW_AT_low_pc [DW_FORM_GNU_addr_index] (indexed (00000002) address = 0x000000000000002c ".text")
6976
; DWARF4-NEXT: DW_AT_high_pc [DW_FORM_data4] (0x00000012)
70-
; DWARF4: DW_AT_name {{.*}} "boo")
77+
; DWARF4: DW_AT_name {{.*}} "boo")
7178

7279
; DWARF4: DW_TAG_subprogram
73-
; DWARF4-NEXT: DW_AT_low_pc [DW_FORM_GNU_addr_index] (indexed (00000002) address = 0x000000000000003e ".text")
74-
; DWARF4-NEXT: DW_AT_high_pc [DW_FORM_data4] (0x00000000)
75-
; DWARF4: DW_AT_name {{.*}} "main")
80+
; DWARF4-NEXT: DW_AT_low_pc [DW_FORM_GNU_addr_index] (indexed (00000003) address = 0x000000000000003e ".text")
81+
; DWARF4-NEXT: DW_AT_high_pc [DW_FORM_GNU_addr_index] (indexed (00000004) address = 0x000000000000006e ".text")
82+
; DWARF4: DW_AT_name {{.*}} "main")
83+
84+
; HDR-NOT: .rela.{{.*}}.dwo
7685

7786
; Ensure there is no unnecessary addresses in .o file
7887
; DWARF4: .debug_addr contents:
7988
; DWARF4: Addrs: [
8089
; DWARF4-NEXT: 0x0000000000000000
8190
; DWARF4-NEXT: 0x000000000000002c
91+
; DWARF4-NEXT: 0x000000000000002c
8292
; DWARF4-NEXT: 0x000000000000003e
93+
; DWARF4-NEXT: 0x000000000000006e
8394
; DWARF4-NEXT: ]
8495

96+
; HDR-NOT: .rela.{{.*}}.dwo
97+
8598
#--- relax_dwo_ranges.cpp
8699
__attribute__((noinline)) int boo();
87100

0 commit comments

Comments
 (0)