Commit graph

8918 commits

Author SHA1 Message Date
bors
a8f6e614f8 Auto merge of #89652 - rcvalle:rust-cfi, r=nagisa
Add LLVM CFI support to the Rust compiler

This PR adds LLVM Control Flow Integrity (CFI) support to the Rust compiler. It initially provides forward-edge control flow protection for Rust-compiled code only by aggregating function pointers in groups identified by their number of arguments.

Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by defining and using compatible type identifiers (see Type metadata in the design document in the tracking issue #89653).

LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto).

Thank you, `@eddyb` and `@pcc,` for all the help!
2021-10-27 09:19:42 +00:00
bors
a9b2bfb5ed Auto merge of #89937 - JohnTitor:fix-89875, r=Amanieu
Properly check `target_features` not to trigger an assertion

Fixes #89875
I think it should be a condition instead of an assertion to check if it's a register as it's possible that `reg` is a register class.
Also, this isn't related to the issue directly, but `is_target_supported` doesn't check `target_features` attributes. Is there any way to check it on rustc_codegen_llvm?

r? `@Amanieu`
2021-10-27 03:08:47 +00:00
bors
c7a30c8b68 Auto merge of #90075 - pierwill:fix-79717, r=petrochenkov
Edit error messages for `rustc_resolve::AmbiguityKind` variants

Edit the language of the ambiguity descriptions for E0659. These strings now appear as notes.

Closes #79717.
2021-10-26 07:57:51 +00:00
Matthias Krüger
fc8df9b0b8
Rollup merge of #90241 - DrMeepster:thiscall_lint_upgrade, r=petrochenkov
Make thiscall abi on unsupported platforms a hard error

As suggested in https://github.com/rust-lang/rust/issues/42202#issuecomment-950205016, this PR makes use of the `thiscall` abi on unsupported a hard error instead of a lint.
2021-10-26 06:14:07 +02:00
Matthias Krüger
b0df3af5c3
Rollup merge of #90181 - notriddle:notriddle/error-pointer, r=estebank
fix(rustc_typeck): report function argument errors on matching type

Fixes #90101
2021-10-26 06:14:06 +02:00
Yuki Okushi
12647eab79
Properly check target_features not to trigger an assertion 2021-10-26 11:02:51 +09:00
Yuki Okushi
630df7c54a
Remove unnecessary check for registers
`is_clobber()` already checks if `reg` is a register and the both
values should be the same.
2021-10-26 11:02:51 +09:00
Yuki Okushi
f5cbb9b9e6
Fix some typos 2021-10-26 11:02:47 +09:00
pierwill
7de1ff1ba8 Edit error messages for rustc_resolve::AmbiguityKind variants
Emit description of the ambiguity as a note.

Co-authored-by: Noah Lev <camelidcamel@gmail.com>
Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
2021-10-25 20:33:07 -05:00
bors
17e13b549f Auto merge of #85830 - bjorn3:separate_provide_extern, r=cjgillot
Avoid a branch on key being local for queries that use the same local and extern providers

Currently based on https://github.com/rust-lang/rust/pull/85810 as it slightly conflicts with it. Only the last two commits are new.
2021-10-26 00:38:58 +00:00
Ramon de C Valle
5d30e93189 Add LLVM CFI support to the Rust compiler
This commit adds LLVM Control Flow Integrity (CFI) support to the Rust
compiler. It initially provides forward-edge control flow protection for
Rust-compiled code only by aggregating function pointers in groups
identified by their number of arguments.

Forward-edge control flow protection for C or C++ and Rust -compiled
code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code
share the same virtual address space) will be provided in later work as
part of this project by defining and using compatible type identifiers
(see Type metadata in the design document in the tracking issue #89653).

LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e.,
-Clto).
2021-10-25 16:23:01 -07:00
DrMeepster
a46daf050b make thiscall on unsupported platforms an error 2021-10-25 14:56:21 -07:00
Matthias Krüger
26e9a719f2
Rollup merge of #90266 - b-naber:uneval_substs, r=lcnr
Prevent duplicate caller bounds candidates by exposing default substs in Unevaluated

Fixes https://github.com/rust-lang/rust/issues/89334

The changes introduced in https://github.com/rust-lang/rust/pull/87280 allowed for "duplicate" caller bounds candidates to be assembled that only differed in their default substs having been "exposed" or not and resulted in an ambiguity error during trait selection. To fix this we expose the defaults substs during the creation of the ParamEnv.

