Commit Graph

3127 Commits

Author SHA1 Message Date
Matthias Krüger
86e9995e7a
Rollup merge of #142410 - RalfJung:align_of, r=WaffleLapkin,workingjubilee
intrinsics: rename min_align_of to align_of

Now that `pref_align_of` is gone (https://github.com/rust-lang/rust/pull/141803), we can give the intrinsic backing `align_of` its proper name.

r? `@workingjubilee` or `@bjorn3`
2025-06-13 05:16:59 +02:00
Matthias Krüger
b24473cfd1
Rollup merge of #142221 - mustartt:aix-fix-strip-order, r=davidtwco
[AIX] strip underlying xcoff object

When stripping, we need to strip the archive member first before archiving. Otherwise, the shared library remain untouched, only the archive symbol table will be modified.
2025-06-13 05:16:57 +02:00
Ralf Jung
62418f4c56 intrinsics: rename min_align_of to align_of 2025-06-12 17:50:25 +02:00
Matthias Krüger
240776176b
Rollup merge of #142352 - workingjubilee:c-int-width-is-an-integer, r=wesleywiser
compiler: Make `c_int_width` an integer

Because it is.

That's all I got.
2025-06-12 03:14:54 +02:00
Jubilee Young
b88c0061c4 compiler: Change c_int_width to be an integer type 2025-06-11 00:42:14 -07:00
Scott McMurray
ed06f361ac Remove unneeded FunctionCx from some codegen methods
No changes; just removing the `self` that wasn't needed.
2025-06-10 16:50:17 -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
Jubilee Young
2e19658315 Remove rustc's notion of "preferred" alignment AKA __alignof
In PR 90877 T-lang decided not to remove `intrinsics::pref_align_of`.
However, the intrinsic and its supporting code
1.  is a nightly feature, so can be removed at compiler/libs discretion
2.  requires considerable effort in the compiler to support, as it
    necessarily complicates every single site reasoning about alignment
3.  has been justified based on relevance to codegen, but it is only a
    requirement for C++ (not C, not Rust) stack frame layout for AIX,
    in ways Rust would not consider even with increased C++ interop
4.  is only used by rustc to overalign some globals, not correctness
5.  can be adequately replaced by other rules for globals, as it mostly
    affects alignments for a few types under 16 bytes of alignment
6.  has only one clear benefactor: automating C -> Rust translation
    for GNU extensions like `__alignof`
7.  such code was likely intended to be `alignof` or `_Alignof`,
    because the GNU extension is a "false friend" of the C keyword,
    which makes the choice to support such a mapping very questionable
8.  makes it easy to do incorrect codegen in the compiler by its mere
    presence as usual Rust rules of alignment (e.g. `size == align * N`)
    do not hold with preferred alignment

The implementation is clearly damaging the code quality of the compiler.
Thus it is within the compiler team's purview to simply rip it out.
If T-lang wishes to have this intrinsic restored for c2rust's benefit,
it would have to use a radically different implementation that somehow
does not cause internal incorrectness.

Until then, remove the intrinsic and its supporting code, as one tool
and an ill-considered GCC extension cannot justify risking correctness.

Because we touch a fair amount of the compiler to change this at all,
and unfortunately the duplication of AbiAndPrefAlign is deep-rooted,
we keep an "AbiAlign" type which we can wean code off later.
2025-06-08 16:41:46 -07:00
Ralf Jung
8808c9d34b intrinsics: use const generic to set atomic ordering 2025-06-07 21:45:58 +02:00
Guillaume Gomez
3a6f1b0375
Rollup merge of #142103 - scottmcm:fieldidx-in-interp, r=oli-obk
Update `InterpCx::project_field` to take `FieldIdx`

As suggested by Ralf in https://github.com/rust-lang/rust/pull/142005#discussion_r2125839015
2025-06-06 23:53:18 +02:00
bors
f315e61458 Auto merge of #142099 - matthiaskrgr:rollup-r9s3c35, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#125087 (Optimize `Seek::stream_len` impl for `File`)
 - rust-lang/rust#141982 (`tests/ui`: A New Order [5/N])
 - rust-lang/rust#142012 (Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of None)
 - rust-lang/rust#142044 (compiler: Document the offset invariant of `OperandValue::Pair`)
 - rust-lang/rust#142047 (Ensure stack in two places that affect s390x)
 - rust-lang/rust#142058 (Clean `rustc_attr_parsing/src/lib.rs` documentation)
 - rust-lang/rust#142067 (canon_abi: make to_erased_extern_abi just a detail in formatting)
 - rust-lang/rust#142072 (doc: Fix inverted meaning in E0783.md)
 - rust-lang/rust#142084 (add myself to rotation)
 - rust-lang/rust#142091 (Fix AIX build)
 - rust-lang/rust#142092 (rustdoc: Support middle::ty associated const equality predicates again)

Failed merges:

 - rust-lang/rust#142042 (Make E0621 missing lifetime suggestion verbose)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-06 12:19:16 +00:00
Scott McMurray
8bce2255e8 Update InterpCx::project_field to take FieldIdx
As suggested by Ralf in 142005.
2025-06-05 19:15:56 -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
Matthias Krüger
29954af23a
Rollup merge of #142044 - workingjubilee:document-operandvalue-pair, r=scottmcm
compiler: Document the offset invariant of `OperandValue::Pair`

A subtle invariant of `OperandValue::Pair` that came up during review and was found to be undocumented.

Visible in code like this:
4b27a04cc8/compiler/rustc_codegen_ssa/src/mir/operand.rs (L376-L392)
2025-06-06 00:58:45 +02:00
bors
cf423712b9 Auto merge of #140872 - bjorn3:elf_use_used_linker, r=nikic
Make #[used(linker)] the default on ELF too

`#[used]` currently is an alias for `#[used(linker)]` on all platforms except ELF based ones where it is an alias for `#[used(compiler)]`. The latter has surprising behavior and the LLVM LangRef explicitly states that it "should only be used in rare circumstances, and should not be exposed to source languages." [^2]

The reason `#[used]` still was an alias to `#[used(compiler)]` on ELF is because the gold linker has issues with it. Luckily gold has been deprecated with GCC 15 [^1] and seems to be unable to bootstrap rustc anyway [^3]. As such we shouldn't really care about supporting gold.

This would also allow re-enabling start-stop-gc with lld.

cc https://github.com/rust-lang/rust/issues/93798
Likely fixes https://github.com/rust-lang/rust/issues/85045

[^1]: https://lists.gnu.org/archive/html/info-gnu/2025-02/msg00001.html
[^2]: https://llvm.org/docs/LangRef.html#the-llvm-compiler-used-global-variable
[^3]: https://github.com/rust-lang/rust/issues/139425
2025-06-05 22:52:17 +00:00
Oli Scherer
fd3da4bebd Replace some Option<Span> with Span and use DUMMY_SP instead of None 2025-06-05 14:14:59 +00:00
bjorn3
f8e9778eb1 Make #[used(linker)] the default on ELF too
#[used] currently is an alias for #[used(linker)] on all platforms
except ELF based ones where it is an alias for #[used(compiler)]. The
latter has surprising behavior and the LLVM LangRef explicitly states
that it "should only be used in rare circumstances, and should not be
exposed to source languages."

The reason #[used] still was an alias to #[used(compiler)] on ELF is
because the gold linker has issues with it. Luckily gold has been
deprecated with GCC 15 and seems to be unable to bootstrap rustc anyway.
As such we shouldn't really care about supporting gold.
2025-06-05 11:35:15 +00:00
WANG Rui
27f8efbae2 Bump object 2025-06-05 07:59:51 +08:00
Jubilee Young
64df9e3c8a compiler: Document the offset invariant of OperandValue::Pair 2025-06-04 16:42:56 -07:00
Scott McMurray
ee9901e65c Change tag_field to FieldIdx in Variants::Multiple
It was already available as a generic parameter anyway, and it's not like we'll ever put a tag in the 5-billionth field.
2025-06-03 23:42:21 -07: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
72ecde27ff compiler: change Conv to CanonAbi 2025-06-03 10:03:44 -07:00
bjorn3
2e8401ae5f Remove type_test from IntrinsicCallBuilderMethods
It is only used within cg_llvm.
2025-06-03 10:00:56 +00:00
bjorn3
00a88b903d Remove get_dbg_loc from DebugInfoBuilderMethods
It is only used within cg_llvm.
2025-06-03 10:00:11 +00:00
bors
99426c570e Auto merge of #141750 - Noratrieb:gold-rush, r=bjorn3
Warn when gold was used as the linker

gold has been deprecated recently and is known to behave incorrectly around Rust programs, including miscompiling `#[used(linker)]`. Tell people to switch to a different linker instead.

closes rust-lang/rust#141748

r? bjorn3
2025-06-02 23:56:54 +00:00
bors
2fc3deed9f Auto merge of #141760 - bjorn3:intrinsic_rework_part2, r=fee1-dead
Improve intrinsic handling in cg_ssa (part 2)

* Avoid computing function type and signature for intrinsics where possible
* Nicer handling of bool returning intrinsics

Follow up to https://github.com/rust-lang/rust/pull/141404
2025-06-02 00:57:45 +00:00
Noratrieb
ba5a7444c3 Warn when gold was used as the linker
gold has been deprecated recently and is known to behave incorrectly
around Rust programs, including miscompiling `#[used(linker)]`.
Tell people to switch to a different linker instead.

Co-Authored-By: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2025-05-31 13:51:39 +00:00
Matthias Krüger
4fce906481
Rollup merge of #141749 - Noratrieb:RUSTC_ACTUALLY_DO_NOT_RETRY_LINKER_ON_SEGFAULT, r=petrochenkov
Remove RUSTC_RETRY_LINKER_ON_SEGFAULT hack

It looks like this was added in rust-lang/rust#40422 6 years ago because of issues with the MacOS linker. MacOS got a new linker in the meantime, so that should probably be resolved now. Hopefully.

r? petrochenkov
2025-05-30 13:39:55 +02:00
bjorn3
284bec5428 Directly use from_immediate for handling bool 2025-05-30 10:12:57 +00:00
bjorn3
0fcea3db28 Avoid computing function type for intrinsic instances 2025-05-30 10:12:18 +00:00
bjorn3
1f717ae778 Use layout field of OperandRef and PlaceRef in codegen_intrinsic_call
This avoids having to get the function signature.
2025-05-30 10:12:16 +00:00
Matthias Krüger
ad2d91ce11
Rollup merge of #141507 - RalfJung:atomic-intrinsics, r=bjorn3
atomic_load intrinsic: use const generic parameter for ordering

We have a gazillion intrinsics for the atomics because we encode the ordering into the intrinsic name rather than making it a parameter. This is particularly bad for those operations that take two orderings. Let's fix that!

This PR only converts `load`, to see if there's any feedback that would fundamentally change the strategy we pursue for the const generic intrinsics.

The first two commits are preparation and could be a separate PR if you prefer.

`@BoxyUwU` -- I hope this is a use of const generics that is unlikely to explode? All we need is a const generic of enum type. We could funnel it through an integer if we had to but an enum is obviously nicer...

`@bjorn3` it seems like the cranelift backend entirely ignores the ordering?
2025-05-30 07:01:30 +02:00
Noratrieb
f1778074fb Remove RUSTC_RETRY_LINKER_ON_SEGFAULT hack
It looks like this was added 6 years ago because of issues with the
MacOS linker. MacOS got a new linker in the meantime, so that should
probably be resolved now. Hopefully.
2025-05-29 23:30:29 +02:00
Guillaume Gomez
161cf3e25b
Rollup merge of #141448 - bjorn3:codegen_refactors, r=WaffleLapkin
A variety of improvements to the codegen backends

Some are just general improvements to cg_ssa or cg_llvm, while others will make it slightly easier to use cg_ssa in cg_clif in the future.
2025-05-29 17:02:59 +02:00
Jacob Pratt
394fde04a8
Rollup merge of #138139 - xizheyin:issue-137384, r=ChrisDenton
Emit warning while outputs is not exe and prints linkage info

cc #137384

```bash
$ rustc +stage1 /dev/null --print native-static-libs --crate-type staticlib  --emit metadata
warning: skipping link step due to conflict: cannot output linkage information without emitting executable

note: consider emitting executable to print link information

warning: 1 warning emitted
```
2025-05-29 04:49:40 +02:00
Ralf Jung
a387c86a92 get rid of rustc_codegen_ssa::common::AtomicOrdering 2025-05-28 22:57:55 +02:00
Ralf Jung
4794ea176b atomic_load intrinsic: use const generic parameter for ordering 2025-05-28 22:57:55 +02:00
bjorn3
865c7b9c78 Remove unused arg_memory_ty method 2025-05-28 20:55:00 +00:00
bjorn3
f0707fad31 Mark all optimize methods and the codegen method as safe
There is no safety contract and I don't think any of them can actually
cause UB in more ways than passing malicious source code to rustc can.
While LtoModuleCodegen::optimize says that the returned ModuleCodegen
points into the LTO module, the LTO module has already been dropped by
the time this function returns, so if the returned ModuleCodegen indeed
points into the LTO module, we would have seen crashes on every LTO
compilation, which we don't. As such the comment is outdated.
2025-05-28 20:55:00 +00:00
bjorn3
d7c0bde0c1 Remove methods from StaticCodegenMethods that are not called in cg_ssa itself 2025-05-28 20:55:00 +00:00
bjorn3
669e2ea848 Make predefine methods take &mut self 2025-05-28 20:55:00 +00:00
bjorn3
0809b41cd9 Move supports_parallel from CodegenBackend to ExtraBackendMethods
It is only relevant when using cg_ssa for driving compilation.
2025-05-28 20:55:00 +00:00
bjorn3
0fd257d66c Remove a couple of uses of interior mutability around statics 2025-05-28 20:55:00 +00:00
bjorn3
a4cb1c72c5 Reduce amount of types that need to be PartialEq 2025-05-28 20:55:00 +00:00
bjorn3
5b0ab2cbdd The personality function is a Function, not a Value 2025-05-28 20:55:00 +00:00
bjorn3
c593c01703 Remove codegen_unit from MiscCodegenMethods 2025-05-28 20:55:00 +00:00
Trevor Gross
1ead0a5ef3
Rollup merge of #141404 - bjorn3:refactor_cg_ssa_call_codegen, r=davidtwco
Improve intrinsic handling in cg_ssa

* Move all intrinsic handling code to the start of `codegen_call_terminator`.
* Push some intrinsic handling code into `codegen_intrinsic_call`.
* Don't depend on FnAbi for intrinsics.
2025-05-28 10:28:09 -04:00
Michael Goulet
29c3babd7c Rename unpack to kind 2025-05-27 11:14:45 +00:00
bjorn3
165fb98849 Reduce indentation in codegen_panic_intrinsic 2025-05-26 10:13:03 +00:00
bjorn3
7122648e34 Don't depend on FnAbi for intrinsics
Intrinsics are not real functions and as such don't have any calling
convention. Trying to compute a calling convention for an intrinsic
anyway is a nonsensical operation.
2025-05-26 10:13:03 +00:00