summary refs log tree commit diff
path: root/src/librustc_codegen_ssa
AgeCommit message (Collapse)AuthorLines
2020-06-26linker: Never pass `-no-pie` to non-gnu linkersVadim Petrochenkov-2/+2
2020-06-02Rollup merge of #72889 - alexcrichton:update-wasm-threads, r=nikomatsakisYuki Okushi-4/+0
rustc: Remove the `--passive-segments` LLD flag on wasm This flag looks like it's been removed in LLVM 10, so this removes rustc unconditionally passing the flag.
2020-06-01rustc: Remove the `--passive-segments` LLD flag on wasmAlex Crichton-4/+0
This flag looks like it's been removed in LLVM 10, so this removes rustc unconditionally passing the flag.
2020-06-01Auto merge of #71192 - oli-obk:eager_alloc_id_canonicalization, r=wesleywiserbors-0/+8
Make TLS accesses explicit in MIR r? @rust-lang/wg-mir-opt cc @RalfJung @vakaras for miri thread locals cc @bjorn3 for cranelift fixes #70685
2020-05-30Rollup merge of #72625 - Amanieu:asm-srcloc, r=petrochenkovRalf Jung-9/+44
Improve inline asm error diagnostics Previously we were just using the raw LLVM error output (with line, caret, etc) as the diagnostic message, which ends up looking rather out of place with our existing diagnostics. The new diagnostics properly format the diagnostics and also take advantage of LLVM's per-line `srcloc` attribute to map an error in inline assembly directly to the relevant line of source code. Incidentally also fixes #71639 by disabling `srcloc` metadata during LTO builds since we don't know what crate it might have come from. We can only resolve `srcloc`s from the currently crate since it indexes into the source map for the current crate. Fixes #72664 Fixes #71639 r? @petrochenkov ### Old style ```rust #![feature(llvm_asm)] fn main() { unsafe { let _x: i32; llvm_asm!( "mov $0, $1 invalid_instruction $0, $1 mov $0, $1" : "=&r" (_x) : "r" (0) :: "intel" ); } } ``` ``` error: <inline asm>:3:14: error: invalid instruction mnemonic 'invalid_instruction' invalid_instruction ecx, eax ^~~~~~~~~~~~~~~~~~~ --> src/main.rs:6:9 | 6 | / llvm_asm!( 7 | | "mov $0, $1 8 | | invalid_instruction $0, $1 9 | | mov $0, $1" ... | 12 | | :: "intel" 13 | | ); | |__________^ ``` ### New style ```rust #![feature(asm)] fn main() { unsafe { asm!( "mov {0}, {1} invalid_instruction {0}, {1} mov {0}, {1}", out(reg) _, in(reg) 0i64, ); } } ``` ``` error: invalid instruction mnemonic 'invalid_instruction' --> test.rs:7:14 | 7 | invalid_instruction {0}, {1} | ^ | note: instantiated into assembly here --> <inline asm>:3:14 | 3 | invalid_instruction rax, rcx | ^^^^^^^^^^^^^^^^^^^ ```
2020-05-30Rollup merge of #72521 - Amanieu:fix-72484, r=petrochenkovRalf Jung-2/+1
Properly handle InlineAsmOperand::SymFn when collecting monomorphized items Fixes #72484
2020-05-30Make TLS accesses explicit in MIROliver Scherer-0/+8
2020-05-29Rollup merge of #71804 - petrochenkov:static-pie, r=cuviperRalf Jung-134/+122
linker: Support `-static-pie` and `-static -shared` This PR adds support for passing linker arguments for creating statically linked position-independent executables and "statically linked" shared libraries. Therefore it incorporates the majority of https://github.com/rust-lang/rust/pull/70740 except for the linker rerun hack and actually flipping the "`static-pie` is supported" switch for musl targets.
2020-05-29Improve inline asm error diagnosticsAmanieu d'Antras-9/+44
2020-05-28Auto merge of #72494 - lcnr:predicate-cleanup, r=nikomatsakisbors-10/+10
Pass more `Copy` types by value. There are a lot of locations where we pass `&T where T: Copy` by reference, which should both be slightly less performant and less readable IMO. This PR currently consists of three fairly self contained commits: - passes `ty::Predicate` by value and stops depending on `AsRef<ty::Predicate>`. - changes `<&List<_>>::into_iter` to iterate over the elements by value. This would break `List`s of non copy types. But as the only list constructor requires `T` to be copy anyways, I think the improved readability is worth this potential future restriction. - passes `mir::PlaceElem` by value. Mir currently has quite a few copy types which are passed by reference, e.g. `Local`. As I don't have a lot of experience working with MIR, I mostly did this to get some feedback from people who use MIR more frequently - tries to reuse `ty::Predicate` in case it did not change in some places, which should hopefully fix the regression caused by #72055 r? @nikomatsakis for the first commit, which continues the work of #72055 and makes adding `PredicateKind::ForAll` slightly more pleasant. Feel free to reassign though
2020-05-24Removed all instances of const_field.Rakshith Ravi-10/+6
2020-05-24Properly handle InlineAsmOperand::SymFn when collecting monomorphized itemsAmanieu d'Antras-2/+1
Fixes #72484
2020-05-23take mir::PlaceElem by valueBastian Kauschke-9/+9
2020-05-23iterate List by valueBastian Kauschke-1/+1
2020-05-22Use `OnceCell` instead of `Once`Dylan MacKenzie-14/+10
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-27/+32
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-21Auto merge of #72205 - ecstatic-morse:nrvo, r=oli-obkbors-1/+2
Dumb NRVO This is a very simple version of an NRVO pass, which scans backwards from the `return` terminator to see if there is an an assignment like `_0 = _1`. If a basic block with two or more predecessors is encountered during this scan without first seeing an assignment to the return place, we bail out. This avoids running a full "reaching definitions" dataflow analysis. I wanted to see how much `rustc` would benefit from even a very limited version of this optimization. We should be able to use this as a point of comparison for more advanced versions that are based on live ranges. r? @ghost
2020-05-20Factor out `NativeLibKind::Dylib` from `NativeLibKind::Unspecified`Vadim Petrochenkov-4/+7
2020-05-20Rename some types describing native librariesVadim Petrochenkov-27/+29
NativeLibrary(Kind) -> NativeLib(Kind) NativeStatic -> StaticBundle NativeStaticNobundle -> StaticNoBundle NativeFramework -> Framework NativeRawDylib -> RawDylib NativeUnknown -> Unspecified
2020-05-20linker: Support `-static-pie` and `-static -shared`Vadim Petrochenkov-131/+118
2020-05-20rustc_target: Add a target spec option for static-pie supportVadim Petrochenkov-3/+4
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-18Fix const handling and add tests for const operandsAmanieu d'Antras-91/+128
2020-05-18Minor fixesAmanieu d'Antras-1/+2
2020-05-18Move InlineAsmTemplatePiece and InlineAsmOptions to librustc_astAmanieu d'Antras-1/+2
2020-05-18Implement asm! codegenAmanieu d'Antras-2/+137
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-16Name return place in debuginfo if it is a user variableDylan MacKenzie-1/+2
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-14Rollup merge of #72126 - nnethercote:change-WorkProduct-saved_files, ↵Dylan DPC-9/+5
r=alexcrichton Change `WorkProduct::saved_files` to an `Option`. Because there is at most one file. r? @bjorn3
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-12Remove ty::UnnormalizedProjectionJack Huey-1/+0
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-35/+54
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-35/+54
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