<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/202131>202131</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISC-V][lld] lld_local_ifunc_pcrel_shared_false_pic_rejection
</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 legal shared-object link with relocation R_RISCV_PCREL_HI20 cannot be used against symbol /'foo/'; recompile with -fPIC.
### Expected behavior
A shared object defines a local non-preemptible GNU IFUNC foo and materializes its address inside the same image with the standard auipc %pcrel_hi(foo) plus addi %pcrel_lo sequence. This is a meaningful low-level pattern for taking the address of a local IFUNC inside a DSO.
### Environment
- linker route: clang integrated assembler + ld.lld version replay with GNU semantic control
- march: rv64gc
- mabi: lp64d
- 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
.text
.type foo_resolver, @function
foo_resolver:
ret
.size foo_resolver, .-foo_resolver
.globl foo
.type foo, %gnu_indirect_function
.set foo, foo_resolver
.globl bar
.type bar, @function
bar:
.L1:
auipc x1, %pcrel_hi(foo)
addi x1, x1, %pcrel_lo(.L1)
ret
.size bar, .-bar
```
### 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_local_ifunc_pcrel_shared_false_pic_rejection/run1..run3 show stable assembly success, stable object relocations R_RISCV_PCREL_HI20 plus R_RISCV_PCREL_LO12_I against local IFUNC foo, and stable link-time rejection from ld.lld 18.1.8/20.1.8/21.1.3. Control minimizations show that local IFUNC data and GOT address materializations succeed, so this is a distinct PC-relative address-materialization root.
### Notes
upstream/binutils-gdb/ld/testsuite/ld-riscv-elf/ifunc-reloc-pcrel-pic.rd and local reduced source
Root key: `lld.riscv.local_ifunc_pcrel_address_materialization_false_pic_rejection`
Case id: `20260526-lld-local-ifunc-pcrel-shared-false-pic`
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUV11v2zoS_TXKy0CCLNmK8-CHfNS3BrptkaR3982gyLHEDUVqOaRT99cvSEm2kzooLmAkNjUcnhmeOTNiRLLRiKtkcZcsHq6Yd62xq_9IZmqpm8_Gz4rZzVVtxGG1Acs0SO0MuFYSvLZSIVgUnkvdAIPHzdN9-jcoqV_QgkNynBFm8NwGs94a4TlakATUMaWS4h6YFrCBlu0RakQNhBh8uRaBWBe2kVcOuNEkyaF26gCMW0MErrUYDKzXlCX5Q5Lfjn-LcvjAk-86Zg_DshKZUgJmy2yWLcPZRT59CyiKWTbLSmBKgcX_IncRhMKGKaCWWRSpqeN6iA9epWvBojKcOWk0PG5D9H9vv98_fvqy_bwpcuBMa-OgRvCEAljDpCYHdOhqoyAp1klxvTNm-JKUd2CRm64PSY3e0933zf0HkX362SN3KKDGlu2lsYPB7QgVRqgCd1IjAYMAVIE2Ou0tYtc7WSuEv77-gM36x9d72BkT09Axh1YyJX8hgXQETAiLRCA1SYGnm5Eda0agcc0xLZgVwLzsOSTFoucW1baVSbGMUd5Ar3z0J0-PlQHC_3nUPPJEUmAHgw6ZlrrZeQXKvKYK96igZ86h1bAzFhx7mXgyATS7Y5hDSCNiBg9P3z5Ko95La3SH2g2P0om91niHSXkLXDHdBNZjY1nIOCPCrlZoISnuYGTVHi0FGljsFTsMaQnJJeyYdpIHBjtr1HRKxyxv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