Commit Graph

3893 Commits

Author SHA1 Message Date
Jonathan Brouwer 5246f6e4bc Rollup merge of #156323 - bjorn3:clif_has_mnemonic, r=wesleywiser
Handle --print=backend-has-mnemonic in cg_clif

And introduce a `has_mnemonic` method on `CodegenBackend` just like `--print=backend-has-zstd`.
2026-05-10 19:05:44 +02:00
Jonathan Brouwer 30ec142b97 Rollup merge of #154972 - chorman0773:return_address, r=Mark-Simulacrum
Implement `core::arch::return_address` and tests

Tracking issue: rust-lang/rust#154966

Implements libs-team#768
2026-05-10 19:05:42 +02:00
Jacob Pratt 71e64b9d25 Rollup merge of #156124 - nnethercote:StableHash-renamings-2, r=jieyouxu
Make stable hashing names consistent (part 2)

This PR finishes the implementation of MCP 893.

r? @jieyouxu
2026-05-09 09:27:58 -04:00
Jonathan Brouwer fbc52c9ecf Rollup merge of #156291 - kupiakos:msvc-link-info, r=jyn514,mati865
Treat MSVC "performing full link" message as informational

When the MSVC incremental linker finds a .ilk file for incremental linking but its associated .exe file is missing, this message is printed to stdout:

```text
LINK : ...\foo.exe not found or not build by the last incremental link; performing full link
```

However, if both the .ilk and .exe files are missing (for a clean build), the message isn't printed and it still does a full link. So, the presence of the message doesn't affect the result of the build.

See rust-lang/rust#156209 for further context.

r? @mati865
cc @jyn514
2026-05-08 16:18:41 +02:00
bjorn3 c2ab95fb61 Handle --print=backend-has-mnemonic in cg_clif
And introduce a has_mnemonic method on CodegenBackend just like
--print=backend-has-zstd
2026-05-08 16:08:56 +02:00
Nicholas Nethercote 33cd10a881 Rename rustc_data_structures::stable_hasher as stable_hash.
Part of MCP 983.
2026-05-08 15:10:33 +10:00
Alyssa Haroldsen 39c766e310 Treat MSVC "performing full link" message as informational
When the MSVC incremental linker finds a .ilk file for incremental
linking but its associated .exe file is missing, this message is
printed to stdout in 1 line:

LINK : ...\foo.exe not found or not build by the last incremental link;
performing full link

However, if both the .ilk and .exe files are missing (for a clean
build), the message isn't printed and it still does a full link. So, the
presence of the message doesn't affect the result of the build.
2026-05-07 13:59:23 -07:00
Jonathan Brouwer 05c012fff5 Rollup merge of #156198 - Zoxc:threads-sync, r=folkertdev
Add `sync` option to `-Z threads` to force synchronization on one thread

This adds a `sync` option to `-Z threads` to force synchronization while still using one thread. This is useful to measure overhead of synchronization without the noise of additional threads.
2026-05-07 22:44:06 +02:00
Aapo Alasuutari 2d88ee87dd Reborrow traits 2026-05-07 21:55:44 +03:00
Jonathan Brouwer a48901b65b Rollup merge of #156245 - bjorn3:move_invocation_temp, r=oli-obk
Move invocation_temp into OutputFilenames

While it was previously defined in Session, it is only ever used with OutputFilenames methods.
2026-05-07 14:13:54 +02:00
Jonathan Brouwer c5941a03a2 Rollup merge of #156243 - bjorn3:lto_refactors18, r=mu001999
Move CrateInfo computation after codegen_crate

CrateInfo is only necessary during linking and non-local LTO.

Part of https://github.com/rust-lang/compiler-team/issues/908
2026-05-07 14:13:51 +02:00
Jonathan Brouwer 25494215e7 Rollup merge of #156024 - rcvalle:rust-cfi-fix-142284, r=bjorn3
CFI: Fix LTO for `#![no_builtins]` crates with CFI

