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

            Bug ID: 34227
           Summary: [RISC-V] GNU ld.bfd pack relative relocs option
                    ignored on legal inputs
           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
=======
Current GNU ld.bfd 2.45 links the legal shared-object and PIE forms
successfully but warns `-z pack-relative-relocs ignored` and emits only
ordinary `.rela.dyn` contents with no `DT_RELR` or `.relr.dyn`. Supported
ld.lld controls emit packed RELR metadata on the same object.

Expected behavior
=================
Link a legal RV64 GOT-address materialization sample in shared-object and PIE
modes with `-z pack-relative-relocs`, so the linker should pack plain relative
relocations into RELR metadata while preserving the remaining symbolic
relocations in `.rela.dyn`.

Environment
===========
- product: binutils
- component: ld
- toolchain route: GNU as plus current GNU ld.bfd 2.45 with ld.lld controls
- march: rv64i
- mabi: lp64
- first failing stage: link

Reduced testcase
================
--- relr-data.s ---
.macro data value
.ifdef __64_bit__
        .quad \value
.else
        .long \value
.endif
.endm

.text
.global _start
_start:
        nop

sym_local:
        nop

.global sym_hidden
.hidden sym_hidden
sym_hidden:
        nop

.global sym_global
sym_global:
        nop

.global sym_global_abs
.set sym_global_abs, 42

.global sym_weak_undef
.weak sym_weak_undef

.section .data.unaligned_local
unaligned_local:
data sym_local

.section .data.unaligned_hidden
unaligned_hidden:
data sym_hidden

.section .data.unaligned_global
unaligned_global:
data sym_global

.section .data.unaligned_DYNAMIC
unaligned_DYNAMIC:
data _DYNAMIC

.section .data.aligned_local
.p2align 1
aligned_local:
data sym_local

.section .data.aligned_hidden
.p2align 1
aligned_hidden:
data sym_hidden

.section .data.aligned_global
.p2align 1
aligned_global:
data sym_global

.section .data.aligned_global_abs
.p2align 1
aligned_global_abs:
data sym_global_abs

.section .data.aligned_weak_undef
.p2align 1
aligned_weak_undef:
data sym_weak_undef

.section .data.aligned_DYNAMIC
.p2align 1
aligned_DYNAMIC:
data _DYNAMIC

--- relr-got.s ---
.text
.option norelax
.option pic
.global _start
_start:
        la      x1, sym_local
        la      x1, sym_hidden
        la      x1, sym_global
        la      x1, sym_global_abs
        la      x1, sym_weak_undef
        la      x1, _DYNAMIC

sym_local:
        nop

.global sym_hidden
.hidden sym_hidden
sym_hidden:
        nop

.global sym_global
sym_global:
        nop

.global sym_global_abs
.set sym_global_abs, 42

.global sym_weak_undef
.weak sym_weak_undef

--- relr-relocs.ld ---
OUTPUT_ARCH(riscv)
ENTRY(_start)
SECTIONS
{
  PROVIDE (__executable_start = 0x8000); . = 0x10000;
  .text : { *(.before) *(.text) *(.after) } =0
  . = 0x20000;
  .got : { *(.got) *(.got.plt) }
  . = 0x12340000;
  .far : { *(.far) }
  .riscv.attributes 0 : { *(.ARM.atttributes) }
  .data : { *(.data) }
}

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_pack_relative_relocs_option_ignored/run1..run3 are stable by
hash. In every run, `got.asm.rc.txt` is 0, both `got.pic.rc.txt` and
`got.pie.rc.txt` are 0, `got.pic.stderr.txt` contains the same ignored-option
warning, and `got.pic.readelf.txt`/`got.pie.readelf.txt` contain only
`.rela.dyn` with no RELR dynamic tags or sections. The parallel ld.lld control
in `lld_pack_relative_relocs_option_ignored_before_15` shows the same object
does produce RELR metadata once the option is implemented, so this current-bfd
root is a distinct missing-support linker defect on valid inputs.

Notes
=====
hunt/cases/confirmed/lld_pie_weak_undef_dynamic_relocs_dropped_after_18/relr-got.s
and relr-relocs.ld

Root key: bfd.riscv.pack_relative_relocs_option_ignored_on_legal_inputs
Case id: 20260528-bfd-pack-relative-relocs-ignored

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

Reply via email to