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

    <tr>
        <th>Summary</th>
        <td>
            [RISC-V][lld] ld.lld symver versioned aliases lost from plain symtab
        </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 22.1.0 all link successfully but the ordinary `.symtab`/plain `nm` view contains two global unversioned `foobar` entries instead of `foobar@@New` and `foobar@Old`, so the official GNU `relax-twice` check cannot find `foobar@@New`. The same lld output also emits `.gnu.version_d` for `New` with `Cnt: 1` and no `Parent 1: Old`, while GNU ld.bfd emits `foobar@@New`, `foobar@Old`, and a `New` version definition with parent `Old`.

### Expected behavior
Link the official GNU RISC-V `relax-twice` shared-object sample with `.symver` aliases `foobar@@New` and `foobar@Old` plus a version script where `New` inherits from `Old`. The final linked ELF should preserve the versioned aliases in ordinary symbol-table views so `foobar@@New` is visible and has the same address as the local implementation symbol `foobar_new`.

### Environment
- linker route: GNU as plus ld.lld version replay with GNU ld.bfd 2.45 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:

#### `relax-twice-1.s`
```asm
        .file   "<artificial>"
        .option pic
        .text
        .globl  foobar_new
        .weak   foobar_new
        .type   foobar_new, @function
foobar_new:
        jr ra
        .size   foobar_new, .-foobar_new
        .symver foobar_new, foobar@@New

        .section        .note.GNU-stack,"",@progbits
```

#### `relax-twice-2.s`
```asm
        .file   "<artificial>"
        .option pic
        .text
        .section        .rodata.str1.8,"aMS",@progbits,1
        .align  3
.LC0:
        .string "%u"
        .text
        .align  1
        .globl  relaxme
        .type   relaxme, @function
relaxme:
        addi    sp,sp,-32
        addi    a2,sp,12
        lla     a1,.LC0
        li      a0,0
        sd      ra,24(sp)
        call    sscanf@plt
        ld      ra,24(sp)
        addi    sp,sp,32
        jr      ra
        .size   relaxme, .-relaxme
        .align  1
        .globl  foobar_new
        .type   foobar_new, @function
foobar_new:
        li      a0,1
        ret
        .size   foobar_new, .-foobar_new
        .symver foobar_new, foobar@@New
        .align  1
        .globl  foobar_old
        .type   foobar_old, @function
foobar_old:
        addi    sp,sp,-16
        sd      ra,8(sp)
        call    foobar@plt
        ld      ra,8(sp)
        snez    a0,a0
        addi    sp,sp,16
        jr      ra
        .size   foobar_old, .-foobar_old
        .symver foobar_old, foobar@Old
        .section        .note.GNU-stack,"",@progbits
```

### 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_riscv_symver_plain_symtab_loses_versions/run1..run3 show stable GNU-as assembly success for both inputs, stable successful links for ld.lld 18.1.8/20.1.8/22.1.0 and GNU ld.bfd 2.45, stable lld plain-nm hash `7b828f750dac45a72911f9324671c61cbaa03546cb67e839da77cf7b32146e65`, and stable bfd plain-nm hash `07c7954602749dad4eccc2261ef318c6d7c6bcb72a1f1729c0866b5ac2c5a338`. In run1, `lld22.1.0.so.nm.txt` shows two unversioned `T foobar` lines at the old/new implementation addresses, while `bfd.so.nm.txt` shows `foobar@@New` at `foobar_new` and `foobar@Old` at `foobar_old`. Local records had no existing `symver`/`relax-twice` root, and web searches for `relax-twice ld.lld RISC-V foobar` and `foobar@@New ld.lld` found no direct upstream LLVM issue match.

### Notes
upstream/binutils-2.45/ld/testsuite/ld-riscv-elf/relax-twice-1.s; upstream/binutils-2.45/ld/testsuite/ld-riscv-elf/relax-twice-2.s; upstream/binutils-2.45/ld/testsuite/ld-riscv-elf/relax-twice.ver; upstream/binutils-2.45/ld/testsuite/ld-riscv-elf/ld-riscv-elf.exp

Root key: `lld.riscv.symver_versioned_aliases_lost_from_plain_symtab`
Case id: `20260604-lld-riscv-relax-twice-symver-plain-symtab`

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy8WF9v4zgO_zTuixDDVhIneehDJ53sFujOHTqdvXsrZImONZUlQ5KTZj79gZYdO__mFri5BYI2kUjqR4qU-BNzTm41wH00_xTNH-9Y40tj7_8tmcml3v5umpSmq7vciMP9E7FME6m9Ib6UjuxLqYBYEA2XeksYeXn6up78SZTU72CJB-c5cxCT1xLFamtEw8ES6YirmFIRXROmBXkiJdsByQE0cQBoy5dAHKtQzTXKE260k86D9upAGLfGOeJLCyhgG-3iKHmMkofuL52GD_naVBWzhzCsRKyUIOkyTuMlrk2T_huioDRO44QwpVoHiGs4B-eKRqkDyRvfYjJWSM3sgURZErtD5VkeZUlEN7ViUuOorqIsITsJewTtmdSO-L0hW2Vypkijd2CdNBoEShfG5MyiBmhvJTgitfPABDHFaH6WRLPkC-xRELGOZ_6hRAthTZwJGItCcskU-e3LN5S0oNjHxO8lB9TnJfB3wpnWxpNCnlk7rhN2rd0DjJppfN14wpQzBCrpXRuBrW7izp83REEKY3Gig7qXvsSfa-2j6QNJe_ja4Og_mQXtSYpTgxMhqRC6EnFeiGG1S4wofz0UuAobIelAEgGF1NLj1xZcHTBEWad7I48-f9TAPQiSQ8l20tgg8Ix5chHyrgouI-9KZkFMTP4duMfQ1gqOMcJs2kGbCkxJ5uCGzzf2n9SqcYQdHXXcytqTfQkWRnGQugSL8SysqUZut5tdSM1C8oMgn583xJWmUYLUFhzYHbSuDunbw5R6KAt3qHKjJp7lCtoicJiV1x2RjuykkyiJPpXMDWXPhLDgH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