Fixes LTO for `#![no_builtins]` crates with CFI enabled by using rustc's `EmitObj::Bitcode` path (and emitting LLVM bitcode in the `.o` for linker-based LTO).

It also adds tests that verify that the examples in [rust-cfi-examples](https://github.com/rcvalle/rust-cfi-examples) build and run with `-Zbuild-std` to prevent other future regressions.
2026-05-07 14:13:51 +02:00
bors 4ddd4538a8 Auto merge of #154327 - WaffleLapkin:drop_in_place_ref, r=RalfJung,scottmcm,saethlin
change the type of the argument of `drop_in_place` lang item to `&mut _`



We used to special case `core::ptr::drop_in_place` when computing LLVM argument attributes with this hack:

https://github.com/rust-lang/rust/blob/db5e2dc248fe5bb26f70d7baec46a3bca9fa3e1d/compiler/rustc_ty_utils/src/abi.rs#L383-L392

This is because even though `drop_in_place` takes a `*mut T` it is semantically a `&mut T` (remember how `&mut Self` is passed to `Drop::drop`). This is apparently relevant for perf.

This PR replaces this hack with a simpler solution -- it makes `drop_in_place` a thin wrapper around newly added `core::ptr::drop_glue`, which is the actual lang item and takes a `&mut T`:

https://github.com/rust-lang/rust/blob/d2563d5003bbecff1efc40c1f5673ceec603825b/library/core/src/ptr/mod.rs#L810-L833

------

The rest of the PR is blessing tests and cleaning up things which are not necessary after this change.

One thing that is a bit awkward is that now that `drop_glue` is the actual lang item, a lot of the comments referring to `drop_in_place` are outdated. Should I try fixing that?

I've also changed `async_drop_in_place` to take a `&mut T`, and it simplified the code handling it a bit. (since it's unstable we don't need to introduce a wrapper)

-------

cc @RalfJung 
Closes https://github.com/rust-lang/rust/issues/154274
2026-05-07 00:52:53 +00:00
John Kåre Alsaker 8aafed8a17 Add sync option to -Z threads to force synchronization on one thread 2026-05-07 02:06:18 +02:00
Ramon de C Valle acc33fe5dd CFI: Fix LTO for #![no_builtins] crates with CFI
Fixes LTO for `#![no_builtins]` crates with CFI enabled by using rustc's
`EmitObj::Bitcode` path (and emitting LLVM bitcode in the `.o` for
linker-based LTO).
2026-05-06 13:44:04 -07:00
bjorn3 9297586cb9 Move invocation_temp into OutputFilenames
While it was previously defined in Session, it is only ever used with
OutputFilenames methods.
2026-05-06 15:01:54 +00:00
bjorn3 da6e4d4890 Move CrateInfo computation after codegen_crate
CrateInfo is only necessary during linking and non-local LTO.
2026-05-06 14:51:38 +00:00
Jacob Pratt b594ef31e9 Rollup merge of #156174 - daxpedda:wasm-clear-exports, r=alexcrichton
Wasm: remove implicit `__heap_base`/`__data_end` exports

This is kind of a follow-up to rust-lang/rust#147225. Currently `__heap_base`/`__data_end` globals are implicitly exported on `wasm*-unknown-unknown` and `wasm32v1-none`, even though they were only used for Wasm multi-threading, requiring the atomics target feature and shared memory.

Instead users should explicitly opt-in to these features, in which case toolchains, like `wasm-bindgen`, would require some linker flags. After this PR the following would be required for multi-threading support in `wasm-bindgen`:
```
-Clink-arg=--shared-memory -Clink-arg=--max-memory=1073741824 -Clink-arg=--import-memory -Clink-arg=--export=__heap_base -Clink-arg=--export=__wasm_init_tls -Clink-arg=--export=__tls_size -Clink-arg=--export=__tls_align -Clink-arg=--export=__tls_base
```

You will notice that the only new addition is `--export=__heap_base`, apparently `wasm-bindgen` doesn't need `__data_end` anymore (I didn't dig into the original motivation).

