about summary refs log tree commit diff
path: root/compiler/rustc_codegen_cranelift/src/driver
AgeCommit message (Collapse)AuthorLines
2025-09-06Ensure fat LTO doesn't merge everything into the allocator modulebjorn3-1/+10
2025-09-04Special case allocator module submission to avoid special casing it elsewherebjorn3-10/+1
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-08-13Port the `#[linkage]` attribute to the new attribute systemSasha Pourcelot-3/+2
2025-07-16use `codegen_instance_attrs` where an instance is (easily) availableFolkert de Vries-2/+2
2025-07-16add `codegen_instance_attrs` queryFolkert de Vries-6/+2
and use it for naked functions
2025-07-16fix `-Zsanitizer=kcfi` on `#[naked]` functionsFolkert de Vries-2/+6
And more broadly only codegen `InstanceKind::Item` using the naked function codegen code. Other instance kinds should follow the normal path.
2025-06-03Move metadata object generation for dylibs to the linker codebjorn3-45/+1
This deduplicates some code between codegen backends and may in the future allow adding extra metadata that is only known at link time.
2025-06-03Only borrow EncodedMetadata in codegen_cratebjorn3-11/+2
And move passing it to the linker to the driver code.
2025-05-25Merge commit '979dcf8e2f213e4f4b645cb62e7fe9f4f2c0c785' into ↵bjorn3-3/+4
sync_cg_clif-2025-05-25
2025-04-14Share part of the global_asm!() implementation between cg_ssa and cg_clifbjorn3-1/+4
2025-04-14Use cg_ssa's version of codegen_naked_asm in cg_clifbjorn3-13/+36
2025-04-11Auto merge of #139453 - compiler-errors:incr, r=jieyouxubors-18/+31
Prepend temp files with per-invocation random string to avoid temp filename conflicts https://github.com/rust-lang/rust/issues/139407 uncovered a very subtle unsoundness with incremental codegen, failing compilation sessions (due to assembler errors), and the "prefer hard linking over copying files" strategy we use in the compiler for file management. Specifically, imagine we're building a single file 3 times, all with `-Csave-temps -Cincremental=...`. Let's call the object file we're building for the codegen unit for `main` "`XXX.o`" just for clarity since it's probably some gigantic hash name: ``` #[inline(never)] #[cfg(any(rpass1, rpass3))] fn a() -> i32 { 0 } #[cfg(any(cfail2))] fn a() -> i32 { 1 } fn main() { evil::evil(); assert_eq!(a(), 0); } mod evil { #[cfg(any(rpass1, rpass3))] pub fn evil() { unsafe { std::arch::asm!("/* */"); } } #[cfg(any(cfail2))] pub fn evil() { unsafe { std::arch::asm!("missing"); } } } ``` Session 1 (`rpass1`): * Type-check, borrow-check, etc. * Serialize the dep graph to the incremental working directory `.../s-...-working/`. * Codegen object file to a temp file `XXX.rcgu.o` which is spit out in the cwd. * Hard-link[^1] `XXX.rcgu.o` to the incremental working directory `.../s-...-working/XXX.o`. * Save-temps option means we don't delete `XXX.rgcu.o`. * Link the binary and stuff. * Finalize[^2] the working incremental session by renaming `.../s-...-working` to ` s-...-asjkdhsjakd` (some other finalized incr comp session dir name). Session 2 (`cfail2`): * Load artifacts from the previous *finalized* incremental session, namely the dep graph. * Type-check, borrow-check, etc. since the file has changed, so most dep graph nodes are red. * Serialize the dep graph to the incremental working directory `.../s-...-working/`. * Codegen object file to a temp file `XXX.rcgu.o`. **HERE IS THE PROBLEM**: The hard-link is still set up to point to the inode from `XXX.o` from the first session, so this also modifies the `XXX.o` in the previous finalized session directory. * Codegen emits an error b/c `missing` is not an instruction, so we abort before finalizing the incremental session. Specifically, this means that the *previous* session is the last finalized session. Session 3 (`rpass3`): * Load artifacts from the previous *finalized* incremental session, namely the dep graph. NOTE that this is from session 1. * All the dep graph nodes are green since we are basically replaying session 1. * codegen object file `XXX.o`, which is detected as *reused* from session 1 since dep nodes were green. That means we **reuse** `XXX.o` which had been dirtied from session 2. * Link the binary and stuff. This results in a binary which reuses some of the build artifacts from session 2, but thinks it's from session 1. At this point, I hope it's clear to see that the incremental results from session 1 were dirtied from session 2, but we reuse them as if session 1 was the previous (finalized) incremental session we ran. This is at best really buggy, and at worst **unsound**. This isn't limited to `-C save-temps`, since there are other combinations of flags that may keep around temporary files (hard linked) in the working directory (like `-C debuginfo=1 -C split-debuginfo=unpacked` on darwin, for example). --- This PR implements a fix which is to prepend temp filenames with a random string that is generated per invocation of rustc. This string is not *deterministic*, but temporary files are transient anyways, so I don't believe this is a problem. That means that temp files are now something like... `{crate-name}.{cgu}.{invocation_temp}.rcgu.o`, where `{invocation_temp}` is the new temporary string we generate per invocation of rustc. Fixes https://github.com/rust-lang/rust/issues/139407 [^1]: https://github.com/rust-lang/rust/blob/175dcc7773d65c1b1542c351392080f48c05799f/compiler/rustc_fs_util/src/lib.rs#L60 [^2]: https://github.com/rust-lang/rust/blob/175dcc7773d65c1b1542c351392080f48c05799f/compiler/rustc_incremental/src/persist/fs.rs#L1-L40
2025-04-10Remove the use of Rayon iteratorsJohn Kåre Alsaker-14/+15
2025-04-07Prepend temp files with a string per invocation of rustcMichael Goulet-8/+27
2025-04-07Simplify temp path creation a bitMichael Goulet-15/+9
2025-03-30Merge commit 'ba315abda789c9f59f2100102232bddb30b0d3d3' into ↵bjorn3-206/+21
sync_cg_clif-2025-03-30
2025-02-26Fill out links_from_incr_cache in cg_clifBen Kimock-8/+10
2025-02-24Avoid no-op unlink+link dances in incr compBen Kimock-1/+7
2025-02-17Move some `Map` methods onto `TyCtxt`.Nicholas Nethercote-1/+1
The end goal is to eliminate `Map` altogether. I added a `hir_` prefix to all of them, that seemed simplest. The exceptions are `module_items` which became `hir_module_free_items` because there was already a `hir_module_items`, and `items` which became `hir_free_items` for consistency with `hir_module_free_items`.
2025-02-08Rustfmtbjorn3-5/+9
2025-02-07Merge commit '8332329f83d4ef34479fec67cc21b21246dca6b5' into ↵bjorn3-6/+6
sync_cg_clif-2025-02-07
2025-02-01Rename `tcx.ensure()` to `tcx.ensure_ok()`Zalathar-1/+1
2025-01-27Change `collect_and_partition_mono_items` tuple return type to a structOli Scherer-1/+1
2025-01-20Merge commit '728bc27f32c05ac8a9b5eb33fd101e479072984f' into ↵bjorn3-1/+9
sync_cg_clif-2025-01-20
2025-01-10Merge commit 'e39eacd2d415803ef82de3b6a314e4f2d0fbc4dc' into ↵bjorn3-3/+5
sync_cg_clif-2025-01-10
2025-01-05Merge commit '918acafef682d0d0ca30b47de4768210417ff362' into ↵bjorn3-5/+4
sync_cg_clif-2025-01-05
2024-12-19Make DependencyList an IndexVecbjorn3-1/+1
2024-12-13Make dependency_formats an FxIndexMap rather than a list of tuplesbjorn3-6/+1
It is treated as a map already. This is using FxIndexMap rather than UnordMap because the latter doesn't provide an api to pick a single value iff all values are equal, which each_linked_rlib depends on.
2024-12-13Remove jobserver from Sessionbjorn3-2/+2
It is effectively a global resource and the jobserver::Client in Session was a clone of GLOBAL_CLIENT anyway.
2024-12-06Merge commit '57845a397ec15e4e6a561ed2c4bfa3dcf49144fb' into ↵bjorn3-148/+157
sync_cg_clif-2024-12-06
2024-11-28Replace `Symbol::intern` calls with preinterned symbolsclubby789-7/+2
2024-11-09Merge commit '1fa693ca4462fc1f790693464cf765ad693616af' into ↵bjorn3-1/+7
sync_cg_clif-2024-11-09
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-15/+11
2024-07-29Reformat `use` declarations.Nicholas Nethercote-5/+7
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-30Merge commit '49cd5dd454d0115cfbe9e39102a8b3ba4616aa40' into ↵bjorn3-55/+28
sync_cg_clif-2024-06-30
2024-06-04Auto merge of #122597 - pacak:master, r=bjorn3bors-0/+23
Show files produced by `--emit foo` in json artifact notifications Right now it is possible to ask `rustc` to save some intermediate representation into one or more files with `--emit=foo`, but figuring out what exactly was produced is difficult. This pull request adds information about `llvm_ir` and `asm` intermediate files into notifications produced by `--json=artifacts`. Related discussion: https://internals.rust-lang.org/t/easier-access-to-files-generated-by-emit-foo/20477 Motivation - `cargo-show-asm` parses those intermediate files and presents them in a user friendly way, but right now I have to apply some dirty hacks. Hacks make behavior confusing: https://github.com/hintron/computer-enhance/issues/35 This pull request introduces a new behavior: now `rustc` will emit a new artifact notification for every artifact type user asked to `--emit`, for example for `--emit asm` those will include all the `.s` files. Most users won't notice this behavior, to be affected by it all of the following must hold: - user must use `rustc` binary directly (when `cargo` invokes `rustc` - it consumes artifact notifications and doesn't emit anything) - user must specify both `--emit xxx` and `--json artifacts` - user must refuse to handle unknown artifact types - user must disable incremental compilation (or deal with it better than cargo does, or use a workaround like `save-temps`) in order not to hit #88829 / #89149
2024-05-22rustc_codegen_llvm: add support for writing summary bitcodeAugie Fackler-1/+1
Typical uses of ThinLTO don't have any use for this as a standalone file, but distributed ThinLTO uses this to make the linker phase more efficient. With clang you'd do something like `clang -flto=thin -fthin-link-bitcode=foo.indexing.o -c foo.c` and then get both foo.o (full of bitcode) and foo.indexing.o (just the summary or index part of the bitcode). That's then usable by a two-stage linking process that's more friendly to distributed build systems like bazel, which is why I'm working on this area. I talked some to @teresajohnson about naming in this area, as things seem to be a little confused between various blog posts and build systems. "bitcode index" and "bitcode summary" tend to be a little too ambiguous, and she tends to use "thin link bitcode" and "minimized bitcode" (which matches the descriptions in LLVM). Since the clang option is thin-link-bitcode, I went with that to try and not add a new spelling in the world. Per @dtolnay, you can work around the lack of this by using `lld --thinlto-index-only` to do the indexing on regular .o files of bitcode, but that is a bit wasteful on actions when we already have all the information in rustc and could just write out the matching minimized bitcode. I didn't test that at all in our infrastructure, because by the time I learned that I already had this patch largely written.
2024-05-13Merge commit '3270432f4b0583104c8b9b6f695bf97d6bbf3ac2' into ↵bjorn3-47/+64
sync_cg_clif-2024-05-13
2024-04-23Merge commit 'de5d6523738fd44a0521b6abf3e73ae1df210741' into ↵bjorn3-0/+1
sync_cg_clif-2024-04-23
2024-04-19Show files produced by --emit foo in json artifact notificationsMichael Baikov-0/+23
2024-04-06Save/restore more items in cache with incremental compilationMichael Baikov-1/+17
2024-03-28Merge commit '09fae60a86b848a2fc0ad219ecc4e438dc1eef86' into ↵bjorn3-15/+199
sync_cg_clif-2024-03-28
2024-01-26Merge commit '3e50cf65025f96854d6597e80449b0d64ad89589' into ↵bjorn3-8/+19
sync_cg_clif-2024-01-26
2024-01-08Use chaining for `DiagnosticBuilder` construction and `emit`.Nicholas Nethercote-3/+4
To avoid the use of a mutable local variable, and because it reads more nicely.
2023-12-31Merge commit '6d355f6844323db03bfd608899613e363e701951' into ↵bjorn3-1/+1
sync_cg_clif-2023-12-31
2023-12-24Remove more `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-3/+3
2023-12-24Remove `Session` methods that duplicate `DiagCtxt` methods.Nicholas Nethercote-8/+8
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier access.
2023-12-18Rename `Session::span_diagnostic` as `Session::dcx`.Nicholas Nethercote-1/+1
2023-10-24Merge commit '93a5433f17ab5ed48cc88f1e69b0713b16183373' into ↵bjorn3-8/+15
sync_cg_clif-2023-10-24
2023-10-21Merge commit 'c07d1e2f88cb3b1a0604ae8f18b478c1aeb7a7fa' into ↵bjorn3-22/+25
sync_cg_clif-2023-10-21