<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/202166>202166</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISC-V][lld] ld.lld CREL relocatable output leaves sh link sh info unset (before LLVM 19)
</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/15.0.7/16.0.6/17.0.6/18.1.8 link the legal `-r` input successfully but emit malformed `.crel.text` and `.crel.text1` sections with `Link: 0` and `Info: 0`, so relocation decoding loses the symbol-table and target-section association and only a bare `R_RISCV_RELAX` remains printable. ld.lld 19.1.7+ repairs the CREL section association metadata on the same input.
### Expected behavior
Produce an RV64 relocatable `-r` output in the CREL path after assembling one object with `--crel` and another with a non-relax `.balign 8`. A correct linker must keep valid `SHT_CREL` relocation sections that still point to the symbol table and the associated text section.
### Environment
- linker route: llvm-mc plus ld.lld version replay with upstream lld relocatable-alignment control
- march: rv64imac
- 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:
#### `a.s`
```asm
.globl _start
_start:
call foo
.section .text1,"ax"
.globl foo
foo:
call foo
```
#### `b.s`
```asm
.option push
.option norelax
.balign 8
b0:
addi a0, a1, 1
.section .text1,"ax"
.balign 8
addi a0, a1, 1
.option pop
```
### 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_crel_assoc_before_19_verify/run1..run3 all show the same version split: every `out.14/15/16/17/18.sections.txt` contains `Link: 0` and `Info: 0` for both `SHT_CREL` sections, every matching `out.*.relocs.err.txt` contains the `unable to print relocation 0 in SHT_CREL` warning, and every `out.19/20/22.sections.txt` restores non-zero association fields. This is a link-stage wrong-output defect on a legal relocatable input, distinct from later ALIGN-loss bugs because the section-association metadata itself is corrupt before LLVM 19.
### Notes
upstream/llvm-project/lld/test/ELF/riscv-relocatable-align.s
Root key: `lld.riscv.crel_relocatable_output_leaves_sh_link_sh_info_unset_before_19`
Case id: `20260528-lld-crel-relocatable-invalid-association-before-19`
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyUV0tv4zgS_jXKpSBBlh-JDz64u-OdAJnBwp3tnZtBUWWLG4oUWKTTnl-_KFLyY9s9MwsEiUKq3lVffRJE6mAQV9n8Uzb_8iCCb61b_a6ErZU5_GLDpJosH2rbnFYv4IQBZbwF3yqCj1ZpBIdNkMocQMD25evn_BtoZd7RgUfyUhAW8Nbya72zTZDoQBFQJ7TOqs8gTAMv0IojQo1ogBBZl28RSHQsRkF7kNaQIo_G6xMI6SwR-NYhv-CCoSIrv2TlevhdTdMPfA1dJ9wpHeum0LqByawoi0VWbSbzoiwe-WExnjyOD0_FpHiKgURXNB6EhmxR5i5blKBMHzxQkBKJ9kHrE9TBA3bKQyf03roOG369kA514fG7ZzGO9eZwwqeE0itrCD6Ub_n-VZn3bLqG8krmxezteMZpIwsOtZWCRaFBaRtOm7aElJJ36mqrcy9qjVGJF-6APh-sgSCyUiVxvraGEwu1cMj2tjuu5bfd9vl1_Tv74bATyhD0TpmotIAxn8tiwmn8xCUWyiX7n7fPr3DPWIdeNMILsOZS5ZjQn9Tw-XuP0mMDNbbiqKxLL_wzdRMIA9tvi9mYjhjvuVA2eK6UMhefeuFbEHuPjt3CrtacOGsQbP0flP5chjznOo01EMb6Fl26FWCsyR1q8T0WtB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