Commit graph

1882 commits

Author SHA1 Message Date
bjorn3
bfdb1c1642 Skip pre-defining naked functions 2025-07-29 14:19:28 +00:00
bjorn3
b664b4e604 Sync from rust b56aaec52b 2025-07-25 12:54:42 +00:00
Camille GILLOT
83907452bf Remove useless lifetime parameter. 2025-07-23 23:54:37 +00:00
Camille GILLOT
ae8c473c9f Give an AllocId to ConstValue::Slice. 2025-07-23 23:54:37 +00:00
bjorn3
8483461b09 Support used(linker) 2025-07-23 15:28:10 +00:00
bjorn3
17f2c4db53 Update to Cranelift 0.122 2025-07-23 14:47:53 +00:00
bjorn3
46fab0c176 Sync from rust 9982d6462b 2025-07-21 08:16:13 +00:00
Folkert de Vries
8e5e64750c use codegen_instance_attrs where an instance is (easily) available 2025-07-16 23:24:32 +02:00
Folkert de Vries
70d199a639 add codegen_instance_attrs query
and use it for naked functions
2025-07-16 21:38:58 +02:00
Folkert de Vries
5320b81d1b fix -Zsanitizer=kcfi on #[naked] functions
And more broadly only codegen `InstanceKind::Item` using the naked
function codegen code. Other instance kinds should follow the normal
path.
2025-07-16 21:38:48 +02:00
bjorn3
46fa9ad1f0 Directly use symbol_value and tls_value
global_value gets legalized to either of the two.
2025-07-15 09:25:27 +00:00
bjorn3
e0860f807c MinGW misses some f16/f128 intrinsics 2025-07-13 15:41:43 +00:00
bjorn3
ef087b0edd Sync from rust 2a023bf80a 2025-07-11 10:20:55 +00:00
Oli Scherer
08dac6fc6c Add opaque TypeId handles for CTFE 2025-07-09 16:37:11 +00:00
bjorn3
593087218e Sync from rust a2d45f73c7 2025-07-08 14:29:27 +00:00
bjorn3
96414a8919 Sync from rust a84ab0ce6c 2025-07-07 12:32:22 +00:00
bjorn3
8dab8de9d2 Get rid of CodegenCx 2025-07-07 10:48:59 +02:00
bjorn3
9360f7c244 Don't call collect_debug_info when debuginfo is disabled 2025-07-07 10:45:01 +02:00
Edoardo Marangoni
805f843f19 compiler: Parse p- specs in datalayout string, allow definition of custom default data address space 2025-07-07 09:04:53 +02:00
Daniel Paoliello
de58bdc3db Make __rust_alloc_error_handler_should_panic a function 2025-07-03 10:52:21 -07:00
bjorn3
868d953b7a Avoid q modifier for user references to arm64 vector registers
It should only be necessary for the clobber save/restore sequences.
2025-07-03 10:16:13 +00:00
bjorn3
588c630b79 Escape { and } before passing to global_asm!() 2025-07-03 10:15:26 +00:00
bjorn3
ecd153360c Sync from rust 6677875279 2025-07-03 08:49:20 +00:00
bjorn3
b506146990 Sync from rust 71e4c005ca 2025-07-02 13:00:24 +00:00
Michael Goulet
ef78e985fb Remove support for dyn* 2025-07-01 19:00:21 +00:00
bjorn3
b87f756d4d Fix building std_detect on s390x 2025-07-01 09:05:14 +00:00
bjorn3
c4743bd2b9 Move to the 2024 edition 2025-07-01 09:04:35 +00:00
bjorn3
1008ad5655 Sync from rust f26e580230 2025-07-01 07:46:48 +00:00
Matthias Krüger
d8c129a0e5 Rollup merge of #143140 - RalfJung:ptr-into-parts, r=oli-obk
give Pointer::into_parts a more scary name and offer a safer alternative

