3319 Commits

Author SHA1 Message Date
bors
637b50be01 Auto merge of #145186 - camsteffen:assoc-impl-kind, r=petrochenkov
Make `AssocItem` aware of its impl kind

The general goal is to have fewer query dependencies by making `AssocItem` aware of its parent impl kind (inherent vs. trait) without having to query the parent def_kind.

See individual commits.
2025-09-13 13:59:48 +00:00
Cameron Steffen
16c218c57f Introduce trait_item_of 2025-09-12 15:10:30 -05:00
Noratrieb
f157ce994e Add --print target-spec-json-schema
This schema is helpful for people writing custom target spec JSON. It
can provide autocomplete in the editor, and also serves as documentation
when there are documentation comments on the structs, as `schemars` will
put them in the schema.
2025-09-12 20:53:28 +02:00
Stuart Cook
48d684111e
Rollup merge of #144549 - folkertdev:va-arg-arm, r=saethlin
match clang's `va_arg` assembly on arm targets

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

For this example

```rust
#![feature(c_variadic)]

#[unsafe(no_mangle)]
unsafe extern "C" fn variadic(a: f64, mut args: ...) -> f64 {
    let b = args.arg::<f64>();
    let c = args.arg::<f64>();

    a + b + c
}
```

We currently generate (via llvm):

```asm
variadic:
    sub     sp, sp, #12
    stmib   sp, {r2, r3}
    vmov    d0, r0, r1
    add     r0, sp, #4
    vldr    d1, [sp, #4]
    add     r0, r0, #15
    bic     r0, r0, #7
    vadd.f64        d0, d0, d1
    add     r1, r0, #8
    str     r1, [sp]
    vldr    d1, [r0]
    vadd.f64        d0, d0, d1
    vmov    r0, r1, d0
    add     sp, sp, #12
    bx      lr
```

LLVM is not doing a good job. In fact, it's well-known that LLVM's implementation of `va_arg` is kind of bad, and we implement it ourselves (based on clang) for many targets already. For arm,  our own `emit_ptr_va_arg` saves 3 instructions.

Next, it turns out it's important for LLVM to explicitly start and end the lifetime of the `va_list`. In https://github.com/rust-lang/rust/pull/146059 I already end the lifetime, but when looking at this again, I noticed that it is important to also start it, see https://godbolt.org/z/EGqvKTTsK: failing to explicitly start the lifetime uses an extra register.

So, the combination of `emit_ptr_va_arg` with starting/ending the lifetime makes rustc emit exactly the instructions that clang generates::

```asm
variadic:
    sub     sp, sp, #12
    stmib   sp, {r2, r3}
    vmov    d16, r0, r1
    vldr    d17, [sp, #4]
    vadd.f64        d16, d16, d17
    vldr    d17, [sp, #12]
    vadd.f64        d16, d16, d17
    vmov    r0, r1, d16
    add     sp, sp, #12
    bx      lr
```

The arguments to `emit_ptr_va_arg` are based on [the clang implementation](03dc2a41f3/clang/lib/CodeGen/Targets/ARM.cpp (L798-L844)).

r? ``@workingjubilee`` (I can re-roll if your queue is too full, but you do seem like the right person here)

try-job: armhf-gnu
2025-09-12 20:02:10 +10:00
Matthias Krüger
92bad93f06
Rollup merge of #146209 - bjorn3:lto_refactors5, r=dianqk
Misc LTO cleanups

Follow up to https://github.com/rust-lang/rust/pull/145955.

* Remove want_summary argument from `prepare_thin`.
   Since https://github.com/rust-lang/rust/pull/133250 ThinLTO summary writing is instead done by `llvm_optimize`.
* Two minor cleanups
2025-09-07 20:02:27 +02:00
Matthias Krüger
cb8b5fa4e2
Rollup merge of #146254 - yotamofek:pr/itertools-all-equal-value, r=cjgillot
Use `Itertools::all_equal_value()` where applicable

