https://sourceware.org/bugzilla/show_bug.cgi?id=34226
Bug ID: 34226
Summary: [RISC-V] GNU ld.bfd discard PIE assert on legal
discarded section case
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 shared-object control successfully and emits
the expected `.rela.dyn` shape, but the legal PIE link crashes at link time
with `BFD (GNU Binutils) 2.45 assertion fail ... bfd/elfnn-riscv.c:3638`.
Expected behavior
=================
Link the official GNU `discard` sample as a shared object and as a PIE, with a
linker script that discards `.discard.*` sections while preserving ordinary
`.text`, `.got`, and `.data` layout. This is a meaningful link-time layout and
dynamic-relocation bookkeeping exercise, not malformed input.
Environment
===========
- product: binutils
- component: ld
- toolchain route: GNU as plus current GNU ld.bfd 2.45 with official GNU ld
legality controls
- march: rv64gc
- mabi: lp64
- first failing stage: link
Reduced testcase
================
--- discard-pie.d ---
#source: discard.s
#as:
#ld: -pie -Tdiscard.ld
#readelf: -rW
Relocation section '\.rela\.dyn'.*
[ ]+Offset[ ]+Info[ ]+Type.*
0+0[ ]+0+0[ ]+R_RISCV_NONE[ ]+0
0+0[ ]+0+0[ ]+R_RISCV_NONE[ ]+0
--- discard.ld ---
OUTPUT_ARCH(riscv)
ENTRY(_start)
SECTIONS
{
/DISCARD/ : { *(.discard.*) }
. = 0x10000;
.text : { *(.text) }
. = 0x20000;
.got : { *(.got) *(.got.plt)}
. = 0x30000;
.data : { *(.data) *(.data.*) }
}
--- discard.s ---
.text
.option pic
.option norvc
.p2align 3
.global _start
_start:
nop
sym_local:
nop
.global sym_global
sym_global:
nop
.global sym_hidden
.hidden sym_hidden
sym_hidden:
nop
.global sym_global_abs
.set sym_global_abs, 42
.global sym_weak_undef
.weak sym_weak_undef
# Got
.section .discard.got_local, "ax"
la x1, sym_local
.section .discard.got_global, "ax"
la x1, sym_global
# Data
.section .discard.local,"a"
.p2align 1
discard_local:
.quad sym_local
.section .discard.global,"a"
.p2align 1
discard_global:
.quad sym_global
.section .discard.hidden,"a"
.p2align 1
discard_hidden:
.quad sym_hidden
.section .discard.global_abs,"a"
.p2align 1
discard_global_abs:
.quad sym_global_abs
.section .discard.weak_undef,"a"
.p2align 1
discard_weak_undef:
.quad sym_weak_undef
.section .discard._DYNAMIC,"a"
.p2align 1
discard_DYNAMIC:
.quad _DYNAMIC
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_discard_pie_assert_after_discarded_sections/run1..run3 are
stable by hash. In every run, `asm.rc.txt` is 0, `bfd.shared.rc.txt` is 0 with
identical `shared.relocs.txt` hashes, and `bfd.pie.rc.txt` is 1 with the same
assertion-bearing `bfd.pie.stderr.txt` hash. The upstream GNU control
`discard-pie.d` treats the PIE link as legal, so the first failure is a current
ld.bfd linker crash on valid input.
Notes
=====
upstream/binutils-gdb/ld/testsuite/ld-riscv-elf/discard.s;
D:/search_ascii/upstream/binutils-gdb/ld/testsuite/ld-riscv-elf/discard.ld;
D:/search_ascii/upstream/binutils-gdb/ld/testsuite/ld-riscv-elf/discard-pie.d
Root key: bfd.riscv.discard_pie_assert_on_legal_discarded_section_case
Case id: 20260528-bfd-discard-pie-assert
--
You are receiving this mail because:
You are on the CC list for the bug.