1928 Commits

Author SHA1 Message Date
Ralf Jung
0c4b0f5726 line-wrap and extend comments, typos 2025-06-19 09:45:09 +09:00
Ralf Jung
cd08652faa move -Ctarget-feature handling into shared code 2025-06-19 09:44:01 +09:00
Jacob Pratt
6acda82078
Rollup merge of #142608 - workingjubilee:redescribe-rustc_target-more-accurately, r=wesleywiser
Refresh module-level docs for `rustc_target::spec`

We have long since gone on a curveball from the flexible-target-specification RFC by introducing stability and soundness promises to the language and compiler which we often struggle with extending to target-specific implementation details. Indeed, we often *literally cannot*. We also have modified the search algorithm details. Update the comments for `rustc_target::spec` considerably.
2025-06-17 23:19:37 +02:00
Jubilee
3800083399
Rollup merge of #142598 - ostylk:fix/ppc64_llvmabi, r=nikic,workingjubilee
Set elf e_flags on ppc64 targets according to abi

(This PR contains the non user-facing changes of https://github.com/rust-lang/rust/pull/142321)

Fixes https://github.com/rust-lang/rust/issues/85589 by making sure that ld.lld errors out instead of generating a broken binary.

Basically the problem is that ld.lld assumes that all ppc64 object files with e_flags=0 are object files which use the ELFv2 ABI (this here is the check https://github.com/llvm/llvm-project/blob/main/lld/ELF/Arch/PPC64.cpp#L639).
This pull request sets the correct e_flags to indicate the used ABI so ld.lld errors out when encountering ELFv1 ABI files instead of generating a broken binary.

For example compare code generation for this program (file name ``min.rs``):
```rust
#![feature(no_core, lang_items, repr_simd)]
#![crate_type = "bin"]
#![no_core]
#![no_main]

#[lang = "sized"]
trait Sized {}
#[lang = "copy"]
trait Copy {}
#[lang = "panic_cannot_unwind"]
pub fn panic() -> ! {
    loop {}
}

pub fn my_rad_unmangled_function() {
    loop {}
}

pub fn my_rad_function() {
    loop {}
}

#[no_mangle]
pub fn _start() {
    my_rad_unmangled_function();
    my_rad_function();
}
```
Compile with ``rustc --target=powerpc64-unknown-linux-gnu -C linker=ld.lld -C relocation-model=static min.rs``

Before change:
```
$ llvm-objdump -d min
Disassembly of section .text:
000000001001030c <.text>:
		...
10010334: 7c 08 02 a6  	mflr 0
10010338: f8 21 ff 91  	stdu 1, -112(1)
1001033c: f8 01 00 80  	std 0, 128(1)
10010340: 48 02 00 39  	bl 0x10030378 <_ZN3min25my_rad_unmangled_function17h7471c49af58039f5E>
10010344: 60 00 00 00  	nop
10010348: 48 02 00 49  	bl 0x10030390 <_ZN3min15my_rad_function17h37112b8fd1008c9bE>
1001034c: 60 00 00 00  	nop
		...
```
The branch instructions ``bl 0x10030378`` and ``bl 0x10030390`` are jumping into the ``.opd`` section which is data. That is a broken binary (because fixing those branches is the task of the linker).

After change:
```
error: linking with `ld.lld` failed: exit status: 1
  |
  = note:  "ld.lld" "/tmp/rustcNYKZCS/symbols.o" "<1 object files omitted>" "--as-needed" "-L" "/tmp/rustcNYKZCS/raw-dylibs" "-Bdynamic" "--eh-frame-hdr" "-z" "noexecstack" "-L" "<sysroot>/lib/rustlib/powerpc64-unknown-linux-gnu/lib" "-o" "min" "--gc-sections" "-z" "relro" "-z" "now"
  = note: some arguments are omitted. use `--verbose` to show all linker arguments
  = note: ld.lld: error: /tmp/rustcNYKZCS/symbols.o: ABI version 1 is not supported
```
Which is correct because ld.lld doesn't support ELFv1 ABI.
2025-06-17 00:28:20 -07:00
Jubilee Young
679a2e3a5b compiler: Redescribe rustc_target search algo more accurately 2025-06-16 21:29:06 -07:00
Jubilee Young
de792eb030 compiler: Redescribe rustc_target::spec more accurately 2025-06-16 21:03:50 -07:00
ostylk
7859a37ffe explicitly set llvm_abiname option on existing ppc64 targets 2025-06-16 21:49:27 +02:00
beetrees
5723c9997c
Fix RISC-V C function ABI when passing/returning structs containing floats 2025-06-16 10:14:07 +01:00
León Orell Valerian Liehr
5cce691c5a
Rollup merge of #142481 - heiher:loong-asm-f16, r=Amanieu
Add `f16` inline asm support for LoongArch

r? `````@Amanieu`````
2025-06-15 23:51:57 +02:00
León Orell Valerian Liehr
16152661ff
Rollup merge of #142389 - beetrees:cranelift-arg-ext, r=bjorn3
Apply ABI attributes on return types in `rustc_codegen_cranelift`

- The [x86-64 System V ABI standard](https://gitlab.com/x86-psABIs/x86-64-ABI/-/jobs/artifacts/master/raw/x86-64-ABI/abi.pdf?job=build) doesn't sign/zero-extend integer arguments or return types.
- But the de-facto standard as implemented by Clang and GCC is to sign/zero-extend arguments to 32 bits (but not return types).
- Additionally, Apple targets [sign/zero-extend both arguments and return values to 32 bits](https://developer.apple.com/documentation/xcode/writing-64-bit-intel-code-for-apple-platforms#Pass-arguments-to-functions-correctly).
- However, the `rustc_target` ABI adjustment code currently [unconditionally extends both arguments and return values to 32 bits](e703dff8fe/compiler/rustc_target/src/callconv/x86_64.rs (L240)) on all targets.
- This doesn't cause a miscompilation when compiling with LLVM as LLVM will ignore the `signext`/`zeroext` attribute when applied to return types on non-Apple x86-64 targets.
- Cranelift, however, does not have a similar special case, requiring `rustc` to set the argument extension attribute correctly.
- However, `rustc_codegen_cranelift` doesn't currently apply ABI attributes to return types at all, meaning `rustc_codegen_cranelift` will currently miscompile `i8`/`u8`/`i16`/`u16` returns on x86-64 Apple targets as those targets require sign/zero-extension of return types.

This PR fixes the bug(s) by making the `rustc_target` x86-64 System V ABI only mark return types as sign/zero-extended on Apple platforms, while also making `rustc_codegen_cranelift` apply ABI attributes to return types. The RISC-V and s390x C ABIs also require sign/zero extension of return types, so this will fix those targets when building with `rustc_codegen_cranelift` too.

r? `````@bjorn3`````
2025-06-15 23:51:56 +02:00
bjorn3
3e944fa391 Remove all support for wasm's legacy ABI 2025-06-14 09:57:06 +00:00
WANG Rui
c49ec83868 Add f16 inline asm support for LoongArch 2025-06-14 09:39:30 +08:00
Tom Vijlbrief
1323fd6f73 Add missing avr64* series 2025-06-13 16:03:57 +02:00
Tom Vijlbrief
00feedcb31 Add modern AVR mcus like avr128db28 and attiny3224 2025-06-13 13:56:48 +02:00
Matthias Krüger
f6b02bbfa3
Rollup merge of #142248 - heiher:loong32-asm-types, r=Amanieu
Add supported asm types for LoongArch32

r? ``````@Amanieu``````
2025-06-13 05:19:15 +02:00
Matthias Krüger
7c3b2e5254
Rollup merge of #140770 - folkertdev:custom-abi, r=tgross35
add `extern "custom"` functions

tracking issue: rust-lang/rust#140829
previous discussion: https://github.com/rust-lang/rust/issues/140566

In short, an `extern "custom"` function is a function with a custom ABI, that rust does not know about. Therefore, such functions can only be defined with `#[unsafe(naked)]` and `naked_asm!`, or via an `extern "C" { /* ... */ }` block. These functions cannot be called using normal rust syntax: calling them can only be done from inline assembly.

The motivation is low-level scenarios where a custom calling convention is used. Currently, we often pick `extern "C"`, but that is a lie because the function does not actually respect the C calling convention.

At the moment `"custom"` seems to be the name with the most support. That name is not final, but we need to pick something to actually implement this.

r? `@traviscross`
cc `@tgross35`

try-job: x86_64-apple-2
2025-06-13 05:19:14 +02:00
Matthias Krüger
1a865fbe4e
Rollup merge of #135927 - azhogin:azhogin/retpoline, r=davidtwco
retpoline and retpoline-external-thunk flags (target modifiers) to enable retpoline-related target features

`-Zretpoline` and `-Zretpoline-external-thunk` flags are target modifiers (tracked to be equal in linked crates).
* Enables target features for `-Zretpoline-external-thunk`:
`+retpoline-external-thunk`, `+retpoline-indirect-branches`, `+retpoline-indirect-calls`.
* Enables target features for `-Zretpoline`:
`+retpoline-indirect-branches`, `+retpoline-indirect-calls`.

It corresponds to clang -mretpoline & -mretpoline-external-thunk flags.

Also this PR forbids to specify those target features manually (warning).

Issue: rust-lang/rust#116852
2025-06-13 05:19:13 +02:00
Folkert de Vries
5f73ce2b7e
add extern "custom" functions 2025-06-12 20:27:10 +02:00
beetrees
eb472e77cd
Apply ABI attributes on return types in rustc_codegen_cranelift 2025-06-12 00:47:01 +01:00
Jubilee Young
87feee9ad5 compiler: Update all targets to the new c_int_width type 2025-06-11 00:42:14 -07:00
Jubilee Young
b88c0061c4 compiler: Change c_int_width to be an integer type 2025-06-11 00:42:14 -07:00
León Orell Valerian Liehr
d11756f811
Rollup merge of #140766 - sayantn:stabilize-keylocker, r=traviscross,tgross35
Stabilize keylocker

This PR stabilizes the feature flag `keylocker_x86` (tracking issue rust-lang/rust#134813).

# Public API
The 2 `x86` target features `kl` and `widekl`, and the associated intrinsics in stdarch.

These target features are very specialized, and are only used to signal the presence of the corresponding CPU instruction. They don't have any nontrivial interaction with the ABI (contrary to something like AVX), and serve the only purpose of enabling 11 stdarch intrinsics, all of which have been implemented and propagated to rustc via a stdarch submodule update.

Also, these were added way back in LLVM12, and as the minimum LLVM required for rustc is LLVM19, we are safe in that front too!

# Associated PRs
 - rust-lang/rust#134814
 - rust-lang/stdarch#1706
 - rust-lang/rust#136831 (stdarch submodule update)
 - rust-lang/stdarch#1795 (stabilizing the runtime detection and intrinsics)
 - rust-lang/rust#141964 (stdarch submodule update for the stabilization of the runtime detection and intrinsics)

As all of the required tasks have been done (adding the target features to rustc, implementing their runtime detection in std_detect and implementing the associated intrinsics in core_arch), these target features can be stabilized now.

cc ````@rust-lang/lang````
cc ````@rust-lang/libs-api```` for the intrinsics and runtime detection

I don't think anyone else worked on this feature, so no one else to ping, maybe cc ````@Amanieu.```` I will send the reference pr soon.
2025-06-10 16:54:46 +02:00
WANG Rui
de8a91b51c Add supported asm types for LoongArch32 2025-06-10 18:50:41 +08:00
Trevor Gross
2f26913270
Rollup merge of #140767 - sayantn:stabilize-sha512, r=traviscross,tgross35
Stabilize `sha512`, `sm3` and `sm4` for x86

This PR stabilizes the feature flag `sha512_sm_x86` (tracking issue rust-lang/rust#126624).

# Public API
The 3 `x86` target features `sha512`, `sm3` and `sm4`, and the associated intrinsics in stdarch.

These target features are very specialized, and are only used to signal the presence of the corresponding CPU instruction. They don't have any nontrivial interaction with the ABI (contrary to something like AVX), and serve the only purpose of enabling 10 stdarch intrinsics, all of which have been implemented and propagated to rustc via a stdarch submodule update.

Also, these were added in LLVM17, and as the minimum LLVM required for rustc is LLVM19, we are safe in that front too!

# Associated PRs
 - rust-lang/rust#126704
 - rust-lang/stdarch#1592
 - rust-lang/stdarch#1790
 - rust-lang/rust#140389 (stdarch submodule update)
 - rust-lang/stdarch#1796 (stabilizing the runtime detection and intrinsics)
 - rust-lang/rust#141964 (stdarch submodule update for the stabilization of the runtime detection and intrinsics)

As all of the required tasks have been done (adding the target features to rustc, implementing their runtime detection in std_detect and implementing the associated intrinsics in core_arch), these target features can be stabilized now.

cc `@rust-lang/lang`
cc `@rust-lang/libs-api` for the intrinsics and runtime detection

I don't think anyone else worked on this feature, so no one else to ping, maybe cc `@Amanieu.` I will send the reference pr soon.
2025-06-09 12:17:52 -05:00
Andrew Zhogin
5601490c9d -Zretpoline and -Zretpoline-external-thunk flags (target modifiers) to enable retpoline-related target features 2025-06-09 21:29:59 +07:00
bors
b6685d748f Auto merge of #141435 - RalfJung:unsupported_calling_conventions, r=workingjubilee
Add (back) `unsupported_calling_conventions` lint to reject more invalid calling conventions

This adds back the `unsupported_calling_conventions` lint that was removed in https://github.com/rust-lang/rust/pull/129935, in order to start the process of dealing with https://github.com/rust-lang/rust/issues/137018. Specifically, we are going for the plan laid out [here](https://github.com/rust-lang/rust/issues/137018#issuecomment-2672118326):
- thiscall, stdcall, fastcall, cdecl should only be accepted on x86-32
- vectorcall should only be accepted on x86-32 and x86-64

The difference to the status quo is that:
- We stop accepting stdcall, fastcall on targets that are windows && non-x86-32 (we already don't accept these on targets that are non-windows && non-x86-32)
- We stop accepting cdecl on targets that are non-x86-32
- (There is no difference for thiscall, this was already a hard error on non-x86-32)
- We stop accepting vectorcall on targets that are windows && non-x86-*

Vectorcall is an unstable ABI so we can just make this a hard error immediately. The others are stable, so we emit the `unsupported_calling_conventions` forward-compat lint. I set up the lint to show up in dependencies via cargo's future-compat report immediately, but we could also make it show up just for the local crate first if that is preferred.

try-job: i686-msvc-1
try-job: x86_64-msvc-1
try-job: test-various
2025-06-09 05:21:49 +00:00
Jubilee
940a43677a
Rollup merge of #142194 - bjorn3:less_unstable_features, r=jieyouxu
Remove all unused feature gates from the compiler
2025-06-08 17:17:58 -07:00
Jubilee
48667ddd5a
Rollup merge of #142179 - folkertdev:min-global-align-parse, r=workingjubilee
store `target.min_global_align` as an `Align`

Parse the alignment properly when the target is defined/parsed, and error out on invalid alignment values. That means this work doesn't need to happen for every global in each backend.
2025-06-08 17:17:56 -07:00
Jubilee
ed61e50224
Rollup merge of #142108 - workingjubilee:track-caller-in-abi-map, r=jieyouxu
compiler: Add track_caller to AbiMapping::unwrap

Same reason as it is on Option's.
2025-06-08 17:17:54 -07:00
Jubilee
840baa46ff
Rollup merge of #142053 - heiher:loong32-none, r=wesleywiser
Add new Tier-3 targets: `loongarch32-unknown-none*`

MCP: https://github.com/rust-lang/compiler-team/issues/865

NOTE: LoongArch32 ELF object support is available starting with object v0.37.0.
2025-06-08 17:17:53 -07:00
bjorn3
9223704f4b Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
Ralf Jung
873122c006 add (back) unsupported_calling_conventions lint to reject more invalid calling conventions 2025-06-08 07:34:41 +02:00
Folkert de Vries
a50bd7ca24
store target.min_global_align as an Align 2025-06-07 22:06:42 +02:00
sayantn
632396ea01
Stabilize sha512_sm_x86, and the sha512, sm3 and sm4 target features 2025-06-07 23:27:15 +05:30
sayantn
cd7533ab44
Stabilize the keylocker_x86 flag, and the kl and widekl target features 2025-06-07 23:25:47 +05:30
Jacob Pratt
1c8b09639c
Rollup merge of #141797 - workingjubilee:apple-likes-frame-pointers-but-not-that-much, r=madsmtm
compiler: set Apple frame pointers by architecture

All Apple targets stop overriding this configuration and instead use the default base of FramePointer::NonLeaf, which means some Apples will have less frame pointers in leaf functions.

r? ``@madsmtm``

cc ``@thomcc``
2025-06-07 07:05:46 +02:00
Jubilee Young
b25aa26298 compiler: set Apple frame pointers by architecture
Apple targets can now overriding this configuration and instead use the
default based on their architecture, which means aarch64 targets now
have less frame pointers in leaf functions.
2025-06-06 10:07:32 -07:00
Jubilee Young
d945c8562b compiler: Add track_caller to AbiMapping::unwrap
Same reason as it is on Option's.
2025-06-05 23:09:31 -07:00
WANG Rui
38d69c3f57 Add new Tier-3 targets: loongarch32-unknown-none*
MCP: https://github.com/rust-lang/compiler-team/issues/865
2025-06-06 08:19:38 +08:00
WANG Rui
27f8efbae2 Bump object 2025-06-05 07:59:51 +08:00
bors
ff223d35cd Auto merge of #141309 - RalfJung:x86-simd-abi, r=tgross35,nikic,workingjubilee
x86 (32/64): go back to passing SIMD vectors by-ptr

Fixes https://github.com/rust-lang/rust/issues/139029 by partially reverting https://github.com/rust-lang/rust/pull/135408 and going back to passing SIMD vectors by-ptr on x86. Sadly, by-val confuses the LLVM inliner so much that it's not worth it...

Also fixes https://github.com/rust-lang/rust/issues/141848 by no longer actually using vector registers with the "Rust" ABI.

r? `@tgross35`
Cc `@nikic`

try-job: `test-various*`
try-job: dist-i586-gnu-i586-i686-musl
try-job: x86_64-gnu-nopt
try-job: `x86_64-msvc*`
try-job: `i686-msvc*`
2025-06-04 21:05:52 +00:00
Ralf Jung
321db85fb4 x86 (32/64): go back to passing SIMD vectors by-ptr 2025-06-04 08:38:49 +02:00
Matthias Krüger
59bdb5c3cf
Rollup merge of #141250 - folkertdev:s390x-z17-target-features, r=workingjubilee
add s390x z17 target features

tracking issue: https://github.com/rust-lang/rust/issues/130869

earlier target features were added in https://github.com/rust-lang/rust/pull/135630, and https://github.com/rust-lang/rust/issues/135413#issuecomment-2886439455 has some extra context on these new features.

r? ``@ghost``
cc ``@uweigand``
2025-06-04 07:54:33 +02:00
Matthias Krüger
644f06ec1f
Rollup merge of #141569 - workingjubilee:canonicalize-abi, r=bjorn3
Replace ad-hoc ABI "adjustments" with an `AbiMap` to `CanonAbi`

Our `conv_from_spec_abi`, `adjust_abi`, and `is_abi_supported` combine to give us a very confusing way of reasoning about what _actual_ calling convention we want to lower our code to and whether we want to compile the resulting code at all. Instead of leaving this code as a miniature adventure game in which someone tries to combine stateful mutations into a Rube Goldberg machine that will let them escape the maze and arrive at the promised land of codegen, we let `AbiMap` devour this complexity. Once you have an `AbiMap`, you can answer which `ExternAbi`s will lower to what `CanonAbi`s (and whether they will lower at all).

Removed:
- `conv_from_spec_abi` replaced by `AbiMap::canonize_abi`
- `adjust_abi` replaced by same
- `Conv::PreserveAll` as unused
- `Conv::Cold` as unused
- `enum Conv` replaced by `enum CanonAbi`

target-spec.json changes:
- If you have a target-spec.json then now your "entry-abi" key will be specified in terms of one of the `"{abi}"` strings Rust recognizes, e.g.
```json
    "entry-abi": "C",
    "entry-abi": "win64",
    "entry-abi": "aapcs",
```
2025-06-03 21:53:36 +02:00
Jubilee Young
307a18dc53 compiler: actually remove Conv now that it is irrelevant 2025-06-03 10:08:11 -07:00
Jubilee Young
2351a3e5b4 compiler: simplify TargetOptions ABI functions
`adjust_abi` is not needed and `is_abi_supported` can be a 1-liner.
2025-06-03 10:04:19 -07:00
Jubilee Young
72ecde27ff compiler: change Conv to CanonAbi 2025-06-03 10:03:44 -07:00
Jubilee Young
2d637f70a8 compiler: use CanonAbi for entry_abi
makes entry_abi a lowering of the ABI string, so now it can be
```json
  "entry_abi": "C",
  "entry_abi": "win64",
  "entry_abi": "aapcs",
```
2025-06-03 10:02:44 -07:00
Jubilee Young
c04e2490ef compiler: add AbiMap
- Add AbiMapping for encoding the nuance of deprecated ABIs
2025-06-03 09:58:52 -07:00
Jubilee Young
f57ed46bc6 compiler: add CanonAbi 2025-05-31 12:36:01 -07:00