Just a small cleanup.
We already have `itertools` as a dep in these crates, so might as well use another of its features.
Makes the code simpler IMHO :)
2025-09-07 08:18:59 +02:00
bjorn3
3a1ae064a7 Move timers into execute_*_work_item 2025-09-06 18:37:23 +00:00
bjorn3
f2933b34a8 Remove want_summary argument from prepare_thin
It is always false nowadays. ThinLTO summary writing is instead done by
llvm_optimize.
2025-09-06 18:37:23 +00:00
bjorn3
e3d0b7d648 Remove thin_link_data method from ThinBufferMethods
It is only used within cg_llvm.
2025-09-06 18:37:23 +00:00
bjorn3
2cf94b92ca Ensure fat LTO doesn't merge everything into the allocator module 2025-09-06 13:31:41 +00:00
bjorn3
0271359768 Make the allocator shim participate in LTO again 2025-09-06 08:35:55 +00:00
Yotam Ofek
f279ae1b05 Use Itertools::all_equal_value() where applicable 2025-09-05 18:43:43 +00:00
Matthias Krüger
81042523c6 remove couple of clones 2025-09-05 15:38:01 +02:00
bjorn3
319fe230f0 Special case allocator module submission to avoid special casing it elsewhere
A lot of places had special handling just in case they would get an
allocator module even though most of these places could never get one or
would have a trivial implementation for the allocator module. Moving all
handling of the allocator module to a single place simplifies things a
fair bit.
2025-09-04 08:21:10 +00:00
bjorn3
eea81b5d75 Ensure the allocator shim never participates in LTO
Making it participate in LTO would be incorrect if you compile a crate
as both a dylib (which needs it) and rlib (which must not include it) in
the same rustc invocation. With linker plugin LTO, the allocator shim
will still participate in LTO as it is safe to do so in that case.
2025-09-04 08:21:10 +00:00
bjorn3
7a01c7f676 Export __rdl_* symbols to the allocator shim when doing LTO 2025-09-04 08:21:10 +00:00
Stuart Cook
6c77c4c115
Rollup merge of #145962 - bjorn3:linkage_fixes, r=WaffleLapkin
Ensure we emit an allocator shim when only some crate types need one

Found this while trying to write a test for https://github.com/rust-lang/rust/pull/145955.
2025-09-04 10:01:56 +10:00
Stuart Cook
f90cc353b8
Rollup merge of #145932 - JamieCunliffe:target-feature-inlining, r=jackh726
Allow `inline(always)` with a target feature behind a unstable feature `target_feature_inline_always`.

Rather than adding the inline always attribute to the function definition, we add it to the callsite. We can then check that the target features match and that the call would be safe to inline. If the function isn't inlined due to a mismatch, we emit a warning informing the user that the function can't be inlined due to the target feature mismatch.

See tracking issue rust-lang/rust#145574
2025-09-04 10:01:55 +10:00
bors
a1208bf765 Auto merge of #146133 - rcvalle:rust-cfi-fix-145981, r=bjorn3
Revert "Make `lto` and `linker-plugin-lto` work the same for `compiler_builtins`

