https://sourceware.org/bugzilla/show_bug.cgi?id=35107
Bug ID: 35107
Summary: GNU ld RISC-V dereferences missing local GOT offsets
after rejecting a shared-object relocation
(/bfd/elfnn-riscv.c:4027:14)
Product: binutils
Version: 2.48 (HEAD)
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: ld
Assignee: unassigned at sourceware dot org
Reporter: emily.west286 at gmail dot com
Target Milestone: ---
Created attachment 17344
--> https://sourceware.org/bugzilla/attachment.cgi?id=17344&action=edit
reproducer
I'm reporting this bug on behalf of my team: Ananta Srikar Puranam, Emily West,
Dr. Swarn Priya, Dr. Peng Gao and Dr. Basavesh Ammanaghatta Shivakumar.
Summary
-------
A RISC-V object plus a regular archive makes ld reject a non-PIC relocation for
a shared object and continue into the final link. Relocation then indexes the
NULL local GOT-offset array at bfd/elfnn-riscv.c:4027, after the assertion at
line 4025 fails.
Reproduction
------------
1. Extract `bfd-riscv-local-got-offsets-null-dereference-reproducer.tar.gz`.
2. Run:
LD=/path/to/ld-new sh repro.sh
Without a local build, use the `bfd-repro` image:
docker run --rm -v "$PWD:/queue:ro" bfd-repro \
/queue/attachments/bfd-riscv-local-got-offsets-null-dereference-reproducer.tar.gz
Observed result
---------------
Master a76487344054, Clang ASan+UBSan. Trigger:
input.a(common.o): relocation R_RISCV_HI20 against
`cross_00f7e5da150d_provider_s134_GO' can not be used when making a shared
object; recompile with -fPIC
input.a(common.o): warning: relocation against
`cross_00f7e5da150d_provider_s30_WO' in read-only section
`.rodata.cst.4[cross_00f7e5da150d_provider_s30_WO]'
BFD (GNU Binutils) 2.47.50.20261204 assertion fail
../../bfd/elfnn-riscv.c:4025
../../bfd/elfnn-riscv.c:4027:14: runtime error: applying non-zero offset
224 to null pointer
==15==WARNING: invalid path to external symbolizer!
==15==WARNING: Failed to use and restart external symbolizer!
#0 0x55a518c7739b (/opt/bfd/ld-new+0x1cb939b) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#1 0x55a518a1d86d (/opt/bfd/ld-new+0x1a5f86d) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#2 0x55a518a12517 (/opt/bfd/ld-new+0x1a54517) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#3 0x55a518c55ee8 (/opt/bfd/ld-new+0x1c97ee8) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#4 0x55a51844ad37 (/opt/bfd/ld-new+0x148cd37) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#5 0x55a518443b81 (/opt/bfd/ld-new+0x1485b81) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
#6 0x7f6a95ebd249 (/lib/x86_64-linux-gnu/libc.so.6+0x27249) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
#7 0x7f6a95ebd304 (/lib/x86_64-linux-gnu/libc.so.6+0x27304) (BuildId:
93ac61ec5a8eb1396f9fbd350e3169a558528a40)
#8 0x55a51844ec6e (/opt/bfd/ld-new+0x1366690) (BuildId:
e954f11978a1462c93a1fefa94c533268ef8adb3)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior
../../bfd/elfnn-riscv.c:4027:14 in
Aborted (core dumped)
The relocatable control exits 0 with no diagnostics.
Root cause
----------
Source reading (not yet confirmed at runtime):
- riscv_elf_check_relocs rejects the non-PIC R_RISCV_HI20 in a shared link with
bad_static_reloc (bfd/elfnn-riscv.c:1746-1748). That returns false, which
stops
the GOT bookkeeping for the rest of that input.
- Local GOT references that come after it are never counted, so the local
GOT-offset array is never allocated.
- ld reports the error but still runs the relocation pass. There the
BFD_ASSERT at lines 4024-4025 fails, and local_got_offsets[r_symndx] is read
from NULL at line 4027.
This is the same pattern as the AArch64 local-GOT report (PR 35086): relocation
continues after check_relocs has already failed.
Expected result
---------------
ld should reject the input with a normal diagnostic, not index the NULL local
GOT-offset array.
Validation
----------
* Master a76487344054, Clang ASan+UBSan: trigger aborts at
elfnn-riscv.c:4027:14; control exits 0.
* Duplicate check (2026-12-03): no matching Sourceware report found.
Scope
-----
Robustness issue. No invalid write across a security boundary is established.
Attachment
----------
- `bfd-riscv-local-got-offsets-null-dereference-reproducer.tar.gz`
--
You are receiving this mail because:
You are on the CC list for the bug.