---

For context why `wasm-bindgen` needed access to `__heap_base`:
There is currently no mechanism in the Wasm tool conventions that automatically allocates the stack for every thread (e.g. via the `start` function). So `wasm-bindgen` has to explicitly call `malloc` to allocate the stack on the new thread.

However, calling `malloc` itself requires a stack to be present! With the help of `__heap_base` `wasm-bindgen` constructs a temporary stack to make this work. This is obviously quite hacky. A newer implementation could go a different route: e.g. allocate the threads stack in the main thread and passing the right information on, not requiring access to `__heap_base` at all (and avoiding this really messy workaround).

I should also note here that e.g. [`js-bindgen`](https://github.com/wasm-bindgen/js-bindgen), the successor currently being worked on, doesn't need any of these exports because it doesn't rely on post-processing. In which case all of these variables can be accessed by name at link-time, instead of requiring the linker to export each variable for post-processing to find them by name. That is to say: all these workaround are toolchain-specific and not universal to the Wasm targets.

---

r? @alexcrichton
2026-05-05 22:50:21 -04:00
bors 740679e1f5 Auto merge of #154861 - mehdiakiki:fix/rlib-digest, r=petrochenkov
Add rlib digest to identify Rust object files



This adds a metadata entry to `rlib` archives that lists which members are Rust object files instead of relying on the filename heuristic in `looks_like_rust_object.file`. I also added a fallback to the old behavior for `rlibs` built by older compilers. 

Part of https://github.com/rust-lang/rust/issues/138243.
2026-05-05 16:26:33 +00:00
Waffle Lapkin 810eae99af rename drop_in_place lang item to drop_glue 2026-05-05 12:36:39 +02:00
daxpedda fbb5809996 Wasm: remove implicit __heap_base/__data_end exports 2026-05-05 07:21:22 +02:00
mehdiakiki 9606b0bd77 Add rlib digest to identify Rust object files 2026-05-04 21:55:47 -04:00
Guillaume Gomez 8bf58ee5d4 Rollup merge of #155962 - romancardenas:cfg-only-stable-target-feature, r=RalfJung
`rustc`: `target_features`: allow for `cfg`-only stable `target_features`

This PR introduces a new stabilization level for `target_features`: `CfgOnlyStable`. The motivation is allowing the Rust compiler to expose `target_features` of targets so users can use `cfg(target_feature = "feature")` for conditional blocks depending on target features. However, `CfgOnlyStable` cannot be used for `#[target_feature(enable = "feature")]`, as this is still considered unstable. Accordingly, the compiler will still raise an error if these expressions are used on stable.

This PR relates partially to rust-lang/rust#150257. As discussed, for RISC-V targets, having the `"d"`, `"e"`, and `"f"` target features exposed will allow baremetal developers to adapt the code depending on the target's properties.

r? @RalfJung
2026-05-05 02:50:08 +02:00
Román Cárdenas Rodríguez ee9a01aecf rustc: target_features: adapt compile errors and warnings for cfg-only stable features 2026-05-04 17:28:35 +02:00
Román Cárdenas Rodríguez df8d029014 rustc: target_features: allow for cfg-only stable target_features 2026-05-04 10:12:27 +02:00
Jacob Pratt c3afa21a40 Rollup merge of #156065 - mejrs:spanculler, r=JonathanBrouwer
Remove unused spans from AttributeKind

Recently I noticed some spans in diagnostic attributes were never used. I went through and checked the other variants too.
2026-05-03 00:25:33 -04:00
mejrs 4a13f36265 Remove more spans from AttributeKind 2026-05-02 17:41:30 +02:00
Ralf Jung e402c1edf0 miri: remove retag statements, make typed copies retag implicitly instead 2026-05-02 17:40:33 +02:00
Jonathan Brouwer 716bccea07 Rollup merge of #156028 - scottmcm:local-arg, r=wesleywiser
Add a `Local::arg(i)` helper constructor

While reading through stuff I was noticing just how many `+1` fixes there were in various places (and comments explaining those fixups), so this adds a new inherent helper on `Local` for making an argument to help make this clearer.

r? mir
2026-05-02 10:18:28 +02:00
Nicholas Nethercote e7d28d3e9b Rename the HashStable* trait/derives as StableHash*.
Specifically:
- `HashStable` -> `StableHash` (trait)
- `HashStable` -> `StableHash` (derive)
- `HashStable_NoContext` -> `StableHash_NoContext` (derive)

Note: there are some names in `compiler/rustc_macros/src/hash_stable.rs`
that are still to be renamed, e.g. `HashStableMode`.

Part of MCP 983.
2026-05-02 10:16:40 +02:00
Nicholas Nethercote 846267e725 Rename the HashStableContext trait as StableHashCtxt.
Part of MCP 983.
2026-05-02 10:16:39 +02:00
Nicholas Nethercote 851049cf58 Rename the hash_stable method as stable_hash.
Part of MCP 983.
2026-05-02 10:15:59 +02:00
bors 67bcaa9c4b Auto merge of #153968 - jyn514:jyn/linker-warn-by-default, r=mati865
linker-messages is warn-by-default again

cc rust-lang/rust#136096 

I ended up keeping it a lint and adding an option for lints to ignore `-Dwarnings` (there was already a lint that did that actually, it was just hard-coded in rustc_middle instead of in rustc_lint_defs like I'd expect). This allows people to actually see the warnings without them failing the build in CI.
2026-05-01 17:15:17 +00:00
Scott McMurray 548cdc1412 Add a Local::arg(i) helper constructor
While reading through stuff I was noticing just how many `+1` fixes there were in various places (and comments explaining that fixup), so this adds a new inherent helper on `Local` for making an argument to help make this clearer.
2026-04-30 20:52:02 -07:00
Jacob Pratt cf607056a0 Rollup merge of #156000 - pmur:murp/fix-155972, r=wesleywiser
Fix ICE when using -Zinstrument-mcount and -Clinker-flavor=lld

-Zinstrument-mcount passes -pg to the gnu linker command. This option is only supported by the cc frontend.

This fixes https://github.com/rust-lang/rust/issues/155972
2026-04-30 22:28:35 -04:00
Jacob Pratt 894bdf298e Rollup merge of #155980 - nnethercote:mv-feature-methods, r=TaKO8Ki
Move `feature*` methods from `parse` mod to `errors` mod.

As the FIXME comment says, these no longer use `ParseSess` and so the `parse` mod is not a good place for them. The `errors` mod is a better home.

r? @TaKO8Ki
2026-04-30 22:28:33 -04:00
Jacob Pratt 0ab1a47246 Rollup merge of #155821 - folkertdev:doc-va-list-clone, r=joshtriplett
c-variadic: document `Clone` and `Drop` instances and require `VaArgSafe: Copy`

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

Fixing some things that came up in the stabilization PR

r? tgross35
cc @kpreid
2026-04-30 22:28:32 -04:00
Jacob Pratt 560cc23c95 Rollup merge of #156003 - bjorn3:lto_refactors17, r=lqd
Pass Session to optimize_and_codegen_fat_lto

This is necessary to fix incremental LTO in cg_gcc as well as to do some LTO refactorings I want to do. The actual fix for cg_gcc will be done on the cg_gcc repo to test it in CI.
2026-04-30 22:28:29 -04:00
Jacob Pratt 0649c3f5d5 Rollup merge of #155249 - hoodmane:wasm-panic-in-cleanup-reland, r=bjorn3
Fix: On wasm targets, call `panic_in_cleanup` if panic occurs in cleanup

Relies on https://github.com/rust-lang/llvm-project/pull/194.
Reland of https://github.com/rust-lang/rust/pull/151771.

Previously this was not correctly implemented. Each funclet may need its own terminate block, so this changes the `terminate_block` into a `terminate_blocks` `IndexVec` which can have a terminate_block for each funclet. We key on the first basic block of the funclet -- in particular, this is the start block for the old case of the top level terminate function.

Rather than using a catchswitch/catchpad pair, I used a cleanuppad. The reason for the pair is to avoid catching foreign exceptions on MSVC. On wasm, it seems that the catchswitch/catchpad pair is optimized back into a single cleanuppad and a catch_all instruction is emitted which will catch foreign exceptions. Because the new logic is only used on wasm, it seemed better to take the simpler approach seeing as they do the same thing.

- [ ] Add test for https://github.com/rust-lang/rust/issues/153948
2026-04-30 22:28:24 -04:00
Nicholas Nethercote 9454be304f Invert dependency between rustc_error_messages and rustc_ast*.
`rustc_error_messages` currently depends on
`rustc_ast`/`rustc_ast_pretty`. This is odd, because
`rustc_error_messages` feels like a very low-level module but
`rustc_ast`/`rustc_ast_pretty` do not.

The reason is that a few AST types impl `IntoDiagArg` via
pretty-printing. `rustc_error_messages` can define `IntoDiagArg` and
then impl it for the AST types. But if we invert the dependency we hit
a problem with the orphan rule: `rustc_ast` must impl `IntoDiagArg`
for the AST types, but that requires calling pretty-printing code which
is in `rustc_ast_pretty`, a downstream crate.

This commit avoids this problem by just removing the `IntoDiagArg` impls
for these AST types. There aren't that many of them, and we can just use
`String` in the relevant error structs and use the pretty printer in the
downstream crates that construct the error structs. There are plenty of
existing examples where `String` is used in error structs.

There is now no dependency between `rustc_ast*` and
`rustc_error_messages`.
2026-05-01 10:58:14 +10:00
Folkert de Vries ac12c696b8 remove custom va_end implementation in the LLVM backend
it should use the fallback body instead
2026-04-30 20:32:15 +02:00
bjorn3 c5e38b741d Pass Session to optimize_and_codegen_fat_lto
This is necessary to fix incremental LTO in cg_gcc as well as to do some
LTO refactorings I want to do. The actual fix for cg_gcc will be done on
the cg_gcc repo to test it in CI.
2026-04-30 14:18:33 +00:00
Paul Murphy 74060d46ca Fix ICE when using -Zinstrument-mcount and -Clinker-flavor=lld
-Zinstrument-mcount passes -pg to the gnu linker command. This
option is only supported by the cc frontend.

This fixes https://github.com/rust-lang/rust/issues/155972
2026-04-30 08:27:31 -05:00
bors f53b654a88 Auto merge of #155018 - nnethercote:simplify-HashStable, r=fee1-dead
Simplify `HashStable`



This PR:
- Simplifies the `HashStable` trait, by moving its generic parameter from the trait to its single method.
- Eliminates the need for the non-obvious `derive(HashStable)`/`derive(HashStable_Generic)` distinction.
- Reduces the need for, and clarifies, the non-obvious `derive(HashStable)`/`derive(HashStable_NoContext)` distinction.

r? @fee1-dead
2026-04-30 07:30:46 +00:00
Jynn Nelson 4e99b682ce Trim MSVC output even if it doesn't start with whitespace
I copied this from Chromium and I think Chromium was just wrong.
2026-04-30 07:49:37 +02:00
Nicholas Nethercote 6d79bc6f01 Move feature* methods from parse mod to errors mod.
As the FIXME comment says, these no longer use `ParseSess` and so the
`parse` mod is not a good place for them. The `errors` mod is a better
home.
2026-04-30 12:02:33 +10:00
Nicholas Nethercote 36c9d23902 Overhaul stable hashing traits.
`std::hash::Hash` looks like this:
```
pub trait Hash {
    fn hash<H>(&self, state: &mut H)
       where H: Hasher;

    ...
}
```
The method is generic.

In contrast, `HashStable` looks like this:
```
pub trait HashStable<Hcx> {
    fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher);
}
```
and impls look like this (in crates upstream of `rustc_middle`):
```
impl<Hcx: HashStableContext> HashStable<Hcx> for Path {
    fn hash_stable(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
        ...
    }
}
```
or this (in `rustc_middle` and crates downstream of `rustc_middle`):
```
impl<'tcx> HashStable<StableHashingContext<'tcx>> for rustc_feature::Features {
    fn hash_stable(&self, hcx: &mut StableHashingContext<'tcx>, hasher: &mut StableHasher) {
	...
    }
}
```
Differences to `std::hash::Hash`:
- The trait is generic, rather than the method.
- The way impls are written depends their position in the crate graph.
- This explains why we have both `derive(HashStable)` and
  `derive(HashStable_Generic)`. The former is for the
  downstream-of-`rustc_middle` case, the latter is for the upstream of
  `rustc_middle` case.

Why the differences? It all boils down to `HashStable` and
`HashStableContext` being in different crates. But the previous commit
fixed that, which means `HashStable` can be simplified to this, with a
generic method:
```
pub trait HashStable {
    fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher);
}
```
and all impls look like this:
```
impl HashStable for Path {
    fn hash_stable<Hcx: HashStableContext>(&self, hcx: &mut Hcx, hasher: &mut StableHasher) {
        ...
    }
}
```

Other consequences:
- `derive(HashStable_Generic)` is no longer needed; `derive(HashStable)`
  can be used instead.
  - In this commit, `derive(HashStable_Generic` is made a synonym of
    `derive(HashStable)`. The next commit will remove this synonym,
    because it's a change that touches many lines.
- `#[stable_hash_generic]` is no longer needed (for `newtype_index`);
  `#[stable_hash]` can be used instead.
  - `#[stable_hash_no_context]` was already a synonym of
    `#[stable_hash_generic]`, so it's also removed in favour of just
    `#[stable_hash]`.
- The difference between `derive(HashStable)` and
  `derive(HashStable_NoContext)` now comes down to the difference
  between `synstructure::AddBounds::Generics` and
  `synstructure::AddBounds::Fields`, which is basically "vanilla derive"
  vs "(near) perfect derive".
  - I have improved the comments on `HashStableMode` to better
    explaining this subtle difference.
- `rustc_middle/src/ich/impls_syntax.rs` is no longer needed; the
  relevant impls can be defined in the crate that defines the relevant
  type.
- Occurrences of `for<'a> HashStable<StableHashingContext<'a>>` are
  replaced with with `HashStable`, hooray.
- The commit adds a `HashStableContext::hashing_controls` method, which
  is no big deal. (It's necessary for `AdtDefData::hash_stable`, which
  calls `hashing_controls` and used to have an `hcx` that was a
  concrete `StableHashingContext` but now has an `hcx` that is just
  `Hcx: HashStableContext`.)

Overall this is a big simplification, removing a lot of confusing
complexity in stable hashing traits.
2026-04-30 08:26:19 +10:00
Jonathan Brouwer 91783dd17f Rollup merge of #155899 - ChrisDenton:dlltool, r=mati865
`dlltool`: Set the working directory to workaround `--temp-prefix` bug

dlltool's `--temp-prefix` argument incorrectly splits paths that contain spaces. To workaround this, we pass a relative path to `--temp-prefix` and set the working directory.

fixes rust-lang/rust#155591
2026-04-29 23:51:35 +02:00
Jonathan Brouwer d936713d27 Rollup merge of #155721 - cezarbbb:fix-archive-ice-148217, r=bjorn3
When archive format is wrong produce an error instead of ICE

Fix rust-lang/rust#145624. Fix rust-lang/rust#147094. Fix rust-lang/rust#148217.
There are now two-step solutions to replace the original ICE:
Step 1: BSD format archive on a GNU/Linux target should emit a format mismatch warning.
Step 2: Corrupt archive with member offset exceeding file boundary should produce an error, not an ICE.

r? @bjorn3
2026-04-29 23:51:32 +02:00
cezarbbb b784a1ca79 When archive format is wrong produce an error instead of ICE 2026-04-29 20:21:02 +08:00