https://sourceware.org/bugzilla/show_bug.cgi?id=34235
Bug ID: 34235
Summary: [RISC-V] GNU ld.bfd got32 PCREL unsupported relocation
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 2.45 fails both RV32 and RV64 `R_RISCV_GOT32_PCREL` objects in both
ET_EXEC and shared links with `internal error: unsupported relocation error`.
ld.lld 22.1.0 links the same objects successfully: ET_EXEC links allocate a GOT
entry and resolve the three data words with no remaining relocations, and
shared links allocate `.got` and emit a dynamic `R_RISCV_64 bar` relocation for
the GOT slot while materializing the GOT-relative data words.
Expected behavior
=================
Link RISC-V objects containing standard `R_RISCV_GOT32_PCREL` data relocations
generated by LLVM MC from `.word %gotpcrel(bar)`, `.word %gotpcrel(bar + 4)`,
and `.word %gotpcrel(bar - 4)`. The current RISC-V psABI defines relocation 41
as `GOT32_PCREL`, a static `word32` relocation for the 32-bit relative offset
to the GOT entry for a symbol, so a RISC-V linker should understand this
relocation in ET_EXEC and shared links.
Environment
===========
- product: binutils
- component: ld
- toolchain route: llvm-mc 22 plus current GNU ld.bfd 2.45 with ld.lld 22.1.0
semantic control; GNU as 2.45 syntax is not used for the canonical object
- march: rv32 and rv64
- mabi: ELF32/ELF64 RISC-V default object ABI from llvm-mc
- first failing stage: link
Reduced testcase
================
--- case.s ---
.text
.align 2
.globl _start
.type _start, @function
_start:
ret
.size _start, .-_start
.data
.align 2
.globl bar
bar:
.word 0
.globl p0, p4, pm4
p0:
.word %gotpcrel(bar)
p4:
.word %gotpcrel(bar + 4)
pm4:
.word %gotpcrel(bar - 4)
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_riscv_got32_pcrel_unsupported_relocation/run1..run3 show stable
llvm-mc assembly success, stable object relocations `R_RISCV_GOT32_PCREL bar +
0`, `bar + 4`, and `bar - 4`, stable ld.lld RV32/RV64 ET_EXEC/shared success,
and stable GNU ld.bfd RV32/RV64 ET_EXEC/shared failure with `internal error:
unsupported relocation error`. Across all runs, the RV64 object hash is stable
as `2da8ca165ac06282a38e52e52fc5ba622b16ef8e9762fa408fbe63c75b2e8ea8` and the
RV64 shared lld output hash is stable as
`85a9e24e19c15ca971dbd4131b4de3b72f4feaca906e5a4ba329808ea6f0a358`; run1 lld
output hashes are
`744a09faf317fd9d7aeb6d724ba9c9a99af5dc77e4984d7eda562978ce74e136` for
`exec.32.lld`,
`38897e1b23917f4fcaf094b76c8cd94867babce3d56fb8f6912c3267c7af2fb8` for
`shared.32.lld`,
`0a28ab186903cfed63dd04ed12236fe19d7bb13b58fca138c13cb4b73f06cf83` for
`exec.64.lld`, and
`85a9e24e19c15ca971dbd4131b4de3b72f4feaca906e5a4ba329808ea6f0a358` for
`shared.64.lld`. Local records had an older lld GOT32_PCREL root removed as
already reported by LLVM PR #72587, but no current GNU ld.bfd root. Web
searches covering Sourceware Bugzilla, Sourceware binutils lists, GitHub,
`R_RISCV_GOT32_PCREL unsupported relocation`, and `R_RISCV_GOT32_PCREL internal
error` found LLVM/lld support references but no direct current Sourceware bug
report for GNU ld.bfd's failure to link standard `R_RISCV_GOT32_PCREL` inputs.
Notes
=====
upstream/llvm-project/lld/test/ELF/riscv64-reloc-got32-pcrel.s is the LLVM/lld
semantic seed; local binutils source evidence is
`upstream/binutils-2.45/bfd/elfxx-riscv.c`,
`upstream/binutils-gdb-full/bfd/elfxx-riscv.c`, and the absence of a RISC-V
relocation-map entry for `R_RISCV_GOT32_PCREL`.
Root key: bfd.riscv.got32_pcrel_unsupported_relocation
Case id: 20260604-bfd-riscv-got32-pcrel-unsupported-relocation
--
You are receiving this mail because:
You are on the CC list for the bug.