Commit Graph

62 Commits

Author SHA1 Message Date
Alex Crichton 7f23e6e8d7
rustc: Link LLVM directly into rustc again
This commit builds on #65501 continue to simplify the build system and
compiler now that we no longer have multiple LLVM backends to ship by
default. Here this switches the compiler back to what it once was long
long ago, which is linking LLVM directly to the compiler rather than
dynamically loading it at runtime. The `codegen-backends` directory of
the sysroot no longer exists and all relevant support in the build
system is removed. Note that `rustc` still supports a dynamically loaded
codegen backend as it did previously, it just no longer supports
dynamically loaded codegen backends in its own sysroot.

Additionally as part of this the `librustc_codegen_llvm` crate now once
again explicitly depends on all of its crates instead of implicitly
loading them through the sysroot. This involved filling out its
`Cargo.toml` and deleting all the now-unnecessary `extern crate`
annotations in the header of the crate. (this in turn required adding a
number of imports for names of macros too).

The end results of this change are:

* Rustbuild's build process for the compiler as all the "oh don't forget
  the codegen backend" checks can be easily removed.
* Building `rustc_codegen_llvm` is much simpler since it's simply
  another compiler crate.
* Managing the dependencies of `rustc_codegen_llvm` is much simpler since
  it's "just another `Cargo.toml` to edit"
* The build process should be a smidge faster because there's more
  parallelism in the main rustc build step rather than splitting
  `librustc_codegen_llvm` out to its own step.
* The compiler is expected to be slightly faster by default because the
  codegen backend does not need to be dynamically loaded.
* Disabling LLVM as part of rustbuild is still supported, supporting
  multiple codegen backends is still supported, and dynamic loading of a
  codegen backend is still supported.
2019-12-11 09:50:11 -05:00
varkor e3a8ea4e18 Use `to_option` in various places 2019-12-06 12:23:23 +00:00
Eduard-Mihai Burtescu 79d908b301 rustc_target: add abi::call::Conv::Rust distinct from Conv::C. 2019-12-03 15:55:21 +02:00
Eduard-Mihai Burtescu e93aa104ab rustc_codegen_llvm: privatize as much of attributes::* as possible. 2019-12-03 15:55:21 +02:00
Eduard-Mihai Burtescu cd3c324b07 rustc_codegen_llvm: take an Instance in attributes::from_fn_attrs. 2019-12-03 15:55:21 +02:00
Eduard-Mihai Burtescu 95b944210f rustc_codegen_ssa: take a FnAbi instead of a FnSig in declare_fn. 2019-12-03 15:28:18 +02:00
Nicholas Nethercote b9cef6984b Simplify various `Symbol` use points.
Including removing a bunch of unnecessary `.as_str()` calls, and a bunch
of unnecessary sigils.
2019-11-02 09:01:02 +11:00
Ralf Jung 79c623f146 some typography 2019-10-12 20:44:05 +02:00
Ralf Jung 9a0b9c6960 remove old branch of unwind logic 2019-10-12 19:46:03 +02:00
bors 4b42e919d6 Auto merge of #65020 - pnkfelix:targetted-fix-for-always-marking-rust-abi-unwind-issue-64655, r=alexcrichton
Always mark rust and rust-call abi's as unwind

PR #63909 identified a bug that had been injected by PR #55982. As discussed on https://github.com/rust-lang/rust/issues/64655#issuecomment-537517428 , we started marking extern items as nounwind, *even* extern items that said they were using "Rust" or "rust-call" ABI.

This is a more targeted variant of PR #63909 that fixes the above bug.

Fix #64655

----

I personally suspect we will want PR #63909 to land in the long-term

But:
 *  it is not certain that PR #63909 *will* land,
 * more importantly, PR #63909 almost certainly will not be backported to beta/stable.

