Skip to content

Commit 88a6458

Browse files
committed
Auto merge of rust-lang#127513 - nikic:llvm-19, r=<try>
Update to LLVM 19 Related changes: * rust-lang#127605 * rust-lang#127613 * rust-lang#127654 * rust-lang#128141 * llvm/llvm-project#98933 try-job: x86_64-msvc try-job: i686-msvc try-job: x86_64-msvc-ext try-job: dist-x86_64-msvc try-job: dist-i686-msvc try-job: dist-aarch64-msvc try-job: dist-x86_64-msvc-alt
2 parents 28e684b + fe8592d commit 88a6458

File tree

12 files changed

+98
-10
lines changed

12 files changed

+98
-10
lines changed

.gitmodules

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
shallow = true
3333
[submodule "src/llvm-project"]
3434
path = src/llvm-project
35-
url = https://github.com/rust-lang/llvm-project.git
36-
branch = rustc/18.1-2024-05-19
35+
url = https://github.com/nikic/llvm-project.git
36+
branch = rust-llvm-19
3737
shallow = true
3838
[submodule "src/doc/embedded-book"]
3939
path = src/doc/embedded-book

compiler/rustc_codegen_llvm/src/attributes.rs

+28-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_codegen_ssa::traits::*;
44
use rustc_hir::def_id::DefId;
55
use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, PatchableFunctionEntry};
66
use rustc_middle::ty::{self, TyCtxt};
7-
use rustc_session::config::{FunctionReturn, OptLevel};
7+
use rustc_session::config::{BranchProtection, FunctionReturn, OptLevel, PAuthKey, PacRet};
88
use rustc_span::symbol::sym;
99
use rustc_target::spec::{FramePointer, SanitizerSet, StackProbeType, StackProtector};
1010
use smallvec::SmallVec;
@@ -407,8 +407,33 @@ pub fn from_fn_attrs<'ll, 'tcx>(
407407
// And it is a module-level attribute, so the alternative is pulling naked functions into new LLVM modules.
408408
// Otherwise LLVM's "naked" functions come with endbr prefixes per https://github.com/rust-lang/rust/issues/98768
409409
to_add.push(AttributeKind::NoCfCheck.create_attr(cx.llcx));
410-
// Need this for AArch64.
411-
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "branch-target-enforcement", "false"));
410+
if llvm_util::get_version() < (19, 0, 0) {
411+
// Prior to LLVM 19, branch-target-enforcement was disabled by setting the attribute to
412+
// the string "false". Now it is disabled by absence of the attribute.
413+
to_add.push(llvm::CreateAttrStringValue(cx.llcx, "branch-target-enforcement", "false"));
414+
}
415+
} else if llvm_util::get_version() >= (19, 0, 0) {
416+
// For non-naked functions, set branch protection attributes on aarch64.
417+
if let Some(BranchProtection { bti, pac_ret }) =
418+
cx.sess().opts.unstable_opts.branch_protection
419+
{
420+
assert!(cx.sess().target.arch == "aarch64");
421+
if bti {
422+
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-target-enforcement"));
423+
}
424+
if let Some(PacRet { leaf, key }) = pac_ret {
425+
to_add.push(llvm::CreateAttrStringValue(
426+
cx.llcx,
427+
"sign-return-address",
428+
if leaf { "all" } else { "non-leaf" },
429+
));
430+
to_add.push(llvm::CreateAttrStringValue(
431+
cx.llcx,
432+
"sign-return-address-key",
433+
if key == PAuthKey::A { "a_key" } else { "b_key" },
434+
));
435+
}
436+
}
412437
}
413438
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::ALLOCATOR)
414439
|| codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::ALLOCATOR_ZEROED)

compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1557,11 +1557,12 @@ LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(LLVMModuleRef M) {
15571557

15581558
extern "C" LLVMValueRef
15591559
LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(LLVMModuleRef M) {
1560-
#if LLVM_VERSION_GE(18, 0)
1560+
#if LLVM_VERSION_GE(18, 0) && LLVM_VERSION_LT(19, 0)
15611561
return wrap(llvm::Intrinsic::getDeclaration(
15621562
unwrap(M), llvm::Intrinsic::instrprof_mcdc_condbitmap_update));
15631563
#else
1564-
report_fatal_error("LLVM 18.0 is required for mcdc intrinsic functions");
1564+
report_fatal_error(
1565+
"The instrprof_mcdc_condbitmap_update only exists in LLVM 18");
15651566
#endif
15661567
}
15671568

src/llvm-project

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Test that the correct module flags are emitted with different branch protection flags.
2+
3+
//@ revisions: BTI PACRET LEAF BKEY NONE
4+
//@ needs-llvm-components: aarch64
5+
//@ [BTI] compile-flags: -Z branch-protection=bti
6+
//@ [PACRET] compile-flags: -Z branch-protection=pac-ret
7+
//@ [LEAF] compile-flags: -Z branch-protection=pac-ret,leaf
8+
//@ [BKEY] compile-flags: -Z branch-protection=pac-ret,b-key
9+
//@ compile-flags: --target aarch64-unknown-linux-gnu
10+
//@ ignore-llvm-version: 19 - 99
11+
12+
#![crate_type = "lib"]
13+
#![feature(no_core, lang_items)]
14+
#![no_core]
15+
16+
#[lang = "sized"]
17+
trait Sized {}
18+
19+
// A basic test function.
20+
pub fn test() {}
21+
22+
// BTI: !"branch-target-enforcement", i32 1
23+
// BTI: !"sign-return-address", i32 0
24+
// BTI: !"sign-return-address-all", i32 0
25+
// BTI: !"sign-return-address-with-bkey", i32 0
26+
27+
// PACRET: !"branch-target-enforcement", i32 0
28+
// PACRET: !"sign-return-address", i32 1
29+
// PACRET: !"sign-return-address-all", i32 0
30+
// PACRET: !"sign-return-address-with-bkey", i32 0
31+
32+
// LEAF: !"branch-target-enforcement", i32 0
33+
// LEAF: !"sign-return-address", i32 1
34+
// LEAF: !"sign-return-address-all", i32 1
35+
// LEAF: !"sign-return-address-with-bkey", i32 0
36+
37+
// BKEY: !"branch-target-enforcement", i32 0
38+
// BKEY: !"sign-return-address", i32 1
39+
// BKEY: !"sign-return-address-all", i32 0
40+
// BKEY: !"sign-return-address-with-bkey", i32 1
41+
42+
// NONE-NOT: branch-target-enforcement
43+
// NONE-NOT: sign-return-address
44+
// NONE-NOT: sign-return-address-all
45+
// NONE-NOT: sign-return-address-with-bkey

tests/codegen/branch-protection.rs

+10
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//@ [LEAF] compile-flags: -Z branch-protection=pac-ret,leaf
88
//@ [BKEY] compile-flags: -Z branch-protection=pac-ret,b-key
99
//@ compile-flags: --target aarch64-unknown-linux-gnu
10+
//@ min-llvm-version: 19
1011

1112
#![crate_type = "lib"]
1213
#![feature(no_core, lang_items)]
@@ -16,23 +17,32 @@
1617
trait Sized {}
1718

1819
// A basic test function.
20+
// CHECK: @test(){{.*}} [[ATTR:#[0-9]+]] {
21+
#[no_mangle]
1922
pub fn test() {}
2023

24+
// BTI: attributes [[ATTR]] = {{.*}} "branch-target-enforcement"
2125
// BTI: !"branch-target-enforcement", i32 1
2226
// BTI: !"sign-return-address", i32 0
2327
// BTI: !"sign-return-address-all", i32 0
2428
// BTI: !"sign-return-address-with-bkey", i32 0
2529

30+
// PACRET: attributes [[ATTR]] = {{.*}} "sign-return-address"="non-leaf"
31+
// PACRET-SAME: "sign-return-address-key"="a_key"
2632
// PACRET: !"branch-target-enforcement", i32 0
2733
// PACRET: !"sign-return-address", i32 1
2834
// PACRET: !"sign-return-address-all", i32 0
2935
// PACRET: !"sign-return-address-with-bkey", i32 0
3036

37+
// LEAF: attributes [[ATTR]] = {{.*}} "sign-return-address"="all"
38+
// LEAF-SAME: "sign-return-address-key"="a_key"
3139
// LEAF: !"branch-target-enforcement", i32 0
3240
// LEAF: !"sign-return-address", i32 1
3341
// LEAF: !"sign-return-address-all", i32 1
3442
// LEAF: !"sign-return-address-with-bkey", i32 0
3543

44+
// BKEY: attributes [[ATTR]] = {{.*}} "sign-return-address"="non-leaf"
45+
// BKEY-SAME: "sign-return-address-key"="b_key"
3646
// BKEY: !"branch-target-enforcement", i32 0
3747
// BKEY: !"sign-return-address", i32 1
3848
// BKEY: !"sign-return-address-all", i32 0

tests/coverage/mcdc/condition-limit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![feature(coverage_attribute)]
22
//@ edition: 2021
33
//@ min-llvm-version: 18
4+
//@ ignore-llvm-version: 19 - 99
45
//@ compile-flags: -Zcoverage-options=mcdc
56
//@ llvm-cov-flags: --show-branches=count --show-mcdc
67

tests/coverage/mcdc/if.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![feature(coverage_attribute)]
22
//@ edition: 2021
33
//@ min-llvm-version: 18
4+
//@ ignore-llvm-version: 19 - 99
45
//@ compile-flags: -Zcoverage-options=mcdc
56
//@ llvm-cov-flags: --show-branches=count --show-mcdc
67

tests/coverage/mcdc/inlined_expressions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![feature(coverage_attribute)]
22
//@ edition: 2021
33
//@ min-llvm-version: 18
4+
//@ ignore-llvm-version: 19 - 99
45
//@ compile-flags: -Zcoverage-options=mcdc -Copt-level=z -Cllvm-args=--inline-threshold=0
56
//@ llvm-cov-flags: --show-branches=count --show-mcdc
67

tests/coverage/mcdc/nested_if.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![feature(coverage_attribute)]
22
//@ edition: 2021
33
//@ min-llvm-version: 18
4+
//@ ignore-llvm-version: 19 - 99
45
//@ compile-flags: -Zcoverage-options=mcdc
56
//@ llvm-cov-flags: --show-branches=count --show-mcdc
67

tests/coverage/mcdc/non_control_flow.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![feature(coverage_attribute)]
22
//@ edition: 2021
33
//@ min-llvm-version: 18
4+
//@ ignore-llvm-version: 19 - 99
45
//@ compile-flags: -Zcoverage-options=mcdc
56
//@ llvm-cov-flags: --show-branches=count --show-mcdc
67

tests/crashes/121444.rs tests/ui/abi/large-byval-align.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
//@ known-bug: #121444
21
//@ compile-flags: -Copt-level=0
3-
//@ edition:2021
42
//@ only-x86_64
53
//@ ignore-windows
4+
//@ min-llvm-version: 19
5+
//@ build-pass
6+
67
#[repr(align(536870912))]
78
pub struct A(i64);
89

10+
#[allow(improper_ctypes_definitions)]
911
pub extern "C" fn foo(x: A) {}
1012

1113
fn main() {

0 commit comments

Comments
 (0)