[llvm] [RISCV] Mark More Relocs as Relaxable (PR #151422)

Jessica Clarke via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 8 16:45:21 PDT 2025


================
@@ -1,32 +1,45 @@
-;; With +relax, J below needs a relocation to ensure the target is correct
-;; after linker relaxation. See https://github.com/ClangBuiltLinux/linux/issues/1965
 
 ; RUN: llc -mtriple=riscv64 -mattr=-relax -filetype=obj < %s \
 ; RUN:     | llvm-objdump -d -r - | FileCheck %s --check-prefixes=CHECK,NORELAX
 ; RUN: llc -mtriple=riscv64 -mattr=+relax -filetype=obj < %s \
 ; RUN:     | llvm-objdump -d -r - | FileCheck %s --check-prefixes=CHECK,RELAX
 
+;; With +relax, All `j` instructions below need a relocation to ensure the target is correct
+;; after linker relaxation. See https://github.com/ClangBuiltLinux/linux/issues/1965
+
 ; CHECK:        j       {{.*}}
 ; RELAX-NEXT:           R_RISCV_JAL  {{.*}}
+; RELAX-NOT:            R_RISCV_RELAX
 ; CHECK-NEXT:   auipc   ra, 0x0
 ; CHECK-NEXT:           R_RISCV_CALL_PLT     f
 ; RELAX-NEXT:           R_RISCV_RELAX        *ABS*
 ; CHECK-NEXT:   jalr    ra
 ; CHECK-NEXT:   j       {{.*}}
+; RELAX-NEXT:           R_RISCV_JAL  {{.*}}
+; RELAX-NOT:            R_RISCV_RELAX
----------------
jrtc27 wrote:

Even aside from that couldn't jal be relaxed to c.jal and j to c.j (with the former only being available on RV32)? I don't think that's a currently-implemented relaxation, it's only done if the original (pseudo)instruction is a call, but for those that believe in the fun that is linker relaxation it would seem an obvious one to implement.

https://github.com/llvm/llvm-project/pull/151422


More information about the llvm-commits mailing list