<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/202124>202124</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-data sample with an out-of-range R_RISCV_PCREL_HI20 error, while GNU ld.bfd links the same object and rewrites it to //

### Expected behavior
A firmware image places .text far above low .data using a linker script. A standard auipc plus %pcrel_lo pair targeting low data should be canonicalized by the linker to an absolute lui+ld 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_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 pcrel form)

Root key: `lld.riscv.far_pcrel_hi20_not_rewritten_to_absolute`
Case id: `20260525-lld-far-pcrel-hi20`

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUV0uT4roV_jVmcwqXEQ2NFyzoB5muupmk6L43yYqSpYOtjCy59IAmvz51ZBu6J8zMMnUpF2D5PL_zNPde1QZxnS0essXThMfQWLf-p-K2Uqb-YuOMzcpJZeV5_QKOG1AmWAiN8nBqlEZwKKNQpgYOu5fXx-kfoJX5hg4C-iC4xxzeGiLrnJVRoAPlwbdc64w9AjcSXqDhR4QK0YBHJFmhQfC8JTYfdQBhjVc-oAn6DFw46z2ExiERuGh8nhVPWbEZvtm8v-A1ti135_5Yy1xrCQ7_jSL4pOLItZJw4G4qeeCksdMIJxUa4AZsDFN7mDpuaoTdnrz7Y__3x93zb_svL6wAdM46cqIH4i9ffwct8-ogEwL-6oStSGXy1eHJqYAeVIBgIWNbum4a__zeoQgoocKGH5V1PcEGDsq1J-4QVMtrhE5zgR7ygO-BfAFe2SOCtifIk1vR9-EZ4uKFU13IYQM-cCO5k8Cj6gR0OnrI2KITDvVeW-i4chC4qzGQBJLY49TYqMkuENxYowTX6j9k6Dn5PMbfEoi88lbHgKCjytiDlnCwroVTg2ZAjISAxpprfQZpwdsfRPPZHJWzpkUT-kfTUZWzMWA230DNfVKSIp3ieDmhuAhrgrN65G65Ew2xuePyTl1PK0WHulvejWcH5TyBqzQB4QOvkzpSfzHFCq7pUaW0CmcQDYpvRPTmIt52aEelg_JSKf3zt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