Skip to content

Commit 2ef56d1

Browse files
committed
[RISCV] relaxDwarfCallFrameFragment: remove unneeded relocations for relaxation
If `evaluateAsAbsolute(Value, Layout.getAssembler())` returns true, we know the address delta is a constant and can suppress relocations (usually SET6/SUB6). While here, replace one evaluateKnownAbsolute call (subtle for Mach-O workarounds; avoid if possible) with evaluateAsAbsolute.
1 parent d663da0 commit 2ef56d1

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,15 @@ bool RISCVAsmBackend::relaxDwarfLineAddr(MCDwarfLineAddrFragment &DF,
273273
bool RISCVAsmBackend::relaxDwarfCFA(MCDwarfCallFrameFragment &DF,
274274
MCAsmLayout &Layout,
275275
bool &WasRelaxed) const {
276-
277276
const MCExpr &AddrDelta = DF.getAddrDelta();
278277
SmallVectorImpl<char> &Data = DF.getContents();
279278
SmallVectorImpl<MCFixup> &Fixups = DF.getFixups();
280279
size_t OldSize = Data.size();
281280

282281
int64_t Value;
283-
bool IsAbsolute = AddrDelta.evaluateKnownAbsolute(Value, Layout);
282+
if (AddrDelta.evaluateAsAbsolute(Value, Layout.getAssembler()))
283+
return false;
284+
bool IsAbsolute = AddrDelta.evaluateAsAbsolute(Value, Layout);
284285
assert(IsAbsolute && "CFA with invalid expression");
285286
(void)IsAbsolute;
286287

llvm/test/DebugInfo/RISCV/relax-debug-frame.ll

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,29 @@
77
; RELAX-NEXT: 0x1C R_RISCV_32_PCREL - 0x0
88
; RELAX-NEXT: 0x20 R_RISCV_ADD32 - 0x0
99
; RELAX-NEXT: 0x20 R_RISCV_SUB32 - 0x0
10-
; RELAX-NOT: }
11-
; RELAX: 0x39 R_RISCV_SET6 - 0x0
12-
; RELAX-NEXT: 0x39 R_RISCV_SUB6 - 0x0
13-
;
10+
; RELAX-NEXT: 0x30 R_RISCV_32_PCREL - 0x0
11+
; RELAX-NEXT: 0x34 R_RISCV_ADD32 - 0x0
12+
; RELAX-NEXT: 0x34 R_RISCV_SUB32 - 0x0
13+
; RELAX-NEXT: 0x44 R_RISCV_32_PCREL - 0x0
14+
; RELAX-NEXT: 0x48 R_RISCV_ADD32 - 0x0
15+
; RELAX-NEXT: 0x48 R_RISCV_SUB32 - 0x0
16+
; RELAX-NEXT: }
17+
1418
; RELAX-DWARFDUMP-NOT: error: failed to compute relocation
15-
; RELAX-DWARFDUMP: CIE
16-
; RELAX-DWARFDUMP: DW_CFA_advance_loc
17-
; RELAX-DWARFDUMP: DW_CFA_def_cfa_offset
18-
; RELAX-DWARFDUMP: DW_CFA_offset
19+
; RELAX-DWARFDUMP: FDE
20+
; RELAX-DWARFDUMP-NEXT: Format:
21+
; RELAX-DWARFDUMP: DW_CFA_advance_loc: 4
22+
; RELAX-DWARFDUMP-NEXT: DW_CFA_def_cfa_offset: +16
23+
; RELAX-DWARFDUMP-EMPTY:
24+
25+
; RELAX-DWARFDUMP: FDE
26+
; RELAX-DWARFDUMP: Format:
27+
; RELAX-DWARFDUMP-NEXT: DW_CFA_advance_loc: 4
28+
; RELAX-DWARFDUMP-NEXT: DW_CFA_def_cfa_offset: +16
29+
; RELAX-DWARFDUMP-NEXT: DW_CFA_advance_loc: 4
30+
; RELAX-DWARFDUMP-NEXT: DW_CFA_offset: X1 -4
31+
; RELAX-DWARFDUMP-NEXT: DW_CFA_nop
32+
; RELAX-DWARFDUMP-EMPTY:
1933
source_filename = "frame.c"
2034

2135
; Function Attrs: noinline nounwind optnone

llvm/test/MC/ELF/RISCV/gen-dwarf.s

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
# RELOC-NEXT: 0x20 R_RISCV_SUB32 - 0x0
4646
# RELOC-NEXT: 0x25 R_RISCV_SET6 - 0x0
4747
# RELOC-NEXT: 0x25 R_RISCV_SUB6 - 0x0
48-
# RELOC-NEXT: 0x28 R_RISCV_SET6 - 0x0
49-
# RELOC-NEXT: 0x28 R_RISCV_SUB6 - 0x0
5048
# RELOC-NEXT: 0x34 R_RISCV_32_PCREL - 0x0
5149
# RELOC-NEXT: 0x38 R_RISCV_ADD32 - 0x0
5250
# RELOC-NEXT: 0x38 R_RISCV_SUB32 - 0x0

0 commit comments

Comments
 (0)