about summary refs log tree commit diff
path: root/src/librustc_codegen_ssa/back/write.rs
AgeCommit message (Collapse)AuthorLines
2020-08-30mv compiler to compiler/mark-1859/+0
2020-08-08Auto merge of #74932 - nnethercote:rm-ast-session-globals, r=petrochenkovbors-5/+5
Remove `librustc_ast` session globals By moving the data onto `Session`. r? @petrochenkov
2020-08-08Eliminate the `SessionGlobals` from `librustc_ast`.Nicholas Nethercote-5/+5
By moving `{known,used}_attrs` from `SessionGlobals` to `Session`. This means they are accessed via the `Session`, rather than via TLS. A few `Attr` methods and `librustc_ast` functions are now methods of `Session`. All of this required passing a `Session` to lots of functions that didn't already have one. Some of these functions also had arguments removed, because those arguments could be accessed directly via the `Session` argument. `contains_feature_attr()` was dead, and is removed. Some functions were moved from `librustc_ast` elsewhere because they now need to access `Session`, which isn't available in that crate. - `entry_point_type()` --> `librustc_builtin_macros` - `global_allocator_spans()` --> `librustc_metadata` - `is_proc_macro_attr()` --> `Session`
2020-08-08fix clippy::map_clone: use .cloned() instead of .map(|x| x.clone())Matthias Krüger-1/+1
2020-07-29MinGW: emit dllexport/dllimport by rustcMateusz Mikuła-2/+2
This fixes various cases where LD could not guess dllexport correctly and greatly improves compatibility with LLD which is not going to support linker scripts anytime soon
2020-06-19Rollup merge of #73347 - tmiasko:incompatible-sanitizers, r=nikicManish Goregaokar-6/+6
Diagnose use of incompatible sanitizers Emit an error when incompatible sanitizer are configured through command line options. Previously the last one configured prevailed and others were silently ignored. Additionally use a set to represent configured sanitizers, making it possible to enable multiple sanitizers at once. At least in principle, since currently all of them are considered to be incompatible with others.
2020-06-15[WIP] injects llvm intrinsic instrprof.increment for coverage reportsRich Kadel-0/+6
This initial version only injects counters at the top of each function. Rust Coverage will require injecting additional counters at each conditional code branch.
2020-06-14Diagnose use of incompatible sanitizersTomasz Miąsko-6/+6
Emit an error when incompatible sanitizer are configured through command line options. Previously the last one configured prevailed and others were silently ignored. Additionally use a set to represent configured sanitizers, making it possible to enable multiple sanitizers at once. At least in principle, since currently all of them are considered to be incompatible with others.
2020-06-09Handle assembler warnings properlyAmanieu d'Antras-7/+13
2020-05-29Improve inline asm error diagnosticsAmanieu d'Antras-6/+33
2020-05-22Use `OnceCell` instead of `Once`Dylan MacKenzie-3/+3
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-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-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-12Change `WorkProduct::saved_files` to an `Option`.Nicholas Nethercote-9/+5
Because there is at most one file.
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-7/+6
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-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-29/+3
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-29/+3
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-26codegen_llvm: Simplify logic for relaxing PIC into PIEVadim Petrochenkov-1/+1
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-22Add a new option `-Cbitcode-in-rlib`.Nicholas Nethercote-1/+2
It defaults to true, but Cargo will set this to false whenever it can to reduce compile times.
2020-04-20Ignore -Zprofile when building compiler_builtinsAmanieu d'Antras-5/+18
2020-04-19Replace uses of `parse_opt_*` with `parse_*` where possible.Nicholas Nethercote-1/+1
This lets us specify the default at the options declaration point, instead of using `.unwrap(default)` or `None | Some(default)` at some use point far away. It also makes the code more concise.
2020-04-11Rollup merge of #70644 - nnethercote:clean-up-ModuleConfig-init, ↵Dylan DPC-162/+140
r=Mark-Simulacrum Clean up `ModuleConfig` initialization Because it's currently a mess. r? @Mark-Simulacrum
2020-04-07Use assoc integer constants in librustc_*Linus Färnstrand-1/+1
2020-04-01Rename `modules_config` as `regular_config`.Nicholas Nethercote-4/+4
That way it matches `ModuleKind::Regular`.
2020-04-01Improve `ModuleConfig` initialization.Nicholas Nethercote-152/+137
There are three `ModuleConfigs`, one for each `ModuleKind`. The code to initialized them is spaghetti imperative code that sets each field to a default value and then modifies many fields in complicated ways. This makes it very hard to tell what value ends up in each field in each config. For example, the `modules_config.emit_pre_lto_bc` field is set twice, which means it can be set to true and then incorrectly set back to false. (This probably hasn't been noticed because it happens in a very obscure case.) This commit changes the code to a declarative style in which `ModuleConfig::new` initializes all fields and then they are never changed again. This is slightly more concise and much easier to read. (And it fixes the abovementioned `emit_pre_lto_bc` error as well.)
2020-04-01Remove some dead code.Nicholas Nethercote-7/+0
The condition checks if `sess.opts.output_types` doesn't contain `OutputType::Assembly` within a match arm that is only reached if `sess.opts.output_types` contains `OutputType::Assembly`.
2020-03-30rustc -> rustc_middle part 3 (rustfmt)Mazdak Farrokhzad-4/+4
2020-03-30rustc -> rustc_middle part 2Mazdak Farrokhzad-4/+4
2020-03-27Remove `no_integrated_as` mode.Nicholas Nethercote-65/+1
Specifically, remove both `-Z no_integrated_as` and `TargetOptions::no_integrated_as`. The latter was only used for the `msp430_none_elf` platform, for which it's no longer required.
2020-03-26Introduce `EmitObj`.Nicholas Nethercote-32/+49
Currently, there are three fields in `ModuleConfig` that dictate how object files are emitted: `emit_obj`, `obj_is_bitcode`, and `embed_bitcode`. Some of the combinations of these fields are nonsensical, in particular having both `obj_is_bitcode` and `embed_bitcode` true at the same time. Also, currently: - we needlessly emit and then delete a bytecode file if `obj_is_bitcode` is true but `emit_obj` is false; - we needlessly embed bitcode in the LLVM module if `embed_bitcode` is true and `emit_obj` is false. This commit combines the three fields into one, with a new type `EmitObj` (and the auxiliary `BitcodeSection`) which can encode five different possibilities. In the old code, `set_flags` would set `obj_is_bitcode` and `embed_bitcode` on all three of the configs (`modules`, `allocator`, `metadata`) if the relevant other conditions were met, even if no object code needed to be emitted for one or more of them. Whereas `start_async_codegen` would set `emit_obj`, but only for those configs that need it. In the new code, `start_async_codegen` does all the work of setting `emit_obj`, and it only does that for the configs that need it. `set_flags` no longer sets anything related to object file emission.
2020-03-25Remove `TargetOptions::embed_bitcode`.Nicholas Nethercote-9/+8
It's unused by any existing targets, and soon we'll be embedding full bitcode by default anyway.
2020-03-24Rollup merge of #70289 - nnethercote:refactor-codegen, r=eddybMazdak Farrokhzad-17/+22
Refactor `codegen` `codegen` in `src/librustc_codegen_llvm/back/write.rs` is long and has complex control flow. These commits refactor it and make it easier to understand.
2020-03-23Combine `ModuleConfig::embed_bitcode{,_marker}`.Nicholas Nethercote-14/+22
Because the `(true, true)` combination isn't valid.
2020-03-22don't create variable bindings just to return the bound value immediately ↵Matthias Krüger-4/+2
(clippy::let_and_return)
2020-03-19Remove unused `ModuleConfig::emit_lto_bc` field.Nicholas Nethercote-3/+0
2020-03-16use direct imports for `rustc::{lint, session}`.Mazdak Farrokhzad-4/+4
2020-03-14Update `krate_attrs` and `get_module`John Kåre Alsaker-2/+2
2020-03-06fix various typosMatthias Krüger-1/+1