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

    <tr>
        <th>Summary</th>
        <td>
            [RISC-V][lld] ld.lld final link align relaxation unimplemented (before LLVM 15)
        </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 14.0.6 rejects the legal final link with `relocation R_RISCV_ALIGN requires unimplemented linker relaxation`, while ld.lld 15.0.7 and 22.1.0 link the same object successfully.

### Expected behavior
Link a normal final RV32 executable that contains several meaningful `.balign` sites represented by `R_RISCV_ALIGN` relocations. A correct final linker must consume those alignment relocations while relaxing instead of rejecting the link.

### Environment
- linker route: llvm-mc 22 plus ld.lld version replay
- march: rv32i
- mabi: ilp32
- 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
.global _start
_start:
  lui a0, %hi(_start)
a:
  addi a0, a0, 0x2
b:
.balign 16
  addi a0, a0, 0x3
c:
  addi a0, a0, 0x4
  addi a0, a0, 0x5
.balign 32
.size a, . - a
  addi a0, a0, 0x6
  addi a0, a0, 0x7
.balign 16
.size b, . - b
  addi a0, a0, 0x8
.size c, . - c
  addi a0, a0, 0x9
.size _start, . - _start

.section .text2,"ax",@progbits
d:
e:
.balign 8
  addi a0, a0, 0x1
f:
  addi a0, a0, 0x2
.balign 32
.size d, . - d
  addi a0, a0, 0x3
.size e, . - e
.size f, . - f

.section .pcrel,"ax",@progbits
.L1:
  auipc a0, %pcrel_hi(_start)
  addi a0, a0, %pcrel_lo(.L1)
.balign 16
.L2:
  auipc a0, %pcrel_hi(_start)
  addi a0, a0, %pcrel_lo(.L1)
```

### 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_final_link_align_relaxation_unimplemented_before_15/run1..run3 show stable assembly success for `32.o`, stable 14.0.6 link-time rejection on multiple `R_RISCV_ALIGN` sites in `.text`, and stable 15.0.7/22.1.0 successful links whose objdump files begin with the expected `_start`/`a`/`b` layout.

### Notes
upstream/llvm-project/lld/test/ELF/riscv-relax-align.s

Root key: `lld.riscv.final_link_align_relaxation_unimplemented_before_15`
Case id: `20260528-lld-final-link-align-relax-unimplemented`

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJy0V0tv47oV_jXy5sCCTMWOvfAidzLuDZB7F5l02p1BkccWJxSp8uHE99cXh5Rsp-NkigIFAkMhz_v5kXuv9gZxXcx_K-b3Ex5Da936n4rbRpn97zbO2Gw1aaw8rh_AcQPKBAuhVR5eW6URHMoolNkDh6eHb1-m30Er84IOAvoguMcSnlsi652VUaAD5cF3XOuCfQFuJDxAyw8IDaIBj0iyQovgeUdsPuoAwhqvfEAT9BG4cNZ7CK1DInDR-LKo7ovqbvhldf6Db7HruDvmYy1LrSXMbsqqXIDDHyiCT5o07rmGnTJcJ-PhVYUWikXlUFvBg7IGnrbk3fft3ePD3_4Eh_-KyqGHaFTXa-zQBJSj5w41f0tsxaIiL3OkRgPmZVXeJs8ZK2dllXWeXLYNWQY-CoHe76LWxw_c-_rWoyC9Dbb8oKzLBI8kjoOxrju59fS9ZoBvKGLgjUYILU9RDVwZDx4P6LiGDrlRZr-LmrwvG67VnnwArwL6lEP02dXmSCTvokKE54j5Eu5AWOfImXNs0UEXf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