Commit Graph

2731 Commits

Author SHA1 Message Date
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
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
Matthias Krüger
98da8e60eb
Rollup merge of #142005 - scottmcm:fieldidx-in-variantsmultiple, r=workingjubilee
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.

This is a first part of pulling smaller pieces out of rust-lang/rust#138759, so
r? workingjubilee
2025-06-04 19:50:26 +02: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
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
e0b07a88a3 cg_llvm: convert to CanonAbi 2025-06-03 10:04:19 -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
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
Guillaume Gomez
cf4fbc0695
Rollup merge of #141622 - folkertdev:powerpc-va_arg, r=workingjubilee
implement `va_arg` for `powerpc`

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

The llvm `va_arg` implementation is well-known to have serious limitations. Some planned changes to rust's `VaList` make it much more likely that LLVM miscompiles `va_arg`, so this PR adds support for the various powerpc targets. Now at least the targets that `core` has explicit support for will continue to work.

For `powerpc` (the 32-bit variant) this implementation also fixes a bug where only up to 20 variadic arguments were supported.

Locally (with qemu), these targets now pass the tests in https://github.com/rust-lang/rust/blob/master/tests/run-make/c-link-to-rust-va-list-fn/checkrust.rs. That test does not actually run for the powerpc targets in CI though.

The implementation is based on clang:

- handling of big endian architectures 3c8089d1ea/clang/lib/CodeGen/ABIInfoImpl.cpp (L191-L193)
- 64-bit 3c8089d1ea/clang/lib/CodeGen/Targets/PPC.cpp (L969)
- 32-bit 3c8089d1ea/clang/lib/CodeGen/Targets/PPC.cpp (L430)

cc `@daltenty` (target maintainer)
r? `@workingjubilee`
`@rustbot` label: +F-c_variadic
2025-06-01 19:35:42 +02:00
Folkert de Vries
be13ce341a
implement va_arg for powerpc
This actually fixes a bug where before only 20 arguments could be passed. As far as I can tell, an arbitrary number of arguments is now supported
2025-06-01 00:51:01 +02:00
Folkert de Vries
108a36efe4
implement va_arg for powerpc64 and powerpc64le 2025-05-30 18:02:47 +02:00
bors
15825b7161 Auto merge of #139385 - joboet:threadlocal_address, r=nikic
rustc_codegen_llvm: use `threadlocal.address` intrinsic to access TLS

Fixes #136044
r? `@nikic`
2025-05-30 15:39:56 +00: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
38a6daeb23 Use layout field of OperandRef in generic_simd_intrinsic 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
5023691213
Rollup merge of #141538 - folkertdev:systemv-x86_64-va_arg, r=workingjubilee
implement `va_arg` for x86_64 systemv

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

Turns out LLVM's `va_arg` is also unreliable for this target.

https://github.com/llvm/llvm-project/issues/141361

So, like clang, we implement our own. I used

- the spec at https://gitlab.com/x86-psABIs/x86-64-ABI
- the clang implementation at 9a440f8477/clang/lib/CodeGen/Targets/X86.cpp (L3041)

We can take a bunch of shortcuts because the return type of `va_list` must implement `VaArgSafe`. I also extended some of the tests, because up to 11 floats can be stored in the `reg_safe_area` for this calling convention.

r? `@workingjubilee`
`@rustbot` label +F-c_variadic

try-job: x86_64-apple-1
2025-05-30 07:01:30 +02: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
Folkert de Vries
94cc72682e
implement va_arg for x86_64 systemv and macOS
Turns out LLVM's `va_arg` is also unreliable for this target, so we need
our own implementation.
2025-05-29 22:06:02 +02:00
joboet
e4d9b06cc8
rustc_codegen_llvm: use threadlocal.address intrinsic to access TLS 2025-05-29 16:07:43 +02:00
Folkert de Vries
b2e9c72e72
emit_xtensa_va_arg: use inbounds_ptradd instead of inbounds_gep 2025-05-29 11:21:19 +02:00
Ralf Jung
a387c86a92 get rid of rustc_codegen_ssa::common::AtomicOrdering 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
0fd257d66c Remove a couple of uses of interior mutability around statics 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
Matthias Krüger
003fbf1fad
Rollup merge of #141650 - Zalathar:revert-unused-local-file, r=Zalathar
coverage: Revert "unused local file IDs" due to empty function names

The changes to coverage metadata generation in rust-lang/rust#140847 appear to be the most likely cause of the `function name is empty` errors reported in rust-lang/rust#141577.

If that guess is correct, great. If not, no big deal.

---

This reverts commit 3b22c21dd8, reversing changes made to 5f292eea6d.

r? ghost
2025-05-27 20:57:57 +02:00
Zalathar
3f526eeec4 coverage: Revert "unused local file IDs" due to empty function names
This reverts commit 3b22c21dd8, reversing
changes made to 5f292eea6d.
2025-05-27 23:33:29 +10:00
Michael Goulet
f0ee1d7100
Rollup merge of #141623 - folkertdev:va-arg-explicit-types, r=workingjubilee
use custom types to clarify arguments to `emit_ptr_va_arg`

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

split out of https://github.com/rust-lang/rust/pull/141622