This reverts commit cf8753e4f9c3597f04cd5d3aa261e4561d5378a6 (PR https://github.com/rust-lang/rust/pull/145368) and fix the regressions reported at rust-lang/rust#145981, rust-lang/rust#146109, and rust-lang/rust#146145.
2025-09-03 19:07:55 +00:00
Folkert de Vries
418900562c
explicitly start va_list lifetime 2025-09-03 00:19:18 +02:00
Ramon de C Valle
916b55e082 Revert "Make lto and linker-plugin-lto work the same for compiler_builtins"
This reverts commit cf8753e4f9c3597f04cd5d3aa261e4561d5378a6 and fixes the
regressions reported.
2025-09-02 13:11:19 -07:00
bors
05abce5d05 Auto merge of #146059 - folkertdev:va-end-lifetime, r=saethlin
explicitly end the lifetime of `va_list`

tracking issue: https://github.com/rust-lang/rust/issues/44930
split out from: https://github.com/rust-lang/rust/pull/144549

The `va_list` is created in the compiler itself when the variable argument list `...` is desugared, and hence the lifetime end is not inserted automatically. The value can't outlive the function in which it was created, so it is correct to end the lifetime here. Ending the lifetime explicitly also appears to give slightly better codegen in https://github.com/rust-lang/rust/pull/144549.

I also included a little drive-by improvement to not cast pointers to integers and back again.

r? codegen
2025-09-02 01:12:13 +00:00
Folkert de Vries
213bb87351
explicitly end va_list lifetime 2025-08-31 16:07:28 +02:00
Daniel Paoliello
4daae65228 Move to 0.50.1 2025-08-29 16:39:16 -07:00
Daniel Paoliello
da8f230d5f Update to ar_archive_writer 0.5.1 2025-08-29 16:37:42 -07:00
bjorn3
f4888c2a68 Correctly handle different crate types disagreeing if the allocator shim is exported
Previously it would attempt to export the allocator shim even linking
for a crate type which pulls in the allocator shim from a dylib rather
than locally defining it.
2025-08-29 08:40:52 +00:00
bjorn3
1d30900830 Fix typo in comment 2025-08-29 08:39:34 +00:00
bjorn3
fc7de9979e Ensure we emit an allocator shim when only some crate types need one 2025-08-29 08:39:34 +00:00
Guillaume Gomez
a60b96a3d4
Rollup merge of #145965 - bjorn3:sanitize_symbol_export_improvements, r=lqd
Move exporting of profiler and sanitizer symbols to the LLVM backend

Only the LLVM backend needs those specific symbols exported and it only needs them to be exported for LTO, not from cdylibs in general.
2025-08-28 21:41:03 +02:00
Guillaume Gomez
9e4a283615
Rollup merge of #145368 - rcvalle:rust-cfi-fix-142284, r=dianqk
CFI: Make `lto` and `linker-plugin-lto` work the same for `compiler_builtins`

Fix rust-lang/rust#142284 by ensuring that `#![no_builtins]` crates can still emit bitcode when proper (i.e., non-rustc) LTO (i.e., -Clinker-plugin-lto) is used.
2025-08-28 21:41:01 +02:00
bjorn3
d76cff3f06 Only export the sanitizer symbols for LTO and move export code to cg_llvm
Don't export them from cdylibs. There is no need to do so and it
complicates exported_non_generic_symbols. In addition the GCC backend
likely uses different symbols and may potentially not even need us to
explicitly tell it to export the symbols it needs.
2025-08-28 19:36:44 +00:00
Stuart Cook
a65ed63b3b
Rollup merge of #143193 - JonathanBrouwer:link_rework, r=jdonszelmann
Port `#[link]` to the new attribute parsing infrastructure

Ports `link` to the new attribute parsing infrastructure for https://github.com/rust-lang/rust/issues/131229#issuecomment-2971353197
2025-08-28 23:10:33 +10:00
Jacob Pratt
5527156d92
Rollup merge of #145894 - zetanumbers:issue-142949, r=WaffleLapkin
Ensure the coordinator thread terminates before its channels drop

Fixes rust-lang/rust#142949

Explanation: https://github.com/rust-lang/rust/issues/142949#issuecomment-3224573185
2025-08-27 21:51:54 -04:00
Jonathan Brouwer
e8d08b5416
Port the #[link] attribute to the new parser 2025-08-27 20:25:16 +02:00
Jonathan Brouwer
aab5e0bf1f
Move NativeLibKind from rustc_session to rustc_hir 2025-08-27 20:24:59 +02:00
James Barford-Evans
bcfc9b5073 inline at the callsite & warn when target features mismatch
Co-authored-by: Jamie Cunliffe <Jamie.Cunliffe@arm.com>
2025-08-27 14:45:01 +01:00
Matthew Maurer
cf8753e4f9 Make lto and linker-plugin-lto work the same for compiler_builtins
Fix #142284 by ensuring that `#![no_builtins]` crates can still emit bitcode
when proper (i.e., non-rustc) LTO (i.e., -Clinker-plugin-lto) is used.
2025-08-26 16:32:29 -07:00
Samuel Tardieu
fe5890e481
Rollup merge of #145892 - jdonszelmann:codegen-fn-attrs-foreign-item, r=bjorn3
add a flag to codegen fn attrs for foreign items

r? `@ghost`

refiled to rerun CI
2025-08-26 23:25:05 +02:00
Samuel Tardieu
ac7f423d52
Rollup merge of #145840 - a4lg:riscv-elf-flags-for-internal-objs, r=WaffleLapkin
rustc_codegen_ssa: More comprehensive RISC-V ELF flags

This change implements more conformant, more comprehensive RISC-V ELF flags handling when generating certain object files directly from rustc.

*   Use `"zca"` instead of `"c"`
    The "Zca" extension (a subset of "C") is the minimal configuration for compressed instructions to set `EF_RISCV_RVC` flag.
*   Set TSO flag from `"ztso"`
    The "Ztso" extension denotes that the program depends on the RVTSO (Total Store Ordering) memory consistency model, which is stronger than the standard RVWMO (Weak Memory Ordering) consistency model and on ELF targets, we need to set `EF_RISCV_TSO` flag.
2025-08-26 23:25:02 +02:00
Daria Sukhonina
dd07459096 Comment on intentional field order 2025-08-26 19:18:39 +03:00
Daria Sukhonina
82cc0eeec1 Ensure the coordinator thread terminates first 2025-08-26 18:55:41 +03:00
Jana Dönszelmann
d66ca53000
add a flag to codegen fn attrs for foreign items 2025-08-26 13:05:51 +02:00
Stuart Cook
820bb7f7df
Rollup merge of #145847 - madsmtm:no-xcrun-warnings, r=jieyouxu
Don't show warnings from xcrun with -Zverbose-internals

These kinds of warnings can make our test suite fail spuriously, so if we want them, we'll need a different flag.

This was introduced in https://github.com/rust-lang/rust/pull/131477. Fixes https://github.com/rust-lang/rust/issues/145543.

r? apiraino
```@bors``` rollup
2025-08-26 14:19:22 +10:00
Stuart Cook
f5633098b0
Rollup merge of #145814 - bjorn3:codegen_worker_fatal_error, r=petrochenkov
Handle unwinding fatal errors in codegen workers

Also directly unwind on fatal errors at the point they are emitted inside the codegen backends.

Fixes the coordinator ICE of https://github.com/rust-lang/rust/issues/132240, https://github.com/rust-lang/rust/issues/135075 and https://github.com/rust-lang/rust/issues/145800.
2025-08-26 14:19:18 +10:00
Tsukasa OI
cb8c905c47 rustc_codegen_ssa: More comprehensive RISC-V ELF flags
This commit implements more conformant, more comprehensive RISC-V ELF
flags handling when generating certain object files directly from rustc.

*   Use "zca" instead of "c"
    The "Zca" extension (a subset of "C") is the minimal configuration
    for compressed instructions to set `EF_RISCV_RVC` flag.
*   Set TSO flag from "ztso"
    The "Ztso" extension denotes that the program depends on the RVTSO
    (Total Store Ordering) memory consistency model, which is stronger
    than the standard RVWMO (Weak Memory Ordering) consistency model and
    on ELF targets, we need to set `EF_RISCV_TSO` flag.
2025-08-26 03:42:37 +00:00
Tsukasa OI
691206470b rustc_codegen_ssa: Fix comment 2025-08-26 03:42:37 +00:00
Mads Marquart
d262463d53 Don't show warnings from xcrun with -Zverbose-internals
These kinds of warnings can make our test suites fail, so if we want
them, we'll need a different flag.
2025-08-25 14:38:34 +02:00
Stuart Cook
488496b3a7
Rollup merge of #145820 - mati865:raw-elf-verdefnum, r=bjorn3
raw-dylib-elf: set correct `DT_VERDEFNUM`

Previously it indicated a single version, regardless of their count.
Observed in: https://github.com/davidlattimore/wild/pull/1041
2025-08-25 19:52:22 +10:00
Mateusz Mikuła
b1be775dd6 raw-dylib-elf: set correct DT_VERDEFNUM
Previously it indicated a single version, regardless of their count.
Observed in: https://github.com/davidlattimore/wild/pull/1041
2025-08-24 18:19:31 +02:00
bjorn3
525c6a3562 Directly raise fatal errors inside the codegen backends
As opposed to passing it around through Result.
2025-08-24 11:20:41 +00:00