powerpc64-ibm-aix: fix cfg(target_abi) value
Our powerpc64-ibm-aix target currently sets `cfg_abi` to "vec-extabi", which means that programs compiled for this target *think* they use that ABI. Even our inline asm logic trusts this field. But that's a lie, we're actually using the default ABI since we are never setting `EnableAIXExtendedAltivecABI` on the LLVM side. We should fix that discrepancy.
Between changing how we generate the code, and changing the label we put into `cfg_abi`, the latter is the less risky change. So let's do that.
This has been tried before in https://github.com/rust-lang/rust/pull/153830. We then decided to wait a bit while the target maintainers investigate whether they want to change the ABI or not. I think we have waited long enough. The last comment from them that I found is [this one](https://github.com/rust-lang/rust/issues/153876#issuecomment-4101480953) which says "I'd conclude the extend vector ABI should be disabled for now"; there have been further questions but no further communication. We can always still change the ABI in the future, but for now let's fix the obvious bug where the ABI we report in `cfg_abi` does not match the actual ABI we are compiling for.
Cc @Gelbpunkt @daltenty @gilamn5tr @amy-kwan @taiki-e
`core::num::f16b` Rust's 16bit Brain Float
Implements the [RFC: f16b type](https://github.com/rust-lang/rfcs/pull/3983). Best reviewed commit by commit, happy to split into separate PRs if that is deemed easier to review. However the line count and surface area is, in my opinion, reasonably small.
Adds;
- ABI plumbing for the `f16b` along with `bfloat` lang item to work with LLVM, GCC is explicitly `unimplemented!(...)`
- `f16b` feature gate, page for `f16b` on libruscdoc and a `struct bf16` in `core::num`
- Tests
- Treat `f16b` as a scalar primitive for scalable vectors
Issues;
- [Tracking Issue](https://github.com/rust-lang/rust/issues/160630)
- [RFC](https://github.com/rust-lang/rfcs/pull/3983)
sparc: make ABI consistent with clang
fixes https://github.com/rust-lang/rust/issues/43894
I've hacked together a version of abi-cafe that can cross-compile. It finds many GCC vs. Clang inconsistencies, but for this target it found 3 ABI bugs that are specific to the rust implementation.
For reference
- [`SparcV8ABIInfo::{classifyArgumentType, classifyReturnType}`](6849789a8f/clang/lib/CodeGen/Targets/Sparc.cpp (L34-L59))
- [`DefaultABIInfo::{classifyArgumentType, classifyReturnType}`](6849789a8f/clang/lib/CodeGen/ABIInfoImpl.cpp (L17-L68))
## Pass ZST arguments
https://godbolt.org/z/P7KoqTWvr
The `sparc` ABI does not skip zero-sized arguments.
## Pass and return `f128` (i.e. `long double`) indirectly
The `long double` type, which corresponds to rust `f128`, is special-cased, it uses `getNaturalAlignIndirect` for both arguments and returns.
## pass aggregate arguments by reference
https://godbolt.org/z/hM8Gh1bfY
The implementation defers to `DefaultABIInfo::{classifyReturnType, classifyArgumentType}`, which use `byval` and `sret` for aggregate types.
RISC-V: Add Zmmul target feature
Zmmul is a ratified subset of the M extension that only supports multiplication, but not division ([spec](https://docs.riscv.org/reference/isa/v20260120/unpriv/m-st-ext.html#11-1-3-zmmul-extension-version-1-0)). LLVM already supports the extension under the same name, so until rust-lang/rust#162235 I'd just been using it directly.
There are two things I would particularly appreciate input on:
- Should M imply Zmmul?
- From the [Machine-Level ISA spec](https://docs.riscv.org/reference/isa/v20260120/priv/machine.html) and [this discussion](https://github.com/riscv/riscv-isa-manual/issues/869) in the RISC-V ISA Manual repo, it seems that Zmmul means all multiplication instructions are always supported, whereas M means they're only supported if the M bit is set in the `misa` register.
- On the other hand, LLVM has M imply Zmmul ([RISCVFeatures.td](f6f71edb43/llvm/lib/Target/RISCV/RISCVFeatures.td (L214-L229))), so it feels nice to match that.
- How might I go about stabilizing this?
- Can it be done right away?
- Should it wait a few releases?
- Is it better to batch it with the stabilization of other RISC-V target features, similarly to how it was done in rust-lang/rust#145948?
No LLMs were used in the making of this PR, and all mistakes are those of a first-time rustc contributor.
fix `is_single_fp_element` for `s390x` and `x86`
In https://github.com/rust-lang/rust/pull/161950#discussion_r3886952310 we discovered that the old `is_single_fp_element` is incorrect in a number of ways.
- it did not consider `f16` or `f128`
- it did not consider transparent wrappers
- on x86, it incorrectly accepted over-aligned types
- on s390x, it incorrectly accepted single-element unions and arrays
So, in practice each target does something slightly different here, and I've split the function into two.
cc @beetrees
wasm: correctly implement `union` trivial aggregates
A union with two scalar fields, even if they overlap exactly, is not a trivial aggregate, based on the implementation in `clang`:
e78970f80f/clang/lib/CodeGen/ABIInfoImpl.cpp (L338-L402)
It never explicitly considers unions, but essentially views them as records. The `clang` implementation is a plausible interpretation of the specification (though I'd like it to be a bit clearer):
83e5d715d0/BasicCABI.md (function-arguments-and-return-values)
> [2] Any struct or union that recursively (including through nested structs, unions, and arrays) contains just a single scalar value and is not specified to have greater than natural alignment.
We previously got this wrong. I also don't think this was really tested very well, so I added a bunch of test for various cases.
This change moves away from using the `homogeneous_aggregate` method, which is convenient because it is a bit broken and now we don't have to consider wasm when we fix that.
I've validated this against `clang` with abi-cafe.
r? alexcrichton
Remove d32 feature from 32-bit Arm targets
Fixes https://github.com/rust-lang/rust/issues/159973
In https://github.com/rust-lang/rust/pull/149512/ I removed `-d32` from some specs, but since LLVM enables `neon` by default for v7 targets `d32` was left enabled while it should be optional on this target. For a similar reason `-d32` was removed from some armv6 targets and has been readded.
This PR adds a test to ensure this specific instance does not happen again and has been tested locally on armv7-unknown-linux-gnueabihf, armv7a-none-eabihf and arm-unknown-linux-gnueabihf.
It might be a good idea in general to have a test that runs `--print cfg` and captures the set of rust target features enabled to show when PRs change them, but most of these targets are not run in Rust's CI so it's out of scope for this issue.
For reference, here is the manually-expanded LLVM features and their implications - necessary as these targets rely on a feature from LLVM that Rust doesn't yet expose:
```
vfp4 -> vfp3 + fp16 + vfp4d16 + vfp4sp
vfp4d16 -> vfp3d16 + fp16 + fp64 + vfp4d16sp
vfp4sp -> vfp3sp + fp16 + d32 + vfp4d16sp
vfp4d16sp -> vfp3d16sp + fp16
vfp3 -> vfp2 + vfp3d16 + vfp3sp
vfp3d16 -> vfp2 + fp64 + vfp3d16sp
vfp3sp -> vfp2 + d32 + vfp3d16sp
vfp3d16sp -> vfp2sp
vfp2 -> vfp2sp + fp64
vfp2sp -> fpregs
```
fix tailcall indirect return
Fixesrust-lang/rust#162585
This branch should only be intended for arguments, but it also marked return values as being passed on the stack. It later caused codegen to panic because return values can't use `on_stack`.
Fix initialization cycle in `target_config`
There is an initialization cycle in `target_config`. Details in the final commit. The previous commits are precursors that support the changes in the final commit.
r? @nikic
cc @cuviper @RalfJung @Zalathar @Patryk27
riscv: stabilize 'd' and 'f' target features
https://github.com/rust-lang/rust/pull/156188 has been reverted in https://github.com/rust-lang/rust/pull/161064 due to concerns about "e" being a negative target feature.
"d" and "f" however are almost normal target features, so let's re-land them.
The one thing that's odd about them is that we cannot allow you to use `-Ctarget-feature` or `#[target_feature]` for them on *some* riscv ABIs. (For now, it remains unstable on all riscv ABIs.) So this means we need the concept of target-features that are fixed by the target spec and cannot be changed by the user. OTOH we kind of already have that, even for fully stable target features:
- On x86-64, we don't let people disable "sse2". On aarch64, we don't let people disable "neon".
- [Soon](https://github.com/rust-lang/rust/pull/160302), on x86-64 softfloat, we don't let people enable "sse2".
"neon" and "sse2" are even stable target features. So I see no reason not to fully stabilize "d" and "f", with the following constraints:
- on riscv targets that use a "d" ABI (ilp32d, lp64d), you can't disable either of them
- on riscv targets that use an "f" ABI (ilp32f, lp64f), you can't disable "f"
- on riscv ilp32e targets, you can't *enable* "d"
Cc @romancardenas
Use lld by default on `loongarch64-unknown-linux-gnu` nightly
This PR makes LLD the default linker for `loongarch64-unknown-linux-gnu` on nightly.
As a prerequisite, it aligns the LoongArch64 Linux `LOAD` segment layout of LLD and other GNU-compatible linkers with GNU ld. This keeps the layout consistent and allows Linux to make better use of file-backed PMD mappings.
The LLD default is initially limited to nightly to allow some soak time before rolling it out to beta and stable.
To opt out of using LLD, `RUSTFLAGS="-Clinker-features=-lld"` would be used. To opt out of using rust-lld, falling back to the LLD installed on the system, `RUSTFLAGS="-Clink-self-contained=-linker"` would be used.
Configure the LoongArch64 Linux targets to place read-only code in the
first LOAD segment when linking with LLD, mold, and other GNU-compatible
linkers.
This keeps the segment layout consistent with GNU ld and allows Linux to
make better use of file-backed PMD mappings, reducing iTLB misses.
Revert "fuchsia: Add safestack as a supported sanitizer for x86_64 fuchsia"
This reverts commit 7a44484407.
This is leading to the issue seen in
https://github.com/rust-lang/rust/issues/162272. We're also seeing the same build issues when using a rust toolchain that contains this commit for building fuchsia targets.
This reverts commit 7a44484407.
This is leading to the issue seen in
https://github.com/rust-lang/rust/issues/162272. We're also seeing the
same build issues when using a rust toolchain that contains this commit
for building fuchsia targets.
windows-gnullvm: always link libunwind statically
Previously shared library was used by default, meaning that programs and libraries couldn't be loaded if `libunwind.dll` was missing from the PATH. Using Wine (on Linux) because it better shows the problem (and is more convenient):
```
❯ cargo new hello &> /dev/null
❯ cargo rustc --target x86_64-pc-windows-gnullvm &> /dev/null
❯ wine target/x86_64-pc-windows-gnullvm/debug/hello.exe
0024:err:module:import_dll Library libunwind.dll (which is needed by L"Z:\\tmp\\hello\\target\\x86_64-pc-windows-gnullvm\\debug\\hello.exe") not found
0024:err:module:loader_init Importing dlls for L"Z:\\tmp\\hello\\target\\x86_64-pc-windows-gnullvm\\debug\\hello.exe" failed, status c0000135
❯ llvm-readobj --coff-imports target/x86_64-pc-windows-gnullvm/debug/hello.exe
...
Import {
Name: libunwind.dll
ImportLookupTableRVA: 0x3D308
ImportAddressTableRVA: 0x3D678
Symbol: _GCC_specific_handler (0)
Symbol: _Unwind_DeleteException (0)
Symbol: _Unwind_GetDataRelBase (0)
Symbol: _Unwind_GetIPInfo (0)
Symbol: _Unwind_GetLanguageSpecificData (0)
Symbol: _Unwind_GetRegionStart (0)
Symbol: _Unwind_GetTextRelBase (0)
Symbol: _Unwind_RaiseException (0)
Symbol: _Unwind_Resume (0)
Symbol: _Unwind_SetGR (0)
Symbol: _Unwind_SetIP (0)
}
...
```
Optionally libunwind could be linked statically via `+crt-static`:
```
❯ cargo rustc --target x86_64-pc-windows-gnullvm -- -C target-feature=+crt-static &> /dev/null
❯ wine target/x86_64-pc-windows-gnullvm/debug/hello.exe
Hello, world!
❯ llvm-readobj --coff-imports target/x86_64-pc-windows-gnullvm/debug/hello.exe | rg 'libunwind.dll' || echo "doesn't depend on shared libunwind"
doesn't depend on shared libunwind
```
After a discussion of approach in rust-lang/rust#159782 with @bjorn3 (thanks BTW!), I changed the proposed approach to always link static libunwind.
I don't have a good solution for https://github.com/rust-lang/rust/pull/121794 that will resurface. I guess the user has three options:
- symlink `libunwind.dll.a` as `libunwind.a`
- add `--unwindlib=none -lunwind` to the linker args
- create linker wrapper
- use self-contained mode which is likely is undesirable
I think the ease of use (not having to deal with additional DLL dependency) outweights the benefit of working with incomplete C toolchain.
The size bloat is also not a problem, sizes (in bytes) of the binary for the literal hello world project:
- debug build:
- shared libunwind 4194816
- static libunwind 4323328
- release build:
- shared libunwind 382464
- static libunwind 423424
Debug diff +125.5 KiB, release diff: +40 KiB.
Size of `libunwind.dll` that has to be provided when linking shared libunwind: 204288 bytes (199.5 KiB).
make `Complex` ABI-compatible on sparc64 and powerpc64
tracking issue: https://github.com/rust-lang/rust/issues/154023
Make the ABI for `Complex` match C for two slightly more involved targets.
For Sparc64 the implementation matches GCC and Clang 24 and up. In https://github.com/llvm/llvm-project/pull/215015 a bug with how small complex numbers are passed was fixed.
For powerpc64 we match Clang exactly (and Clang is compatible with GCC for this target).
cc @beetrees @Gelbpunkt
Promote `wasm32-wasip3` to a tier 2 target
This commit updates documentation, configuration, etc, within the compiler to promote the `wasm32-wasip3` target to tier 2. This means that precompiled binaries will be made available in `rustup` for usage. This target MCP for this change is [rust-lang/compiler-team/100][mcp].
This target requires LLVM 23 which rustc recently has updated to, and then additionally requires wasi-sdk-34 which additionally uses LLVM 23 which was also updated recently. With these ingredients in place the ABI for `wasm32-wasip3` is all lined up and ready to go. These changes were all necessary to bring cooperative threading to the target in the future, but that's not quite ready in the ecosystem yet.
I've locally been testing this target and it's done well so far, but I suspect this'll need subsequent bug fixes here and there as other new issues crop up. I don't expect anything major will be necessary, however.
[mcp]: https://github.com/rust-lang/compiler-team/issues/1001
Add new Tier-3 target: `powerpc64-sony-ps3`
Implements a compatible target for the Sony PlayStation 3 console's PPU processor.
> A tier 3 target must have a designated developer or developers (the “target maintainers”) on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)
I ([@ZephyrCodesStuff](https://github.com/ZephyrCodesStuff)) am the maintainer and developer, both for this PR's target, as well as a [Rust PS3 SDK](https://github.com/zephyrcodesstuff/rust-ps3) to help developers get started.
> Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.
Addressed. The PPU is a standard `powerpc64` core, with only marginal changes made for the PS3's hardware configuration. `sony` is used among other Sony console targets, and `ps3` is the console's shorthand.
> Target names should not introduce undue confusion or ambiguity unless absolutely necessary to maintain ecosystem compatibility. For example, if the name of the target makes people extremely likely to form incorrect beliefs about what it targets, the name should be changed or augmented to disambiguate it.
If possible, use only letters, numbers, dashes and underscores for the name. Periods (.) are known to cause issues in Cargo.
Addressed.
> Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.
The target must not introduce license incompatibilities.
Although it does require a separate linker (`mold`) and a post-fix binary patching tool (included in the SDK above), no part of the build process, from the code, to the compiler, linker or SDK are closed-source. This target is compatible with the aformentioned SDK without any reliance on community "homebrew" tools, nor any licensed Sony / SN Systems compiler or linker.
> Anything added to the Rust repository must be under the standard Rust license (MIT OR Apache-2.0).
All of my code in this PR, including the SDK above, are licensed `MIT OR Apache-2.0`.
> The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the tidy tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to be subject to any new license requirements.
Compiling, linking, and emitting functional binaries, libraries, or other code for the target (whether hosted on the target itself or cross-compiling from another target) must not depend on proprietary (non-FOSS) libraries. Host tools built for the target itself may depend on the ordinary runtime libraries supplied by the platform and commonly used by other applications built for the target, but those libraries must not be required for code generation for the target; cross-compilation to the target must not require such libraries at all. For instance, rustc built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust’s license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3.
Addressed.
> “onerous” here is an intentionally subjective term. At a minimum, “onerous” legal/licensing terms include but are not limited to: non-disclosure requirements, non-compete requirements, contributor license agreements (CLAs) or equivalent, “non-commercial”/“research-only”/etc terms, requirements conditional on the employer or employment of any particular Rust developers, revocable terms, any requirements that create liability for the Rust project or its developers or users, or any requirements that adversely affect the livelihood or prospects of the Rust project or its developers or users.
Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target’s tier status, though they may otherwise participate in discussions.
All of the components are free, open-source software.
> This requirement does not prevent part or all of this policy from being cited in an explicit contract or work agreement (e.g. to implement or maintain support for a target). This requirement exists to ensure that a developer or team responsible for reviewing and approving a target does not face any legal threats or obligations that would prevent them from freely exercising their judgment in such approval, even if such judgment involves subjective matters or goes beyond the letter of these requirements.
Addressed.
> Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.
This target currently does not support the `std` library, but can fully support the `core` and `alloc` feature-sets. Tested and verified on official hardware with the aid of the SDK above.
> The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary.
Documentation is included, both in this PR's Markdown files, as well as the SDK's repository.
> Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via @) to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.
This target should not cause issues, as its scope is relatively limited to Sony PlayStation 3 development.
> Backlinks such as those generated by the issue/PR tracker when linking to an issue or PR are not considered a violation of this policy, within reason. However, such messages (even on a separate repository) must not generate notifications to anyone involved with a PR who has not requested such notifications.
Noted.
> Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.
This patch does not touch any other target.
> In particular, this may come up when working on closely related targets, such as variations of the same architecture with different features. Avoid introducing unconditional uses of features that another variation of the target may not have; use conditional compilation or runtime detection, as appropriate, to let each target run code supported by that target.
This target only has one feature, `+altivec`, universally supported on any Sony PlayStation 3 unit.
> Tier 3 targets must be able to produce assembly using at least one of rustc’s supported backends from any host target. (Having support in a fork of the backend is not sufficient, it must be upstream.)
Artifacts built by this target are confirmed to be fully functional on official hardware, once linked with the `mold` linker and patched by the SDK toolchain.