Commit Graph

190 Commits

Author SHA1 Message Date
Matthias Krüger
6d2033512b
Rollup merge of #99207 - 5225225:msan-eager-checks, r=jackh726
Enable eager checks for memory sanitizer

Fixes #99179
2022-09-09 07:02:30 +02:00
Krasimir Georgiev
a3b60f1769 llvm-wrapper: adapt for LLVM API changes
No functional changes intended.

Adapts PassWrapper for two recent LLVM API changes:
* e7bac3b9fa
* 93600eb50c
* 5e38b2a456
2022-09-07 13:37:59 +00:00
Matthias Krüger
0fee731a95
Rollup merge of #101025 - semarie:openbsd-archs, r=petrochenkov
Add tier-3 support for powerpc64 and riscv64 openbsd

# powerpc64
- MCP for [powerpc64-unknown-openbsd tier-3 support](https://github.com/rust-lang/compiler-team/issues/551)
- only need to add spec definition in rustc_target

# riscv64
- MCP for [riscv64-unknown-openbsd tier-3 support](https://github.com/rust-lang/compiler-team/issues/552)
- add spec definition in rustc_target
- follow freebsd about avoiding linking with `libatomic`
2022-08-31 07:57:58 +02:00
bors
230a8ee364 Auto merge of #98100 - bjorn3:use_object_for_bitcode_reading, r=wesleywiser
Use object instead of LLVM for reading bitcode from rlibs

Together with changes I plan to make as part of https://github.com/rust-lang/rust/pull/97485 this will allow entirely removing usage of LLVM's archive reader and thus allow removing `archive_ro.rs` and `ArchiveWrapper.cpp`.
2022-08-30 11:13:58 +00:00
Sébastien Marie
1de5b22678 add riscv64gc-unknown-openbsd support (target riscv64-unknown-openbsd on OpenBSD)
- add platform-support documentation
- add riscv64gc-unknown-openbsd spec
- do not try to link with -latomic on openbsd
2022-08-28 05:22:21 +00:00
bors
39a9b88f4e Auto merge of #100627 - krasimirgg:lto-llvm-16, r=cuviper
llvm-wrapper: adapt for LLVM API change

No functional changes intended.

LLVM commit 633f5663c3 removed `createWriteThinLTOBitcodePass`.
This adapts PassWrapper similarly to the example mentioned upstream: 853b57fe80.

Detected via our experimental rust + llvm @ head bot: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/12768#0182a6be-ed6e-4dc6-a230-7a46f9d3a2c2/205-537
2022-08-21 07:19:49 +00:00
5225225
09ea9f0a87 Add diagnostic translation lints to crates that don't emit them 2022-08-18 19:29:02 +01:00
Krasimir Georgiev
7cba1f9eab llvm-wrapper: use new pass manager for thin lto with LLVM version 15
No functional changes intended.

LLVM commit 633f5663c3 removed `createWriteThinLTOBitcodePass`.
This adapts PassWrapper similarly to the example mentioned upstream: 633f5663c3.
2022-08-17 09:16:37 +00:00
Matthias Krüger
0b19a185db
Rollup merge of #100460 - cuviper:drop-llvm-12, r=nagisa
Update the minimum external LLVM to 13

With this change, we'll have stable support for LLVM 13 through 15 (pending release).
For reference, the previous increase to LLVM 12 was #90175.

r? `@nagisa`
2022-08-16 06:05:57 +02:00
Matthias Krüger
f347c42461
Rollup merge of #100384 - ridwanabdillahi:instr_profile_output, r=wesleywiser
Add support for generating unique profraw files by default when using `-C instrument-coverage`

Currently, enabling the rustc flag `-C instrument-coverage` instruments the given crate and by default uses the naming scheme `default.profraw` for any instrumented profile files generated during the execution of a binary linked against this crate. This leads to multiple binaries being executed overwriting one another and causing only the last executable run to contain actual coverage results.

This can be overridden by manually setting the environment variable `LLVM_PROFILE_FILE` to use a unique naming scheme.

This PR adds a change to add support for a reasonable default for rustc to use when enabling coverage instrumentation similar to how the Rust compiler treats generating these same `profraw` files when PGO is enabled.

The new naming scheme is set to `default_%m_%p.profraw` to ensure the uniqueness of each file being generated using [LLVMs special pattern strings](https://clang.llvm.org/docs/SourceBasedCodeCoverage.html#running-the-instrumented-program).

Today the compiler sets the default for PGO `profraw` files to `default_%m.profraw` to ensure a unique file for each run. The same can be done for the instrumented profile files generated via the `-C instrument-coverage` flag as well which LLVM has API support for.

Linked Issue: https://github.com/rust-lang/rust/issues/100381

r? `@wesleywiser`
2022-08-16 06:05:56 +02:00
Josh Stone
2970ad8aee Update the minimum external LLVM to 13 2022-08-14 13:46:51 -07:00
5225225
66dcf5dfee Enable eager checks for memory sanitizer 2022-08-14 10:37:03 +01:00
Michael Woerister
622da5d834 debuginfo: Change C++-like encoding for enums.
The updated encoding should be able to handle niche layouts where
more than one variant has fields.
2022-08-12 10:53:07 +02:00
ridwanabdillahi
100882296e Add support for generating unique *.profraw files by default when using the -C instrument-coverage flag.
Respond to PR comments.
2022-08-11 16:04:08 -07:00
Nikita Popov
1db81713f6 Link libatomic on 32-bit targets
This is needed since https://reviews.llvm.org/D128070.
2022-08-09 12:39:59 +02:00
Augie Fackler
cdbe956ec3 RustWrapper: update for TypedPointerType in LLVM
This is a result of https://reviews.llvm.org/D130592.
2022-08-04 11:31:57 -04:00
est31
eca274a1f9 Also gate AllocatedPointer and AllocAlign definitions by LLVM_VERSION_GE
Fixes a warning:

warning: llvm-wrapper/RustWrapper.cpp:159:11: warning: enumeration values 'AllocatedPointer' and 'AllocAlign' not handled in switch [-Wswitch]
warning:   switch (Kind) {
warning:           ^

Which was fall out from 130a1df71e.
2022-07-30 18:53:51 +02:00
Nikita Popov
f653d3ab30 Add elementtype attributes for llvm.arm.ldrex/strex intrinsics
These intrinsics (and a few more, but there are the only ones
exposed by stdarch) require an elementtype attribute in LLVM 15.
2022-07-27 16:19:07 +02:00
Yuki Okushi
7f608e99dc
Rollup merge of #99759 - bjorn3:remove_llvm_dead_code, r=nikic
Remove dead code from cg_llvm

Found while working on https://github.com/rust-lang/rust/pull/97485
2022-07-27 11:52:56 +09:00
Augie Fackler
130a1df71e codegen: use new {re,de,}allocator annotations in llvm
This obviates the patch that teaches LLVM internals about
_rust_{re,de}alloc functions by putting annotations directly in the IR
for the optimizer.

The sole test change is required to anchor FileCheck to the body of the
`box_uninitialized` method, so it doesn't see the `allocalign` on
`__rust_alloc` and get mad about the string `alloca` showing up. Since I
was there anyway, I added some checks on the attributes to prove the
right attributes got set.

While we're here, we also emit allocator attributes on
__rust_alloc_zeroed. This should allow LLVM to perform more
optimizations for zeroed blocks, and probably fixes #90032. [This
comment](https://github.com/rust-lang/rust/issues/24194#issuecomment-308791157)
mentions "weird UB-like behaviour with bitvec iterators in
rustc_data_structures" so we may need to back this change out if things
go wrong.

The new test cases require LLVM 15, so we copy them into LLVM
14-supporting versions, which we can delete when we drop LLVM 14.
2022-07-26 09:43:28 -04:00
bjorn3
017e1726ff Remove dead code from cg_llvm 2022-07-26 11:29:18 +00:00
bjorn3
395d564f25 Use object instead of LLVM for reading bitcode from rlibs 2022-07-25 16:07:23 +00:00
bors
93ffde6f04 Auto merge of #98208 - ivanloz:master, r=nagisa
Add support for LLVM ShadowCallStack.

LLVMs ShadowCallStack provides backward edge control flow integrity protection by using a separate shadow stack to store and retrieve a function's return address.

LLVM currently only supports this for AArch64 targets. The x18 register is used to hold the pointer to the shadow stack, and therefore this only works on ABIs which reserve x18. Further details are available in the [LLVM ShadowCallStack](https://clang.llvm.org/docs/ShadowCallStack.html) docs.

# Usage
`-Zsanitizer=shadow-call-stack`

# Comments/Caveats
* Currently only enabled for the aarch64-linux-android target
* Requires the platform to define a runtime to initialize the shadow stack, see the [LLVM docs](https://clang.llvm.org/docs/ShadowCallStack.html) for more detail.
2022-07-23 20:01:07 +00:00
bors
74f600b990 Auto merge of #98162 - nextsilicon:support_lto_embed_bitcode, r=davidtwco
Allow to disable thinLTO buffer to support lto-embed-bitcode lld feature

Hello
This change is to fix issue (https://github.com/rust-lang/rust/issues/84395) in which passing "-lto-embed-bitcode=optimized" to lld when linking rust code via linker-plugin-lto doesn't produce the expected result.

Instead of emitting a single unified module into a llvmbc section of the linked elf, it emits multiple submodules.
This is caused because rustc emits the BC modules after running llvm `createWriteThinLTOBitcodePass` pass.
Which in turn triggers a thinLTO linkage and causes the said issue.

This patch allows via compiler flag (-Cemit-thin-lto=<bool>) to select between running `createWriteThinLTOBitcodePass` and `createBitcodeWriterPass`.
Note this pattern of selecting between those 2 passes is common inside of LLVM code.
The default is to match the old behavior.
2022-07-21 10:13:59 +00:00
Ivan Lozano
adf61e3b2b Add ShadowCallStack Support
Adds support for the LLVM ShadowCallStack sanitizer.
2022-07-20 13:43:34 +00:00
bors
03d488b48a Auto merge of #98843 - Urgau:check-cfg-stage0, r=Mark-Simulacrum
Enable check-cfg in stage0

Now that the bootstrap cargo supports `rustc-check-cfg` we can now enable it with `-Zcheck-cfg=output` and use it in `rustc_llvm` to unblock `--check-cfg` support in stage0.

r? `@Mark-Simulacrum`
2022-07-20 04:23:09 +00:00
Dylan DPC
a027b01f33
Rollup merge of #98998 - workingjubilee:naked-means-no-clothes-enforcement-technology, r=Amanieu
Remove branch target prologues from `#[naked] fn`

This patch hacks around rust-lang/rust#98768 for now via injecting appropriate attributes into the LLVMIR we emit for naked functions. I intend to pursue this upstream so that these attributes can be removed in general, but it's slow going wading through C++ for me.
2022-07-18 21:14:43 +05:30
bors
e6c43cf8b9 Auto merge of #95685 - oxidecomputer:restore-static-dwarf, r=pnkfelix
Revert "Work around invalid DWARF bugs for fat LTO"

Since September, the toolchain has not been generating reliable DWARF
information for static variables when LTO is on. This has affected
projects in the embedded space where the use of LTO is typical. In our
case, it has kept us from bumping past the 2021-09-22 nightly toolchain
lest our debugger break. This has been a pretty dramatic regression for
people using debuggers and static variables. See #90357 for more info
and a repro case.

This commit is a mechanical revert of
d5de680e20 from PR #89041, which caused
the issue. (Note on that PR that the commit's author has requested it be
reverted.)

I have locally verified that this fixes #90357 by restoring the
functionality of both the repro case I posted on that bug, and debugger
behavior on real programs. There do not appear to be test cases for this
in the toolchain; if I've missed them, point me at 'em and I'll update
them.
2022-07-16 00:18:54 +00:00
Ziv Dunkelman
724c91234d rustc: add ability to output regular LTO bitcode modules
Adding the option to control from rustc CLI
if the resulted ".o" bitcode module files are with
thinLTO info or regular LTO info.

Allows using "-lto-embed-bitcode=optimized" during linkage
correctly.

Signed-off-by: Ziv Dunkelman <ziv.dunkelman@nextsilicon.com>
2022-07-14 22:21:26 +03:00
Krasimir Georgiev
a89d014a21 llvm-wrapper: adapt for LLVM API change 2022-07-12 16:00:52 +00:00
Jubilee Young
92174f988b Stop emitting CET prologues for naked functions
We can apply nocf_check as a hack for now.
2022-07-06 22:44:54 -07:00
Urgau
0e82c53028 Add cargo:rustc-check-cfg to rustc_llvm build script 2022-07-03 16:17:17 +02:00
Krasimir Georgiev
a3a88c73f1 llvm-wrapper: adapt for LLVMConstExtractValue removal 2022-06-30 12:47:34 +00:00
Krasimir Georgiev
fe02ee8be9 llvm-wrapper: adapt for an LLVM API change
This adapts llvm-wrapper for
dacfa24f75,
which removed ASanGlobalsMetadataAnalysis.
2022-06-28 14:08:35 +00:00
flip1995
e96e6e2c89
Add metadata generation for vtables when using VFE
This adds the typeid and `vcall_visibility` metadata to vtables when the
-Cvirtual-function-elimination flag is set.

The typeid is generated in the same way as for the
`llvm.type.checked.load` intrinsic from the trait_ref.

The offset that is added to the typeid is always 0. This is because LLVM
assumes that vtables are constructed according to the definition in the
Itanium ABI. This includes an "address point" of the vtable. In C++ this
is the offset in the vtable where information for RTTI is placed. Since
there is no RTTI information in Rust's vtables, this "address point" is
always 0. This "address point" in combination with the offset passed to
the `llvm.type.checked.load` intrinsic determines the final function
that should be loaded from the vtable in the
`WholeProgramDevirtualization` pass in LLVM. That's why the
`llvm.type.checked.load` intrinsics are generated with the typeid of the
trait, rather than with that of the function that is called. This
matches what `clang` does for C++.

The vcall_visibility metadata depends on three factors:

1. LTO level: Currently this is always fat LTO, because LLVM only
   supports this optimization with fat LTO.
2. Visibility of the trait: If the trait is publicly visible, VFE
   can only act on its vtables after linking.
3. Number of CGUs: if there is more than one CGU, also vtables with
   restricted visibility could be seen outside of the CGU, so VFE can
   only act on them after linking.

To reflect this, there are three visibility levels: Public, LinkageUnit,
and TranslationUnit.
2022-06-14 14:50:52 +02:00
flip1995
20f597ffcd
Add LLVM module flags required for the VFE opt
To apply the optimization the `Virtual Function Elim` module flag has to
be set. To apply this optimization post-link the `LTOPostLink` module
flag has to be set.
2022-06-14 14:50:52 +02:00
Augie Fackler
1c26dd0db4 RustWrapper: adapt to APInt API changes in LLVM 15
In https://reviews.llvm.org/D125556 upstream changed sext() and zext()
to allow some no-op cases, which previously required use of the *OrSelf()
methods, which I assume is what was going on here. The *OrSelf() methods
got removed in https://reviews.llvm.org/D125559 after two weeks of
deprecation because they came with some bonus (probably-undesired)
behavior. Since the behavior of sext() and zext() changed slightly, I
kept the old *OrSelf() calls in LLVM 14 and earlier, and only use the
new version in LLVM 15.

r? @nikic
2022-06-07 14:47:57 -04:00
Jack Huey
410dcc9674 Fully stabilize NLL 2022-06-03 17:16:41 -04:00
Mateusz Mikuła
60361f2ca3 Add LLVM based mingw-w64 targets 2022-05-13 20:14:15 +02:00
Augie Fackler
e8ae06a31b RustWrapper: explicitly don't handle DXILPointerTyID
This new enum entry was introduced in https://reviews.llvm.org/D122268,
and if I'm reading correctly there's no case where we'd ever encounter
it in our uses of LLVM. To preserve the ability to compile this file
with -Werror -Wswitch we add an explicit case for this entry.
2022-04-28 13:53:52 -04:00
Nikita Popov
6dc0bcc5db Stub out more PassManagerBuilder functions 2022-04-20 09:36:02 +02:00
Nikita Popov
890cabac8a Stub out various legacy PM functions with LLVM 15 2022-04-20 09:25:47 +02:00
Nikita Popov
7dc307fc7a Add missing include 2022-04-20 09:25:47 +02:00
Amanieu d'Antras
547405e801 Add codegen for global_asm! sym operands 2022-04-15 14:36:30 +01:00
Luqman Aden
84fb481bf5 Respect -Z verify-llvm-ir and other flags that add extra passes when combined with -C no-prepopulate-passes in the new LLVM Pass Manager. 2022-04-10 15:40:16 -04:00
Pietro Albini
181d28bb61
trivial cfg(bootstrap) changes 2022-04-05 23:18:40 +02:00
Cliff L. Biffle
98190b7168 Revert "Work around invalid DWARF bugs for fat LTO"
Since September, the toolchain has not been generating reliable DWARF
information for static variables when LTO is on. This has affected
projects in the embedded space where the use of LTO is typical. In our
case, it has kept us from bumping past the 2021-09-22 nightly toolchain
lest our debugger break. This has been a pretty dramatic regression for
people using debuggers and static variables. See #90357 for more info
and a repro case.

This commit is a mechanical revert of
d5de680e20 from PR #89041, which caused
the issue. (Note on that PR that the commit's author has requested it be
reverted.)

I have locally verified that this fixes #90357 by restoring the
functionality of both the repro case I posted on that bug, and debugger
behavior on real programs. There do not appear to be test cases for this
in the toolchain; if I've missed them, point me at 'em and I'll update
them.
2022-04-05 10:38:13 -07:00
Vadim Petrochenkov
1004783ef9 Stabilize native library modifier syntax and the whole-archive modifier specifically 2022-03-30 23:53:21 +03:00
Augie Fackler
185e3b95ca RustWrapper: add missing include
This is required after LLVM change 3c4410dfcaaf (aka
https://reviews.llvm.org/D121168) did some includes cleanup.
2022-03-10 11:16:33 -05:00
bjorn3
0cfc3e1016 Remove build_helper
The majority of the code is only used by either rustbuild or
rustc_llvm's build script. Rust_build is compiled once for rustbuild and
once for every stage. This means that the majority of the code in this
crate is needlessly compiled multiple times. By moving only the code
actually used by the respective crates to rustbuild and rustc_llvm's
build script, this needless duplicate compilation is avoided.
2022-03-05 15:31:22 +01:00