`into_parts` is a bit too innocent of a name for a somewhat subtle operation.
r? `@oli-obk`
2025-06-30 20:49:41 +02:00
bjorn3
e0ea4b016a Put unwinding support behind a cargo feature 2025-06-30 08:08:15 +00:00
bjorn3
0c7e953885 Fix panic=unwind for JIT 2025-06-30 08:08:15 +00:00
bjorn3
ede659174d Implement exception handling support 2025-06-30 08:08:14 +00:00
Oli Scherer
95281ed1c1 Stop backends from needing to support nullary intrinsics 2025-06-30 08:04:19 +00:00
Guillaume Gomez
2505864a71 Rollup merge of #142078 - sayantn:more-intrinsics, r=workingjubilee
Add SIMD funnel shift and round-to-even intrinsics

This PR adds 3 new SIMD intrinsics

 - `simd_funnel_shl` - funnel shift left
 - `simd_funnel_shr` - funnel shift right
 - `simd_round_ties_even` (vector version of `round_ties_even_fN`)

TODO (future PR): implement `simd_fsh{l,r}` in miri, cg_gcc and cg_clif (it is surprisingly hard to implement without branches, the common tricks that rotate uses doesn't work because we have 2 elements now. e.g, the `-n&31` trick used by cg_gcc to implement rotate doesn't work with this because then `fshl(a, b, 0)` will be `a | b`)

