[lld][ELF][Mips] Link MIPS n32 bitcode as ELF32 #18

Merged
techwritescode merged 1 commit from lld-mips-n32-lto into r5900-ee 2026-10-15 22:08:17 +00:00

PS2-194: LLVM -flto failed to link EE code. lld treated any 64-bit MIPS bitcode as ELF64 and never recognised it as n32, so every n32 LTO link failed with "is incompatible with".

File Change
lld/ELF/InputFiles.cpp getBitcodeELFKind: bitcode with an n32 triple (isABIN32()) is ELF32
lld/ELF/Arch/MipsArchTree.cpp isN32Abi: bitcode reports n32 from its triple; before, only ELF headers were read
lld/test/ELF/lto/mips-n32.ll n32 bitcode links alone, with -m elf32ltsmipn32, and next to an n32 object, in either order

This is generic MIPS n32 code, not R5900-gated, so it is an exception to the fork rule in UPDATING.md. Upstream main and lld 22.1.8 have the same bug (all three test cases fail on stock lld 22.1.8).

For EE code, #20 adds the mips64r5900el-ps2-elf triple, which implies n32 and the R5900, and ps2/ps2build#20 switches to it. Any other n32 triple (gnuabin32, muslabin32) also works with this PR alone.

Tested: the sdk-core bench built with -O2 -flto links (ELF32, abi2, 5900) and runs on the console rig with all 9 checksums matching the non-LTO build (runs 20261015T210020-0378 and 20261015T210043-0379, using an n32 triple and --plugin-opt=mcpu=r5900).

🤖 Generated with Claude Code

PS2-194: LLVM `-flto` failed to link EE code. lld treated any 64-bit MIPS bitcode as ELF64 and never recognised it as n32, so every n32 LTO link failed with "is incompatible with". | File | Change | |---|---| | `lld/ELF/InputFiles.cpp` | `getBitcodeELFKind`: bitcode with an n32 triple (`isABIN32()`) is ELF32 | | `lld/ELF/Arch/MipsArchTree.cpp` | `isN32Abi`: bitcode reports n32 from its triple; before, only ELF headers were read | | `lld/test/ELF/lto/mips-n32.ll` | n32 bitcode links alone, with `-m elf32ltsmipn32`, and next to an n32 object, in either order | This is generic MIPS n32 code, not R5900-gated, so it is an exception to the fork rule in UPDATING.md. Upstream main and lld 22.1.8 have the same bug (all three test cases fail on stock lld 22.1.8). For EE code, #20 adds the `mips64r5900el-ps2-elf` triple, which implies n32 and the R5900, and ps2/ps2build#20 switches to it. Any other n32 triple (`gnuabin32`, `muslabin32`) also works with this PR alone. Tested: the sdk-core bench built with `-O2 -flto` links (ELF32, abi2, 5900) and runs on the console rig with all 9 checksums matching the non-LTO build (runs 20261015T210020-0378 and 20261015T210043-0379, using an n32 triple and `--plugin-opt=mcpu=r5900`). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
[lld][ELF][Mips] Link MIPS n32 bitcode as ELF32
Some checks failed
action.yml / [lld][ELF][Mips] Link MIPS n32 bitcode as ELF32 (push) Failing after 0s
release-binaries-all.yml / [lld][ELF][Mips] Link MIPS n32 bitcode as ELF32 (push) Failing after 0s
release-binaries.yml / [lld][ELF][Mips] Link MIPS n32 bitcode as ELF32 (push) Failing after 0s
release-documentation.yml / [lld][ELF][Mips] Link MIPS n32 bitcode as ELF32 (push) Failing after 0s
release-sources.yml / [lld][ELF][Mips] Link MIPS n32 bitcode as ELF32 (push) Failing after 0s
Check for private emails used in PRs / validate_email (pull_request) Has been skipped
action.yml / [lld][ELF][Mips] Link MIPS n32 bitcode as ELF32 (pull_request) Failing after 0s
Check LLVM ABI annotations / Check LLVM_ABI annotations with ids (pull_request) Has been skipped
CI Checks / Build and Test Linux (pull_request) Has been skipped
CI Checks / Build and Test Windows (pull_request) Has been skipped
CI Checks / Compute macOS Projects (pull_request) Has been skipped
CI Checks / Build and Test macOS arm64 (pull_request) Has been skipped
release-binaries-all.yml / [lld][ELF][Mips] Link MIPS n32 bitcode as ELF32 (pull_request) Failing after 0s
release-binaries.yml / [lld][ELF][Mips] Link MIPS n32 bitcode as ELF32 (pull_request) Failing after 0s
release-documentation.yml / [lld][ELF][Mips] Link MIPS n32 bitcode as ELF32 (pull_request) Failing after 0s
release-sources.yml / [lld][ELF][Mips] Link MIPS n32 bitcode as ELF32 (pull_request) Failing after 0s
Add buildbot information to first PRs from new contributors / buildbot_comment (pull_request_target) Has been skipped
Labelling new pull requests / greeter (pull_request_target) Has been cancelled
Labelling new pull requests / automate-prs-labels (pull_request_target) Has been cancelled
fc1c20144a
lld gave any 64-bit MIPS bitcode file the ELF64 kind and never saw it as
n32, so -flto failed for n32 code with "is incompatible with". Bitcode
whose triple has an n32 environment (gnuabin32, muslabin32) is now ELF32
and passes the n32 check, against -m elf32ltsmipn32 and alongside n32
objects.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
techwritescode deleted branch lld-mips-n32-lto 2026-10-15 22:08:18 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ps2/llvm!18
No description provided.