<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/202196>202196</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISC-V][lld] ld.lld variant cc linker defined alias loses flag
</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 links successfully but when `foo` is created by the linker as an alias of variant-CC function `real`, the output keeps `[VARIANT_CC]` on `real` while making alias `foo` plain. On shared links, `ld.lld` still emits `R_RISCV_JUMP_SLOT foo + 0` but drops both alias `foo`'s `STO_RISCV_VARIANT_CC` bit and `DT_RISCV_VARIANT_CC`. On relocatable `-r` links, alias `foo` likewise becomes plain while `real` stays `[VARIANT_CC]`. GNU ld.bfd preserves `[VARIANT_CC]` on both `real` and linker-defined alias `foo`, and emits `DT_RISCV_VARIANT_CC` on the matching shared outputs. Plain-target controls are correct on both linkers.
### Expected behavior
Link valid RISC-V objects where a real function `real` is marked `[VARIANT_CC]`, a caller references linker-defined alias `foo` through an ordinary `call foo`, and the final link defines `foo` as `real` through `--defsym`, linker-script assignment, or `PROVIDE`. A correct link must preserve `STO_RISCV_VARIANT_CC` on alias `foo` and, for shared links with `R_RISCV_JUMP_SLOT foo`, emit `DT_RISCV_VARIANT_CC`.
### Environment
- linker route: GNU as 2.45 input, current ld.lld 22.1.0 and GNU ld.bfd 2.45 shared plus relocatable `-r` links, RV32/RV64, with three alias-introduction routes (`--defsym=foo=real`, `foo = real;`, and `PROVIDE(foo = real);`) and plain `real` controls.
- march: rv32gc and rv64gc
- mabi: ilp32 and lp64
- first failing stage: link
- local stability check: True
### Reduced testcase
These are the reduced input files from the minimized reproducer I used locally:
#### `caller.s`
```asm
.text
.globl caller
.type caller,@function
caller:
call foo
ret
```
#### `real_variant.s`
```asm
.text
.globl real
.type real,@function
.variant_cc real
real:
ret
```
### Reproduction notes
- Reproduction command from the packaged case directory:
`powershell -ExecutionPolicy Bypass -File ./case/run.ps1`
- The reduced inputs live under `case/` and the stable witness outputs live 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_variant_cc_linker_defined_alias_loses_flag/run1..run3` are stable: each run reports 12 plain controls as `ok_plain_alias_match`, 6 variant shared rows as `wrong_drop_alias_variant_shared`, and 6 variant relocatable rows as `wrong_drop_alias_variant_relocatable`. Representative run1 RV64 `rv64_variant_assign/out.shared.bfd.dynsyms.txt` shows both `foo` and `real` as `FUNC GLOBAL DEFAULT [VARIANT_CC]`, `out.shared.bfd.dynamic.txt` contains `RISCV_VARIANT_CC`, and `out.shared.bfd.relocs.txt` contains `R_RISCV_JUMP_SLOT foo + 0`. The matching `out.shared.lld.dynsyms.txt` keeps `real` as `[VARIANT_CC]` but makes `foo` plain, `out.shared.lld.dynamic.txt` has no `RISCV_VARIANT_CC`, and `out.shared.lld.relocs.txt` still contains `R_RISCV_JUMP_SLOT foo + 0`. The canonical RV64 repro in `hunt/cases/confirmed/lld_riscv_variant_cc_linker_defined_alias_loses_flag` reproduces the same contrast with the smallest `--defsym=foo=real` form, and its `-r` output shows GNU ld.bfd preserving `[VARIANT_CC]` on alias `foo` while ld.lld drops it.
### Notes
upstream/llvm-project/lld/test/ELF/riscv-variant-cc.s` covers single-object defined/undefined/hidden/local/IFUNC cases, but no linker-defined alias route. Web searches over LLVM GitHub issue queries for `variant_cc`, `STO_RISCV_VARIANT_CC`, `DT_RISCV_VARIANT_CC`, `defsym`, `PROVIDE`, and `alias` did not find a direct current report; representative search URLs: https://github.com/llvm/llvm-project/issues?q=is%3Aissue+variant_cc+lld and https://github.com/llvm/llvm-project/issues?q=is%3Aissue+DT_RISCV_VARIANT_CC+lld .
Root key: `lld.riscv.variant_cc_linker_defined_alias_loses_flag`
Case id: `20260605-lld-riscv-variant-cc-linker-defined-alias-loses-flag`
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysWFFz4rjS_TXOSxcuYweSPOSBhGE3X2VnppJM9nujhNzGusiSV5LJcH_9rZZkMIFk72zdqtTUgKRW6_Tp7tMwa8VaId4mk7tkMr9gnau1uf1_wfRKqPXvuhvn45uLlS53tw9gmAKhnAZXCwtvtZAIBsuOC7UGBk8Pz_ejV5BCbdCAQ-s4s5jCS03bWqPLjqMBYcE2TMokvwemSniAmm0RVogKLCLZcjWCZQ0ds510wLWywjpUTu6AcaOtBVcbpA2mUzZNsnmSzeK_eRH-4LlrGmZ24WtZplKW3jsLtuMcra06KXew6hy81aggmWaV1sk0Ix-5QeawhNXOuxNfxSwwBUwKZkFXsGVGMOVG9_dQdYo7ob0Vg0wm04xeSGd159rOwQaxtbScTO5eZ08Ps68vy_v7ZDKnG48ORmwbtvHI-tsOzrWSCZXCNwW2Zgbjm-iyZJqFZ9I264SUgI1w_vDTkuLzuvy_H398Xz4_fnuBSmtI8jvIaDeBUBrdWlhpV7-_M8mv_Kfnl2_RzOABdFo4H8tkms1fzu3w7hqUmjPHVhJp58jQ0b3z758pxQbfhCVmcN2gDe-O0Aywso7tPoI1hd--_gBZpquqhNagRbPFz2LgHz8wTo8KoR-VWAmF5Sk0gcZ7oM8DQMaJCw1zvKaoxtgFbtgUvtPrRo6ZNXrCO6OlBWYQuDYGudu7F_z5iPRffrbIPXGxZluhTdjwKNQGtkyKss9TvfoXckd5jAaBAT35HIspGRpmNlh-gJtHADiTEg0YrNCg4mj_BjdKYN2ta8onbUqhmNnRKtmBY2gJt0ooJr1JCAaHpoLd3t_eMFGMbre7JhqLHlluROsgFL8GlaM1bejA96dvrw_zL546sz3y_tqms27Poc-SQauTtzJV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