<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/202173>202173</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [RISC-V][lld] ld.lld local IFUNC nonplt executable missing second irelative
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </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, 21.1.3, and 22.1.0 emit only one `R_RISCV_IRELATIVE` relocation for the legal `ifunc-nonplt` executable, while the official GNU control requires two independent IFUNC relocations for the two local-IFUNC materializations.

### Expected behavior
Link the official GNU `ifunc-nonplt` executable sample, which materializes a local GNU IFUNC through both GOT and data references in one executable.

### Environment
- linker route: llvm-mc plus ld.lld version replay with official GNU ld executable IFUNC 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:

#### `ifunc-nonplt.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, %got_pcrel_hi (foo)
.ifdef __64_bit__
        ld      x1, %pcrel_lo (.L1) (x1)
.else
        lw      x1, %pcrel_lo (.L1) (x1)
.endif

.L2:
        auipc   x2, %pcrel_hi (foo_addr)
.ifdef __64_bit__
        ld      x2, %pcrel_lo (.L2) (x2)
.else
        lw      x2, %pcrel_lo (.L2) (x2)
.endif
        ret
        .size   bar, .-bar

        .data
foo_addr:
.ifdef __64_bit__
        .quad   foo
.else
        .long   foo
.endif
```

### 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_nonplt_exe_missing_second_irelative/run1..run3 show stable hashes for `nonplt.exe.21.relocs.txt`; every run contains exactly one `.rela.dyn R_RISCV_IRELATIVE`. The copied GNU control `ifunc-nonplt-exe.rd` requires two `R_RISCV_IRELATIVE` entries in `.rela.plt`, matching the GNU `bfd.rel.txt` control captured earlier in the campaign.

### Notes
upstream///binutils-gdb/ld/testsuite/ld-riscv-elf/ifunc-nonplt.s; D:/search_ascii/upstream///binutils-gdb/ld/testsuite/ld-riscv-elf/ifunc-nonplt-exe.rd

Root key: `lld.riscv.local_ifunc_nonplt_executable_missing_second_irelative`
Case id: `20260528-lld-local-ifunc-nonplt-missing-second-irelative`

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysV9tu4zgS_RrlpWBBlhw7fvBD0olnAvT2Aul0774JFFmSakORGl7suL9-QVHypduZnQEWMHKh6nJOsVR1zKylRiFuktuH5PbxhnnXarP5NzFdkWp-136ez9c3lRaHzTMYpoCU0-BasrBvSSIYFJ6TaoDBy_PXT7PvIEm9oQGH1nFmMYXXNpj1RgvP0QBZsB2TMsk_AVMCnqFlO4QKUYFFDLFci2BZF9yslw64VpasQ-XkARg32lpwrcFgYLyyaZI9Jtn9-DMv4ge--q5j5hCPpUilFDC_S-fpXcidz9N5Wkwo8jydpxlgRw60kgfQCiFZZi9loPW9fH55-nz_-vz9KVlmYFBqzhxpBbU2A1yJDZPBgWqv-Exp1UsXbPEduXeskhhSxaIFB13XxIlJ-O3Lt0DQGS3B4B-eDFpwew2kBPaoBCoHz9tvXz6d5bXHxMEynMpZtOmYQ0NM0o9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