https://sourceware.org/bugzilla/show_bug.cgi?id=34216

            Bug ID: 34216
           Summary: [RISC-V] GNU ld.bfd call relax skipped across output
                    sections
           Product: binutils
           Version: 2.45
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: l784896635 at gmail dot com
  Target Milestone: ---

I ran into this while reducing a RISC-V linker testcase. The reproducer is
already quite small, and I have been seeing the same result consistently across
three reruns.

Summary
=======
GNU ld.bfd preserves auipc+jalr for an in-range R_RISCV_CALL_PLT +
R_RISCV_RELAX relocation when the callee is placed in a different output
section, while ld.lld relaxes the same legal input to jal.

Expected behavior
=================
A fixed-layout startup stub calls a helper in another output section at
0x110000 from a call site at 0x10004, which is within the legal RV64 JAL range
and should be relaxable under --relax.

Environment
===========
- product: binutils
- component: ld
- toolchain route: gas+ld.bfd with gas+ld.lld control
- march: rv64im
- mabi: lp64
- first failing stage: link

Reduced testcase
================
--- helper.S ---
    .option norvc
    .section .text.helper,"ax",@progbits
    .globl helper
    .type helper,@function
helper:
    addi a0, a0, 1
    ret

--- layout.ld ---
SECTIONS
{
  . = 0x10000;
  .text.main : { *(.text.main) }
  . = 0x110000;
  .text.helper : { *(.text.helper) }
  /DISCARD/ : { *(.comment) *(.note*) }
}

--- main.S ---
    .option norvc
    .section .text.main,"ax",@progbits
    .globl _start
    .type _start,@function
_start:
    addi a0, zero, 7
    call helper
    ret

Reproduction notes
==================
- This packaged root does not have a single canonical `run.ps1` wrapper.
- Use the reduced inputs under `case/` and follow the commands documented in
`case/README.md`.
- Stable witness outputs, when present, are preserved under
`verify/run1..run3/`.

What I checked
==============
- Reduced inputs are preserved under case/.
- Stable witness outputs are preserved under verify/run1..run3/.
- The strict recheck says stable normalized run signatures across three runs:
True.
- Tracker guidance link:
https://sourceware.org/binutils/docs/ld/Bug-Reporting.html
- evidence summary: main.o contains R_RISCV_CALL_PLT and R_RISCV_RELAX at
offset 0x4; helper at 0x110000 is 0xFFFFC bytes from the call site at 0x10004,
which is within JAL range; 3 clean reproductions under
hunt/verify/bfd_relax_cross_output_sections/run1..run3 show stable ld.bfd
auipc+jalr vs ld.lld jal behavior.

Notes
=====
https://lists.gnu.org/archive/html/bug-binutils/2022-11/msg00110.html

Root key: bfd.riscv.call_relax_skipped_across_output_sections
Case id: 20260525-bfd-rv64-call-relax-cross-output-sections

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to