Skip to content

Commit d260a23

Browse files
Auto merge of #146338 - CrooseGit:dev/reucru01/AArch64-enable-GCS, r=<try>
Extends AArch64 branch protection support to include GCS try-job: *aarch64*
2 parents 2f4dfc7 + f043fb8 commit d260a23

File tree

15 files changed

+40
-19
lines changed

15 files changed

+40
-19
lines changed

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,13 +407,16 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
407407
to_add.extend(sanitize_attrs(cx, codegen_fn_attrs.no_sanitize));
408408

409409
// For non-naked functions, set branch protection attributes on aarch64.
410-
if let Some(BranchProtection { bti, pac_ret }) =
410+
if let Some(BranchProtection { bti, pac_ret, gcs }) =
411411
cx.sess().opts.unstable_opts.branch_protection
412412
{
413413
assert!(cx.sess().target.arch == "aarch64");
414414
if bti {
415415
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-target-enforcement"));
416416
}
417+
if gcs {
418+
to_add.push(llvm::CreateAttrString(cx.llcx, "guarded-control-stack"));
419+
}
417420
if let Some(PacRet { leaf, pc, key }) = pac_ret {
418421
if pc {
419422
to_add.push(llvm::CreateAttrString(cx.llcx, "branch-protection-pauth-lr"));

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,8 @@ pub(crate) unsafe fn create_module<'ll>(
370370
);
371371
}
372372

373-
if let Some(BranchProtection { bti, pac_ret }) = sess.opts.unstable_opts.branch_protection {
373+
if let Some(BranchProtection { bti, pac_ret, gcs }) = sess.opts.unstable_opts.branch_protection
374+
{
374375
if sess.target.arch == "aarch64" {
375376
llvm::add_module_flag_u32(
376377
llmod,
@@ -403,6 +404,12 @@ pub(crate) unsafe fn create_module<'ll>(
403404
"sign-return-address-with-bkey",
404405
u32::from(pac_opts.key == PAuthKey::B),
405406
);
407+
llvm::add_module_flag_u32(
408+
llmod,
409+
llvm::ModuleFlagMergeBehavior::Min,
410+
"guarded-control-stack",
411+
gcs.into(),
412+
);
406413
} else {
407414
bug!(
408415
"branch-protection used on non-AArch64 target; \

compiler/rustc_interface/src/tests.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -772,7 +772,8 @@ fn test_unstable_options_tracking_hash() {
772772
branch_protection,
773773
Some(BranchProtection {
774774
bti: true,
775-
pac_ret: Some(PacRet { leaf: true, pc: true, key: PAuthKey::B })
775+
pac_ret: Some(PacRet { leaf: true, pc: true, key: PAuthKey::B }),
776+
gcs: true,
776777
})
777778
);
778779
tracked!(codegen_backend, Some("abc".to_string()));

compiler/rustc_session/src/config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,6 +1615,7 @@ pub struct PacRet {
16151615
pub struct BranchProtection {
16161616
pub bti: bool,
16171617
pub pac_ret: Option<PacRet>,
1618+
pub gcs: bool,
16181619
}
16191620

16201621
pub(crate) const fn default_lib_output() -> CrateType {

compiler/rustc_session/src/options.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ mod desc {
866866
pub(crate) const parse_polonius: &str = "either no value or `legacy` (the default), or `next`";
867867
pub(crate) const parse_stack_protector: &str =
868868
"one of (`none` (default), `basic`, `strong`, or `all`)";
869-
pub(crate) const parse_branch_protection: &str = "a `,` separated combination of `bti`, `pac-ret`, followed by a combination of `pc`, `b-key`, or `leaf`";
869+
pub(crate) const parse_branch_protection: &str = "a `,` separated combination of `bti`, `gcs`, `pac-ret`, (optionally with `pc`, `b-key`, `leaf` if `pac-ret` is set)";
870870
pub(crate) const parse_proc_macro_execution_strategy: &str =
871871
"one of supported execution strategies (`same-thread`, or `cross-thread`)";
872872
pub(crate) const parse_remap_path_scope: &str =
@@ -1903,6 +1903,7 @@ pub mod parse {
19031903
Some(pac) => pac.pc = true,
19041904
_ => return false,
19051905
},
1906+
"gcs" => slot.gcs = true,
19061907
_ => return false,
19071908
};
19081909
}

src/ci/docker/host-aarch64/aarch64-gnu-debug/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
FROM ubuntu:22.04
1+
FROM ubuntu:25.04
22

33
ARG DEBIAN_FRONTEND=noninteractive
44
RUN apt-get update && apt-get install -y --no-install-recommends \
5-
g++ \
5+
g++-15 \
66
make \
77
ninja-build \
88
file \

src/ci/docker/host-aarch64/aarch64-gnu-llvm-20/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:25.04
1+
FROM ubuntu:25.10
22

33
ARG DEBIAN_FRONTEND=noninteractive
44

src/ci/docker/host-aarch64/aarch64-gnu/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ubuntu:22.04
1+
FROM ubuntu:25.10
22

33
ARG DEBIAN_FRONTEND=noninteractive
44
RUN apt-get update && apt-get install -y --no-install-recommends \

src/doc/unstable-book/src/compiler-flags/branch-protection.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ It takes some combination of the following values, separated by a `,`.
1313
- `leaf` - Enable pointer authentication for all functions, including leaf functions.
1414
- `b-key` - Sign return addresses with key B, instead of the default key A.
1515
- `bti` - Enable branch target identification.
16+
- `gcs` - Enable guarded control stack support.
1617

1718
`leaf`, `b-key` and `pc` are only valid if `pac-ret` was previously specified.
1819
For example, `-Z branch-protection=bti,pac-ret,leaf` is valid, but

tests/assembly-llvm/aarch64-pointer-auth.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// Test that PAC instructions are emitted when branch-protection is specified.
22

33
//@ add-core-stubs
4-
//@ revisions: PACRET PAUTHLR_NOP PAUTHLR
4+
//@ revisions: GCS PACRET PAUTHLR_NOP PAUTHLR
55
//@ assembly-output: emit-asm
66
//@ needs-llvm-components: aarch64
77
//@ compile-flags: --target aarch64-unknown-linux-gnu
8+
//@ min-llvm-version: 21
9+
//@ [GCS] compile-flags: -Z branch-protection=gcs
810
//@ [PACRET] compile-flags: -Z branch-protection=pac-ret,leaf
911
//@ [PAUTHLR_NOP] compile-flags: -Z branch-protection=pac-ret,pc,leaf
1012
//@ [PAUTHLR] compile-flags: -C target-feature=+pauth-lr -Z branch-protection=pac-ret,pc,leaf
@@ -17,6 +19,7 @@
1719
extern crate minicore;
1820
use minicore::*;
1921

22+
// GCS: .aeabi_attribute 2, 1 // Tag_Feature_GCS
2023
// PACRET: hint #25
2124
// PACRET: hint #29
2225
// PAUTHLR_NOP: hint #25

0 commit comments

Comments
 (0)