The identified bug was more severe than I think anyone realized (apart from perhaps @gnzlbg, as noted [here](https://github.com/rust-lang/rust/pull/63909#issuecomment-524818838)).

Thus, I was motivated to write this PR, which fixes *just* the issue with extern rust/rust-call functions, and deliberately avoids injecting further deviation from current behavior (you can see further notes on this in the comments of the code added here).
2019-10-12 02:31:03 +00:00
Tomasz Miąsko 6c9f218f3e Disable stack probe when thread sanitizer is enabled
When thread sanitizer instrumentation is enabled during compilation of
stack probe function, the function will be miscompiled and trigger
segmentation fault at runtime. Disable stack probes when tsan is
enabled.
2019-10-04 16:13:29 +02:00
Felix S Klock II 5e7e8cd41f
Update attributes.rs
Some comment refinements inspired by review feedback.
2019-10-03 11:08:28 +02:00
Felix S Klock II e7e6dec06a
Apply suggestions from code review
Co-Authored-By: Mazdak Farrokhzad <twingoow@gmail.com>
Co-Authored-By: Ralf Jung <post@ralfj.de>
2019-10-03 10:46:01 +02:00
Felix S. Klock II 9fbb2a9b34 Fix missing calls to drop on unwind with lto=fat; issue 64655. 2019-10-02 21:52:15 +02:00
Nikita Popov b57c499ea2 Translate target features for LLVM 9 2019-07-09 21:55:29 +02:00
Michael Woerister b7fe2ca5e0 Stabilize profile-guided optimization. 2019-06-21 09:54:58 +02:00
Eduard-Mihai Burtescu f3f9d6dfd9 Unify all uses of 'gcx and 'tcx. 2019-06-14 18:58:23 +03:00
Eduard-Mihai Burtescu 17cdd356da rustc: replace `TyCtxt<'tcx, 'gcx, 'tcx>` with `TyCtxt<'gcx, 'tcx>`. 2019-06-12 13:38:27 +03:00
John Kåre Alsaker 46f2511296 Update wasm_import_module_map and target_features_whitelist 2019-05-23 18:51:50 +02:00
Nicholas Nethercote fb084a48e2 Pass a `Symbol` to `check_name`, `emit_feature_err`, and related functions. 2019-05-13 09:29:22 +10:00
Michael Woerister 7b1df42acc Clean up handling of -Zpgo-gen commandline option. 2019-04-11 14:50:32 +02:00
Yuki OKUSHI 77774e4e96 Use CString 2019-03-30 21:37:02 +09:00
Yuki OKUSHI 3281248b88 Use target_mcount 2019-03-30 18:50:34 +09:00
Yuki OKUSHI 261a91519d Use platform dependent mcount function 2019-03-29 06:44:31 +09:00
Mazdak Farrokhzad 9661a81968 librustc_codegen_llvm: deny(elided_lifetimes_in_paths) 2019-02-25 08:40:18 +01:00
gnzlbg c4b46ace55 Implement ffi_returns_twice attribute 2019-02-23 15:48:40 +01:00
Taiki Endo 1b7ca961d9 librustc_codegen_llvm => 2018 2019-02-18 03:58:58 +09:00
Simonas Kazlauskas ce289c6c99 Resolve breakage 2019-01-25 19:20:38 +02:00
Simonas Kazlauskas 4d97b28893 Support revisions for codegen tests
`compile-flags: -Copt-level` will avoid adding -O. Similarly for -g and
-Cdebuglevel.
2019-01-24 20:13:51 +02:00
Simonas Kazlauskas f38d0da893 Implement optimize(size) and optimize(speed) 2019-01-24 20:13:50 +02:00
Jun Wu 31a5066e0b Add `-Z instrument-mcount`
This flag inserts `mcount` function call to the beginning of every function
after inline processing. So tracing tools like uftrace [1] (or ftrace for
Linux kernel modules) have a chance to examine function calls.

It is similar to the `-pg` flag provided by gcc or clang, but without
generating a `__gmon_start__` function for executables. If a program
runs without being traced, no `gmon.out` will be written to disk.

Under the hood, it simply adds `"instrument-function-entry-inlined"="mcount"`
attribute to every function. The `post-inline-ee-instrument` LLVM pass does
the actual job.

[1]: https://github.com/namhyung/uftrace
2018-12-30 11:59:03 -08:00
Mark Rousskov 2a663555dd Remove licenses 2018-12-25 21:08:33 -07:00
kennytm 4f0f1102bf
Rollup merge of #56609 - michaelwoerister:unconditional-target-cpu-attr, r=alexcrichton
Unconditionally emit the target-cpu LLVM attribute.

This PR makes `rustc` always emit the `target-cpu` LLVM attribute for functions. The goal is to allow for cross-language inlining of functions defined in `libstd`. So far `libstd` functions were the only function without a `target-cpu` attribute, so in whole-crate-graph cross-lang LTO scenarios they were not eligible for inlining into foreign code.

r? @alexcrichton
2018-12-14 22:10:04 +08:00
Alex Crichton 1091eee65b rustc: Switch `extern` functions to abort by default on panic
This was intended to land way back in 1.24, but it was backed out due to
breakage which has long since been fixed. An unstable `#[unwind]`
attribute can be used to tweak the behavior here, but this is currently
simply switching rustc's internal default to abort-by-default if an
`extern` function panics, making our codegen sound primarily (as
currently you can produce UB with safe code)

Closes #52652
2018-12-12 08:07:28 -08:00
Alexander Regueiro ee89c088b0 Various minor/cosmetic improvements to code 2018-12-07 23:53:34 +00:00
Michael Woerister 86822eb940 Unconditionally emit the target-cpu LLVM attribute. 2018-12-07 13:51:03 -05:00
Eduard-Mihai Burtescu 0b569249c8 [eddyb] rustc_codegen_ssa: rename `interfaces` to `traits`. 2018-11-16 15:08:18 +02:00
Denis Merigoux 015e4441f5 Finished moving backend-agnostic code to rustc_codegen_ssa 2018-11-16 15:08:18 +02:00
Denis Merigoux 6a993fe353 Generalized mir::codegen_mir (and all subsequent functions) 2018-11-16 14:33:10 +02:00
Denis Merigoux 9c41e1aa10 Removed genericity over Value in various functions
Prelude to using associated types in traits rather than type parameters
2018-11-16 14:11:34 +02:00
Denis Merigoux 34c5dc045f Generalized base.rs#call_memcpy and everything that it uses
Generalized operand.rs#nontemporal_store and fixed tidy issues

Generalized operand.rs#nontemporal_store's implem even more
With a BuilderMethod trait implemented by Builder for LLVM

Cleaned builder.rs : no more code duplication, no more ValueTrait

Full traitification of builder.rs
2018-11-16 14:11:09 +02:00
bors ca2639e82e Auto merge of #55014 - ljedrz:lazyboye_unwraps, r=matthewjasper
Prefer unwrap_or_else to unwrap_or in case of function calls/allocations

The contents of `unwrap_or` are evaluated eagerly, so it's not a good pick in case of function calls and allocations. This PR also changes a few `unwrap_or`s with `unwrap_or_default`.

An added bonus is that in some cases this change also reveals if the object it's called on is an `Option` or a `Result` (based on whether the closure takes an argument).
2018-10-20 11:22:48 +00:00
Oliver Scherer ee81739dc1 Deprecate the `FxHashMap()` and `FxHashSet()` constructor function hack 2018-10-19 14:34:44 +02:00
ljedrz d28aed6dc4 Prefer unwrap_or_else to unwrap_or in case of function calls/allocations 2018-10-19 09:45:45 +02:00
bors 77af314083 Auto merge of #54592 - GabrielMajeri:no-plt, r=nagisa
Support for disabling PLT for better function call performance

This PR gives `rustc` the ability to skip the PLT when generating function calls into shared libraries. This can improve performance by reducing branch indirection.

AFAIK, the only advantage of using the PLT is to allow for ELF lazy binding. However, since Rust already [enables full relro for security](https://github.com/rust-lang/rust/pull/43170), lazy binding was disabled anyway.

This is a little known feature which is supported by [GCC](https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html) and [Clang](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-fplt) as `-fno-plt` (some Linux distros [enable it by default](https://git.archlinux.org/svntogit/packages.git/tree/trunk/makepkg.conf?h=packages/pacman#n40) for all builds).

Implementation inspired by [this patch](https://reviews.llvm.org/D39079#change-YvkpNDlMs_LT) which adds `-fno-plt` support to Clang.

## Performance

I didn't run a lot of benchmarks, but these are the results on my machine for a `clap` [benchmark](https://github.com/clap-rs/clap/blob/master/benches/05_ripgrep.rs):

```
 name              control ns/iter  no-plt ns/iter  diff ns/iter  diff %  speedup
 build_app_long    11,097           10,733                  -364  -3.28%   x 1.03
 build_app_short   11,089           10,742                  -347  -3.13%   x 1.03
 build_help_long   186,835          182,713               -4,122  -2.21%   x 1.02
 build_help_short  80,949           78,455                -2,494  -3.08%   x 1.03
 parse_clean       12,385           12,044                  -341  -2.75%   x 1.03
 parse_complex     19,438           19,017                  -421  -2.17%   x 1.02
 parse_lots        431,493          421,421              -10,072  -2.33%   x 1.02
```

A small performance improvement across the board, with no downsides. It's likely binaries which make a lot of function calls into dynamic libraries could see even more improvements. [This comment](https://patchwork.ozlabs.org/patch/468993/#1028255) suggests that, in some cases, `-fno-plt` could improve PIC/PIE code performance by 10%.

## Security benefits

**Bonus**: some of the speculative execution attacks rely on the PLT, by disabling it we reduce a big attack surface and reduce the need for [`retpoline`](https://reviews.llvm.org/D41723).

## Remaining PLT calls

The compiled binaries still have plenty of PLT calls, coming from C/C++ libraries. Building dependencies with `CFLAGS=-fno-plt CXXFLAGS=-fno-plt` removes them.
2018-10-11 19:38:15 +00:00
Gabriel Majeri 6009da0794 Support for disabling the PLT on ELF targets
Disable the PLT where possible to improve performance
for indirect calls into shared libraries.

This optimization is enabled by default where possible.

- Add the `NonLazyBind` attribute to `rustllvm`:
  This attribute informs LLVM to skip PLT calls in codegen.

- Disable PLT unconditionally:
  Apply the `NonLazyBind` attribute on every function.

- Only enable no-plt when full relro is enabled:
  Ensures we only enable it when we have linker support.

- Add `-Z plt` as a compiler option
2018-10-11 21:11:00 +03:00
ljedrz 0af79143ae codegen_llvm: improve common patterns 2018-10-08 19:17:24 +02:00
ljedrz cd41765851 codegen_llvm: improve allocations 2018-10-08 16:55:04 +02:00
kennytm 6b55f04725
Rollup merge of #52514 - DiamondLovesYou:amdgpu-fixes, r=eddyb
Fix a few AMDGPU related issues

* AMDGPU ignores `noinline` and sadly doesn't clear the attribute when it slaps `alwaysinline` on everything,
* an AMDGPU related load bit range metadata assertion,
* I didn't enable the `amdgpu` component in the `librustc_llvm` build script,
* Add AMDGPU call abi info.
2018-09-12 12:17:22 +08:00
Alex Crichton 1fd45a13de Fix warnings about the `native` target-cpu
This fixes a regression from #53031 where specifying `-C target-cpu=native` is
printing a lot of warnings from LLVM about `native` being an unknown CPU. It
turns out that `native` is indeed an unknown CPU and we have to perform a
mapping to an actual CPU name, but this mapping is only performed in one
location rather than all locations we inform LLVM about the target CPU.

This commit centralizes the mapping of `native` to LLVM's value of the native
CPU, ensuring that all locations we inform LLVM about the `target-cpu` it's
never `native`.

Closes #53322
2018-08-28 13:32:11 -07:00