[llvm] cd68532 - [RISCV] relaxDwarfCallFrameFragment: remove unneeded relocations for -mno-relax

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 30 11:10:42 PDT 2024


Author: Fangrui Song
Date: 2024-06-30T11:10:37-07:00
New Revision: cd68532e37e2671e9f35fad2fd1078451d1d8a38

URL: https://github.com/llvm/llvm-project/commit/cd68532e37e2671e9f35fad2fd1078451d1d8a38
DIFF: https://github.com/llvm/llvm-project/commit/cd68532e37e2671e9f35fad2fd1078451d1d8a38.diff

LOG: [RISCV] relaxDwarfCallFrameFragment: remove unneeded relocations for -mno-relax

Follow-up to 2ef56d16adbe888a7e8c20684aa98d3f07c0eb98 for -mrelax.
https://reviews.llvm.org/D155357 allowed us to use Layout as the
parameter without correctness issues.

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
    llvm/test/MC/RISCV/cfi-advance.s

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
index 182a9c1544fd2..23d18e98d43d1 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -280,7 +280,7 @@ bool RISCVAsmBackend::relaxDwarfCFA(MCDwarfCallFrameFragment &DF,
   size_t OldSize = Data.size();
 
   int64_t Value;
-  if (AddrDelta.evaluateAsAbsolute(Value, Layout.getAssembler()))
+  if (AddrDelta.evaluateAsAbsolute(Value, Layout))
     return false;
   [[maybe_unused]] bool IsAbsolute =
       AddrDelta.evaluateKnownAbsolute(Value, Layout);

diff  --git a/llvm/test/MC/RISCV/cfi-advance.s b/llvm/test/MC/RISCV/cfi-advance.s
index b99af38f553aa..1d00214da46c6 100644
--- a/llvm/test/MC/RISCV/cfi-advance.s
+++ b/llvm/test/MC/RISCV/cfi-advance.s
@@ -1,26 +1,41 @@
-# RUN: llvm-mc -filetype=obj -triple riscv32 %s -o %t.o  
-# RUN: llvm-readelf -sr %t.o | FileCheck %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=-relax %s -o %t.o
+# RUN: llvm-readelf -sr %t.o | FileCheck %s --check-prefix=NORELAX
 # RUN: llvm-dwarfdump --debug-frame %t.o 2>&1 \
 # RUN:     | FileCheck -check-prefix=CHECK-DWARFDUMP %s
+# RUN: llvm-mc -filetype=obj -triple riscv32 -mattr=+relax %s -o %t.relax.o
+# RUN: llvm-readelf -sr %t.relax.o | FileCheck %s --check-prefix=RELAX
 
+# NORELAX:      Relocation section '.rela.text1' at offset {{.*}} contains 1 entries:
+# NORELAX-NEXT:  Offset     Info    Type                Sym. Value  Symbol's Name + Addend
+# NORELAX-NEXT: 00000000  00000313 R_RISCV_CALL_PLT       00000004   .L0 + 0
+# NORELAX-EMPTY:
+# NORELAX-NEXT: Relocation section '.rela.eh_frame' at offset {{.*}} contains 1 entries:
+# NORELAX:       Offset     Info    Type                Sym. Value  Symbol's Name + Addend
+# NORELAX-NEXT: 0000001c  00000139 R_RISCV_32_PCREL       00000000   .L0 + 0
+# NORELAX-EMPTY:
+# NORELAX:      Symbol table '.symtab' contains 13 entries:
+# NORELAX-NEXT:    Num:    Value  Size Type    Bind   Vis       Ndx Name
+# NORELAX-NEXT:      0: 00000000     0 NOTYPE  LOCAL  DEFAULT   UND
+# NORELAX-NEXT:      1: 00000000     0 NOTYPE  LOCAL  DEFAULT     2 .L0 {{$}}
+# NORELAX:           3: 00000004     0 NOTYPE  LOCAL  DEFAULT     2 .L0{{$}}
+# NORELAX-NOT: .L0
 
-# CHECK:      Relocation section '.rela.text1' at offset {{.*}} contains 1 entries:
-# CHECK-NEXT:  Offset     Info    Type                Sym. Value  Symbol's Name + Addend
-# CHECK-NEXT: 00000000  00000313 R_RISCV_CALL_PLT       00000004   .L0 + 0
-# CHECK-EMPTY:
-# CHECK-NEXT: Relocation section '.rela.eh_frame' at offset {{.*}} contains 3 entries:
-# CHECK:       Offset     Info    Type                Sym. Value  Symbol's Name + Addend
-# CHECK-NEXT: 0000001c  00000139 R_RISCV_32_PCREL       00000000   .L0 + 0
-# CHECK-NEXT: 00000035  00000b35 R_RISCV_SET6           00010178   .L0 + 0
-# CHECK-NEXT: 00000035  00000934 R_RISCV_SUB6           0001016e   .L0 + 0
-# CHECK-EMPTY:
-# CHECK:      Symbol table '.symtab' contains 15 entries:
-# CHECK-NEXT:    Num:    Value  Size Type    Bind   Vis       Ndx Name
-# CHECK-NEXT:      0: 00000000     0 NOTYPE  LOCAL  DEFAULT   UND
-# CHECK-NEXT:      1: 00000000     0 NOTYPE  LOCAL  DEFAULT     2 .L0 {{$}}
-# CHECK:           3: 00000004     0 NOTYPE  LOCAL  DEFAULT     2 .L0{{$}}
-# CHECK:           9: 0001016e     0 NOTYPE  LOCAL  DEFAULT     2 .L0 {{$}}
-# CHECK:          11: 00010178     0 NOTYPE  LOCAL  DEFAULT     2 .L0 {{$}}
+# RELAX:        Relocation section '.rela.eh_frame' at offset {{.*}} contains 5 entries:
+# RELAX-NEXT:    Offset     Info    Type                Sym. Value  Symbol's Name + Addend
+# RELAX-NEXT:   0000001c  00000139 R_RISCV_32_PCREL       00000000   .L0 + 0
+# RELAX-NEXT:   00000020  00000c23 R_RISCV_ADD32          0001017a   .L0 + 0
+# RELAX-NEXT:   00000020  00000127 R_RISCV_SUB32          00000000   .L0 + 0
+# RELAX-NEXT:   00000035  00000b35 R_RISCV_SET6           00010176   .L0 + 0
+# RELAX-NEXT:   00000035  00000934 R_RISCV_SUB6           0001016e   .L0 + 0
+# RELAX-EMPTY:
+# RELAX:        Symbol table '.symtab' contains 16 entries:
+# RELAX-NEXT:      Num:    Value  Size Type    Bind   Vis       Ndx Name
+# RELAX-NEXT:        0: 00000000     0 NOTYPE  LOCAL  DEFAULT   UND
+# RELAX-NEXT:        1: 00000000     0 NOTYPE  LOCAL  DEFAULT     2 .L0 {{$}}
+# RELAX:             3: 00000004     0 NOTYPE  LOCAL  DEFAULT     2 .L0{{$}}
+# RELAX:             9: 0001016e     0 NOTYPE  LOCAL  DEFAULT     2 .L0 {{$}}
+# RELAX:            11: 00010176     0 NOTYPE  LOCAL  DEFAULT     2 .L0 {{$}}
+# RELAX:            12: 0001017a     0 NOTYPE  LOCAL  DEFAULT     2 .L0 {{$}}
 
 # CHECK-DWARFDUMP: DW_CFA_advance_loc1: 104
 # CHECK-DWARFDUMP-NEXT: DW_CFA_def_cfa_offset: +8


        


More information about the llvm-commits mailing list