about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/back
AgeCommit message (Collapse)AuthorLines
2022-03-06Improved error message for failed bitcode loadJoe-1/+1
"bc" is an unnecessary shorthand that obfuscates the compilation error
2022-03-02Auto merge of #87402 - nagisa:nagisa/request-feature-requests-for-features, ↵bors-5/+12
r=estebank Direct users towards using Rust target feature names in CLI This PR consists of a couple of changes on how we handle target features. In particular there is a bug-fix wherein we avoid passing through features that aren't prefixed by `+` or `-` to LLVM. These appear to be causing LLVM to assert, which is pretty poor a behaviour (and also makes it pretty clear we expect feature names to be prefixed). The other commit, I anticipate to be somewhat more controversial is outputting a warning when users specify a LLVM-specific, or otherwise unknown, feature name on the CLI. In those situations we request users to either replace it with a known Rust feature name (e.g. `bmi` -> `bmi1`) or file a feature request. I've a couple motivations for this: first of all, if users are specifying these features on the command line, I'm pretty confident there is also a need for these features to be usable via `#[cfg(target_feature)]` machinery. And second, we're growing a fair number of backends recently and having ability to provide some sort of unified-ish interface in this place seems pretty useful to me. Sponsored by: standard.ai
2022-03-01Querify `global_backend_features`Simonas Kazlauskas-5/+12
At the very least this serves to deduplicate the diagnostics that are output about unknown target features provided via CLI.
2022-02-25Fix MinGW target detection in raw-dylibMateusz Mikuła-1/+3
LLVM target doesn't have to be the same as Rust target so relying on it is wrong.
2022-02-19Adopt let else in more placesest31-12/+3
2022-02-10Unconditionally update symbolsbjorn3-10/+1
All paths to an ArchiveBuilder::build call update_symbols first.
2022-02-03clippy::perf fixesMatthias Krüger-1/+1
single_char_pattern and to_string_in_format_args
2022-01-18Rollup merge of #90782 - ricobbe:binutils-dlltool, r=michaelwoeristerMatthias Krüger-46/+159
Implement raw-dylib support for windows-gnu Add support for `#[link(kind = "raw-dylib")]` on windows-gnu targets. Work around binutils's linker's inability to read import libraries produced by LLVM by calling out to the binutils `dlltool` utility to create an import library from a temporary .DEF file; this approach is effectively a slightly refined version of `@mati865's` earlier attempt at this strategy in PR #88801. (In particular, this attempt at this strategy adds support for `#[link_ordinal(...)]` as well.) In support of #58713.
2022-01-14Remove LLVMRustMarkAllFunctionsNounwindAmanieu d'Antras-17/+0
This was originally introduced in #10916 as a way to remove all landing pads when performing LTO. However this is no longer necessary today since rustc properly marks all functions and call-sites as nounwind where appropriate. In fact this is incorrect in the presence of `extern "C-unwind"` which must create a landing pad when compiled with `-C panic=abort` so that foreign exceptions are caught and properly turned into aborts.
2022-01-12Call out to binutils' dlltool for raw-dylib on windows-gnu platforms.Richard Cobbe-46/+159
2022-01-06sess/cg: re-introduce split dwarf kindDavid Wood-14/+21
In #79570, `-Z split-dwarf-kind={none,single,split}` was replaced by `-C split-debuginfo={off,packed,unpacked}`. `-C split-debuginfo`'s packed and unpacked aren't exact parallels to single and split, respectively. On Unix, `-C split-debuginfo=packed` will put debuginfo into object files and package debuginfo into a DWARF package file (`.dwp`) and `-C split-debuginfo=unpacked` will put debuginfo into dwarf object files and won't package it. In the initial implementation of Split DWARF, split mode wrote sections which did not require relocation into a DWARF object (`.dwo`) file which was ignored by the linker and then packaged those DWARF objects into DWARF packages (`.dwp`). In single mode, sections which did not require relocation were written into object files but ignored by the linker and were not packaged. However, both split and single modes could be packaged or not, the primary difference in behaviour was where the debuginfo sections that did not require link-time relocation were written (in a DWARF object or the object file). This commit re-introduces a `-Z split-dwarf-kind` flag, which can be used to pick between split and single modes when `-C split-debuginfo` is used to enable Split DWARF (either packed or unpacked). Signed-off-by: David Wood <david.wood@huawei.com>
2021-12-30Auto merge of #91125 - eskarn:llvm-passes-plugin-support, r=nagisabors-18/+13
Allow loading LLVM plugins with both legacy and new pass manager Opening a draft PR to get feedback and start discussion on this feature. There is already a codegen option `passes` which allow giving a list of LLVM pass names, however we currently can't use a LLVM pass plugin (as described here : https://llvm.org/docs/WritingAnLLVMPass.html), the only available passes are the LLVM built-in ones. The proposed modification would be to add another codegen option `pass-plugins`, which can be set with a list of paths to shared library files. These libraries are loaded using the LLVM function `PassPlugin::Load`, which calls the expected symbol `lvmGetPassPluginInfo`, and register the pipeline parsing and optimization callbacks. An example usage with a single plugin and 3 passes would look like this in the `.cargo/config`: ```toml rustflags = [ "-C", "pass-plugins=/tmp/libLLVMPassPlugin", "-C", "passes=pass1 pass2 pass3", ] ``` This would give the same functionality as the opt LLVM tool directly integrated in rust build system. Additionally, we can also not specify the `passes` option, and use a plugin which inserts passes in the optimization pipeline, as one could do using clang.
2021-12-20rustc_codegen_llvm: move should_use_new_llvm_pass_manager function to llvm_utilAxel Cohen-18/+9
2021-12-18Rollup merge of #91931 - LegionMammal978:less-inband-codegen_llvm, r=davidtwcoMatthias Krüger-3/+3
Remove `in_band_lifetimes` from `rustc_codegen_llvm` See #91867 for more information. This one took a while. This crate has dozens of functions not associated with any type, and most of them were using in-band lifetimes for `'ll` and `'tcx`.
2021-12-18Rollup merge of #91566 - cbeuw:remap-dwo-name, r=davidtwcoMatthias Krüger-1/+4
Apply path remapping to DW_AT_GNU_dwo_name when producing split DWARF `--remap-path-prefix` doesn't apply to paths to `.o` (in case of packed) or `.dwo` (in case of unpacked) files in `DW_AT_GNU_dwo_name`. GCC also has this bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91888
2021-12-16Remove `in_band_lifetimes` from `rustc_codegen_llvm`LegionMammal978-3/+3
See #91867 for more information.
2021-12-13Revert "Produce .dwo file for Packed as well"Andy Wang-8/+11
This reverts commit 32810223c6b743de889eda96b442f621c293a848.
2021-12-13Auto merge of #91654 - nikic:llvmbc-section-flags, r=nagisabors-42/+60
Use module inline assembly to embed bitcode In LLVM 14, our current method of setting section flags to avoid embedding the `.llvmbc` section into final compilation artifacts will no longer work, see issue #90326. The upstream recommendation is to instead embed the entire bitcode using module-level inline assembly, which is what this change does. I've kept the existing code for platforms where we do not need to set section flags, but possibly we should always be using the inline asm approach (which would have to look a bit different for MachO). r? `@nagisa`
2021-12-13Use the existing llvm-plugins option for both legacy and new pm registrationAxel Cohen-3/+3
2021-12-13Add a codegen option to allow loading LLVM pass pluginsAxel Cohen-0/+4
2021-12-11Remap path in MCOptionsAndy Wang-1/+4
2021-12-09Remove redundant [..]sest31-21/+17
2021-12-08Use module inline assembly to embed bitcodeNikita Popov-42/+60
In LLVM 14, our current method of setting section flags to avoid embedding the `.llvmbc` section into final compilation artifacts will no longer work, see issue #90326. The upstream recommendation is to instead embed the entire bitcode using module-level inline assembly, which is what this change does. I've kept the existing code for platforms where we do not need to set section flags, but possibly we should always be using the inline asm approach.
2021-12-06Produce .dwo file for Packed as wellAndy Wang-11/+8
2021-11-16Emit LLVM optimization remarks when enabled with `-Cremark`Tomasz Miąsko-3/+27
The default diagnostic handler considers all remarks to be disabled by default unless configured otherwise through LLVM internal flags: `-pass-remarks`, `-pass-remarks-missed`, and `-pass-remarks-analysis`. This behaviour makes `-Cremark` ineffective on its own. Fix this by configuring a custom diagnostic handler that enables optimization remarks based on the value of `-Cremark` option. With `-Cremark=all` enabling all remarks.
2021-11-16Use brief format for optimization remarksTomasz Miąsko-7/+2
2021-11-09Rollup merge of #90701 - michaelwoerister:more-artifact-sizes, r=davidtwcoMatthias Krüger-0/+46
Record more artifact sizes during self-profiling. This PR adds artifact size recording for - "linked artifacts" (executables, RLIBs, dylibs, static libs) - object files - dwo files - assembly files - crate metadata - LLVM bitcode files - LLVM IR files - codegen unit size estimates Currently the identifiers emitted for these are hard-coded as string literals. Is it worth adding constants to https://github.com/rust-lang/measureme/blob/master/measureme/src/rustc.rs instead? We don't do that for query names and the like -- but artifact kinds might be more stable than query names.
2021-11-08Record more artifact sizes during self-profiling.Michael Woerister-0/+46
2021-11-08Don't abort compilation after giving a lint errorJoshua Nelson-1/+1
The only reason to use `abort_if_errors` is when the program is so broken that either: 1. later passes get confused and ICE 2. any diagnostics from later passes would be noise This is never the case for lints, because the compiler has to be able to deal with `allow`-ed lints. So it can continue to lint and compile even if there are lint errors.
2021-10-25Rollup merge of #89581 - jblazquez:master, r=Mark-SimulacrumMatthias Krüger-0/+2
Add -Z no-unique-section-names to reduce ELF header bloat. This change adds a new compiler flag that can help reduce the size of ELF binaries that contain many functions. By default, when enabling function sections (which is the default for most targets), the LLVM backend will generate different section names for each function. For example, a function `func` would generate a section called `.text.func`. Normally this is fine because the linker will merge all those sections into a single one in the binary. However, starting with [LLVM 12](https://github.com/llvm/llvm-project/commit/ee5d1a04), the backend will also generate unique section names for exception handling, resulting in thousands of `.gcc_except_table.*` sections ending up in the final binary because some linkers like LLD don't currently merge or strip these EH sections (see discussion [here](https://reviews.llvm.org/D83655)). This can bloat the ELF headers and string table significantly in binaries that contain many functions. The new option is analogous to Clang's `-fno-unique-section-names`, and instructs LLVM to generate the same `.text` and `.gcc_except_table` section for each function, resulting in a smaller final binary. The motivation to add this new option was because we have a binary that ended up with so many ELF sections (over 65,000) that it broke some existing ELF tools, which couldn't handle so many sections. Here's our old binary: ``` $ readelf --sections old.elf | head -1 There are 71746 section headers, starting at offset 0x2a246508: $ readelf --sections old.elf | grep shstrtab [71742] .shstrtab STRTAB 0000000000000000 2977204c ad44bb 00 0 0 1 ``` That's an 11MB+ string table. Here's the new binary using this option: ``` $ readelf --sections new.elf | head -1 There are 43 section headers, starting at offset 0x29143ca8: $ readelf --sections new.elf | grep shstrtab [40] .shstrtab STRTAB 0000000000000000 29143acc 0001db 00 0 0 1 ``` The whole binary size went down by over 20MB, which is quite significant.
2021-10-11Add -Z no-unique-section-names to reduce ELF header bloat.Javier Blazquez-0/+2
This change adds a new compiler flag that can help reduce the size of ELF binaries that contain many functions. By default, when enabling function sections (which is the default for most targets), the LLVM backend will generate different section names for each function. For example, a function "func" would generate a section called ".text.func". Normally this is fine because the linker will merge all those sections into a single one in the binary. However, starting with LLVM 12 (llvm/llvm-project@ee5d1a0), the backend will also generate unique section names for exception handling, resulting in thousands of ".gcc_except_table.*" sections ending up in the final binary because some linkers don't currently merge or strip these EH sections. This can bloat the ELF headers and string table significantly in binaries that contain many functions. The new option is analogous to Clang's -fno-unique-section-names, and instructs LLVM to generate the same ".text" and ".gcc_except_table" section for each function, resulting in smaller object files and potentially a smaller final binary.
2021-10-08Default to disabling the new pass manager for the s390x targets.Hans Kratz-4/+13
2021-10-07Rollup merge of #89025 - ricobbe:raw-dylib-link-ordinal, r=michaelwoeristerJubilee-5/+5
Implement `#[link_ordinal(n)]` Allows the use of `#[link_ordinal(n)]` with `#[link(kind = "raw-dylib")]`, allowing Rust to link against DLLs that export symbols by ordinal rather than by name. As long as the ordinal matches, the name of the function in Rust is not required to match the name of the corresponding function in the exporting DLL. Part of #58713.
2021-10-06Enable AutoFDO.Michael Benfield-0/+15
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-1/+1
2021-10-02Auto merge of #89405 - GuillaumeGomez:fix-clippy-lints, r=cjgillotbors-18/+17
Fix clippy lints I'm currently working on allowing clippy to run on librustdoc after a discussion I had with `@Mark-Simulacrum.` So in the meantime, I fixed a few lints on the compiler crates.
2021-10-01Rollup merge of #89376 - andjo403:selfProfileUseAfterDropFix, r=Mark-SimulacrumManish Goregaokar-4/+6
Fix use after drop in self-profile with llvm events self-profile with `-Z self-profile-events=llvm` have failed with a segmentation fault due to this use after drop. this type of events can be more useful now that the new passmanager is the default.
2021-10-01Fix clippy lintsGuillaume Gomez-18/+17
2021-10-01Rollup merge of #88820 - hlopko:add_pie_relocation_model, r=petrochenkovManish Goregaokar-1/+2
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-1/+2
2021-09-29Fix use after drop in self-profile with llvm eventsAndreas Jonson-4/+6
2021-09-25Enable new pass manager on LLVM 13Nikita Popov-2/+3
The new pass manager is enabled by default in clang since Clang/LLVM 13. While the discussion about this is still ongoing (https://lists.llvm.org/pipermail/llvm-dev/2021-August/152305.html) it's expected that support for the legacy pass manager will be dropped either in LLVM 14 or 15. This switches us to use the new pass manager if LLVM >= 13 is used.
2021-09-20Implement #[link_ordinal] attribute in the context of #[link(kind = ↵Richard Cobbe-5/+5
"raw-dylib")].
2021-09-17Work around invalid DWARF bugs for fat LTOYilin Chen-2/+16
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
2021-09-01Move add_rlib and add_native_library to cg_ssabjorn3-80/+18
This deduplicates logic between codegen backends
2021-08-16Handle SrcMgr diagnosticsNikita Popov-40/+3
This is how InlineAsm diagnostics with source information are reported now. Previously a separate InlineAsm diagnostic handler was used.
2021-07-09Add support for raw-dylib with stdcall, fastcall functions on ↵Richard Cobbe-5/+22
i686-pc-windows-msvc.
2021-06-04Add first cut of functionality for #58713: support for #[link(kind = ↵Richard Cobbe-1/+82
"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-05-12Use () for codegen queries.Camille GILLOT-4/+2
2021-05-08Support -C passes in NewPMNikita Popov-12/+31
And report an error if parsing the additional pass pipeline fails. Threading through the error accounts for most of the changes here.