summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/back
AgeCommit message (Collapse)AuthorLines
2021-06-10gcc-lld mvp1000teslas-1/+30
ignore test if rust-lld not found create ld -> rust-lld symlink at build time instead of run time for testing in ci copy instead of symlinking remove linux check test for linker, suggestions from bjorn3 fix overly restrictive lld matcher use -Zgcc-ld flag instead of -Clinker-flavor refactor code adding lld to gcc path revert ci changes suggestions from petrochenkov rename gcc_ld to gcc-ld in dirs
2021-06-10Rollup merge of #82037 - calavera:strip_debuginfo_osx, r=petrochenkovYuki Okushi-13/+49
Make symbols stripping work on MacOS X As reported in the [stabilization issue](https://github.com/rust-lang/rust/issues/72110), MacOS' linker doesn't support the `-s` and `-S` flags to strip symbols anymore. However, the os ships a separated tool to perform these operations. This change allows the compiler to use that tool after a target has been compiled to strip symbols. For rationale, see: https://github.com/rust-lang/rust/issues/72110#issuecomment-641169818 For option selection, see: https://www.unix.com/man-page/osx/1/strip/ Signed-off-by: David Calavera <david.calavera@gmail.com>
2021-06-09Make symbols stripping work on MacOS XDavid Calavera-13/+49
As reported in the stabilization issue, MacOS' linker doesn't support the `-s` and `-S` flags to strip symbols anymore. However, the os ships a separated tool to perform these operations. This change allows the compiler to use that tool after a target has been compiled to strip symbols. For rationale, see: https://github.com/rust-lang/rust/issues/72110#issuecomment-641169818 For option selection, see: https://www.unix.com/man-page/osx/1/strip/ Signed-off-by: David Calavera <david.calavera@gmail.com>
2021-06-07Rollup merge of #86025 - bjorn3:no_rpath_cfg_prefix, r=jackh726Yuki Okushi-36/+5
Remove the install prefix from the rpath set when using -Crpath It was broken anyway for rustup installs and nobody seems to have noticed. Fixes https://github.com/rust-lang/rust/issues/82392
2021-06-07Rollup merge of #86016 - luqmana:infer-linker-flavor, r=petrochenkovYuki Okushi-1/+2
Unify duplicate linker_and_flavor methods in rustc_codegen_{cranelift,ssa}. The two methods were exactly the same so this removes the cranelift copy. This will help make sure both they don't get out of sync.
2021-06-07Auto merge of #85810 - bjorn3:further_driver_cleanup, r=varkorbors-21/+2
Driver improvements This PR contains a couple of cleanups for the driver and a few small improvements for the custom codegen backend interface. It also implements `--version` and `-Cpasses=list` support for custom codegen backends.
2021-06-06linker: Re-apply Solaris fixes for `-z ignore`Vadim Petrochenkov-5/+10
2021-06-06linker: Restore the old order of linking native librariesVadim Petrochenkov-4/+12
2021-06-06linker: Reorder linker argumentsVadim Petrochenkov-146/+151
- Combine all native library arguments together, to simplify potential support for library deduplication and similar things - Split arguments into order-independent and order-dependent, to define more precisely what (pre,post,late)-link-args mean
2021-06-06linker: Inline `fn link_local_crate_native_libs_and_dependent_crate_libs`Vadim Petrochenkov-57/+38
2021-06-06Rollup merge of #85920 - luqmana:wasm-linker-tweaks, r=petrochenkovYuki Okushi-3/+7
Tweak wasm_base target spec to indicate linker is not GNU and update linker inferring logic for wasm-ld. Reported via [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/wasi.20linker.20unknown.20argument.3A.20--as-needed): we try passing `--as-needed` to the linker if it's GNU ld which `wasm-ld` is not. Usually this isn't an issue for wasm as we would use the WasmLd linker driver but because the linker in question (`wasm32-unknown-wasi-wasm-ld`) ended with `-ld` our linker inferring [logic](https://github.com/rust-lang/rust/blob/f64503eb555475d65ae5503ef22439ca5dd394fd/compiler/rustc_codegen_ssa/src/back/link.rs#L957-L1040) used the `GccLinker` implementations. (UPD: The linker inferring logic actually didn't apply in this case because the linker is actually invoked through gcc in the reported issue. But it's still worth updating the logic I think.) This change then has 2 parts: 1. Update wasm_base target spec to indicate `linker_is_gnu: false` plus a few additions of `target.is_like_wasm` to handle flags `wasm-ld` does in fact support. 2. Improve the linker detection logic to properly determine the correct flavor of wasm linker we're using when we can. We need to add the new `target.is_like_wasm` branches to handle the case where the "linker" used could be something like clang which would then under the hood call wasm-ld.
2021-06-06Rollup merge of #85772 - luqmana:ignored-metadata, r=petrochenkovYuki Okushi-3/+6
Preserve metadata w/ Solaris-like linkers. #84468 moved the `-zignore` linker flag from the `gc_sections` method to `add_as_needed` which is more accurate but Solaris-style linkers will also end up removing an unreferenced ELF sections [1]. This had the unfortunate side effect of causing the `.rustc` section (which has the metada) to be removed which could cause issues when trying to link against the resulting crates or use proc macros. Since the `-zignore` is positional, we fix this by moving the metadata objects to before the flag. [1] Specifically a section is considered unreferenced if: * The section is allocatable * No other sections bind to (relocate) to this section * The section provides no global symbols https://docs.oracle.com/cd/E19683-01/817-3677/6mj8mbtbs/index.html#chapter4-19
2021-06-05Unify duplicate linker_and_flavor methods in rustc_codegen_{cranelift,ssa}.Luqman Aden-1/+2
2021-06-06Auto merge of #84171 - ricobbe:raw-dylib-via-llvm, r=petrochenkovbors-6/+70
Partial support for raw-dylib linkage First cut of functionality for issue #58713: add support for `#[link(kind = "raw-dylib")]` on `extern` blocks in lib crates compiled to .rlib files. Does not yet support `#[link_name]` attributes on functions, or the `#[link_ordinal]` attribute, or `#[link(kind = "raw-dylib")]` on `extern` blocks in bin crates; I intend to publish subsequent PRs to fill those gaps. It's also not yet clear whether this works for functions in `extern "stdcall"` blocks; I also intend to investigate that shortly and make any necessary changes as a follow-on PR. This implementation calls out to an LLVM function to construct the actual `.idata` sections as temporary `.lib` files on disk and then links those into the generated .rlib.
2021-06-06Auto merge of #79608 - alessandrod:bpf, r=nagisabors-0/+130
BPF target support This adds `bpfel-unknown-none` and `bpfeb-unknown-none`, two new no_std targets that generate little and big endian BPF. The approach taken is very similar to the cuda target, where `TargetOptions::obj_is_bitcode` is enabled and code generation is done by the linker. I added the targets to `dist-various-2`. There are [some tests](https://github.com/alessandrod/bpf-linker/tree/main/tests/assembly) in bpf-linker and I'm planning to add more. Those are currently not ran as part of rust CI.
2021-06-05Remove get_install_prefix_lib_path completelybjorn3-34/+4
It was broken anyway for rustup installs and nobody seems to have noticed.
2021-06-05Use sysroot instead of CFG_PREFIX for the rpathbjorn3-3/+2
CFG_PREFIX is incorrect for rustup installed rustc versions. It also causes unnecessary recompilation when changing the install prefix.
2021-06-04Add first cut of functionality for #58713: support for #[link(kind = ↵Richard Cobbe-6/+70
"raw-dylib")]. This does not yet support #[link_name] attributes on functions, the #[link_ordinal] attribute, #[link(kind = "raw-dylib")] on extern blocks in bin crates, or stdcall functions on 32-bit x86.
2021-06-04rustc: Store metadata-in-rlibs in object filesAlex Crichton-56/+194
This commit updates how rustc compiler metadata is stored in rlibs. Previously metadata was stored as a raw file that has the same format as `--emit metadata`. After this commit, however, the metadata is encoded into a small object file which has one section which is the contents of the metadata. The motivation for this commit is to fix a common case where #83730 arises. The problem is that when rustc crates a `dylib` crate type it needs to include entire rlib files into the dylib, so it passes `--whole-archive` (or the equivalent) to the linker. The problem with this, though, is that the linker will attempt to read all files in the archive. If the metadata file were left as-is (today) then the linker would generate an error saying it can't read the file. The previous solution was to alter the rlib just before linking, creating a new archive in a temporary directory which has the metadata file removed. This problem from before this commit is now removed if the metadata file is stored in an object file that the linker can read. The only caveat we have to take care of is to ensure that the linker never actually includes the contents of the object file into the final output. We apply similar tricks as the `.llvmbc` bytecode sections to do this. This involved changing the metadata loading code a bit, namely updating some of the LLVM C APIs used to use non-deprecated ones and fiddling with the lifetimes a bit to get everything to work out. Otherwise though this isn't intended to be a functional change really, only that metadata is stored differently in archives now. This should end up fixing #83730 because by default dylibs will no longer have their rlib dependencies "altered" meaning that split-debuginfo will continue to have valid paths pointing at the original rlibs. (note that we still "alter" rlibs if LTO is enabled to remove Rust object files and we also "alter" for the #[link(cfg)] feature, but that's rarely used). Closes #83730
2021-06-04Move crate_name field from OngoingCodegen to CrateInfobjorn3-5/+1
2021-06-04Move windows_subsystem field from CodegenResults to CrateInfobjorn3-15/+1
2021-06-04Remove unnecessary wasm_import_module_map providebjorn3-1/+0
For extern providers, both provide and provide_extern are called. wasm_import_module_map is already provided in provide, so it doesn't need to be provided in provide_extern.
2021-06-01Tweak wasm_base target spec to indicate linker is not GNU and update linker ↵Luqman Aden-3/+7
inferring logic for wasm-ld.
2021-06-01Revert "Reduce the amount of untracked state in TyCtxt"Camille Gillot-1/+1
2021-05-30Make allocator_kind a query.Camille GILLOT-1/+1
2021-05-27Move metadata objects to before as-needed/zignore flags to make sure they ↵Luqman Aden-3/+6
are kept.
2021-05-23Pass target features to bpf-linkerAlessandro Decina-0/+4
2021-05-23Fix formattingAlessandro Decina-1/+4
2021-05-23Add BPF targetAlessandro Decina-0/+123
This change adds the bpfel-unknown-none and bpfeb-unknown-none targets which can be used to generate little endian and big endian BPF
2021-05-22native lib: defer the duplicate check after relevant_lib check.12101111-6/+8
2021-05-18Rollup merge of #85274 - luqmana:linker-is-gnu-gc-sections, r=petrochenkovJack Huey-9/+10
Only pass --[no-]gc-sections if linker is GNU ld. Fixes a regression from #84468 where linking now fails with solaris linkers. LinkerFlavor::Gcc does not always mean GNU ld specifically. And in the case of at least the solaris ld in illumos, that flag is unrecognized and will cause the linking step to fail. Even though removing the `is_like_solaris` branch from `gc_sections` in #84468 made sense as `-z ignore/record` are more analogous to the `--[no-]-as-needed` flags, it inadvertently caused solaris linkers to be passed the `--gc-sections` flag. So let's just change it to be more explicit about when we pass those flags.
2021-05-18Don't pass -pie to linker on windows targets.Luqman Aden-2/+5
2021-05-18Undo unnecessary changes.Luqman Aden-13/+4
2021-05-17Adjust linker_is_gnu branches for cases that don't work on windows.Luqman Aden-7/+16
2021-05-17Auto merge of #85178 - cjgillot:local-crate, r=oli-obkbors-23/+17
Remove CrateNum parameter for queries that only work on local crate The pervasive `CrateNum` parameter is a remnant of the multi-crate rustc idea. Using `()` as query key in those cases avoids having to worry about the validity of the query key.
2021-05-14Auto merge of #83640 - bjorn3:shared_metadata_reader, r=nagisabors-0/+72
Use the object crate for metadata reading This allows sharing the metadata reader between cg_llvm, cg_clif and other codegen backends. This is not currently useful for rlib reading with cg_spirv ([rust-gpu](https://github.com/EmbarkStudios/rust-gpu/)) as it uses tar rather than ar as .rlib format, but it is useful for dylib reading required for loading proc macros. (cc `@eddyb)` The object crate is already trusted as dependency of libstd through backtrace. As far as I know it supports reading all object file formats used by targets for which we support rust dylibs with crate metadata, but I am not certain. If this happens to not be the case, I could keep using LLVM for reading dylib metadata. Marked as WIP for a perf run and as it is based on #83637.
2021-05-13Only pass --[no-]gc-sections if linker is GNU ld.Luqman Aden-4/+2
LinkerFlavor::Gcc does not always mean GNU ld specifically. And in the case of at least the solaris ld in illumos, that flag is unrecognized and will cause the linking step to fail.
2021-05-12Use () for codegen queries.Camille GILLOT-8/+6
2021-05-12Use () for lang items.Camille GILLOT-1/+1
2021-05-12Use () for proc_macro_decls_static.Camille GILLOT-2/+2
2021-05-12Use () for plugin_registrar_fn.Camille GILLOT-2/+2
2021-05-12Use () for entry_fn.Camille GILLOT-1/+1
2021-05-12Use () in reachable_set.Camille GILLOT-8/+4
2021-05-12Use () in dependency_formats.Camille GILLOT-1/+1
2021-05-12Auto merge of #83610 - bjorn3:driver_cleanup, r=cjgillotbors-33/+49
rustc_driver cleanup Best reviewed one commit at a time.
2021-05-10Adjust target search algorithm for rustlib pathSimonas Kazlauskas-1/+1
With this the concerns expressed in #83800 should be addressed.
2021-05-10Better error messagesbjorn3-8/+14
2021-05-08Support -C passes in NewPMNikita Popov-1/+1
And report an error if parsing the additional pass pipeline fails. Threading through the error accounts for most of the changes here.
2021-05-08Explicitly register GCOV profiling pass as wellNikita Popov-13/+9
2021-05-08Explicitly register instrprof passNikita Popov-6/+2
Don't use "passes" for this purpose, explicitly insert it into the correct place in the pipeline instead.