Skip to content

Commit f14d5e7

Browse files
committed
[dwarf] make dwarf fission compatible with RISCV relaxations 2/2
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.
1 parent c4b1df9 commit f14d5e7

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
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: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
; RUN: llc -dwarf-version=5 -split-dwarf-file=foo.dwo -O0 %s -mtriple=riscv64-unknown-linux-gnu -filetype=obj -o %t
22
; RUN: llvm-dwarfdump -v %t | FileCheck --check-prefix=DWARF5 %s
33
; RUN: llvm-dwarfdump --debug-info %t 2> %t.txt
4-
; RUN: FileCheck --input-file=%t.txt %s --check-prefix=RELOCS --implicit-check-not=warning:
4+
; RUN: FileCheck --input-file=%t.txt %s --check-prefix=RELOCS --allow-empty --implicit-check-not=warning:
55

66
; RUN: llc -dwarf-version=4 -split-dwarf-file=foo.dwo -O0 %s -mtriple=riscv64-unknown-linux-gnu -filetype=obj -o %t
77
; RUN: llvm-dwarfdump -v %t | FileCheck --check-prefix=DWARF4 %s
88
; RUN: llvm-dwarfdump --debug-info %t 2> %t.txt
9-
; RUN: FileCheck --input-file=%t.txt %s --check-prefix=RELOCS --implicit-check-not=warning:
9+
; RUN: FileCheck --input-file=%t.txt %s --check-prefix=RELOCS --allow-empty --implicit-check-not=warning:
10+
; RUN: llvm-objdump -h %t | FileCheck --check-prefix=HDR %s
1011

1112
; In the RISC-V architecture, the .text section is subject to
1213
; relaxation, meaning the start address of each function can change
@@ -49,60 +50,75 @@
4950

5051
; clang -g -S -gsplit-dwarf --target=riscv64 -march=rv64gc -O0 relax_dwo_ranges.cpp
5152

52-
; Currently, square() still uses an offset to represent the function's end address,
53-
; which requires a relocation here.
54-
; RELOCS: warning: unexpected relocations for dwo section '.debug_info.dwo'
53+
; RELOCS-NOT: warning: unexpected relocations for dwo section '.debug_info.dwo'
5554

55+
; Make sure we don't produce any relocations in any .dwo section
56+
; HDR-NOT: .rela.{{.*}}.dwo
57+
58+
; Ensure that 'square()' function uses indexed start and end addresses
5659
; DWARF5: .debug_info.dwo contents:
5760
; DWARF5: DW_TAG_subprogram
58-
; DWARF5-NEXT: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000000) address = 0x0000000000000000 ".text")
59-
; DWARF5-NEXT: DW_AT_high_pc [DW_FORM_data4] (0x00000000)
61+
; DWARF5-NEXT: DW_AT_low_pc [DW_FORM_addrx] (indexed (00000000) address = 0x0000000000000000 ".text")
62+
; DWARF5-NEXT: DW_AT_high_pc [DW_FORM_addrx] (indexed (00000001) address = 0x0000000000000044 ".text")
6063
; DWARF5: DW_AT_name {{.*}} "square")
6164
; DWARF5: DW_TAG_formal_parameter
6265

66+
; HDR-NOT: .rela.{{.*}}.dwo
67+
6368
; Ensure there is no unnecessary addresses in .o file
6469
; DWARF5: .debug_addr contents:
6570
; DWARF5: Addrs: [
6671
; DWARF5-NEXT: 0x0000000000000000
72+
; DWARF5-NEXT: 0x0000000000000044
6773
; DWARF5-NEXT: 0x0000000000000046
6874
; DWARF5-NEXT: 0x000000000000006c
6975
; DWARF5-NEXT: 0x00000000000000b0
7076
; DWARF5-NEXT: ]
7177

