about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/back
AgeCommit message (Collapse)AuthorLines
2025-10-01Don't enable shared memory with Wasm atomicsdaxpedda-32/+1
2025-09-28Add a leading dash to linker plugin arguments in the gcc codegenAntoni Boucher-2/+17
2025-09-23Rollup merge of #146784 - dpaoliello:findmsvc, r=wesleywiserMatthias Krüger-6/+5
[win] Use find-msvc-tools instead of cc to find the linker and rc on Windows `find-msvc-tools` was factored out from `cc` to allow updating the use in `rustc_codegen_ssa` (finding the linker when running the Rust compiler) and `rustc_windows_rc` (finding the Windows Resource Compiler when running the Rust compiler) to be separate from the use in `rustc_llvm` (building LLVM as part of building the Rust compiler).
2025-09-23Auto merge of #146317 - saethlin:panic=immediate-abort, r=nnethercotebors-5/+5
Add panic=immediate-abort MCP: https://github.com/rust-lang/compiler-team/issues/909 This adds a new panic strategy, `-Cpanic=immediate-abort`. This panic strategy essentially just codifies use of `-Zbuild-std-features=panic_immediate_abort`. This PR is intended to just set up infrastructure, and while it will change how the compiler is invoked for users of the feature, there should be no other impacts. In many parts of the compiler, `PanicStrategy::ImmediateAbort` behaves just like `PanicStrategy::Abort`, because actually most parts of the compiler just mean to ask "can this unwind?" so I've added a helper function so we can say `sess.panic_strategy().unwinds()`. The panic and unwind strategies have some level of compatibility, which mostly means that we can pre-compile the sysroot with unwinding panics then the sysroot can be linked with aborting panics later. The immediate-abort strategy is all-or-nothing, enforced by `compiler/rustc_metadata/src/dependency_format.rs` and this is tested for in `tests/ui/panic-runtime/`. We could _technically_ be more compatible with the other panic strategies, but immediately-aborting panics primarily exist for users who want to eliminate all the code size responsible for the panic runtime. I'm open to other use cases if people want to present them, but not right now. This PR is already large. `-Cpanic=immediate-abort` sets both `cfg(panic = "immediate-abort")` _and_ `cfg(panic = "abort")`. bjorn3 pointed out that people may be checking for the abort cfg to ask if panics will unwind, and also the sysroot feature this is replacing used to require `-Cpanic=abort` so this seems like a good back-compat step. At least for the moment. Unclear if this is a good idea indefinitely. I can imagine this being confusing. The changes to the standard library attributes are purely mechanical. Apart from that, I removed an `unsafe` we haven't needed for a while since the `abort` intrinsic became safe, and I've added a helpful diagnostic for people trying to use the old feature. To test that `-Cpanic=immediate-abort` conflicts with other panic strategies, I've beefed up the core-stubs infrastructure a bit. There is now a separate attribute to set flags on it. I've added a test that this produces the desired codegen, called `tests/run-make-cargo/panic-immediate-abort-codegen/` and also a separate run-make-cargo test that checks that we can build a binary.
2025-09-21Add panic=immediate-abortBen Kimock-5/+5
2025-09-19Enable `limit_rdylib_exports` on wasm targetsAlex Crichton-0/+5
This commit updates the target specification of wasm targets to set the `limit_rdylib_exports` value to `true` like it is on other native platforms. This was originally not implemented long ago as `wasm-ld` didn't have options for symbol exports, but since then it's grown a `--export` flag and such to control this. A custom case is needed in the linker implementation to handle wasm targets as `wasm-ld` doesn't support linker scripts used on other targets, but other than that the implementation is straightforward. The goal of this commit is enable building dynamic libraries on `wasm32-wasip2` which don't export every single symbol in the Rust standard library. Currently, without otherwise control over symbol visibility, all symbols end up being exported which generates excessively large binaries because `--gc-sections` ends up doing nothing as it's all exported anyway.
2025-09-19[win] Use find-msvc-tools instead of cc to find the linker and rc on WindowsDaniel Paoliello-6/+5
2025-09-12Add --print target-spec-json-schemaNoratrieb-1/+1
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-06Move timers into execute_*_work_itembjorn3-27/+20
2025-09-06Remove want_summary argument from prepare_thinbjorn3-1/+1
It is always false nowadays. ThinLTO summary writing is instead done by llvm_optimize.
2025-09-06Ensure fat LTO doesn't merge everything into the allocator modulebjorn3-1/+2
2025-09-06Make the allocator shim participate in LTO againbjorn3-24/+30
2025-09-04Special case allocator module submission to avoid special casing it elsewherebjorn3-87/+48
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-04Ensure the allocator shim never participates in LTObjorn3-9/+11
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-04Export __rdl_* symbols to the allocator shim when doing LTObjorn3-0/+14
2025-09-04Rollup merge of #145962 - bjorn3:linkage_fixes, r=WaffleLapkinStuart Cook-34/+60
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-03Auto merge of #146133 - rcvalle:rust-cfi-fix-145981, r=bjorn3bors-1/+12
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-02Revert "Make `lto` and `linker-plugin-lto` work the same for ↵Ramon de C Valle-1/+12
`compiler_builtins`" This reverts commit cf8753e4f9c3597f04cd5d3aa261e4561d5378a6 and fixes the regressions reported.
2025-08-29Move to 0.50.1Daniel Paoliello-9/+11
2025-08-29Update to ar_archive_writer 0.5.1Daniel Paoliello-2/+4
2025-08-29Correctly handle different crate types disagreeing if the allocator shim is ↵bjorn3-29/+46
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-29Fix typo in commentbjorn3-1/+1
2025-08-29Ensure we emit an allocator shim when only some crate types need onebjorn3-4/+13
2025-08-28Rollup merge of #145965 - bjorn3:sanitize_symbol_export_improvements, r=lqdGuillaume Gomez-48/+1
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-28Rollup merge of #145368 - rcvalle:rust-cfi-fix-142284, r=dianqkGuillaume Gomez-12/+1
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-28Only export the sanitizer symbols for LTO and move export code to cg_llvmbjorn3-48/+1
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-28Rollup merge of #143193 - JonathanBrouwer:link_rework, r=jdonszelmannStuart Cook-3/+6
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-27Rollup merge of #145894 - zetanumbers:issue-142949, r=WaffleLapkinJacob Pratt-2/+5
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-27Port the `#[link]` attribute to the new parserJonathan Brouwer-2/+5
2025-08-27Move `NativeLibKind` from `rustc_session` to `rustc_hir`Jonathan Brouwer-1/+1
2025-08-26Make `lto` and `linker-plugin-lto` work the same for `compiler_builtins`Matthew Maurer-12/+1
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-26Rollup merge of #145892 - jdonszelmann:codegen-fn-attrs-foreign-item, r=bjorn3Samuel Tardieu-1/+1
add a flag to codegen fn attrs for foreign items r? `@ghost` refiled to rerun CI
2025-08-26Rollup merge of #145840 - a4lg:riscv-elf-flags-for-internal-objs, r=WaffleLapkinSamuel Tardieu-3/+9
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-26Comment on intentional field orderDaria Sukhonina-0/+3
2025-08-26Ensure the coordinator thread terminates firstDaria Sukhonina-2/+2
2025-08-26add a flag to codegen fn attrs for foreign itemsJana Dönszelmann-1/+1
2025-08-26Rollup merge of #145847 - madsmtm:no-xcrun-warnings, r=jieyouxuStuart Cook-1/+1
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-26Rollup merge of #145814 - bjorn3:codegen_worker_fatal_error, r=petrochenkovStuart Cook-50/+37
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-26rustc_codegen_ssa: More comprehensive RISC-V ELF flagsTsukasa OI-2/+8
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-26rustc_codegen_ssa: Fix commentTsukasa OI-1/+1
2025-08-25Don't show warnings from xcrun with -Zverbose-internalsMads Marquart-1/+1
These kinds of warnings can make our test suites fail, so if we want them, we'll need a different flag.
2025-08-24raw-dylib-elf: set correct `DT_VERDEFNUM`Mateusz Mikuła-3/+10
Previously it indicated a single version, regardless of their count. Observed in: https://github.com/davidlattimore/wild/pull/1041
2025-08-24Directly raise fatal errors inside the codegen backendsbjorn3-23/+21
As opposed to passing it around through Result.
2025-08-24Handle unwinding fatal errors in codegen workersbjorn3-32/+21
2025-08-19Rollup merge of #145578 - vexide:armv7a-vex-v5+linked-files, r=davidtwco许杰友 Jieyou Xu (Joe)-2/+7
Add VEXos "linked files" support to `armv7a-vex-v5` Third-party programs running on the VEX V5 platform need a linker script to ensure code and data are always placed in the allowed range `0x3800000-0x8000000` which is read/write/execute. However, developers can also configure the operating system (VEXos) to preload a separate file at any location between these two addresses before the program starts (as a sort of basic linking or configuration loading system). Programs have to know about this at compile time - in the linker script - to avoid placing data in a spot that overlaps where the linked file will be loaded. This is a very popular feature with existing V5 runtimes because it can be used to modify a program's behavior without re-uploading the entire binary to the robot controller. It's important for Rust to support this because while VEXos's runtime user-exposed file system APIs may only read data from an external SD card, linked files are allowed to load data directly from the device's onboard storage. This PR adds the `__linked_file_start` symbol to the existing VEX V5 linker script which can be used to shrink the stack and heap so that they do not overlap with a memory region containing a linked file. It expects the linked file to be loaded in the final N bytes of user RAM (this is not technically required but every existing runtime does it this way to avoid having discontinuous memory regions). With these changes, a developer targeting VEX V5 might add a second linker script to their project by specifying `-Clink-arg=-Tcustom.ld` and creating the file `custom.ld` to configure their custom memory layout. The linker would prepend this to the builtin target linker script. ```c /* custom.ld: Reserves 10MiB for a linked file. */ /* (0x7600000-0x8000000) */ __linked_file_length = 10M; /* The above line is equivalent to -Clink-arg=--defsym=__linked_file_length=10M */ /* Optional: specify one or more sections that */ /* represent the developer's custom format. */ SECTIONS { .linked_file_metadata (NOLOAD) : { __linked_file_metadata_start = .; . += 1M; __linked_file_metadata_end = .; } .linked_file_data (NOLOAD) : { __linked_file_data_start = .; . += 9M; __linked_file_data_end = .; } } INSERT AFTER .stack; ``` Then, using an external tool like the `vex-v5-serial` crate, they would configure the metadata of their uploaded program to specify the path of their linked file and the address where it should be loaded into memory (in the above example, `0x7600000`).
2025-08-18Specify linker scripts after user link argsLewis McClelland-2/+7
2025-08-15Rollup merge of #145004 - bjorn3:remove_unused_fields, r=WaffleLapkinStuart Cook-13/+2
Couple of minor cleanups
2025-08-14Complete functionality and general cleanupMarcelo Domínguez-17/+1
2025-08-13Port the `#[linkage]` attribute to the new attribute systemSasha Pourcelot-1/+2
2025-08-12Auto merge of #144678 - jdonszelmann:no-mangle-extern, r=bjorn3bors-1/+1
Make no_mangle on foreign items explicit instead of implicit for a followup PR I'm working on I need some foreign items to mangle. I could add a new attribute: `no_no_mangle` or something silly like that but by explicitly putting `no_mangle` in the codegen fn attrs of foreign items we can default it to `no_mangle` and then easily remove it when we don't want it. I guess you'd know about this r? `@bjorn3.` Shouldn't be too hard to review :) Builds on rust-lang/rust#144655 which should merge first.