Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync rustc_codegen_gcc #92457

Merged
merged 45 commits into from
Jan 1, 2022
Merged

Sync rustc_codegen_gcc #92457

merged 45 commits into from
Jan 1, 2022

Conversation

bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Dec 31, 2021

r? @ghost

cc @antoyo

@rustbot label +A-codegen +A-gcc +T-compiler

cjgillot and others added 30 commits September 30, 2021 20:22
Before this commit all vtables would have the same name "vtable" in
debuginfo. Now they get a name that identifies the implementing type
and the trait that is being implemented.
…info, r=wesleywiser

Create more accurate debuginfo for vtables.

Before this PR all vtables would have the same name (`"vtable"`) in debuginfo. Now they get an unambiguous name that identifies the implementing type and the trait that is being implemented.

This is only one of several possible improvements:
- This PR describes vtables as arrays of `*const u8` pointers. It would nice to describe them as structs where function pointer is represented by a field with a name indicative of the method it maps to. However, this requires coming up with a naming scheme that avoids clashes between methods with the same name (which is possible if the vtable contains multiple traits).
- The PR does not update the debuginfo we generate for the vtable-pointer field in a fat `dyn` pointer. Right now there does not seem to be an easy way of getting ahold of a vtable-layout without also knowing the concrete self-type of a trait object.

r? `@wesleywiser`
As per the libs team decision in rust-lang#58935.

Closes rust-lang#58935
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 rust-lang#89653).

LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e.,
-Clto).
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 rust-lang#89653).

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

Thank you, `@eddyb` and `@pcc,` for all the help!
* Rebase fallout.

* Move rustc_middle::middle::cstore to rustc_session.

* Create more accurate debuginfo for vtables.

Before this commit all vtables would have the same name "vtable" in
debuginfo. Now they get a name that identifies the implementing type
and the trait that is being implemented.

* Remove alloc::prelude

As per the libs team decision in rust-lang#58935.

Closes rust-lang#58935

* Make hash_result an Option.

* Properly check `target_features` not to trigger an assertion

* 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 rust-lang#89653).

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

* Update to nightly-2021-10-30

* Add deduplication of constant values as rustc relies on LLVM doing that

Co-authored-by: Camille GILLOT <gillot.camille@gmail.com>
Co-authored-by: Michael Woerister <michaelwoerister@posteo>
Co-authored-by: Amanieu d'Antras <amanieu@gmail.com>
Co-authored-by: Yuki Okushi <yuki.okushi@huawei.com>
Co-authored-by: Ramon de C Valle <rcvalle@users.noreply.github.com>
fix sparc64 ABI for aggregates with floating point members

Fixes rust-lang#86163
We already use the object crate for generating uncompressed .rmeta
metadata object files. This switches the generation of compressed
.rustc object files to use the object crate as well. These have
slightly different requirements in that .rmeta should be completely
excluded from any final compilation artifacts, while .rustc should
be part of shared objects, but not loaded into memory.

The primary motivation for this change is rust-lang#90326: In LLVM 14, the
current way of setting section flags (and in particular, preventing
the setting of SHF_ALLOC) will no longer work. There are other ways
we could work around this, but switching to the object crate seems
like the most elegant, as we already use it for .rmeta, and as it
makes this independent of the codegen backend. In particular, we
don't need separate handling in codegen_llvm and codegen_gcc.
codegen_cranelift should be able to reuse the implementation as
well, though I have omitted that here, as it is not based on
codegen_ssa.

This change mostly extracts the existing code for .rmeta handling
to allow using it for .rustc as well, and adjust the codegen
infrastructure to handle the metadata object file separately: We
no longer create a backend-specific module for it, and directly
produce the compiled module instead.

This does not fix rust-lang#90326 by itself yet, as .llvmbc will need to be
handled separately.
Also restricts r8-r14 from being used on Thumb1 targets as per rust-lang#90736.
Use object crate for .rustc metadata generation

We already use the object crate for generating uncompressed .rmeta
metadata object files. This switches the generation of compressed
.rustc object files to use the object crate as well. These have
slightly different requirements in that .rmeta should be completely
excluded from any final compilation artifacts, while .rustc should
be part of shared objects, but not loaded into memory.

