about summary refs log tree commit diff
path: root/src/librustc_codegen_ssa/back
AgeCommit message (Collapse)AuthorLines
2020-05-22Use `OnceCell` instead of `Once`Dylan MacKenzie-13/+9
2020-05-22Auto merge of #72460 - RalfJung:rollup-28fs06y, r=RalfJungbors-1/+15
Rollup of 4 pull requests Successful merges: - #71610 (InvalidUndefBytes: Track size of undef region used) - #72161 (Replace fcntl-based file lock with flock) - #72306 (Break tokens before checking if they are 'probably equal') - #72325 (Always generated object code for `#![no_builtins]`) Failed merges: r? @ghost
2020-05-22Rollup merge of #72325 - alexcrichton:ignore-linker-plugin-lto, r=nnethercoteRalf Jung-1/+15
Always generated object code for `#![no_builtins]` This commit updates the code generation for `#![no_builtins]` to always produce object files instead of conditionally respecting `-Clinker-plugin-lto` and sometimes producing bitcode. This is intended to address rust-lang/cargo#8239. The issue at hand here is that Cargo has tried to get "smarter" about codegen in whole crate graph scenarios. When LTO is enabled it attempts to avoid codegen on as many crates as possible, opting to pass `-Clinker-plugin-lto` where it can to only generate bitcode. When this is combined with `-Zbuild-std`, however, it means that `compiler-builtins` only generates LLVM bitcode instead of object files. Rustc's own LTO passes then explicitly skip `compiler-builtins` (because it wouldn't work anyway) which means that LLVM bitcode gets sent to the linker, which chokes most of the time. The fix in this PR is to not actually respect `-Clinker-plugin-lto` for `#![no_builtins]` crates. These crates, even if slurped up by the linker rather than rustc, will not work with LTO. They define symbols which are only referenced as part of codegen, so LTO's aggressive internalization would trivially remove the symbols only to have the linker realize later that the symbol is undefined. Since pure-bitcode never makes sense for these libraries, the `-Clinker-plugin-lto` flag is silently ignored.
2020-05-22Rollup merge of #72309 - petrochenkov:linkunspec, r=matthewjasperRalf Jung-23/+27
Some renaming and minor refactoring for `NativeLibraryKind`
2020-05-22Rollup merge of #72133 - bdbai:master, r=joshtriplettRalf Jung-0/+1
Add target thumbv7a-uwp-windows-msvc Add target spec for thumbv7a-uwp-windows-msvc, so that libraries written in Rust will have a chance to run on ARM-based devices with Windows 10. So far I managed to create a proof-of-concept library for Universal Windows Platform apps to consume and it worked on a Windows Phone. However, building a standalone executable seemed troublesome due to `LLVM ERROR: target does not implement codeview register mapping` stuff (see also https://github.com/rust-lang/rust/issues/52659#issuecomment-408233322 ). Steps to test: 1. Clone and build this version ```sh git clone https://github.com/bdbai/rust.git cd rust python x.py build -i --target thumbv7a-uwp-windows-msvc --stage 1 src/libstd rustup toolchain link arm-uwp-stage1 .\build\x86_64-pc-windows-msvc\stage1\ ``` 2. Create a new library crate ```sh cargo new --lib arm-uwp-test cd arm-uwp-test ``` 3. Change `crate-type` in `Cargo.toml` to `staticlib` ```toml [lib] crate-type=["staticlib"] ``` 4. Replace the following code in `src/lib.rs` ```rust #[no_mangle] pub extern "system" fn call_rust() -> i32 { 2333 } ``` 5. Build the crate ```sh cargo +arm-uwp-stage1 build -v --target thumbv7a-uwp-windows-msvc ``` 6. `arm-uwp-test.lib` should appear in `target\thumbv7a-uwp-windows-msvc\debug` To consume this library: 1. Make sure Visual Studio 2017 and Windows 10 SDK (10.0.17134 or above) are installed 2. Create a new Blank App (C++/WinRT) in Visual Studio 2017 (Visual Studio 2019 cannot deploy UWP apps to Windows Phone) 3. Go to Property Pages, and then Linker->Input->Additional Dependencies, add `arm-uwp-test.lib` produced just now 4. Manually declare function prototypes in `MainPage.h` ```c++ extern "C" { int call_rust(); } ``` 5. Replace the `ClickHandler` part in `MainPage.cpp` ```c++ myButton().Content(box_value(std::to_wstring(call_rust()))); ``` 6. Build and deploy this app to an ARM device running Windows 10. The app should run and show `2333` when the button is clicked.
2020-05-21Rollup merge of #72296 - ChrisDenton:msvc-link-check, r=petrochenkovRalf Jung-0/+49
Suggest installing VS Build Tools in more situations When MSVC's `link.exe` wasn't found but another `link.exe` was, the error message given can be [impenetrable](https://pastebin.com/MRMCr7HM) to many users. The usual suspect is GNU's `link` tool. In this case, inform the user that they may need to install VS build tools. This only applies when Microsoft's link tool is expected.
2020-05-20Factor out `NativeLibKind::Dylib` from `NativeLibKind::Unspecified`Vadim Petrochenkov-3/+6
2020-05-20Rename some types describing native librariesVadim Petrochenkov-23/+24
NativeLibrary(Kind) -> NativeLib(Kind) NativeStatic -> StaticBundle NativeStaticNobundle -> StaticNoBundle NativeFramework -> Framework NativeRawDylib -> RawDylib NativeUnknown -> Unspecified
2020-05-20Suggest installing VS Build Tools in more situationsChris Denton-0/+49
When MSVC's `link.exe` wasn't found but another `link.exe` was, the error message given can be impenetrable to many users. The usual suspect is GNU's `link` tool. In this case, inform the user that they may need to install VS build tools. This only applies when Microsoft's link tool is expected. Not `lld-link` or other MSVC compatible linkers.
2020-05-20Auto merge of #71769 - petrochenkov:crto, r=cuviperbors-62/+106
linker: More systematic handling of CRT objects Document which kinds of `crt0.o`-like objects we link and in which cases, discovering bugs in process. `src/librustc_target/spec/crt_objects.rs` is the place to start reading from. This PR also automatically contains half of the `-static-pie` support (https://github.com/rust-lang/rust/pull/70740), because that's one of the six cases that we need to consider when linking CRT objects. This is a breaking change for custom target specifications that specify CRT objects. Closes https://github.com/rust-lang/rust/issues/30868
2020-05-18Always generated object code for `#![no_builtins]`Alex Crichton-1/+15
This commit updates the code generation for `#![no_builtins]` to always produce object files instead of conditionally respecting `-Clinker-plugin-lto` and sometimes producing bitcode. This is intended to address rust-lang/cargo#8239. The issue at hand here is that Cargo has tried to get "smarter" about codegen in whole crate graph scenarios. When LTO is enabled it attempts to avoid codegen on as many crates as possible, opting to pass `-Clinker-plugin-lto` where it can to only generate bitcode. When this is combined with `-Zbuild-std`, however, it means that `compiler-builtins` only generates LLVM bitcode instead of object files. Rustc's own LTO passes then explicitly skip `compiler-builtins` (because it wouldn't work anyway) which means that LLVM bitcode gets sent to the linker, which chokes most of the time. The fix in this PR is to not actually respect `-Clinker-plugin-lto` for `#![no_builtins]` crates. These crates, even if slurped up by the linker rather than rustc, will not work with LTO. They define symbols which are only referenced as part of codegen, so LTO's aggressive internalization would trivially remove the symbols only to have the linker realize later that the symbol is undefined. Since pure-bitcode never makes sense for these libraries, the `-Clinker-plugin-lto` flag is silently ignored.
2020-05-17Auto merge of #72208 - tmandry:fix-fuchsia-solink, r=Mark-Simulacrumbors-1/+1
Don't pass --dynamic-linker for Fuchsia dylibs This was causing a PT_INTERP header in Fuchsia dylibs (implying that they're executable when they're not). r? @Mark-Simulacrum cc @frobtech @petrhosek
2020-05-16Auto merge of #72178 - tmiasko:inliner-lifetimes, r=nikicbors-0/+2
Consistently use LLVM lifetime markers during codegen Ensure that inliner inserts lifetime markers if they have been emitted during codegen. Otherwise if allocas from inlined functions are merged together, lifetime markers from one function might invalidate load & stores performed by the other one. Fixes #72154.
2020-05-15Rollup merge of #72062 - overdrivenpotato:psp, r=jonas-schievinkDylan DPC-0/+25
Add built in PSP target This adds a new target, `mipsel-sony-psp`, corresponding to the Sony PSP. The linker script is necessary to handle special sections, which are required by the target. This has been tested with my [rust-psp] crate and I can confirm it works as intended. The linker script is taken from [here]. It has been slightly adapted to work with rust and LLD. The `stdarch` submodule was also updated in order for `libcore` to build successfully. [rust-psp]: https://github.com/overdrivenpotato/rust-psp [here]: https://github.com/pspdev/pspsdk/blob/master/src/base/linkfile.prx.in
2020-05-14Don't pass --dynamic-linker for Fuchsia dylibsTyler Mandry-1/+1
This was causing a PT_INTERP header in Fuchsia dylibs (implying that they're executable when they're not).
2020-05-14Consistently use LLVM lifetime markers during codegenTomasz Miąsko-0/+2
Ensure that inliner inserts lifetime markers if they have been emitted during codegen. Otherwise if allocas from inlined functions are merged together, lifetime markers from one function might invalidate load & stores performed by the other one.
2020-05-14linker: More systematic handling of CRT objectsVadim Petrochenkov-62/+106
2020-05-12Add target thumbv7a-uwp-windows-msvcbdbai-0/+1
2020-05-12Change `WorkProduct::saved_files` to an `Option`.Nicholas Nethercote-9/+5
Because there is at most one file.
2020-05-10Run rustfmtMarko Mijalkovic-6/+1
2020-05-10Renamed lld_link_script to link_script and support all GNU-like linkersMarko Mijalkovic-10/+9
2020-05-10Auto merge of #71825 - contrun:cg-option-strip, r=petrochenkovbors-34/+53
add codegen option strip closes https://github.com/rust-lang/rust/issues/71757 I don't know if the flags added here works for all linkers. I only tested on my Linux pc. I also don't know what is the best for emlinker, PtxLinker, MsvcLinker. The option for WasmLd is copied from https://aransentin.github.io/cwasm/.
2020-05-10Add lld_link_script to TargetOptionsMarko Mijalkovic-0/+31
2020-05-10add linking option stripYI-34/+53
move strip option to "Z" add more strip options, remove strip-debuginfo-if-disabled merge strip and debuginfo
2020-05-10Auto merge of #72020 - alexcrichton:fix-incremental-linker-plugin-lto, r=oli-obkbors-30/+39
Fix disagreeement about CGU reuse and LTO This commit fixes an issue where the codegen backend's selection of LTO disagreed with what the codegen later thought was being done. Discovered in #72006 we have a longstanding issue where if `-Clinker-plugin-lto` in optimized mode is compiled incrementally it will always panic on the second compilation. The underlying issue turned out to be that the production of the original artifact determined that LTO should not be done (because it's being postponed to the linker) but the CGU reuse selection thought that LTO was done so it was trying to load pre-LTO artifacts which were never generated. The fix here is to ensure that the logic when generating code which determines what kind of LTO is being done is shared amongst the CGU reuse decision and the backend actually doing LTO. This means that they'll both be in agreement about whether the previous compilation did indeed produce incremental pre-LTO artifacts. Closes #72006
2020-05-09Fix disagreeement about CGU reuse and LTOAlex Crichton-30/+39
This commit fixes an issue where the codegen backend's selection of LTO disagreed with what the codegen later thought was being done. Discovered in #72006 we have a longstanding issue where if `-Clinker-plugin-lto` in optimized mode is compiled incrementally it will always panic on the second compilation. The underlying issue turned out to be that the production of the original artifact determined that LTO should not be done (because it's being postponed to the linker) but the CGU reuse selection thought that LTO was done so it was trying to load pre-LTO artifacts which were never generated. The fix here is to ensure that the logic when generating code which determines what kind of LTO is being done is shared amongst the CGU reuse decision and the backend actually doing LTO. This means that they'll both be in agreement about whether the previous compilation did indeed produce incremental pre-LTO artifacts. Closes #72006
2020-05-08Simplify bitcode embedding - either None or FullTom Karpiniec-16/+6
2020-05-07Provide configurable LLVM cmdline section via target specTom Karpiniec-0/+2
The App Store performs certain sanity checks on bitcode, including that an acceptable set of command line arguments was used when compiling a given module. For Rust code to be distributed on the app store with bitcode rustc must pretend to have the same command line arguments.
2020-05-07Force embed-bitcode on non-simulator iOS/tvOS targetsTom Karpiniec-0/+2
At this time Apple recommends Bitcode be included for iOS apps, and requires it for tvOS. It is unlikely that a developer would want to disable bitcode when building for these targets, yet by default it will not be generated. This presents a papercut for developers on those platforms. Introduces a new TargetOption boolean key for specific triples to indicate that bitcode should be generated, even if cargo attempts to optimise with -Cembed-bitcode=no.
2020-05-04Auto merge of #71754 - alexcrichton:no-bitcode-in-cache, r=nnethercotebors-21/+6
Don't copy bytecode files into the incr. comp. cache. It's no longer necessary now that bitcode is embedded into object files. This change meant that `WorkProductFileKind::Bytecode` is no longer necessary, which means that type is no longer necessary, which allowed several places in the code to become simpler. This commit was written by @nnethercote in https://github.com/rust-lang/rust/pull/70458 but that didn't land. In the meantime though we managed to land it in https://github.com/rust-lang/rust/pull/71528 and that doesn't seem to be causing too many fires, so I'm re-sending this patch!
2020-05-02cleanup: `config::CrateType` -> `CrateType`Vadim Petrochenkov-52/+49
2020-05-02Auto merge of #71716 - alexcrichton:bitcode-follow-up, r=nnethercotebors-2/+2
Rename `bitcode-in-rlib` option to `embed-bitcode` This commit finishes work first pioneered in #70458 and started in #71528. The `-C bitcode-in-rlib` option, which has not yet reached stable, is renamed to `-C embed-bitcode` since that more accurately reflects what it does now anyway. Various tests and such are updated along the way as well. This'll also need to be backported to the beta channel to ensure we don't accidentally stabilize `-Cbitcode-in-rlib` as well.
2020-05-01Rename `bitcode-in-rlib` option to `embed-bitcode`Alex Crichton-2/+2
This commit finishes work first pioneered in #70458 and started in #71528. The `-C bitcode-in-rlib` option, which has not yet reached stable, is renamed to `-C embed-bitcode` since that more accurately reflects what it does now anyway. Various tests and such are updated along the way as well. This'll also need to be backported to the beta channel to ensure we don't accidentally stabilize `-Cbitcode-in-rlib` as well.
2020-05-01Don't copy bytecode files into the incr. comp. cache.Nicholas Nethercote-21/+6
It's no longer necessary now that bitcode is embedded into object files. This change meant that `WorkProductFileKind::Bytecode` is no longer necessary, which means that type is no longer necessary, which allowed several places in the code to become simpler.
2020-05-01Auto merge of #71623 - petrochenkov:localink, r=estebankbors-1/+16
Disable localization for all linkers We previously disabled non-English output from `link.exe` due to encoding issues (#35785). In https://github.com/rust-lang/rust/pull/70740 it was pointed out that it also prevents correct inspection of the linker output, which we have to do occasionally. So this PR disables localization for all linkers.
2020-05-01Auto merge of #70674 - cjgillot:query-arena-all, r=matthewjasperbors-8/+5
Have the per-query caches store the results on arenas This PR leverages the cache for each query to serve as storage area for the query results. It introduces a new cache `ArenaCache`, which moves the result to an arena, and only stores the reference in the hash map. This allows to remove a sizeable part of the usage of the global `TyCtxt` arena. I only migrated queries that already used arenas before.
2020-04-30Auto merge of #70175 - Amanieu:remove_nlp, r=pnkfelixbors-2/+2
Remove -Z no-landing-pads flag Since #67502, `-Z no-landing-pads` will cause all attempted unwinds to abort since we don't generate a `try` / `catch`. This previously worked because `__rust_try` was located in libpanic_unwind which is always compiled with `-C panic=unwind`, but `__rust_try` is now directly inline into the crate that uses `catch_unwind`. As such, `-Z no-landing-pads` is now mostly useless and people should use `-C panic=abort` instead.
2020-04-29Auto merge of #71528 - alexcrichton:no-more-bitcode, r=nnethercotebors-49/+5
Store LLVM bitcode in object files, not compressed This commit is an attempted resurrection of #70458 where LLVM bitcode emitted by rustc into rlibs is stored into object file sections rather than in a separate file. The main rationale for doing this is that when rustc emits bitcode it will no longer use a custom compression scheme which makes it both easier to interoperate with existing tools and also cuts down on compile time since this compression isn't happening. The blocker for this in #70458 turned out to be that native linkers didn't handle the new sections well, causing the sections to either trigger bugs in the linker or actually end up in the final linked artifact. This commit attempts to address these issues by ensuring that native linkers ignore the new sections by inserting custom flags with module-level inline assembly. Note that this does not currently change the API of the compiler at all. The pre-existing `-C bitcode-in-rlib` flag is co-opted to indicate whether the bitcode should be present in the object file or not. Finally, note that an important consequence of this commit, which is also one of its primary purposes, is to enable rustc's `-Clto` bitcode loading to load rlibs produced with `-Clinker-plugin-lto`. The goal here is that when you're building with LTO Cargo will tell rustc to skip codegen of all intermediate crates and only generate LLVM IR. Today rustc will generate both object code and LLVM IR, but the object code is later simply thrown away, wastefully.
2020-04-29Store LLVM bitcode in object files, not compressedAlex Crichton-49/+5
This commit is an attempted resurrection of #70458 where LLVM bitcode emitted by rustc into rlibs is stored into object file sections rather than in a separate file. The main rationale for doing this is that when rustc emits bitcode it will no longer use a custom compression scheme which makes it both easier to interoperate with existing tools and also cuts down on compile time since this compression isn't happening. The blocker for this in #70458 turned out to be that native linkers didn't handle the new sections well, causing the sections to either trigger bugs in the linker or actually end up in the final linked artifact. This commit attempts to address these issues by ensuring that native linkers ignore the new sections by inserting custom flags with module-level inline assembly. Note that this does not currently change the API of the compiler at all. The pre-existing `-C bitcode-in-rlib` flag is co-opted to indicate whether the bitcode should be present in the object file or not. Finally, note that an important consequence of this commit, which is also one of its primary purposes, is to enable rustc's `-Clto` bitcode loading to load rlibs produced with `-Clinker-plugin-lto`. The goal here is that when you're building with LTO Cargo will tell rustc to skip codegen of all intermediate crates and only generate LLVM IR. Today rustc will generate both object code and LLVM IR, but the object code is later simply thrown away, wastefully.
2020-04-29Remove Session::no_landing_pads()Amanieu d'Antras-2/+2
2020-04-28Use the query system to allocate.Camille GILLOT-8/+5
2020-04-27Disable localization for all linkersVadim Petrochenkov-1/+16
2020-04-26codegen_llvm: Simplify logic for relaxing PIC into PIEVadim Petrochenkov-1/+1
2020-04-26rustc_target: Stop using "string typing" for relocation modelsVadim Petrochenkov-11/+2
Introduce `enum RelocModel` instead.
2020-04-25Rollup merge of #71544 - cuviper:filter_map_next, r=Mark-SimulacrumDylan DPC-5/+1
Replace filter_map().next() calls with find_map() These are semantically the same, but `find_map()` is more concise.
2020-04-25Rollup merge of #71364 - Amanieu:zprofile_compiler_builtins, r=cramertjDylan DPC-5/+18
Ignore -Zprofile when building compiler_builtins #70846 made the `compiler_builtins` crate ignore the default codegen-units setting and instead always split each function into a different codegen unit. This unfortunately breaks `-Zprofile` which requires a single codegen unit per crate (see #71283). You can notice this when building with `cargo -Zbuild-std` and `RUSTFLAGS` containing `-Zprofile`. This PR works around this issue by just ignoring `-Zprofile` for the `compiler-builtins` crate.
2020-04-24Replace filter_map().next() calls with find_map()Josh Stone-5/+1
These are semantically the same, but `find_map()` is more concise.
2020-04-23Modify `as_local_hir_id` to return a bare `HirId`marmeladema-1/+1
2020-04-23Modify `as_local_hir_id` to accept a `LocalDefId` instead of a `DefId`marmeladema-2/+2
2020-04-23librustc_middle: return LocalDefId instead of DefId in local_def_idmarmeladema-5/+5