r? `@lcnr`
2021-10-25 22:59:49 +02:00
Matthias Krüger
2f67647606
Rollup merge of #89581 - jblazquez:master, r=Mark-Simulacrum
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-25 22:59:46 +02:00
Michael Howell
8520105464 fix(rustc_typeck): report function argument errors on matching type
Fixes #90101
2021-10-25 12:23:52 -07:00
bors
84c2a8505d Auto merge of #90265 - GuillaumeGomez:rollup-gx3ficp, r=GuillaumeGomez
Rollup of 5 pull requests

Successful merges:

 - #90017 (Add a couple tests for normalize under binder issues)
 - #90079 (enable `i8mm` target feature on aarch64 and arm)
 - #90233 (Tooltip overflow)
 - #90257 (Changed slice.swap documentation for better readability)
 - #90261 (Move back to linux builder on try builds)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-25 14:40:45 +00:00
Guillaume Gomez
bd48b9975a
Rollup merge of #90079 - SparrowLii:i8mm, r=Amanieu
enable `i8mm` target feature on aarch64 and arm

As in https://github.com/rust-lang/stdarch/issues/1233, `i8mm` needs to be turned on to support the implementation of `vmmla` and `vusmmla`neon instructions in stdarch.
r? ``@Amanieu``
2021-10-25 16:34:52 +02:00
b-naber
c6b69017e2 expose default substs in param_env 2021-10-25 16:04:57 +02:00
bjorn3
f5c3e83013 Avoid a branch on key being local for queries that use the same local and extern providers 2021-10-25 13:36:23 +02:00
bors
235d9853d8 Auto merge of #90042 - pietroalbini:1.56-master, r=Mark-Simulacrum
Bump bootstrap compiler to 1.57

Fixes https://github.com/rust-lang/rust/issues/90152

r? `@Mark-Simulacrum`
2021-10-25 11:31:47 +00:00
bors
32f3887b9b Auto merge of #90249 - matthiaskrgr:rollup-xwtfhq3, r=matthiaskrgr
Rollup of 4 pull requests

Successful merges:

 - #89889 (Use the "nice E0277 errors"[1] for `!Send` `impl Future` from foreign crate)
 - #90127 (Do not mention a reexported item if it's private)
 - #90143 (tidy: Remove submodules from edition exception list)
 - #90238 (Add alias for guillaume.gomez@huawei.com)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-25 08:22:07 +00:00
SparrowLii
b88fcc1ea3 enable i8mm on arm 2021-10-25 15:10:14 +08:00
SparrowLii
14007eca0a enable i8mm target feature on aarch64 2021-10-25 14:18:42 +08:00
Matthias Krüger
c734a9e076
Rollup merge of #90127 - JohnTitor:fix-90113, r=estebank
Do not mention a reexported item if it's private

Fixes #90113
The _actual_ regression was introduced in #73652, then #88838 made it worse. This fixes the issue by not counting such an import as a candidate.
2021-10-25 07:54:13 +02:00
Matthias Krüger
b25172b504
Rollup merge of #89889 - estebank:unmet-send-bound-on-foreign-future, r=tmandry
Use the "nice E0277 errors"[1] for `!Send` `impl Future` from foreign crate

Partly address #78543 by making the error quieter.

We don't have access to the `typeck` tables from foreign crates, so we
used to completely skip the new code when checking foreign crates. Now,
we carry on and don't provide as nice output (we don't clarify *what* is
making the `Future: !Send`), but at least we no longer emit a sea of
derived obligations in the output.

[1]: https://blog.rust-lang.org/inside-rust/2019/10/11/AsyncAwait-Not-Send-Error-Improvements.html

r? `@tmandry`
2021-10-25 07:54:12 +02:00
bors
56694b0453 Auto merge of #89808 - tmiasko:llvm-multithreaded, r=nagisa
Cleanup LLVM multi-threading checks

The support for runtime multi-threading was removed from LLVM. Calls to
`LLVMStartMultithreaded` became no-ops equivalent to checking if LLVM
was compiled with support for threads http://reviews.llvm.org/D4216.
2021-10-25 05:28:07 +00:00
bors
28d0e75269 Auto merge of #90210 - cjgillot:qarray2, r=Mark-Simulacrum
Build the query vtable directly.

Continuation of https://github.com/rust-lang/rust/pull/89978.

This shrinks the query interface and attempts to reduce the amount of function pointer calls.
2021-10-25 01:10:50 +00:00
bors
41d8c94d45 Auto merge of #89427 - estebank:collect-overlapping-impls, r=jackh726
Point at overlapping impls when type annotations are needed