The primary motivation for this change is rust-lang#90326: In LLVM 14, the
current way of setting section flags (and in particular, preventing
the setting of SHF_ALLOC) will no longer work. There are other ways
we could work around this, but switching to the object crate seems
like the most elegant, as we already use it for .rmeta, and as it
makes this independent of the codegen backend. In particular, we
don't need separate handling in codegen_llvm and codegen_gcc.
codegen_cranelift should be able to reuse the implementation as
well, though I have omitted that here, as it is not based on
codegen_ssa.

This change mostly extracts the existing code for .rmeta handling
to allow using it for .rustc as well, and adjusts the codegen
infrastructure to handle the metadata object file separately: We
no longer create a backend-specific module for it, and directly
produce the compiled module instead.

This does not `fix` rust-lang#90326 by itself yet, as .llvmbc will need to be
handled separately.

r? `@nagisa`
…plett

Remove the reg_thumb register class for asm! on ARM

Also restricts r8-r14 from being used on Thumb1 targets as per rust-lang#90736.

cc ``@Lokathor``

r? ``@joshtriplett``
They are also removed from the prelude as per the decision in
rust-lang#87228.

stdarch and compiler-builtins are updated to work with the new, stable
asm! and global_asm! macros.
The resulting profile will include the crate name and will be stored in
the `--out-dir` directory.

This implementation makes it convenient to use LLVM time trace together
with cargo, in the contrast to the previous implementation which would
overwrite profiles or store them in `.cargo/registry/..`.
matthiaskrgr and others added 14 commits December 15, 2021 01:28
Use `OutputFilenames` to generate output file for `-Zllvm-time-trace`

The resulting profile will include the crate name and will be stored in
the `--out-dir` directory.

This implementation makes it convenient to use LLVM time trace together
with cargo, in the contrast to the previous implementation which would
overwrite profiles or store them in `.cargo/registry/..`.
* Use new initialization functions

* Fix for new reflection patch

* Fix for new TLS patch
Remove `SymbolStr`

This was originally proposed in rust-lang#74554 (comment). As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences.

Best reviewed one commit at a time.

r? `@oli-obk`
Support for portable-simd isn't implemented yet
These only finish in reasonable time with optimizations enabled.

This patch file is copied from cg_clif.
rustc_interface already calls it for you
@rustbot rustbot added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-codegen Area: Code generation A-gcc Things relevant to the [future] GCC backend labels Dec 31, 2021
@bjorn3
Copy link
Member Author

bjorn3 commented Dec 31, 2021

@bors r+ subtree sync

I asked @antoyo in advance if it was ok to do this sync.

@bors
Copy link
Contributor

bors commented Dec 31, 2021

📌 Commit b799d6e has been approved by bjorn3

@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Dec 31, 2021
@rust-log-analyzer

This comment has been minimized.

Copy link
Contributor

@antoyo antoyo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@bjorn3
Copy link
Member Author

bjorn3 commented Dec 31, 2021

@bors r=antoyo

@bors
Copy link
Contributor

bors commented Dec 31, 2021

📌 Commit e7357e3 has been approved by antoyo

bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 1, 2022
…askrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#88310 (Lock bootstrap (x.py) build directory)
 - rust-lang#92097 (Implement split_at_spare_mut without Deref to a slice so that the spare slice is valid)
 - rust-lang#92412 (Fix double space in pretty printed TryBlock)
 - rust-lang#92420 (Fix whitespace in pretty printed PatKind::Range)
 - rust-lang#92457 (Sync rustc_codegen_gcc)
 - rust-lang#92460 ([rustc_builtin_macros] add indices to format_foreign::printf::Substitution::Escape)
 - rust-lang#92469 (Make tidy check for magic numbers that spell things)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit a76128b into rust-lang:master Jan 1, 2022
@rustbot rustbot added this to the 1.59.0 milestone Jan 1, 2022
@bjorn3 bjorn3 deleted the sync_cg_gcc-2021-12-31 branch January 1, 2022 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation A-gcc Things relevant to the [future] GCC backend S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.