Skip to content

Commit c87f767

Browse files
committed
sess: -Tpointer-authentication (again)
1 parent 5a13e40 commit c87f767

7 files changed

Lines changed: 39 additions & 12 deletions

compiler/rustc_session/src/options.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ pub enum TargetModifierValue {
270270
String(String),
271271
BranchProtection(BranchProtection),
272272
Sanitizers(SanitizerSet),
273+
PointerAuthentication(Vec<(PointerAuthOption, bool)>),
273274
}
274275

275276
impl fmt::Display for TargetModifierValue {
@@ -281,6 +282,14 @@ impl fmt::Display for TargetModifierValue {
281282
Self::String(val) => write!(f, "={val}"),
282283
Self::BranchProtection(val) => write!(f, "={val}"),
283284
Self::Sanitizers(val) => write!(f, "={val}"),
285+
Self::PointerAuthentication(vals) => {
286+
let mut parts = Vec::new();
287+
for (opt, pos) in vals {
288+
let polarity = if *pos { "+" } else { "-" };
289+
parts.push(format!("{polarity}{opt}"));
290+
}
291+
write!(f, "={}", parts.join(","))
292+
}
284293
}
285294
}
286295
}
@@ -301,6 +310,7 @@ noop_target_modifier_ty!(
301310
// tidy-alphabetical-start
302311
SanitizerSet => Self::Sanitizers,
303312
String => Self::String,
313+
Vec<(PointerAuthOption, bool)> => Self::PointerAuthentication,
304314
bool => Self::Bool,
305315
u32 => Self::U32,
306316
usize => Self::Usize,
@@ -2537,6 +2547,25 @@ options! {
25372547
"panic strategy to compile crate with"),
25382548
passes: Vec<String> = (Vec::new(), parse_list, [TRACKED],
25392549
"a list of extra LLVM passes to run (space separated)"),
2550+
pointer_authentication: Vec<(PointerAuthOption, bool)> = (
2551+
Vec::new(),
2552+
parse_pointer_authentication_list_with_polarity,
2553+
[TRACKED_UNSTABLE] { TARGET_MODIFIER: Only },
2554+
"A comma-separated list of pointer authentication options, each prefixed with `+` (enable) or `-` (disable). Available options:
2555+
`aarch64-jump-table-hardening` - enable hardened lowering for jump-table dispatch
2556+
`auth-traps` - trap immediately on pointer authentication failure
2557+
`calls` - enable signing and authentication of all indirect calls
2558+
`elf-got` - enable authentication of pointers from GOT (ELF only)
2559+
`function-pointer-type-discrimination` - enable type discrimination on C function pointers
2560+
`indirect-gotos` - enable signing and authentication of indirect goto targets
2561+
`init-fini` - enable signing of function pointers in init/fini arrays
2562+
`init-fini-address-discrimination` - enable address discrimination in init/fini arrays
2563+
`intrinsics` - pointer authentication intrinsics
2564+
`return-addresses` - enable signing and authentication of return addresses
2565+
`typeinfo-vt-ptr-discrimination - incorporate type and address discrimination in authenticated vtable pointers for std::type_info
2566+
`vt-ptr-addr-discrimination - incorporate address discrimination in authenticated vtable pointers
2567+
`vt-ptr-type-discrimination - incorporate type discrimination in authenticated vtable pointers
2568+
Example: `-Zpointer-authentication=+calls,-init-fini`."),
25402569
prefer_dynamic: bool = (false, parse_bool, [TRACKED],
25412570
"prefer dynamic linking to static linking (default: no)"),
25422571
profile_generate: SwitchWithOptPath = (SwitchWithOptPath::Disabled,

compiler/rustc_session/src/session.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ pub fn build_session(
13551355
let timings = TimingSectionHandler::new(sopts.json_timings);
13561356

13571357
let pointer_auth_config: Option<PointerAuthConfig> =
1358-
PointerAuthConfig::from_raw(&sopts.target_opts.pointer_authentication, &target);
1358+
PointerAuthConfig::from_raw(&sopts.cg.pointer_authentication, &target);
13591359

13601360
let sess = Session {
13611361
target,
@@ -1437,9 +1437,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
14371437
);
14381438
}
14391439

1440-
if sess.target.cfg_abi != CfgAbi::Pauthtest
1441-
&& !sess.opts.target_opts.pointer_authentication.is_empty()
1442-
{
1440+
if sess.target.cfg_abi != CfgAbi::Pauthtest && !sess.opts.cg.pointer_authentication.is_empty() {
14431441
sess.dcx().emit_warn(diagnostics::PointerAuthenticationNotSupportedForTarget {
14441442
target_triple: &sess.opts.target_triple,
14451443
});
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: incorrect value `+I,+do,-not,-exist` for target option `pointer-authentication` - a comma-separated list of options, each of the form `+<name>` or `-<name>`, where `<name>` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected
1+
error: incorrect value `+I,+do,-not,-exist` for codegen option `pointer-authentication` - a comma-separated list of options, each of the form `+<name>` or `-<name>`, where `<name>` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected
22

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: incorrect value `` for target option `pointer-authentication` - a comma-separated list of options, each of the form `+<name>` or `-<name>`, where `<name>` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected
1+
error: incorrect value `` for codegen option `pointer-authentication` - a comma-separated list of options, each of the form `+<name>` or `-<name>`, where `<name>` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected
22

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: incorrect value `+elf-got,-imaginary` for target option `pointer-authentication` - a comma-separated list of options, each of the form `+<name>` or `-<name>`, where `<name>` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected
1+
error: incorrect value `+elf-got,-imaginary` for codegen option `pointer-authentication` - a comma-separated list of options, each of the form `+<name>` or `-<name>`, where `<name>` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected
22

tests/ui/pointer_authentication/enable_pointer_authentication_validation.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#![no_main]
2020
#![no_core]
2121

22-
//[empty]~? ERROR incorrect value `` for target option `pointer-authentication`
23-
//[unprefixed]~? ERROR incorrect value `auth-traps` for target option `pointer-authentication`
24-
//[all_unknown]~? ERROR incorrect value `+I,+do,-not,-exist` for target option `pointer-authentication`
25-
//[mixed]~? ERROR incorrect value `+elf-got,-imaginary` for target option `pointer-authentication`
22+
//[empty]~? ERROR incorrect value `` for codegen option `pointer-authentication`
23+
//[unprefixed]~? ERROR incorrect value `auth-traps` for codegen option `pointer-authentication`
24+
//[all_unknown]~? ERROR incorrect value `+I,+do,-not,-exist` for codegen option `pointer-authentication`
25+
//[mixed]~? ERROR incorrect value `+elf-got,-imaginary` for codegen option `pointer-authentication`
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: incorrect value `auth-traps` for target option `pointer-authentication` - a comma-separated list of options, each of the form `+<name>` or `-<name>`, where `<name>` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected
1+
error: incorrect value `auth-traps` for codegen option `pointer-authentication` - a comma-separated list of options, each of the form `+<name>` or `-<name>`, where `<name>` is one of: `aarch64-jump-table-hardening`, `auth-traps`, `calls`, `elf-got`, `function-pointer-type-discrimination`, `indirect-gotos`, `init-fini`, `init-fini-address-discrimination`, `intrinsics`, `return-addresses`, `typeinfo-vt-ptr-discrimination`, `vt-ptr-addr-discrimination` or `vt-ptr-type-discrimination` was expected
22

0 commit comments

Comments
 (0)