Commit Graph

217 Commits

Author SHA1 Message Date
Krasimir Georgiev
cbdc00f6e6 llvm-wrapper: adapt for LLVM API changes
This is a follow-up of
75aec4703d.
There, I updated the wrapper to only include llvm/ADT/Optional.h for
LLVM version below 16. But I missed updating some of the None references.

Found by our experimental rust + llvm at HEAD bot:
https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/15587#0185006b-e0af-49e5-8b06-280ed125ff0d/200-539
2022-12-11 09:14:50 +00:00
Matthias Krüger
947fe7e341
Rollup merge of #105109 - rcvalle:rust-kcfi, r=bjorn3
Add LLVM KCFI support to the Rust compiler

This PR adds LLVM Kernel Control Flow Integrity (KCFI) support to the Rust compiler. It initially provides forward-edge control flow protection for operating systems kernels for Rust-compiled code only by aggregating function pointers in groups identified by their return and parameter types. (See llvm/llvm-project@cff5bef.)

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 identifying C char and integer type uses at the time types are encoded (see Type metadata in the design document in the tracking issue #89653).

LLVM KCFI can be enabled with -Zsanitizer=kcfi.

Thank you again, `@bjorn3,` `@eddyb,` `@nagisa,` and `@ojeda,` for all the help!
2022-12-10 09:24:43 +01:00
bors
e10201c9bb Auto merge of #104572 - pkubaj:patch-1, r=cuviper
Fix build on powerpc-unknown-freebsd

Probably also fixes build on arm and mips*. Related to https://github.com/rust-lang/rust/issues/104220
2022-12-09 12:00:58 +00:00
Ramon de C Valle
65698ae9f3 Add LLVM KCFI support to the Rust compiler
This commit adds LLVM Kernel Control Flow Integrity (KCFI) support to
the Rust compiler. It initially provides forward-edge control flow
protection for operating systems kernels for Rust-compiled code only by
aggregating function pointers in groups identified by their return and
parameter types. (See llvm/llvm-project@cff5bef.)

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 identifying C char and integer type uses at the
time types are encoded (see Type metadata in the design document in the
tracking issue #89653).

LLVM KCFI can be enabled with -Zsanitizer=kcfi.

Co-authored-by: bjorn3 <17426603+bjorn3@users.noreply.github.com>
2022-12-08 17:24:39 -08:00
pkubaj
32c777e891 Fix build on powerpc-unknown-freebsd
Probably also fixes build on mips*. Related to https://github.com/rust-lang/rust/issues/104220
2022-12-09 02:11:15 +01:00
Matthias Krüger
e434f613fd
Rollup merge of #105298 - krasimirgg:llvm-16-dec-1, r=cuviper
llvm-wrapper: adapt for an LLVM API change

Adapts llvm-wrapper for 8c7c20f033.
No functional changes intended.

Found via our experimental rust + llvm @ HEAD bot: https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds/15404#0184d95d-5a68-4db6-ad32-51ddbc3ab543/202-571
2022-12-06 23:13:49 +01:00
Krasimir Georgiev
75aec4703d llvm-wrapper: adapt for and LLVM API change 2022-12-06 18:25:33 +00:00
bjorn3
0673cde5a3 Use LLVM for getting symbols from COFF bigobj files 2022-11-26 19:35:32 +00:00
bjorn3
be6708428f Rewrite LLVM's archive writer in Rust
This allows it to be used by other codegen backends
2022-11-26 19:35:32 +00:00
Krasimir Georgiev
e5ccd27e67 [llvm-wrapper] adapt for LLVM API change
Adapt for the LLVM API changes from
721f975d35 (diff-5a347903b8412ed1b1b1948c3fce47f9a6ff05dc70bfaeedb6d06b622e399d91).
2022-11-25 11:29:00 +00:00
Matthias Krüger
1e0df8827b
Rollup merge of #104517 - dfordivam:patch-1, r=cuviper
Throw error on failure in loading llvm-plugin

The following code silently ignores the error as the `LLVMRustSetLastError` only tracks one error at a time. At all other places where `LLVMRustSetLastError` is used the code immediately returns.

251831ece9/compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp (L801-L804)
2022-11-24 08:42:33 +01:00
bors
ccde51a912 Auto merge of #102717 - beetrees:repr128-c-style-debuginfo, r=nagisa
Pass 128-bit C-style enum enumerator values to LLVM

Pass the full 128 bits of C-style enum enumerators through to LLVM. This means that debuginfo for C-style repr128 enums is now emitted correctly for DWARF platforms (as compared to not being correctly emitted on any platform).

Tracking issue: #56071
2022-11-21 01:44:12 +00:00
Divam Narula
693c6311f0
Throw error on failure in loading llvm-plugin 2022-11-17 15:25:18 +09:00
Camille GILLOT
b550eabfa6 Introduce composite debuginfo. 2022-11-15 17:53:50 +00:00
Krasimir Georgiev
212ce1f10c [llvm-wrapper] adapt for LLVM API change 2022-11-14 14:59:32 +00:00
Manish Goregaokar
1b91bdfda9
Rollup merge of #103709 - cuviper:netbsd-9, r=pietroalbini
ci: Upgrade dist-x86_64-netbsd to NetBSD 9.0

This is another step in toolchain upgrades for LLVM 16, which will need at least GCC 7.1.

Our previous NetBSD 8.0 cross-toolchain used its system GCC 5.5. While there are newer versions available in pkgsrc, I could not get those working for cross-compilation. Upgrading to NetBSD 9.0 gets us GCC 7.4, which is sufficient for now.

This will affect the compatibility of the build we ship for `x86_64-unknown-netbsd`, but others may still build their own from source if that is needed. It is expected that NetBSD 8 will reach EOL soon anyway, approximately one month after 10 is released, but there is no firm date for that.
2022-11-13 21:49:24 -05:00
Tim Neumann
c15cfc91c4 LLVM 16: Switch to using MemoryEffects 2022-11-04 17:58:16 +00:00
Josh Stone
32a3130813 Upgrade dist-x86_64-netbsd to NetBSD 9.0 2022-10-28 18:49:48 -07:00
Matthew Maurer
6ea75aea56 llvm-16: Don't initialize removed legacy passes
LLVM removed initialization for legacy passes:
https://reviews.llvm.org/D136615
2022-10-25 15:03:21 -07:00
beetrees
25c1c635e5
Pass 128-bit C-style enum enumerator values to LLVM 2022-10-09 09:33:36 +01:00
Josh Stone
35adb36779 Avoid LLVM-deprecated Optional::hasValue
LLVM 15 added `Optional::has_value`, and LLVM `main` (16) has deprecated
`hasValue`. However, its `explicit operator bool` does the same thing,
and was added long ago, so we can use that across our full LLVM range of
compatibility.
2022-09-26 16:51:18 -07:00
fee1-dead
07467c5308
Rollup merge of #101997 - cuviper:drop-legacy-pm, r=nikic
Remove support for legacy PM

This removes support for optimizing with LLVM's legacy pass manager, as well as the unstable `-Znew-llvm-pass-manager` option. We have been defaulting to the new PM since LLVM 13 (except for s390x that waited for 14), and LLVM 15 removed support altogether. The only place we still use the legacy PM is for writing the output file, just like `llc` does.

cc #74705
r? ``@nikic``
2022-09-25 22:06:38 +08:00
Josh Stone
fac12e25dd Use LLVM C-API to build atomic cmpxchg and fence 2022-09-18 16:01:57 -07:00
Josh Stone
04a318e13e Use the helper for internalizing with new PM 2022-09-18 13:26:03 -07:00
Josh Stone
d6318de13a Never use legacy PM for writing bitcode 2022-09-18 13:26:03 -07:00
Josh Stone
2860f77a0d Remove support for LLVM's legacy pass manager 2022-09-18 13:25:49 -07:00
Tomasz Miąsko
7279106166 Introduce a fallible variant of LLVMConstIntGetZExtValue
which verifies that a constant bit width is within 64 bits or fails.
2022-09-09 15:54:14 +02:00
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