[#t-compiler > More SIMD intrinsics](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/More.20SIMD.20intrinsics/with/522130286)

`@rustbot` label T-compiler T-libs A-intrinsics F-core_intrinsics
r? `@workingjubilee`
2025-06-29 12:29:53 +02:00
Ralf Jung
0bd5a21843 give Pointer::into_parts a more scary name and offer a safer alternative 2025-06-29 00:16:19 +02:00
bors
d049f5db15 Auto merge of #141759 - 1c3t3a:discriminants-query, r=saethlin
Insert checks for enum discriminants when debug assertions are enabled

Similar to the existing null-pointer and alignment checks, this checks for valid enum discriminants on creation of enums through unsafe transmutes. Essentially this sanitizes patterns like the following:
```rust
let val: MyEnum = unsafe { std::mem::transmute<u32, MyEnum>(42) };
```

An extension of this check will be done in a follow-up that explicitly sanitizes for extern enum values that come into Rust from e.g. C/C++.

This check is similar to Miri's capabilities of checking for valid construction of enum values.

This PR is inspired by saethlin@'s PR
https://github.com/rust-lang/rust/pull/104862. Thank you so much for keeping this code up and the detailed comments!

I also pair-programmed large parts of this together with vabr-g@.

r? `@saethlin`
2025-06-28 10:25:00 +00:00
Bastian Kersting
ac8ce3e3be Insert checks for enum discriminants when debug assertions are enabled
Similar to the existing nullpointer and alignment checks, this checks
for valid enum discriminants on creation of enums through unsafe
transmutes. Essentially this sanitizes patterns like the following:
```rust
let val: MyEnum = unsafe { std::mem::transmute<u32, MyEnum>(42) };
```
An extension of this check will be done in a follow-up that explicitly
sanitizes for extern enum values that come into Rust from e.g. C/C++.

This check is similar to Miri's capabilities of checking for valid
construction of enum values.

This PR is inspired by saethlin@'s PR
https://github.com/rust-lang/rust/pull/104862. Thank you so much for
keeping this code up and the detailed comments!

I also pair-programmed large parts of this together with vabr-g@.
2025-06-27 09:37:36 +00:00
bjorn3
b2cafc96ec Use ConstantCx for defining anonymous strings
As opposed to directly defining them in the module.
2025-06-26 10:44:26 +00:00
bjorn3
4042f40266 Remove global_asm from CodegenCx 2025-06-26 10:44:26 +00:00
bjorn3
23110bdf76 Remove output_filenames from CodegenCx 2025-06-26 10:44:26 +00:00
bjorn3
9ead1c10aa Move invocation_temp out of CodegenCx 2025-06-26 10:44:26 +00:00
bjorn3
8bf928a2e5 Move inline_asm_index from CodegenCx to FunctionCx 2025-06-26 10:44:26 +00:00
bjorn3
b37d10e318 Merge commit '8c848e0604' into sync_cg_clif-2025-06-24 2025-06-24 11:32:02 +00:00
bjorn3
fc8631bb1b Sync from rust be19eda0dc 2025-06-23 09:59:06 +00:00
Martin Liska
e3882618c8 cranelift: fix target feature name type: "fxsr" 2025-06-22 16:32:54 +02:00
bjorn3
856ffb63c8 Sync from rust c68340350c 2025-06-19 09:20:04 +00:00
bors
ca578bf159 Auto merge of #141061 - dpaoliello:shimasfn, r=bjorn3
Change __rust_no_alloc_shim_is_unstable to be a function

This fixes a long sequence of issues:

1. A customer reported that building for Arm64EC was broken: #138541
2. This was caused by a bug in my original implementation of Arm64EC support, namely that only functions on Arm64EC need to be decorated with `#` but Rust was decorating statics as well.
3. Once I corrected Rust to only decorate functions, I started linking failures where the linker couldn't find statics exported by dylib dependencies. This was caused by the compiler not marking exported statics in the generated DEF file with `DATA`, thus they were being exported as functions not data.
4. Once I corrected the way that the DEF files were being emitted, the linker started failing saying that it couldn't find `__rust_no_alloc_shim_is_unstable`. This is because the MSVC linker requires the declarations of statics imported from other dylibs to be marked with `dllimport` (whereas it will happily link to functions imported from other dylibs whether they are marked `dllimport` or not).
5. I then made a change to ensure that `__rust_no_alloc_shim_is_unstable` was marked as `dllimport`, but the MSVC linker started emitting warnings that `__rust_no_alloc_shim_is_unstable` was marked as `dllimport` but was declared in an obj file. This is a harmless warning which is a performance hint: anything that's marked `dllimport` must be indirected via an `__imp` symbol so I added a linker arg in the target to suppress the warning.
6. A customer then reported a similar warning when using `lld-link` (<https://github.com/rust-lang/rust/pull/140176#issuecomment-2872448443>). I don't think it was an implementation difference between the two linkers but rather that, depending on the obj that the declaration versus uses of `__rust_no_alloc_shim_is_unstable` landed in we would get different warnings, so I suppressed that warning as well: #140954.
7. Another customer reported that they weren't using the Rust compiler to invoke the linker, thus these warnings were breaking their build: <https://github.com/rust-lang/rust/pull/140176#issuecomment-2881867433>. At that point, my original change was reverted (#141024) leaving Arm64EC broken yet again.

Taking a step back, a lot of these linker issues arise from the fact that `__rust_no_alloc_shim_is_unstable` is marked as `extern "Rust"` in the standard library and, therefore, assumed to be a foreign item from a different crate BUT the Rust compiler may choose to generate it either in the current crate, some other crate that will be statically linked in OR some other crate that will by dynamically imported.

Worse yet, it is impossible while building a given crate to know if `__rust_no_alloc_shim_is_unstable` will statically linked or dynamically imported: it might be that one of its dependent crates is the one with an allocator kind set and thus that crate (which is compiled later) will decide depending if it has any dylib dependencies or not to import `__rust_no_alloc_shim_is_unstable` or generate it. Thus, there is no way to know if the declaration of `__rust_no_alloc_shim_is_unstable` should be marked with `dllimport` or not.

There is a simple fix for all this: there is no reason `__rust_no_alloc_shim_is_unstable` must be a static. It needs to be some symbol that must be linked in; thus, it could easily be a function instead. As a function, there is no need to mark it as `dllimport` when dynamically imported which avoids the entire mess above.

There may be a perf hit for changing the `volatile load` to be a `tail call`, so I'm happy to change that part back (although I question what the codegen of a `volatile load` would look like, and if the backend is going to try to use load-acquire semantics).

Build with this change applied BEFORE #140176 was reverted to demonstrate that there are no linking issues with either MSVC or MinGW: <https://github.com/rust-lang/rust/actions/runs/15078657205>

Incidentally, I fixed `tests/run-make/no-alloc-shim` to work with MSVC as I needed it to be able to test locally (FYI for #128602)

r? `@bjorn3`
cc `@jieyouxu`
2025-06-18 09:24:40 +00:00
bjorn3
7ed06e50b3 Sync from rust 45acf54eea 2025-06-17 11:53:24 +00:00
Daniel Paoliello
db5a427b31 Change __rust_no_alloc_shim_is_unstable to be a function 2025-06-16 10:54:07 -07:00
beetrees
e3916036f9 Fix RISC-V C function ABI when passing/returning structs containing floats 2025-06-16 10:14:07 +01:00