<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/202137>202137</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISC-V][lld] ld.lld shared object default visible local JAL not redirected to PLT
</td>
</tr>
<tr>
<th>Labels</th>
<td>
lld
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
XiaobingHou1219
</td>
</tr>
</table>
<pre>
I ran into this while reducing a RISC-V linker testcase. The reproducer is small, and I have been seeing the same result consistently across three reruns.
### Summary
ld.lld 18.1.8, 20.1.8, and 21.1.3 all reject the shared link with relocation R_RISCV_JAL cannot be used against symbol foo_default; recompile with -fPIC, even though the input object also contains an R_RISCV_CALL_PLT relocation to the same symbol and GNU binutils added this exact testcase as a valid shared-object link in PR28509.
### Expected behavior
A shared-object input defines a default-visible local function foo_default and references it once with CALL_PLT-capable call and once with direct JAL. GNU binutils PR28509 treats this exact pattern as a legal shared link whose two call sites should both resolve via foo_default@plt.
### Environment
- linker route: gas + ld.lld version replay
- march: rv64i
- mabi: lp64
- first failing stage: link
- local stability check: True
### Reduced testcase
These are the reduced input files from the minimized reproducer I used locally:
#### `case.s`
```asm
.option nopic
.text
.align 1
call foo_default
jal foo_default
.globl foo_default
.type foo_default, @function
foo_default:
nop
ret
.size foo_default, .-foo_default
```
#### `source_notes.txt`
```text
Primary-source legality evidence:
- GNU binutils PR28509 / shared-lib-nopic-04 test expects a successful shared link.
- The expected final disassembly uses `jal ... <foo_default@plt>` for both call sites.
```
### 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://llvm.org/docs/HowToSubmitABug.html
- evidence summary: 3 clean reproductions under hunt/verify/lld_shared_default_visible_local_jal_not_redirected_to_plt/run1..run3 show stable assembly success, stable object relocations R_RISCV_CALL_PLT plus R_RISCV_JAL against foo_default, and stable link-time rejection from ld.lld 18.1.8/20.1.8/21.1.3 at .text+0x8. Primary-source legality evidence comes from GNU binutils PR28509, which introduced shared-lib-nopic-04 as a successful RISC-V ld testcase expecting both call sites to become foo_default@plt.
### Notes
hunt/cases/confirmed/lld_shared_default_visible_local_jal_not_redirected_to_plt plus https://sourceware.org/pipermail/binutils-cvs/2022-September/059858.html
Root key: `lld.riscv.shared_object_default_visible_local_jal_not_redirected_to_plt`
Case id: `20260526-lld-shared-default-visible-local-jal-not-plt`
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykV01v4zgS_TXKpSBBlmPHPvjgpNs7GWQHjSQzuzeDIksW0xQpsEg7nl-_KH3Edtq9M4ttBG5bJOvj8dWrkiDSO4u4Smb3yezLjYihdn71by1cqe3uFxcnxWR5Uzp1XD2CFxa0DQ5CrQkOtTYIHlWU2u5AwPPjy0P6Bxhtv6OHgBSkIMzgteZtrXcqSvSgCagRxiTFAwir4BFqsUcoES0QItsKNQKJho9RNAGks6QpoA3mCEJ6RwSh9sgbfLSUJfmXJF8Pn8W0_4OX2DTCH_vHRmXGKJgsskm2YN9FPn7jKIpJNsmmIIwBj28oQx9ELTyqLiU46FCDR-OkCNpZeN5ywn9sf10_gRTWugAlQiRUIHZCWwpAx6Z0BirntgorEU1IpvfgUbqmZfA6k2n17fGBw8A9Wgi1i7u6c65tGwO4sotGGHKMQ2DLIE7uH9ZPT9tvT6_noXVXNEA4xMA5_uO336HUNgZtCIRSqPqbxHfB-Q4XBoJAwF4YrYb80yGGDgZt4dtzsZjly5-g_vW9RRlQQYm12Gvn-w3rT8b67BRW2iI7HABK95p0aRA4GQNVtLJL6QzDLhePFXq0Egl0AGflgOYIRypFK9iO5CvlE6c9SnuO4Nf1U3aJyZAYBI8i0Dk4rQgBve2xMbgT5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