<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/202186>202186</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[RISC-V][lld] ld.lld big endian emulation and output format names unsupported
</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 22.1.0 links the big-endian objects successfully when the target is inferred from the input object, but rejects explicit big-endian selectors: `ld.lld -melf32briscv` and `-melf64briscv` fail with `unknown emulation`, and linker scripts containing `OUTPUT_FORMAT(elf32-bigriscv)` or `OUTPUT_FORMAT(elf64-bigriscv)` fail with `unknown output format name`. GNU ld.bfd 2.45 accepts the same explicit emulations and output-format scripts and emits ELF headers marked big-endian.
### Expected behavior
Link LLVM-MC-generated big-endian RISC-V objects by explicitly selecting the GNU-compatible big-endian target through `ld.lld -melf32briscv`/`-melf64briscv` or through linker-script `OUTPUT_FORMAT(elf32-bigriscv)`/`OUTPUT_FORMAT(elf64-bigriscv)`. Since ld.lld already accepts the same input objects by target inference and emits big-endian RISC-V ELF outputs, the explicit selector routes should be recognized consistently rather than rejected before normal link processing.
### Environment
- linker route: LLVM MC 22 `riscv32be`/`riscv64be` objects plus current ld.lld 22.1.0; current GNU ld.bfd 2.45 with the same `-melf32briscv`/`-melf64briscv` and `OUTPUT_FORMAT` scripts as positive controls
- march: riscv32be and riscv64be
- mabi: ELF32/ELF64 big-endian RISC-V objects from llvm-mc
- 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
.globl _start
_start:
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/lld_be_emulation_names/run1..run3` show stable LLVM-MC assembly success, stable lld inference success, stable lld explicit-selector rejection, and stable GNU ld.bfd success. The combined summary has 36 rows: `lld_infer_success=6`, `lld_emulation_unknown=6`, `lld_output_format_unknown=6`, `bfd_emulation_success=6`, and `bfd_output_format_success=6`. Representative run1 RV64 `lld-infer` output has a big-endian ELF header, while run1 `lld-emulation` stderr is `ld.lld: error: unknown emulation: elf64briscv` and run1 `lld-output-format` stderr is `ld.lld: error: unknown output format name: elf64-bigriscv`. Local source/test search shows `upstream/llvm-project/lld/test/ELF/emulation-riscv.s` covering only little-endian `elf32lriscv`/`elf64lriscv` and `elf32-littleriscv`/`elf64-littleriscv`. Web searches on 2026-06-05 over LLVM GitHub issues/PRs and broad web queries for `elf32briscv`, `elf64briscv`, `unknown emulation: elf64briscv`, and `elf64-bigriscv ld.lld` found no direct current upstream issue report; results were generic LLVM issues or unrelated RISC-V compiler/linker reports.
### Notes
upstream/llvm-project/lld/test/ELF/emulation-riscv.s`. GNU ld.bfd 2.45 accepts `elf32briscv`/`elf64briscv` and `elf32-bigriscv`/`elf64-bigriscv` locally. The RISC-V psABI currently notes that the big-endian ABI is not yet included, so this should be reported as ld.lld self-consistency/GNU-compatibility for its implemented `elf*-bigriscv` output support rather than ratified psABI conformance.
Root key: `lld.riscv.big_endian_emulation_and_output_format_names_unsupported`
Case id: `20260605-lld-riscv-big-endian-emulation-output-format-unsupported`
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykWEtv4zgS_jXKpWBBkW0lOeSQl7sDpHsG6aRnbwFFli1uKNLLRzzeX78okpLtxJnpxQBBw00Wi_X4quqjmHNypREvi_l1Mb89YcF3xl7-Sz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