78+
; HDR-NOT: .rela.{{.*}}.dwo
79+
7280
; Ensure that 'boo()' and 'main()' use DW_RLE_startx_length and DW_RLE_startx_endx
7381
; entries respectively
7482
; DWARF5: .debug_rnglists.dwo contents:
7583
; DWARF5: ranges:
76-
; DWARF5-NEXT: 0x00000014: [DW_RLE_startx_length]: 0x0000000000000001, 0x0000000000000024 => [0x0000000000000046, 0x000000000000006a)
84+
; DWARF5-NEXT: 0x00000014: [DW_RLE_startx_length]: 0x0000000000000002, 0x0000000000000024 => [0x0000000000000046, 0x000000000000006a)
7785
; DWARF5-NEXT: 0x00000017: [DW_RLE_end_of_list ]
78-
; DWARF5-NEXT: 0x00000018: [DW_RLE_startx_endx ]: 0x0000000000000002, 0x0000000000000003 => [0x000000000000006c, 0x00000000000000b0)
86+
; DWARF5-NEXT: 0x00000018: [DW_RLE_startx_endx ]: 0x0000000000000003, 0x0000000000000004 => [0x000000000000006c, 0x00000000000000b0)
7987
; DWARF5-NEXT: 0x0000001b: [DW_RLE_end_of_list ]
8088
; DWARF5-EMPTY:
8189

90+
; HDR-NOT: .rela.{{.*}}.dwo
91+
8292
; DWARF4: .debug_info.dwo contents:
8393
; DWARF4: DW_TAG_subprogram
84-
; DWARF4-NEXT: DW_AT_low_pc [DW_FORM_GNU_addr_index] (indexed (00000000) address = 0x0000000000000000 ".text")
85-
; DWARF4-NEXT: DW_AT_high_pc [DW_FORM_data4] (0x00000000)
94+
; DWARF4-NEXT: DW_AT_low_pc [DW_FORM_GNU_addr_index] (indexed (00000000) address = 0x0000000000000000 ".text")
95+
; DWARF4-NEXT: DW_AT_high_pc [DW_FORM_GNU_addr_index] (indexed (00000001) address = 0x0000000000000044 ".text")
8696
; DWARF4: DW_AT_name {{.*}} "square")
8797

8898
; DWARF4: DW_TAG_subprogram
89-
; DWARF4-NEXT: DW_AT_low_pc [DW_FORM_GNU_addr_index] (indexed (00000001) address = 0x0000000000000046 ".text")
99+
; DWARF4-NEXT: DW_AT_low_pc [DW_FORM_GNU_addr_index] (indexed (00000002) address = 0x0000000000000046 ".text")
90100
; DWARF4-NEXT: DW_AT_high_pc [DW_FORM_data4] (0x00000024)
91101
; DWARF4: DW_AT_name {{.*}} "boo")
92102

93103
; DWARF4: DW_TAG_subprogram
94-
; DWARF4-NEXT: DW_AT_low_pc [DW_FORM_GNU_addr_index] (indexed (00000002) address = 0x000000000000006c ".text")
95-
; DWARF4-NEXT: DW_AT_high_pc [DW_FORM_data4] (0x00000000)
104+
; DWARF4-NEXT: DW_AT_low_pc [DW_FORM_GNU_addr_index] (indexed (00000003) address = 0x000000000000006c ".text")
105+
; DWARF4-NEXT: DW_AT_high_pc [DW_FORM_GNU_addr_index] (indexed (00000004) address = 0x00000000000000b0 ".text")
96106
; DWARF4: DW_AT_name {{.*}} "main")
97107

108+
; HDR-NOT: .rela.{{.*}}.dwo
109+
98110
; Ensure there is no unnecessary addresses in .o file
99111
; DWARF4: .debug_addr contents:
100112
; DWARF4: Addrs: [
101113
; DWARF4-NEXT: 0x0000000000000000
114+
; DWARF4-NEXT: 0x0000000000000044
102115
; DWARF4-NEXT: 0x0000000000000046
103116
; DWARF4-NEXT: 0x000000000000006c
117+
; DWARF4-NEXT: 0x00000000000000b0
104118
; DWARF4-NEXT: ]
105119

120+
; HDR-NOT: .rela.{{.*}}.dwo
121+
106122
; Function Attrs: mustprogress noinline optnone
107123
define dso_local noundef signext i32 @_Z6squarei(i32 noundef signext %0) #0 !dbg !11 {
108124
%2 = alloca i32, align 4

0 commit comments

Comments
 (0)