about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
AgeCommit message (Collapse)AuthorLines
2021-07-07Auto merge of #86105 - bjorn3:link_info_refactor, r=petrochenkovbors-2/+18
Refactor the generation of the metadata for linking
2021-07-07Remove a sorting operation from used_cratesbjorn3-2/+18
2021-07-06Auto merge of #86911 - bjorn3:crate_info_refactor, r=petrochenkovbors-187/+162
Refactor linker code This merges `LinkerInfo` into `CrateInfo` as there is no reason to keep them separate. `LinkerInfo::to_linker` is merged into `get_linker` as both have different logic for each linker type and `to_linker` is directly called after `get_linker`. Also contains a couple of small cleanups. See the individual commits for all changes.
2021-07-06Auto merge of #86636 - wesleywiser:misc_enum_improvements, r=michaelwoeristerbors-10/+14
[msvc] Consistently show active variant and fix visualization for single variant enums Prior to this change, there were a few cases where inspecting an enum in either WinDbg or Visual Studio would not show the active variant name. After these changes, we now consistently show the active variant name as `[variant]` in the debugger. We also didn't handle single variant enums very well. That is now also resolved. Before: ![image](https://user-images.githubusercontent.com/831192/123480097-dc8b5f00-d5cf-11eb-93a8-9fc05a97029b.png) After: ![image](https://user-images.githubusercontent.com/831192/123479966-aa79fd00-d5cf-11eb-955e-9798616a8829.png) r? `@michaelwoerister`
2021-07-06Fold LinkerInfo into CrateInfobjorn3-86/+48
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-06Remove unused panic_runtime field from CrateInfobjorn3-5/+0
2021-07-06Move LinkerInfo into CrateInfobjorn3-12/+10
2021-07-05Deduplicate info.used_crate_source indexingbjorn3-2/+3
2021-07-05Remove LibSourcebjorn3-39/+42
The information is stored in used_crate_source too anyway
2021-07-02Refactor `msvc_enum_fallbck()` a bitWesley Wiser-19/+12
2021-07-02Show the variant name for univariant enumsWesley Wiser-0/+11
Previously, only the fields would be displayed with no indication of the variant name. If you already knew the enum was univariant, this was ok but if the enum was univariant because of layout, for example, a `Result<T, !>` then it could be very confusing which variant was the active one.
2021-07-02Auto merge of #85269 - dpaoliello:dpaoliello/DebugSymbols, r=michaelwoeristerbors-88/+272
Improve debug symbol names to avoid ambiguity and work better with MSVC's debugger There are several cases where names of types and functions in the debug info are either ambiguous, or not helpful, such as including ambiguous placeholders (e.g., `{{impl}}`, `{{closure}}` or `dyn _'`) or dropping qualifications (e.g., for dynamic types). Instead, each debug symbol name should be unique and useful: * Include disambiguators for anonymous `DefPathDataName` (closures and generators), and unify their formatting when used as a path-qualifier vs item being qualified. * Qualify the principal trait for dynamic types. * If there is no principal trait for a dynamic type, emit all other traits instead. * Respect the `qualified` argument when emitting ref and pointer types. * For implementations, emit the disambiguator. * Print const generics when emitting generic parameters or arguments. Additionally, when targeting MSVC, its debugger treats many command arguments as C++ expressions, even when the argument is defined to be a symbol name. As such names in the debug info need to be more C++-like to be parsed correctly: * Avoid characters with special meaning (`#`, `[`, `"`, `+`). * Never start a name with `<` or `{` as this is treated as an operator. * `>>` is always treated as a right-shift, even when parsing generic arguments (so add a space to avoid this). * Emit function declarations using C/C++ style syntax (e.g., leading return type). * Emit arrays as a synthetic `array$<type, size>` type. * Include a `$` in all synthetic types as this is a legal character for C++, but not Rust (thus we avoid collisions with user types).
2021-07-01Auto merge of #86749 - bjorn3:link_info_refactor_part1, r=petrochenkovbors-3/+3
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-01Update cdb tests for expected outputWesley Wiser-2/+12
Also an fix issue with tuple type names where we can't cast to them in natvis (required by the visualizer for `HashMap`) because of peculiarities with the natvis expression evaluator.
2021-07-01Rename all_crate_nums query to crates and remove useless wrapperbjorn3-3/+3
2021-07-01Rollup merge of #86652 - nagisa:nagisa/non-leaf-fp, r=petrochenkovGuillaume Gomez-2/+2
Add support for leaf function frame pointer elimination This PR adds ability for the target specifications to specify frame pointer emission type that's not just “always” or “whatever cg decides”. In particular there's a new mode that allows omission of the frame pointer for leaf functions (those that don't call any other functions). We then set this new mode for Aarch64-based Apple targets. Fixes #86196
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-30Improve debug symbol names to avoid ambiguity and work better with MSVC's ↵Daniel Paoliello-86/+260
debugger There are several cases where names of types and functions in the debug info are either ambiguous, or not helpful, such as including ambiguous placeholders (e.g., `{{impl}}`, `{{closure}}` or `dyn _'`) or dropping qualifications (e.g., for dynamic types). Instead, each debug symbol name should be unique and useful: * Include disambiguators for anonymous `DefPathDataName` (closures and generators), and unify their formatting when used as a path-qualifier vs item being qualified. * Qualify the principal trait for dynamic types. * If there is no principal trait for a dynamic type, emit all other traits instead. * Respect the `qualified` argument when emitting ref and pointer types. * For implementations, emit the disambiguator. * Print const generics when emitting generic parameters or arguments. Additionally, when targeting MSVC, its debugger treats many command arguments as C++ expressions, even when the argument is defined to be a symbol name. As such names in the debug info need to be more C++-like to be parsed correctly: * Avoid characters with special meaning (`#`, `[`, `"`, `+`). * Never start a name with `<` or `{` as this is treated as an operator. * `>>` is always treated as a right-shift, even when parsing generic arguments (so add a space to avoid this). * Emit function declarations using C/C++ style syntax (e.g., leading return type). * Emit arrays as a synthetic `array$<type, size>` type. * Include a `$` in all synthetic types as this is a legal character for C++, but not Rust (thus we avoid collisions with user types).
2021-06-30Add support for leaf fn frame pointer eliminationSimonas Kazlauskas-2/+2
This PR adds ability for the target specifications to specify frame pointer emission type that's not just “always” or “whatever cg decides”. In particular there's a new mode that allows omission of the frame pointer for leaf functions (those that don't call any other functions). We then set this new mode for Aarch64-based Apple targets. Fixes #86196
2021-06-29Auto merge of #86475 - crlf0710:miri_vtable_refactor, r=bjorn3bors-39/+6
Change vtable memory representation to use tcx allocated allocations. This fixes https://github.com/rust-lang/rust/issues/86324. However i suspect there's more to change before it can land. r? `@bjorn3` cc `@rust-lang/miri`
2021-06-28Update other codegens to use tcx managed vtable allocations.Charles Lew-39/+6
2021-06-28Auto merge of #85909 - cjgillot:alloc-kind-query, r=Aaron1011bors-2/+2
Make allocator_kind a query. Part of #85153 r? `@Aaron1011`
2021-06-21Auto merge of #86166 - tmiasko:no-alloca-for-zsts, r=nagisabors-93/+74
Do not emit alloca for ZST locals with multiple assignments This extends 35566bfd7dd2e316d190078703de54a4dadda062 to additionally stop emitting unnecessary allocas for zero sized locals that are assigned multiple times. When rebuilding the standard library with `-Zbuild-std` this reduces the number of locals that require an allocation from 62315 to 61767.
2021-06-20Make allocator_kind a query.Camille GILLOT-2/+2
2021-06-15Refactor to make interpreter and codegen backend neutral to vtable internal ↵Charles Lew-34/+34
representation.
2021-06-11Auto merge of #86204 - alexcrichton:wasm-simd-stable, r=Amanieubors-1/+1
std: Stabilize wasm simd intrinsics This commit performs two changes to stabilize Rust support for WebAssembly simd intrinsics: * The stdarch submodule is updated to pull in rust-lang/stdarch#1179. * The `wasm_target_feature` feature gate requirement for the `simd128` feature has been removed, stabilizing the name `simd128`. This should conclude the FCP started on #74372 and... Closes #74372
2021-06-10std: Stabilize wasm simd intrinsicsAlex Crichton-1/+1
This commit performs two changes to stabilize Rust support for WebAssembly simd intrinsics: * The stdarch submodule is updated to pull in rust-lang/stdarch#1179. * The `wasm_target_feature` feature gate requirement for the `simd128` feature has been removed, stabilizing the name `simd128`. This should conclude the FCP started on #74372 and... Closes #74372
2021-06-11Auto merge of #85961 - 1000teslas:issue-71519-fix, r=petrochenkovbors-1/+30
MVP for using rust-lld as part of cc Will fix #71519. I need to figure out how to write a test showing that lld is used instead of whatever linker cc normally uses. When I manually run rustc using `echo 'fn main() {}' | RUSTC_LOG=rustc_codegen_ssa::back::link=debug ./rustc -Clinker-flavor=gcc-lld --crate-type bin -Clink-arg=-Wl,-v` (thanks to bjorn3 on Zulip), I can see that lld is used, but I'm not sure how to inspect that output in a test.
2021-06-10Do not emit alloca for ZST locals with multiple assignmentsTomasz Miąsko-93/+74
When rebuilding the standard library with `-Zbuild-std` this reduces the number of locals that require an allocation from 62315 to 61767.
2021-06-10Auto merge of #85741 - tmiasko:ssa, r=nagisabors-1/+4
Use preorder traversal when checking for SSA locals Traverse blocks in topological sort of dominance partial order, to ensure that local analyzer correctly identifies locals that are already in static single assignment form, while avoiding dependency on implicit numeric order of blocks. When rebuilding the standard library, this change reduces the number of locals that require an alloca from 62452 to 62348.
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-07Use preorder traversal when checking for SSA localsTomasz Miąsko-1/+4
When rebuilding the standard library, this change reduces the number of locals that require an alloca from 62452 to 62348.
2021-06-07Auto merge of #85810 - bjorn3:further_driver_cleanup, r=varkorbors-26/+31
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-07Rollup merge of #85965 - tmiasko:a, r=nagisaGuillaume Gomez-46/+4
Remove dead code from `LocalAnalyzer`
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