Address https://github.com/rust-lang/rust/issues/89254.
2021-10-24 22:26:41 +00:00
Esteban Kuber
6dcff4e9f6 Use the "nice E0277 errors"[1] for !Send impl Future from foreign crate
Partly address #78543 by making the error quieter.

We don't have access to the `typeck` tables from foreign crates, so we
used to completely skip the new code when checking foreign crates. Now,
we carry on and don't provide as nice output (we don't clarify *what* is
making the `Future: !Send`), but at least we no longer emit a sea of
derived obligations in the output.

[1]: https://blog.rust-lang.org/inside-rust/2019/10/11/AsyncAwait-Not-Send-Error-Improvements.html
2021-10-24 20:45:33 +00:00
Esteban Kuber
881a50c0b7 Always sort suggestions before emitting them 2021-10-24 20:28:44 +00:00
Esteban Kuber
ef212e7fb3 Point at overlapping impls when type annotations are needed 2021-10-24 18:33:04 +00:00
bors
00d5e42e77 Auto merge of #90235 - matthiaskrgr:rollup-7pqtevk, r=matthiaskrgr
Rollup of 6 pull requests

Successful merges:

 - #89558 (Add rustc lint, warning when iterating over hashmaps)
 - #90100 (Skip documentation for tier 2 targets on dist-x86_64-apple-darwin)
 - #90155 (Fix alignment of method headings for scannability)
 - #90162 (Mark `{array, slice}::{from_ref, from_mut}` as const fn)
 - #90221 (Fix ICE when forgetting to `Box` a parameter to a `Self::func` call)
 - #90234 (Temporarily turn overflow checks off for rustc-rayon-core)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-24 14:12:10 +00:00
Matthias Krüger
d576393e34
Rollup merge of #90221 - JakobDegen:issue-90213, r=cjgillot
Fix ICE when forgetting to `Box` a parameter to a `Self::func` call

Closes #90213 .

Assuming we can get the `DefId` of the receiver causes an ICE if the receiver is `Self`. We can just avoid doing this though.
2021-10-24 15:48:45 +02:00
Matthias Krüger
87822b27ee
Rollup merge of #89558 - lcnr:query-stable-lint, r=estebank
Add rustc lint, warning when iterating over hashmaps

r? rust-lang/wg-incr-comp
2021-10-24 15:48:42 +02:00
bors
ed08a67566 Auto merge of #85254 - cjgillot:reveal-mir, r=lcnr
Normalize MIR with RevealAll before optimizations.

Fixes #78442
2021-10-24 11:04:54 +00:00
bors
bdcb528512 Auto merge of #90208 - Mark-Simulacrum:hash-bytes-fast, r=oli-obk
Specialize HashStable for [u8] slices

Particularly for ctfe-stress-4, the hashing of byte slices as part of the
MIR Allocation is quite hot. Previously, we were falling back on byte-by-byte
copying of the slice into the SipHash buffer (64 bytes long) before hashing a 64
byte chunk, and then doing that again and again; now we use the dedicated byte-slice write.
2021-10-24 06:29:41 +00:00
Jakob Degen
4b970231fd Fix ICE when forgetting to Box a parameter to a Self::func call 2021-10-24 00:33:29 -04:00
Dylan MacKenzie
abd3fe347b Ignore errors re: unreachable blocks in dataflow cursor unit tests 2021-10-23 21:55:57 -04:00
Pietro Albini
b63ab8005a update cfg(bootstrap) 2021-10-23 21:55:57 -04:00
bors
45591408b1 Auto merge of #90175 - cuviper:min-llvm-12, r=nagisa
Update the minimum external LLVM to 12

With this change, we'll have stable support for LLVM 12 and 13.
For reference, the previous increase to LLVM 10 was #83387,
and this replaces the pending increase to LLVM 11 in #90062.

r? `@nagisa` `@nikic`
2021-10-23 20:59:29 +00:00
Camille GILLOT
138e96b719 Do not require QueryCtxt for cache_on_disk. 2021-10-23 18:12:43 +02:00
Mark Rousskov
3cd5c95ab0 Specialize HashStable for [u8] slices
Particularly for ctfe-stress-4, the hashing of byte slices as part of the
MIR Allocation is quite hot. Previously, we were falling back on byte-by-byte
copying of the slice into the SipHash buffer (64 bytes long) before hashing a 64
byte chunk, and then doing that again and again.

