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

            Bug ID: 34220
           Summary: [RISC-V] GNU ld.bfd missing second pass relax to
                    compressed jumps
           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 stops after the first relaxation pass and leaves the critical site
as 32-bit jal zero / jal ra, while ld.lld reaches the 16-bit c.j / c.jal form
on the same legal inputs.

Expected behavior
=================
A series of call/jump sites become shorter after ordinary relaxation, making a
later critical site eligible for a second relaxation from jal/j to c.jal/c.j.
The linker should continue until the compressed form is reached.

Environment
===========
- product: binutils
- component: ld
- toolchain route: gas+ld.bfd with gas+ld.lld control
- march: rv64ic for j-to-cj and rv32ic for jal-to-cjal
- mabi: lp64/ilp32
- first failing stage: link

Reduced testcase
================
--- j-to-cj.s ---
       .text
       .globl _start
_start:
       tail f1
       tail f2
       tail f3
       tail f4
       tail f5
       tail f6
       tail f7
       tail f8
       tail f9
       tail f10

critical:
       tail target

       .option norvc
       .rept 505
       nop
       .endr
       .option rvc

f1:    ret
f2:    ret
f3:    ret
f4:    ret
f5:    ret
f6:    ret
f7:    ret
f8:    ret
f9:    ret
f10:   ret

target:
       ret

--- jal-to-cjal.s ---
       .text
       .globl _start
_start:
       call f1
       call f2
       call f3
       call f4
       call f5
       call f6
       call f7
       call f8
       call f9
       call f10

critical:
       call target

       .option norvc
       .rept 505
       nop
       .endr
       .option rvc

f1:    ret
f2:    ret
f3:    ret
f4:    ret
f5:    ret
f6:    ret
f7:    ret
f8:    ret
f9:    ret
f10:   ret

target:
       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: 3 clean reproductions under
hunt/verify/bfd_second_pass_compressed_relax/run1..run3 show stable bfd 32-bit
critical jumps in both the j-to-cj and jal-to-cjal tests, while lld compresses
the matching critical sites.

Notes
=====
https://sourceware.org/pipermail/binutils/2026-January/147293.html

Root key: bfd.riscv.missing_second_pass_relax_to_compressed_jumps
Case id: 20260525-bfd-second-pass-compressed-relax

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

Reply via email to