about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src/back
AgeCommit message (Collapse)AuthorLines
2021-10-09Rollup merge of #89634 - hawkw:eliza/enable-err-warn, r=oli-obkMatthias Krüger-5/+4
rustc_driver: Enable the `WARN` log level by default This commit changes the `tracing_subscriber` initialization in `rustc_driver` so that the `WARN` verbosity level is enabled by default when the `RUSTC_LOG` env variable is empty. If the `RUSTC_LOG` env variable is set, the filter string in the environment variable is honored, instead. Fixes #76824 Closes #89623 cc ``@eddyb,`` ``@oli-obk``
2021-10-07Rollup merge of #88137 - joshtriplett:osx-strip-symbols-no-option, ↵Jubilee-12/+10
r=michaelwoerister On macOS, make strip="symbols" not pass any options to strip This makes the output with `strip="symbols"` match the result of just calling `strip` on the output binary, minimizing the size of the binary.
2021-10-07lol i forgot the syntax for my own crate's macrosEliza Weisman-2/+2
T_____T Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-10-07comma-related changesEliza Weisman-1/+1
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-10-07use structured fields in some existing warningsEliza Weisman-5/+4
Signed-off-by: Eliza Weisman <eliza@buoyant.io>
2021-10-06Enable AutoFDO.Michael Benfield-0/+7
This largely involves implementing the options debug-info-for-profiling and profile-sample-use and forwarding them on to LLVM. AutoFDO can be used on x86-64 Linux like this: rustc -O -Cdebug-info-for-profiling main.rs -o main perf record -b ./main create_llvm_prof --binary=main --out=code.prof rustc -O -Cprofile-sample-use=code.prof main.rs -o main2 Now `main2` will have feedback directed optimization applied to it. The create_llvm_prof tool can be obtained from this github repository: https://github.com/google/autofdo Fixes #64892.
2021-10-03Move rustc_middle::middle::cstore to rustc_session.Camille GILLOT-3/+3
2021-10-01Rollup merge of #88820 - hlopko:add_pie_relocation_model, r=petrochenkovManish Goregaokar-2/+6
Add `pie` as another `relocation-model` value MCP: https://github.com/rust-lang/compiler-team/issues/461
2021-10-01Add `pie` as another `relocation-model` valueMarcel Hlopko-2/+6
2021-09-30Move EncodedMetadata to rustc_metadata.Camille GILLOT-2/+2
2021-09-08Move get_tools_search_paths from FileSearch to Sessionbjorn3-7/+4
It only uses fields of FileSearch that are stored in Session too
2021-09-07Auto merge of #88161 - michaelwoerister:fix-whole-archive-no-bundle, ↵bors-10/+49
r=petrochenkov Fix handling of +whole-archive native link modifier. This PR fixes a bug in `add_upstream_native_libraries` that led to the `+whole-archive` modifier being ignored when linking in native libs. ~~Note that the PR does not address the situation when `+whole-archive` is combined with `+bundle`.~~ `@wesleywiser's` commit adds validation code that turns combining `+whole-archive` with `+bundle` into an error. Fixes https://github.com/rust-lang/rust/issues/88085. r? `@petrochenkov` cc `@wesleywiser` `@gcoakes`
2021-09-01Move add_rlib and add_native_library to cg_ssabjorn3-19/+47
This deduplicates logic between codegen backends
2021-08-30Don't allow both the `+bundle` and `+whole-archive` modifiers for rlibsWesley Wiser-0/+14
2021-08-30Fix handling of +whole-archive native link modifier.Michael Woerister-10/+35
2021-08-29Auto merge of #88250 - rusticstuff:macos-lld, r=nagisabors-14/+33
Make `-Z gcc-ld=lld` work for Apple targets `-Z gcc-ld=lld` was introduced in #85961. It does not work on Macos because lld needs be either named `ld64` or passed `-flavor darwin` as the first two arguments in order to select the Mach-O flavor. Rust invokes cc (=clang) on Macos for linking which calls `ld` as linker binary and not `ld64`, so just creating an `ld64` binary and modifying the search path with `-B` does not work. In order to solve this patch does: * Set the `lld_flavor` for all Apple-derived targets to `LldFlavor::Ld64`. As far as I can see this actually works towards fixing `-Xlinker=rust-lld` as all those targets use the Mach-O object format. * Copy/hardlink rust-lld to the gcc-ld subdirectory as ld64 next to ld. * If `-Z gcc-ld=lld` is used and the target lld flavor is Ld64 add `-fuse-ld=/path/to/ld64` to the linker invocation. Fixes #86945.
2021-08-26Adjust linking order of static nobundle libraries12101111-36/+33
Link the static libraries with "-bundle" modifier from upstream rust crate right after linking this rust crate. Some linker such as GNU linker `ld.bdf` treat order of linking as order of dependency. After this change, static libraries with "-bundle" modifier is linked in the same order as "+bundle" modifier. So we can change the value of "bundle" modifier without causing linking error.
2021-08-23Pass -fuse-ld=/path/to/ld64 if -Z gcc-ld and the lld_flavor for the target ↵Hans Kratz-14/+33
is Ld64
2021-08-18On macOS, make strip="symbols" not pass any options to stripJosh Triplett-12/+10
This makes the output with `strip="symbols"` match the result of just calling `strip` on the output binary, minimizing the size of the binary.
2021-08-10Replace #[plugin_registrar] with exporting __rustc_plugin_registrarbjorn3-4/+0
2021-07-31Allow more "unknown argument" strings from linkerMichael Hackner-10/+11
Some toolchains emit slightly different errors, e.g. ppc-vle-gcc: error: unrecognized option '-no-pie'
2021-07-18Auto merge of #87004 - JamieCunliffe:pgo-gc-sections, r=Mark-Simulacrumbors-1/+6
Don't use gc-sections with profile-generate. When building with profile-generate don't call gc_sections as this can can sometimes strip out profile data. This missing information in the prof files can then result in missing functions when using the profile information. #78226 r? `@Mark-Simulacrum`
2021-07-16Consider all fields when comparing DllImports, to remove nondetermininsm in ↵Richard Cobbe-65/+49
multiple-definitions test
2021-07-14Keep metadata when using gc-sections with profile-generate.Jamie Cunliffe-1/+6
When building with profile-generate request that metadata is kept during the gc_sections call, as this can sometimes strip out profile data. This missing information in the prof files can then result in missing functions when using the profile information.
2021-07-09Add support for raw-dylib with stdcall, fastcall functions on ↵Richard Cobbe-25/+44
i686-pc-windows-msvc.
2021-07-06Fold LinkerInfo into CrateInfobjorn3-81/+37
2021-07-06Don't store the full LinkerInfo inside Linker implsbjorn3-27/+44
2021-07-06Merge LinkerInfo::to_linker into get_linkerbjorn3-44/+40
2021-07-06Move get_linker to linker.rsbjorn3-93/+96
2021-07-06Don't pass local_crate_name to link_binary separatelybjorn3-2/+6
It is already part of CodegenResults
2021-07-06Move LinkerInfo into CrateInfobjorn3-10/+5
2021-07-05Deduplicate info.used_crate_source indexingbjorn3-2/+3
2021-07-05Remove LibSourcebjorn3-32/+38
The information is stored in used_crate_source too anyway
2021-07-01Auto merge of #86749 - bjorn3:link_info_refactor_part1, r=petrochenkovbors-2/+2
Rename all_crate_nums query to crates and remove useless wrapper Split out of https://github.com/rust-lang/rust/pull/86105 r? `@petrochenkov`
2021-07-01Rename all_crate_nums query to crates and remove useless wrapperbjorn3-2/+2
2021-07-01Rollup merge of #86558 - Smittyvb:link-error-sugg, r=petrochenkovGuillaume Gomez-5/+14
Add suggestions for "undefined reference" link errors This adds a suggestion for "undefined reference to ..." linking errors to install or specify the location to an external library. Since there is no defined error format for linkers, we just check if there was a failure and if that failure contains the string `undefined reference to`. This also makes it impossible to test this, since the output depends on the system linker. The output now looks like: ``` error: linking with `cc` failed: exit status: 1 | = note: "cc" "-m64" "linking_failure.linking_failure.7rcbfp3g-cgu.0.rcgu.o" "linking_failure.linking_failure.7rcbfp3g-cgu.1.rcgu.o" "linking_failure.linking_failure.7rcbfp3g-cgu.2.rcgu.o" "linking_failure.linking_failure.7rcbfp3g-cgu.3.rcgu.o" "linking_failure.linking_failure.7rcbfp3g-cgu.4.rcgu.o" "linking_failure.linking_failure.7rcbfp3g-cgu.5.rcgu.o" "linking_failure.linking_failure.7rcbfp3g-cgu.6.rcgu.o" "linking_failure.linking_failure.7rcbfp3g-cgu.7.rcgu.o" "linking_failure.linking_failure.7rcbfp3g-cgu.8.rcgu.o" "linking_failure.53u64zklswtfazes.rcgu.o" "-Wl,--as-needed" "-L" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,--start-group" "-Wl,-Bstatic" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd-01ce3ba5c629d02f.rlib" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libpanic_unwind-f1f2102409186354.rlib" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libminiz_oxide-1e8b6b56a999f838.rlib" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libadler-d0e93eb4e14f1d19.rlib" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libobject-1d7e39d75d082b43.rlib" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libaddr2line-ade42e945045b261.rlib" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libgimli-1a65064fccf4ebc1.rlib" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libstd_detect-4d699c310fdfe72d.rlib" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_demangle-1cafa68a696ec800.rlib" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libhashbrown-e9f1c8c4dab2f046.rlib" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_alloc-ecc1a743be25c7f7.rlib" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libunwind-e074031c4b66b6b6.rlib" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcfg_if-9aa6ed9f1d3bfd53.rlib" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liblibc-7862bf96c2250ca0.rlib" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/liballoc-f02ce0dc7895b5fd.rlib" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/librustc_std_workspace_core-3af9c60917570521.rlib" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcore-ca16fc7bb3645684.rlib" "-Wl,--end-group" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib/libcompiler_builtins-d8e1a5b7299604cc.rlib" "-Wl,-Bdynamic" "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/smit/rustc-dev/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "linking_failure" "-Wl,--gc-sections" "-pie" "-Wl,-zrelro" "-Wl,-znow" "-nodefaultlibs" = note: /usr/bin/ld: linking_failure.linking_failure.7rcbfp3g-cgu.3.rcgu.o: in function `linking_failure::main': linking_failure.7rcbfp3g-cgu.3:(.text._ZN15linking_failure4main17h52b6e3052e444479E+0x3): undefined reference to `doesnt_exist_thiwthwfyl' clang: error: linker command failed with exit code 1 (use -v to see invocation) = help: some `extern` functions couldn't be found; you may need to install or specify the path to some dependencies = note: use the -L flag to specify the library lookup path = note: use the cargo:rustc-link-search directive to specify the library lookup path with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-search) error: aborting due to previous error ```
2021-06-30Add suggestions for "undefined reference" link errorsSmitty-5/+14
2021-06-20Make allocator_kind a query.Camille GILLOT-1/+1
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