This should hopefully be an improvement for that code.
2021-10-23 12:11:05 -04:00
bors
91b931926f Auto merge of #90203 - matthiaskrgr:rollup-v215wew, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #85833 (Scrape code examples from examples/ directory for Rustdoc)
 - #88041 (Make all proc-macro back-compat lints deny-by-default)
 - #89829 (Consider types appearing in const expressions to be invariant)
 - #90168 (Reset qualifs when a storage of a local ends)
 - #90198 (Add caveat about changing parallelism and function call overhead)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-10-23 15:53:50 +00:00
Camille GILLOT
7c0920f5fb Build the query vtable directly. 2021-10-23 16:59:19 +02:00
Matthias Krüger
74a0c492c1
Rollup merge of #90168 - tmiasko:const-qualif-storage, r=matthewjasper
Reset qualifs when a storage of a local ends

Reset qualifs when a storage of a local ends to ensure that the local qualifs
are affected by the state from previous loop iterations only if the local is
kept alive.

The change should be forward compatible with a stricter handling of indirect
assignments, since storage dead invalidates all existing pointers to the local.
2021-10-23 14:58:42 +02:00
Matthias Krüger
2b874f0242
Rollup merge of #89829 - voidc:assoc-const-variance, r=lcnr
Consider types appearing in const expressions to be invariant

This is an approach to fix #80977.
Currently, a type parameter which is only used in a constant expression is considered bivariant and will trigger error E0392 *"parameter T is never used"*.
Here is a short example:

```rust
pub trait Foo {
    const N: usize;
}

struct Bar<T: Foo>([u8; T::N])
where [(); T::N]:;
```
([playgound](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2015&gist=b51a272853f75925e72efc1597478aa5))

While it is possible to silence this error by adding a `PhantomData<T>` field, I think the better solution would be to make `T` invariant.
This would be analogous to the invariance constraints added for associated types.
However, I'm quite new to the compiler and unsure whether this is the right approach.

r? ``@varkor`` (since you authored #60058)
2021-10-23 14:58:41 +02:00
Matthias Krüger
17c602d423
Rollup merge of #88041 - Aaron1011:deny-proc-macro-hack, r=wesleywiser
Make all proc-macro back-compat lints deny-by-default

The affected crates have had plenty of time to update.
By keeping these as lints rather than making them hard errors,
we ensure that downstream crates will still be able to compile,
even if they transitive depend on broken versions of the affected
crates.

This should hopefully discourage anyone from writing any
new code which relies on the backwards-compatibility behavior.
2021-10-23 14:58:40 +02:00
bors
aa5740c715 Auto merge of #90104 - spastorino:coherence-for-negative-trait, r=nikomatsakis
Implement coherence checks for negative trait impls

The main purpose of this PR is to be able to [move Error trait to core](https://github.com/rust-lang/project-error-handling/issues/3).

This feature is necessary to handle the following from impl on box.

```rust
impl From<&str> for Box<dyn Error> { ... }
```

Without having negative traits affect coherence moving the error trait into `core` and moving that `From` impl to `alloc` will cause the from impl to no longer compiler because of a potential future incompatibility. The compiler indicates that `&str` _could_ introduce an `Error` impl in the future, and thus prevents the `From` impl in `alloc` that would cause overlap with `From<E: Error> for Box<dyn Error>`. Adding `impl !Error for &str {}` with the negative trait coherence feature will disable this error by encoding a stability guarantee that `&str` will never implement `Error`, making the `From` impl compile.

We would have this in `alloc`:

```rust
impl From<&str> for Box<dyn Error> {} // A
impl<E> From<E> for Box<dyn Error> where E: Error {} // B
```

and this in `core`:

```rust
trait Error {}
impl !Error for &str {}
```

r? `@nikomatsakis`

This PR was built on top of `@yaahc` PR #85764.

Language team proposal: to https://github.com/rust-lang/lang-team/issues/96
2021-10-23 12:51:15 +00:00
Santiago Pastorino
3287f72d39
Avoid code duplication by extracting checks into fns 2021-10-23 08:55:48 -03:00
bors
55ccbd090d Auto merge of #90065 - cjgillot:novalcache, r=Mark-Simulacrum
Do not depend on the stored value when trying to cache on disk.

Having different criteria for loading and saving of query results can lead to saved results that may never be loaded.
Since the on-disk cache is discarded as soon as a compilation error is issued, there should not be any need for an exclusion mecanism based on errors.

As a result, the possibility to condition the storage on the value itself does not appear useful.
2021-10-23 09:21:45 +00:00