<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/202125>202125</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISC-V][lld] local_rvc_state_relax
</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 relaxes the call sequence in the local norvc region into the 16-bit encoding 0xa021 (disassembled as j), producing an RVC jump where local code generation state explicitly disabled RVC.
### Expected behavior
A mixed rvc/norvc object uses a non-compressed tail call inside a local .option norvc region. Linker relaxation must not emit a compressed jump there.
### Environment
- linker route: gas+ld.lld
- 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:
#### `case.S`
```asm
.option rvc
.globl _start
_start:
add a0, a0, a1
add a1, a1, a2
.balign 4
.option norvc
add a0, a1, a2
tail foo
.space 4
.balign 8
foo:
ret
```
### 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/local_rvc_state_relax/run1..run3 show the input object contains an auipc+jr call sequence at offset 0xA, but the final ld.lld output contains the 16-bit j encoding at the corresponding site; the unbuffered sibling variant also fails at link time with an insufficient-padding R_RISCV_ALIGN error caused by the same unexpected shrink.
### Notes
https://maskray.me/blog/2021-03-14-the-dark-side-of-riscv-linker-relaxation
Root key: `lld.riscv.relax_ignores_local_norvc_state`
Case id: `20260525-lld-rv64-local-rvc-state-relax`
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyEVl9P6zoS_zTpyyhRkv459KEPBQ57ke7eB2DP7hua2JPE4NhZj13ofvqVnbSFI9CVqkLt-T-_-Y2RWXWGaJetr7P17QKD763b_UehbZTp_rChqqvtorHyuLsHhwaU8RZ8rxjeeqUJHMkglOkA4eH-8Sb_BVqZV3Lgib1ApgKe-ig2OiuDIAeKgQfUOqtvAI2Ee-jxQNAQGWCiaMv3BIxDVOOgPQhrWLEn4_URUDjLDL53FAVcMFxk5W1W7ufvejl94DEMA7rjdKxlobUERxrfiZMLgVoD038DGUGgTDrUVqAGY91BgKNO2XPOBNUmb5QHMsLKGGf5jmVdQVZfScXITEOjSQIyvGT1NiY4ZZ3qY-Dh1w28hGGEt57cyZOwkqAjQw59dMYePQG9j1oJFfONppPZh1833yT6830k4UlCQz0elHWTwB4G9U4S3EFk9d2Ukm1eSHgITAwIxppc2GF0xEwSPCo9VUUZVpIA5yALO6bgPpalgD-nTqeSTsEPgT0Y64EG5QHhg-2UuI-Jf5eEOShnzUDGT1f5CUrOBk_Zcg8dclZfT508yQzoRB8v3WGzUgOKy0Wj4rkeN6vTWasce2hR6dgS9tglu9HP2WdKmD02Sit_BNGTeI1CTy7Q15E_xBmI5ZshP90_9cQE6ChBx80yyozBQ6s0MbTODulyUEYN6n-xVZc5uY9NklM8-pgt9186j_6zTZkm7THblPP1ppw-yMN0cupgxMJ00GnbaHhmj24u-Pz_yRMASglYpkGdvqtPN9V8Fr_r003RoFadgdXHcD_h5wvrv9lIOGytPdvkEQWdTJ5dXE2_o-AlZkf-txp817Sp0nNcnviEgKfIbiOKV-xiR6z1IC1xwnWiKgRWptORQIw1KuIl25QumGLkKtuU8OZwHMkVJ4v_4i9AwBCMJHfqXlbfRdXIiK3V2r5NFGWHAY1kkFaEOBpJ-4POw8_97T9_FoPMNuXZ36OPjAFvyhtiBht89Bdr_NaTgTiS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