Skip to content

Commit c5ecdd3

Browse files
committed
[DebugInfo] Some fields do not need relocations even relax is enabled.
In debug frame information, some fields, e.g., Length in CIE/FDE and Offset in FDE are attributes to describe the structure of CIE/FDE. They are not related to the relaxed code. However, these attributes are symbol differences. So, in current design, these attributes will be filled as zero and LLVM generates relocations for them. We only need to generate relocations for symbols in executable sections. So, if the symbols are not located in executable sections, we still evaluate their values under relaxation. Differential Revision: https://reviews.llvm.org/D61584 llvm-svn: 366531
1 parent f688226 commit c5ecdd3

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

llvm/lib/MC/MCExpr.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,24 @@ static void AttemptToFoldSymbolOffsetDifference(
577577
A = B = nullptr;
578578
}
579579

580+
static bool canFold(const MCAssembler *Asm, const MCSymbolRefExpr *A,
581+
const MCSymbolRefExpr *B, bool InSet) {
582+
if (InSet)
583+
return true;
584+
585+
if (!Asm->getBackend().requiresDiffExpressionRelocations())
586+
return true;
587+
588+
const MCSymbol &CheckSym = A ? A->getSymbol() : B->getSymbol();
589+
if (!CheckSym.isInSection())
590+
return true;
591+
592+
if (!CheckSym.getSection().hasInstructions())
593+
return true;
594+
595+
return false;
596+
}
597+
580598
/// Evaluate the result of an add between (conceptually) two MCValues.
581599
///
582600
/// This routine conceptually attempts to construct an MCValue:
@@ -617,8 +635,7 @@ EvaluateSymbolicAdd(const MCAssembler *Asm, const MCAsmLayout *Layout,
617635
// the backend requires this to be emitted as individual relocations, unless
618636
// the InSet flag is set to get the current difference anyway (used for
619637
// example to calculate symbol sizes).
620-
if (Asm &&
621-
(InSet || !Asm->getBackend().requiresDiffExpressionRelocations())) {
638+
if (Asm && canFold(Asm, LHS_A, LHS_B, InSet)) {
622639
// First, fold out any differences which are fully resolved. By
623640
// reassociating terms in
624641
// Result = (LHS_A - LHS_B + LHS_Cst) + (RHS_A - RHS_B + RHS_Cst).

llvm/test/DebugInfo/RISCV/dwarf-riscv-relocs.ll

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66

77
; Check that we actually have relocations, otherwise this is kind of pointless.
88
; READOBJ-RELOCS: Section (8) .rela.debug_info {
9-
; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_ADD32 - 0x0
10-
; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_SUB32 - 0x0
11-
; READOBJ-RELOCS: Section (11) .rela.debug_addr {
12-
; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_ADD32 - 0x0
13-
; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_SUB32 - 0x0
9+
; READOBJ-RELOCS: 0x1B R_RISCV_ADD32 - 0x0
10+
; READOBJ-RELOCS-NEXT: 0x1B R_RISCV_SUB32 - 0x0
11+
; READOBJ-RELOCS: Section (15) .rela.debug_frame {
12+
; READOBJ-RELOCS: 0x20 R_RISCV_ADD32 - 0x0
13+
; READOBJ-RELOCS-NEXT: 0x20 R_RISCV_SUB32 - 0x0
1414
; READOBJ-RELOCS: Section (17) .rela.debug_line {
15-
; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_ADD32 - 0xFFFFFFFC
16-
; READOBJ-RELOCS-NEXT: 0x0 R_RISCV_SUB32 .Lline_table_start0 0x0
15+
; READOBJ-RELOCS: 0x5A R_RISCV_ADD16 - 0x0
16+
; READOBJ-RELOCS-NEXT: 0x5A R_RISCV_SUB16 - 0x0
1717

1818
; Check that we can print the source, even with relocations.
1919
; OBJDUMP-SOURCE: Disassembly of section .text:

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
;
77
; RELAX: Section{{.*}}.rela.{{eh|debug}}_frame {
88
; RELAX-NOT: {{[}]}}
9+
; RELAX-NOT: 0x0 R_RISCV_ADD32
10+
; RELAX-NOT: 0x0 R_RISCV_SUB32
11+
; RELAX-NOT: {{[}]}}
912
; RELAX: 0x20 R_RISCV_ADD32
1013
; RELAX: 0x20 R_RISCV_SUB32
1114
; RELAX-NOT: {{[}]}}

llvm/test/MC/RISCV/fde-reloc.s

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@ func:
1414
# preparation for follow-on patches to fix it.
1515

1616
# RELAX-RELOC: Section (4) .rela.eh_frame {
17-
# RELAX-RELOC-NEXT: 0x0 R_RISCV_ADD32 - 0xFFFFFFFC
18-
# RELAX-RELOC-NEXT: 0x0 R_RISCV_SUB32 - 0x0
19-
# RELAX-RELOC-NEXT: 0x14 R_RISCV_ADD32 - 0x0
20-
# RELAX-RELOC-NEXT: 0x14 R_RISCV_SUB32 - 0x0
21-
# RELAX-RELOC-NEXT: 0x18 R_RISCV_ADD32 - 0x0
22-
# RELAX-RELOC-NEXT: 0x18 R_RISCV_SUB32 - 0x0
17+
# RELAX-RELOC-NEXT: 0x0 R_RISCV_32 - 0x10
18+
# RELAX-RELOC-NEXT: 0x14 R_RISCV_32 - 0x10
19+
# RELAX-RELOC-NEXT: 0x18 R_RISCV_32 - 0x18
2320
# RELAX-RELOC-NEXT: 0x1C R_RISCV_ADD32 - 0x0
2421
# RELAX-RELOC-NEXT: 0x1C R_RISCV_SUB32 - 0x0
2522
# RELAX-RELOC-NEXT: 0x20 R_RISCV_ADD32 - 0x0

0 commit comments

Comments
 (0)