summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/back
AgeCommit message (Collapse)AuthorLines
2025-01-07Pass objcopy args for stripping on OSXNoratrieb-18/+7
When `-Cstrip` was changed to use the bundled rust-objcopy instead of /usr/bin/strip on OSX, strip-like arguments were preserved. But strip and objcopy are, while being the same binary, different, they have different defaults depending on which binary they are. Notably, strip strips everything by default, and objcopy doesn't strip anything by default. Additionally, `-S` actually means `--strip-all`, so debuginfo stripped everything and symbols didn't strip anything. We now correctly pass `--strip-debug` and `--strip-all`.
2025-01-01upstream rustc_codegen_llvm changes for enzyme/autodiffManuel Drehwald-0/+21
2024-12-29review fixes: Adjust whitespacePiotr Osiewicz-0/+3
2024-12-29rustc_codegen_ssa: Buffer file writes in link_rlibPiotr Osiewicz-5/+5
This makes this step take ~25ms on my machine (M3 Max 64GB) for Zed repo instead of ~150ms. Additionally it takes down the time needed for a clean cargo build of ripgrep from ~6.1s to 5.9s. This change is mostly relevant for crates with multiple large CGUs.
2024-12-20Rollup merge of #134561 - bjorn3:less_fatal_error_raise, r=compiler-errorsMatthias Krüger-6/+6
Reduce the amount of explicit FatalError.raise() Instead use dcx.abort_if_error() or guar.raise_fatal() instead. These guarantee that an error actually happened previously and thus we don't silently abort.
2024-12-20Reduce the amount of explicit FatalError.raise()bjorn3-6/+6
Instead use dcx.abort_if_error() or guar.raise_fatal() instead. These guarantee that an error actually happened previously and thus we don't silently abort.
2024-12-20Review commentsbjorn3-3/+2
2024-12-19Make DependencyList an IndexVecbjorn3-11/+6
2024-12-18Re-export more `rustc_span::symbol` things from `rustc_span`.Nicholas Nethercote-5/+4
`rustc_span::symbol` defines some things that are re-exported from `rustc_span`, such as `Symbol` and `sym`. But it doesn't re-export some closely related things such as `Ident` and `kw`. So you can do `use rustc_span::{Symbol, sym}` but you have to do `use rustc_span::symbol::{Ident, kw}`, which is inconsistent for no good reason. This commit re-exports `Ident`, `kw`, and `MacroRulesNormalizedIdent`, and changes many `rustc_span::symbol::` qualifiers in `compiler/` to `rustc_span::`. This is a 200+ net line of code reduction, mostly because many files with two `use rustc_span` items can be reduced to one.
2024-12-16rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_structuresJonathan Dönszelmann-2/+3
2024-12-15Rollup merge of #133633 - jyn514:hide-linker-args, r=bjorn3,jyn514Stuart Cook-2/+2
don't show the full linker args unless `--verbose` is passed the linker arguments can be *very* long, especially for crates with many dependencies. often they are not useful. omit them unless the user specifically requests them. split out from https://github.com/rust-lang/rust/pull/119286. fixes https://github.com/rust-lang/rust/issues/109979. r? `@bjorn3` try-build: i686-mingw
2024-12-14don't show the full linker args unless `--verbose` is passedjyn-2/+2
the linker arguments can be *very* long, especially for crates with many dependencies. some parts of them are not very useful. unless specifically requested: - omit object files specific to the current invocation - fold rlib files into a single braced argument (in shell expansion format) this shortens the output significantly without removing too much information.
2024-12-13Make dependency_formats an FxIndexMap rather than a list of tuplesbjorn3-22/+14
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-5/+2
It is effectively a global resource and the jobserver::Client in Session was a clone of GLOBAL_CLIENT anyway.
2024-12-12Auto merge of #129181 - beetrees:asm-spans, r=pnkfelix,compiler-errorsbors-13/+8
Pass end position of span through inline ASM cookie Before this PR, only the start position of the span was passed though the inline ASM cookie to diagnostics. LLVM 19 has full support for 64-bit inline ASM cookies; this PR uses that to pass the end position of the span in the upper 32 bits, meaning inline ASM diagnostics now point at the entire line the error occurred on, not just the first character of it.
2024-12-11Rollup merge of #134139 - mustartt:pgo-linker-flag, r=saethlinJacob Pratt-0/+2
[AIX] keep profile-rt symbol alive Clang passes `-u __llvm_profile_runtime` on AIX. https://reviews.llvm.org/D136192 We want to preserve the symbol in the case there are no instrumented object files.
2024-12-10Rollup merge of #133967 - daltenty:daltenty/bnoipath, r=jieyouxuLeón Orell Valerian Liehr-0/+9
[AIX] Pass -bnoipath when adding rust upstream dynamic crates Unlike ELF linkers, AIX doesn't feature `DT_SONAME` to override the dependency name when outputing a shared library, which is something we rely on for dylib crates. See for reference: https://github.com/rust-lang/rust/blob/bc145cec4565a97a1b08df52d26ddf48ce3d7d0a/compiler/rustc_codegen_ssa/src/back/linker.rs#L464) Thus, `ld` on AIX will use the full path to shared libraries as the dependency if passed it by default unless `noipath` is passed, so pass it here so we don't end up with full path dependencies for dylib crates.
2024-12-06Remove all threading through of ErrorGuaranteed from the driverbjorn3-32/+24
It was inconsistently done (sometimes even within a single function) and most of the rest of the compiler uses fatal errors instead, which need to be caught using catch_with_exit_code anyway. Using fatal errors instead of ErrorGuaranteed everywhere in the driver simplifies things a bit.
2024-12-06Store a single copy of the error registry in DiagCtxtbjorn3-1/+5
And pass this to the individual emitters when necessary.
2024-12-06Move some timers aroundbjorn3-2/+0
2024-12-06Clarify commentDavid Tenty-2/+4
2024-12-06Pass -bnoipath when adding rust upstream dynamic cratesKai Luo-0/+7
2024-12-03keep profile-rt symbol aliveHenry Jiang-0/+2
2024-12-03Rollup merge of #133041 - madsmtm:print-deployment-target-env-var, r=davidtwcoMatthias Krüger-1/+1
Print name of env var in `--print=deployment-target` The deployment target environment variable is OS-specific, and if you're in a place where you're asking `rustc` for the deployment target, you're likely to also wanna know the name of the environment variable. I myself wanted this for some code I'm working on in bootstrap, for example. Behaviour before this PR: ```console $ rustc --print=deployment-target --target=aarch64-apple-darwin deployment_target=11.0 $ rustc --print=deployment-target --target=aarch64-apple-visionos deployment_target=1.0 ``` Behaviour after this PR: ```console $ rustc --print=deployment-target --target=aarch64-apple-darwin MACOSX_DEPLOYMENT_TARGET=11.0 $ rustc --print=deployment-target --target=aarch64-apple-visionos XROS_DEPLOYMENT_TARGET=1.0 ``` My _belief_ is that this option is extremely rarely used in general, and a GitHub search for "rustc print deployment-target" seems to confirm this, it revealed only the following actual pieces of code using this: - https://github.com/PyO3/maturin/blob/b292ef69349f2a56cb8ab1b59fda0be3d3b9f138/src/build_context.rs#L1199-L1220 - https://github.com/rust-lang/cc-rs/blob/daab9244b03e244c4f2511944870d719c443f61f/src/lib.rs#L3422-L3426 `maturin` does `.split('=').last()`, so it will continue to work after this change, but `cc v1.0.84` did `.strip_prefix("deployment_target=")` since [this PR](https://github.com/rust-lang/cc-rs/pull/848), so it would break. That's _probably_ fine though, it was broken in a lot of scenarios anyway, and [got](https://github.com/rust-lang/cc-rs/pull/901) [reverted](https://github.com/rust-lang/cc-rs/pull/943) in `v1.0.85`. So while this is _technically_ a breaking change, I really doubt that anyone is going to observe it, so it's probably fine. ``@BlackHoleFox`` wdyt? ``@rustbot`` label O-apple r? compiler
2024-12-01Rollup merge of #132974 - madsmtm:linker-arguments-with-commas, r=petrochenkovMatthias Krüger-61/+82
Properly pass linker arguments that contain commas When linking with the system C compiler, we sometimes want to forward certain arguments unchanged to the linker. This can be done with `-Wl,arg1,arg2` or `-Xlinker arg1 -Xlinker arg2`. `-Wl` is used when possible, since it is more compact, but it does not support commas in the argument itself - in those cases, we need to use `-Xlinker`, and that is what this PR implements. This also fixes using sanitizers on macOS with `-Clinker-flavor=ld`, as those were previously manually using `-Wl`/`-Xlinker` (probably since the support wasn't present in the `link_args` function). Note that there has been [a previous PR for this](https://github.com/rust-lang/rust/pull/38798), but it only implemented this in certain cases when passing `-rpath`. r? compiler
2024-11-28Share inline(never) generics across cratesMark Rousskov-1/+11
This reduces code sizes and better respects programmer intent when marking inline(never). Previously such a marking was essentially ignored for generic functions, as we'd still inline them in remote crates.
2024-11-26Pass end position of span through inline ASM cookiebeetrees-13/+8
2024-11-25Rollup merge of #133297 - DianQK:embed-bitcode-ios, r=nikic许杰友 Jieyou Xu (Joe)-4/+2
Remove legacy bitcode for iOS Follow #117364.
2024-11-24Remove forces_embed_bitcodeDianQK-4/+2
2024-11-24Remove unnecessary 0 link args optimizationMads Marquart-14/+3
2024-11-24Support rpath with -Clinker-flavor=ldMads Marquart-47/+21
Using `cc_args` panics when using `-Clinker-flavor=ld`, because the arguments are in a form tailored for `-Clinker-flavor=gcc`. So instead, we use `link_args` and let that wrap the arguments with the appropriate `-Wl` or `-Xlinker` when needed.
2024-11-24Support linker arguments that contain commasMads Marquart-9/+67
2024-11-23Rollup merge of #133217 - xingxue-ibm:fix-strip, r=compiler-errors许杰友 Jieyou Xu (Joe)-10/+12
[AIX] Add option -X32_64 to the "strip" command The AIX `strip` utility requires option `-X` to specify the object mode. This patch adds the `-X32_64` option to the `strip` command so that it can handle both 32-bit and 64-bit objects. The parameter `option` of function `strip_symbols_with_external_utility`, previously a single string, has been changed to `options`, an array of string slices, to accommodate multiple `strip` options.
2024-11-22Print env var in --print=deployment-targetMads Marquart-1/+1
The deployment target environment variable is OS-specific, and if you're in a place where you're asking `rustc` for the deployment target, you're likely to also wanna know the environment variable.
2024-11-21Auto merge of #132362 - mustartt:aix-dylib-detection, r=jieyouxubors-2/+39
[AIX] change system dynamic library format Historically on AIX, almost all dynamic libraries are distributed in `.a` Big Archive Format which can consists of both static and shared objects in the same archive (e.g. `libc++abi.a(libc++abi.so.1)`). During the initial porting process, the dynamic libraries are kept as `.a` to simplify the migration, but semantically having an XCOFF object under the archive extension is wrong. For crate type `cdylib` we want to be able to distribute the libraries as archives as well. We are migrating to archives with the following format: ``` $ ar -t lib<name>.a lib<name>.so ``` where each archive contains a single member that is a shared XCOFF object that can be loaded.
2024-11-21Change to pass "strip" options in an array of string slices and add option ↵Xing Xue-10/+12
"-X32_64" for AIX.
2024-11-21aix: fix archive formatHenry Jiang-2/+39
fmt fix cfg for windows remove unused imports address comments update libc to 0.2.164 fmt remove unused imports
2024-11-20Account for `wasm32v1-none` when exporting TLS symbolsdaxpedda-2/+2
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-2/+4
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-15rustc_metadata: Preprocess search paths for better performancePiotr Osiewicz-1/+1
Over in Zed we've noticed that loading crates for a large-ish workspace can take almost 200ms. We've pinned it down to how rustc searches for paths, as it performs a linear search over the list of candidate paths. In our case the candidate list had about 20k entries which we had to iterate over for each dependency being loaded. This commit introduces a simple FilesIndex that's just a sorted Vec under the hood. Since crates are looked up by both prefix and suffix, we perform a range search on said Vec (which constraints the search space based on prefix) and follow up with a linear scan of entries with matching suffixes. FilesIndex is also pre-filtered before any queries are performed using available target information; query prefixes/sufixes are based on the target we are compiling for, so we can remove entries that can never match up front. Overall, this commit brings down build time for us in dev scenarios by about 6%. 100ms might not seem like much, but this is a constant cost that each of our workspace crates has to pay, even when said crate is miniscule.
2024-11-11Rollup merge of #132820 - bjorn3:default_backend_link_impl, r=jieyouxuMatthias Krüger-4/+12
Add a default implementation for CodegenBackend::link As a side effect this should add raw-dylib support to cg_gcc as the default ArchiveBuilderBuilder that is used implements create_dll_import_lib. I haven't tested if the raw-dylib support actually works however.
2024-11-09Pass owned CodegenResults to link_binarybjorn3-4/+4
After link_binary the temporary files referenced by CodegenResults are deleted, so calling link_binary again with the same CodegenResults should not be allowed.
2024-11-09Add a default implementation for CodegenBackend::linkbjorn3-0/+8
As a side effect this should add raw-dylib support to cg_gcc as the default ArchiveBuilderBuilder that is used implements create_dll_import_lib. I haven't tested if the raw-dylib support actually works however.
2024-11-09Rollup merge of #132774 - bjorn3:cranelift_lld, r=lqdMatthias Krüger-17/+0
Use lld with non-LLVM backends On arm64, Cranelift used to produce object files that don't work with lld. This has since been fixed. The GCC backend should always produce object files that work with lld unless lld for whatever reason drops GCC support. Most of the other more niche backends don't use cg_ssa's linker code at all. If they do and don't work with lld, they can always disable lld usage using a cli argument. Without this commit using cg_clif is by default in a non-trivial amount of cases a perf regression on Linux due to ld.bfd being a fair bit slower than lld. It is possible to explicitly enable it without this commit, but most users are unlikely to do this.
2024-11-09Rollup merge of #132552 - taiki-e:sparc-target-feature, r=workingjubileeMatthias Krüger-1/+1
Add v9, v8plus, and leoncasa target feature to sparc and use v8plus in create_object_file This adds the following three unstable target features: - `v9`: SPARC-V9 instructions ([LLVM definition][sparc-v9]) - Relevant to https://github.com/rust-lang/rust/pull/131222#issuecomment-2453310963 - Relevant to https://github.com/rust-lang/rust/pull/132472#discussion_r1832606081 - This is also needed to implement https://github.com/taiki-e/atomic-maybe-uninit/pull/31 (depends on inline assembly support) more robustly. - `v8plus`: SPARC-V8+ ABI ([LLVM definition][sparc-v8plus]) - This is added in LLVM 20. In LLVM 19 and older, it is emulated to work the same way as LLVM in each LLVM version. - See https://github.com/rust-lang/rust/issues/132585#issuecomment-2453926257 for more. - `leoncasa`: CASA instruction[^1] of LEON3 and LEON4 processors ([LLVM definition][sparc-leoncasa], LLVM feature name: `hasleoncasa`) - This is needed to implement https://github.com/taiki-e/atomic-maybe-uninit/pull/31 (depends on inline assembly support) more robustly. [^1]: Atomic CAS instruction [sparc-v9]: https://github.com/llvm/llvm-project/blob/f5e4ffaa49254706ad6fa209de8aec28e20f0041/llvm/lib/Target/Sparc/Sparc.td#L37-L39 [sparc-v8plus]: https://github.com/llvm/llvm-project/blob/f5e4ffaa49254706ad6fa209de8aec28e20f0041/llvm/lib/Target/Sparc/Sparc.td#L37-L39 [sparc-leoncasa]: https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/llvm/lib/Target/Sparc/LeonFeatures.td#L32-L37
2024-11-09Add v8plus target feature to sparc and use it in create_object_fileTaiki Endo-1/+1
2024-11-08Use lld with non-LLVM backendsbjorn3-17/+0
On arm64, Cranelift used to produce object files that don't work with lld. This has since been fixed. The GCC backend should always produce object files that work with lld unless lld for whatever reason drops GCC support. Most of the other more niche backends don't use cg_ssa's linker code at all. If they do and don't work with lld, they can always disable lld usage using a cli argument. Without this commit using cg_clif is by default in a non-trivial amount of cases a perf regression on Linux due to ld.bfd being a fair bit slower than lld. It is possible to explicitly enable it without this commit, but most users are unlikely to do this.
2024-11-07Rollup merge of #130586 - dpaoliello:fixrawdylib, r=wesleywiserJubilee-34/+64
Set "symbol name" in raw-dylib import libraries to the decorated name `windows-rs` received a bug report that mixing raw-dylib generated and the Windows SDK import libraries was causing linker failures: <https://github.com/microsoft/windows-rs/issues/3285> The root cause turned out to be #124958, that is we are not including the decorated name in the import library and so the import name type is also not being correctly set. This change modifies the generation of import libraries to set the "symbol name" to the fully decorated name and correctly marks the import as being data vs function. Note that this also required some changes to how the symbol is named within Rust: for MSVC we now need to use the decorated name but for MinGW we still need to use partially decorated (or undecorated) name. Fixes #124958 Passing i686 MSVC and MinGW build: <https://github.com/rust-lang/rust/actions/runs/11000433888?pr=130586> r? `@ChrisDenton`
2024-11-05codegen_ssa: use `llvm-objcopy` for macOS stripDavid Wood-5/+17
2024-11-03Rollup merge of #132565 - bjorn3:less_target_name_dependence, r=workingjubileeJubilee-5/+7
Reduce dependence on the target name The target name can be anything with custom target specs. Matching on fields inside the target spec is much more robust than matching on the target name. Also remove the unused is_builtin target spec field.