r? ``@workingjubilee``
``@rustbot`` label: +F-c_variadic
2025-05-27 13:01:43 +02:00
Folkert de Vries
7fe8263285
use custom types to clarify arguments to emit_ptr_va_arg 2025-05-27 01:24:19 +02:00
bjorn3
0a14e1b2e7 Remove usage of FnAbi in codegen_intrinsic_call 2025-05-26 10:13:03 +00:00
bjorn3
6016f84e71 Pass PlaceRef rather than Bx::Value to codegen_intrinsic_call 2025-05-26 10:13:03 +00:00
Noratrieb
fa2bb599bc Cleanup CodegenFnAttrFlags
- Rename `USED` to `USED_COMPILER` to better reflect its behavior.
- Reorder some items to group the used and allocator flags together
- Renumber them without gaps
2025-05-24 20:31:37 +02:00
Folkert de Vries
c24e1c378f
add s390x z17 target features 2025-05-19 17:40:37 +02:00
Stuart Cook
3b22c21dd8
Rollup merge of #140847 - Zalathar:unused-local-file, r=SparrowLii
coverage: Detect unused local file IDs to avoid an LLVM assertion

Each function's coverage metadata contains a *local file table* that maps local file IDs (used by the function's mapping regions) to global file IDs (shared by all functions in the same CGU).

LLVM requires all local file IDs to have at least one mapping region, and has an assertion that will fail if it detects a local file ID with no regions. To make sure that assertion doesn't fire, we need to detect and skip functions whose metadata would trigger it.

(This can't actually happen yet, because currently all of a function's spans must belong to the same file and expansion. But this will be an important edge case when adding expansion region support.)
2025-05-19 21:10:42 +10:00
Stuart Cook
599b08ada8
Rollup merge of #140874 - mejrs:rads, r=WaffleLapkin
make `rustc_attr_parsing` less dominant in the rustc crate graph

It has/had a glob re-export of `rustc_attr_data_structures`, which is a crate much lower in the graph, and a lot of crates were using it *just* (or *mostly*) for that re-export, while they can rely on `rustc_attr_data_structures` directly.

Previous graph:
![graph_1](https://github.com/user-attachments/assets/f4a5f13c-4222-4903-b56d-28c83511fcbd)

Graph with this PR:
![graph_2](https://github.com/user-attachments/assets/1e053d9c-75cc-402b-84df-86229c98277a)

The first commit keeps the re-export, and just changes the dependency if possible. The second commit is the "breaking change" which removes the re-export, and "explicitly" adds the `rustc_attr_data_structures` dependency where needed. It also switches over some src/tools/*.

The second commit is actually a lot more involved than I expected. Please let me know if it's a better idea to back it out and just keep the first commit.
2025-05-19 13:24:54 +10:00
Jieyou Xu
734a5b1aa7
Revert "Fix linking statics on Arm64EC #140176"
Unfortunately, multiple people are reporting linker warnings related to
`__rust_no_alloc_shim_is_unstable` after this change. The solution isn't
quite clear yet, let's revert to green for now, and try a reland with a
determined solution for `__rust_no_alloc_shim_is_unstable`.

This reverts commit c8b7f32434, reversing
changes made to 667247db71.
2025-05-15 16:54:27 +08:00
bors
4eca99a18e Auto merge of #140887 - pietroalbini:pa-bootstrap-update, r=compiler-errors
Stage0 bootstrap update

This PR [follows the release process](https://forge.rust-lang.org/release/process.html#master-bootstrap-update-tuesday) to update the stage0 compiler.

The only thing of note is 58651d1b31, which was flagged by clippy as a correctness fix. I think allowing that lint in our case makes sense, but it's worth to have a second pair of eyes on it.

r? `@Mark-Simulacrum`
2025-05-13 09:54:28 +00:00
bors
1a7f290a9a Auto merge of #140914 - Zalathar:asm-bindings, r=compiler-errors
cg_llvm: Clean up some inline assembly bindings

This PR combines a few loosely-related cleanups to LLVM bindings related to inline assembly. These include:
- Replacing `LLVMRustInlineAsm` with LLVM-C's `LLVMGetInlineAsm`
- Adjusting FFI declarations to avoid the need for explicit `as_c_char_ptr` conversions
- Flattening control flow in `inline_asm_call`

There should be no functional changes.
2025-05-12 17:39:21 +00:00
Pietro Albini
2ce08ca5d6
update cfg(bootstrap) 2025-05-12 15:33:37 +02:00
Zalathar
dbdbde2a72 Rename OperandBundleOwned to OperandBundleBox
As with `DIBuilderBox`, the "Box" suffix does a better job of communicating
that this is an owning pointer to some borrowable resource.

This also renames the `raw` method to `as_ref`, which is what it would have
been named originally if the `Deref` problem had been known at the time.
2025-05-11 21:21:38 +10:00
Zalathar
eccf0647d3 Flatten control-flow in inline_asm_call after verification 2025-05-11 14:38:42 +10:00
Zalathar
b6300294a8 Make LLVMRustInlineAsmVerify take *const c_uchar
This avoids the need for an explicit `as_c_char_ptr` conversion.
2025-05-11 14:38:42 +10:00
Zalathar
b1094f6a0a Add a safe wrapper for LLVMAppendModuleInlineAsm
This patch also changes the Rust-side declaration to take `*const c_uchar`
instead of `*const c_char`, to avoid the need for `AsCCharPtr`.
2025-05-11 14:38:42 +10:00
Zalathar
d1bb310a7a Use LLVMGetInlineAsm
This LLVM-C binding replaces the existing `LLVMRustInlineAsm` function.
2025-05-11 14:37:54 +10:00