<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/202123>202123</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISC-V][lld] lld_far_pcrel_rewrite_missing
</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 rejects the valid far-GOT sample with an out-of-range R_RISCV_GOT_HI20 error, while GNU ld.bfd links the same object and rewrites it to //
### Expected behavior
A firmware image places .text far above the GOT using a linker script. A %got_pcrel_hi plus %pcrel_lo pair targeting low GOT entries should be canonicalized by the linker to the absolute GOT-base form when GNU ld can legally do so.
### Environment
- linker route: gas+ld.lld with gas+ld.bfd control
- 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:
#### `far_got_pcrel_min.s`
```asm
.text
.globl _start
_start:
.LA0: auipc a5, %got_pcrel_hi (ll)
ld a0, %pcrel_lo (.LA0)(a5)
.globl ll
.data
ll:
.dword 0
```
#### `far_pcrel_min.s`
```asm
.text
.globl _start
_start:
.LA0: auipc a5, %pcrel_hi (ll)
ld a0, %pcrel_lo (.LA0)(a5)
.globl ll
.data
ll:
.dword 0
```
#### `link.ld`
```ld
ENTRY(_start)
SECTIONS
{
.got 0x1000 : {
*(.got)
}
.data 0x2000: {
*(.data)
}
.text 0x900000000 : {
*(.text)
}
}
```
### 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_far_pcrel_rewrite_missing/run1..run3 show stable ld.lld out-of-range diagnostics for far_got_pcrel_min.o and stable GNU ld.bfd control output beginning with //
### Notes
upstream///binutils-gdb/ld/testsuite/ld-riscv-elf/pcrel-lo-addend-3a.s (reduced far got_pcrel form)
Root key: `lld.riscv.far_got_hi20_not_rewritten_to_absolute_got_form`
Case id: `20260525-lld-far-got-hi20`
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUV1tv4koS_jXmpWTLtDGBBx7IJJyJtDsjJZyzu0-o7S7s3ml3W32BsL9-VW0bkpzMnMfVIgtwu-qr-8XcOdloxE1S3iflw4wH3xq7-afkppK6-WrCnM3Xs8qIy-YJLNcgtTfgW-ng3EqFYFGEWuoGODw_vXxJ_wAl9Q-04NH5mjvMYN8SWW-NCDVakA5cx5VK2BfgWsATtPyEUCFqcIiE5VsExztic0F5qI120nnUXl2A19Y4B761SAQ2aJcl-UOSb8dvVgwXvISu4_YyHCuRKSXA4r-x9i6KOHElBRy5TX_7vieBvUI4S98C12CCT80xtVw3CM8HMu6Pw2_f94evTywHtNZYsmDwwm_ffgclsuooovnuZoGpSF401OLZSo8OpAdvIGE7uj7V_PG1x9qjgApbfpLGDgRbOErbnblFkB1vEHrFa3SQeXz1ZAjwypwwSieTghsiM4bE1Vb2PoMtJKxsjD_0tUV1aCX0Kjg6HA6UgZ5LC57bBj1BKHOOgKi9lejAtSYo0g5qro2WNVfyP6TuJcqeUsDEO145o4KPKqUVdwhHYzs4t6hHxxEKKGy4UhcQBpz5SUQf9UlaozvUfniUTrKsCR6TYgsNdwm7H6Mdg3k9ofDURntr1MTdcVu3xGZPy4W8nVaSDlW_XExnR2kd-VgqcojzvIniSPxVFVNzRY8qqaS_QN1i_YOI9jbg5wY9U_mguFbL8HzfokOgMPt2LDEUIHUfPBylQgdHa7r4sJNadtH3b0rsCYJDMeijL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