Skip to content

Commit df1ae0f

Browse files
committed
Auto merge of rust-lang#159325 - jhpratt:rollup-wVbUouH, r=jhpratt
Rollup of 5 pull requests Successful merges: - rust-lang#156712 (Pointer authentication config and user facing options) - rust-lang#158522 (Lint against invalid POSIX symbol definitions) - rust-lang#159229 (ast_lowering: Reject invalid direct_const_arg owners) - rust-lang#159270 (Only force backtraces when a panic occurs in bootstrap) - rust-lang#159308 (Reorganize `tests/ui/issues` [24/N])
2 parents 47101ad + 66be5f8 commit df1ae0f

86 files changed

Lines changed: 1369 additions & 248 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -499,15 +499,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
499499

500500
ExprKind::MacCall(_) => panic!("{:?} shouldn't exist here", e.span),
501501

502-
ExprKind::DirectConstArg(_) => {
503-
let e = self
504-
.tcx
505-
.dcx()
506-
.struct_span_err(
507-
e.span,
508-
"expected expression, found `direct_const_arg!()` constant",
509-
)
510-
.emit();
502+
ExprKind::DirectConstArg(expr) => {
503+
let e = self.emit_bad_direct_const_arg(e.span, expr, "expression");
511504
hir::ExprKind::Err(e)
512505
}
513506
};

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ use rustc_data_structures::steal::Steal;
5353
use rustc_data_structures::tagged_ptr::TaggedRef;
5454
use rustc_data_structures::unord::ExtendUnord;
5555
use rustc_errors::codes::*;
56-
use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle};
56+
use rustc_errors::{DiagArgFromDisplay, DiagCtxtHandle, ErrorGuaranteed};
5757
use rustc_hir::def::{DefKind, LifetimeRes, Namespace, PartialRes, PerNS, Res};
5858
use rustc_hir::def_id::{DefId, LOCAL_CRATE, LocalDefId, LocalDefIdMap};
5959
use rustc_hir::definitions::PerParentDisambiguatorState;
@@ -1760,12 +1760,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
17601760
let fields = self.arena.alloc_slice(fields);
17611761
hir::TyKind::View(ty, fields)
17621762
}
1763-
TyKind::DirectConstArg(_) => {
1764-
let e = self
1765-
.tcx
1766-
.dcx()
1767-
.struct_span_err(t.span, "expected type, found `direct_const_arg!()` constant")
1768-
.emit();
1763+
TyKind::DirectConstArg(expr) => {
1764+
let e = self.emit_bad_direct_const_arg(t.span, expr, "type");
17691765
hir::TyKind::Err(e)
17701766
}
17711767
TyKind::Dummy => panic!("`TyKind::Dummy` should never be lowered"),
@@ -1774,6 +1770,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
17741770
hir::Ty { kind, span: self.lower_span(t.span), hir_id: self.lower_node_id(t.id) }
17751771
}
17761772

1773+
pub(crate) fn emit_bad_direct_const_arg(
1774+
&mut self,
1775+
span: Span,
1776+
expr: &Expr,
1777+
expected: &'static str,
1778+
) -> ErrorGuaranteed {
1779+
let msg = format!("expected {expected}, found `direct_const_arg!()` constant");
1780+
if expr::WillCreateDefIdsVisitor.visit_expr(expr).is_break() {
1781+
// FIXME(mgca): make this non-fatal once we have a better way to handle
1782+
// nested items in invalid `direct_const_arg!()` arguments.
1783+
self.dcx().struct_span_fatal(span, msg).emit()
1784+
} else {
1785+
self.dcx().struct_span_err(span, msg).emit()
1786+
}
1787+
}
1788+
17771789
fn lower_ty_direct_lifetime(
17781790
&mut self,
17791791
t: &Ty,

compiler/rustc_codegen_gcc/src/common.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ use gccjit::{LValue, RValue, ToRValue, Type};
22
use rustc_abi::Primitive::Pointer;
33
use rustc_abi::{self as abi, HasDataLayout};
44
use rustc_codegen_ssa::traits::{
5-
BaseTypeCodegenMethods, ConstCodegenMethods, MiscCodegenMethods, PacMetadata,
6-
StaticCodegenMethods,
5+
BaseTypeCodegenMethods, ConstCodegenMethods, MiscCodegenMethods, StaticCodegenMethods,
76
};
87
use rustc_middle::mir::Mutability;
98
use rustc_middle::mir::interpret::{GlobalAlloc, PointerArithmetic, Scalar};
109
use rustc_middle::ty::layout::LayoutOf;
10+
use rustc_session::PointerAuthSchema;
1111

1212
use crate::consts::const_alloc_to_gcc;
1313
use crate::context::{CodegenCx, new_array_type};
@@ -247,7 +247,7 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
247247
cv: Scalar,
248248
layout: abi::Scalar,
249249
ty: Type<'gcc>,
250-
_pac: Option<PacMetadata>,
250+
_schema: Option<&PointerAuthSchema>,
251251
) -> RValue<'gcc> {
252252
let bitsize = if layout.is_bool() { 1 } else { layout.size(self).bits() };
253253
match cv {

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ use gccjit::{Block, CType, Context, Function, FunctionType, LValue, Location, RV
55
use rustc_abi::{Align, HasDataLayout, PointeeInfo, Size, TargetDataLayout, VariantIdx};
66
use rustc_codegen_ssa::base::wants_msvc_seh;
77
use rustc_codegen_ssa::errors as ssa_errors;
8-
use rustc_codegen_ssa::traits::{
9-
BackendTypes, BaseTypeCodegenMethods, MiscCodegenMethods, PacMetadata,
10-
};
8+
use rustc_codegen_ssa::traits::{BackendTypes, BaseTypeCodegenMethods, MiscCodegenMethods};
119
use rustc_data_structures::base_n::{ALPHANUMERIC_ONLY, ToBaseN};
1210
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1311
use rustc_middle::mir::interpret::Allocation;
@@ -18,9 +16,9 @@ use rustc_middle::ty::layout::{
1816
LayoutOfHelpers,
1917
};
2018
use rustc_middle::ty::{self, ExistentialTraitRef, Instance, Ty, TyCtxt};
21-
use rustc_session::Session;
2219
#[cfg(feature = "master")]
2320
use rustc_session::config::DebugInfo;
21+
use rustc_session::{PointerAuthSchema, Session};
2422
use rustc_span::{DUMMY_SP, Span, Symbol, respan};
2523
use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, TlsModel, X86Abi};
2624

@@ -400,7 +398,11 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
400398
get_fn(self, instance)
401399
}
402400

403-
fn get_fn_addr(&self, instance: Instance<'tcx>, _pac: Option<PacMetadata>) -> RValue<'gcc> {
401+
fn get_fn_addr(
402+
&self,
403+
instance: Instance<'tcx>,
404+
_pointer_auth_schema: Option<&PointerAuthSchema>,
405+
) -> RValue<'gcc> {
404406
let func_name = self.tcx.symbol_name(instance).name;
405407

406408
let func = if let Some(variable) = self.get_declared_value(func_name) {

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@ use rustc_session::config::{
1212
};
1313
use rustc_span::sym;
1414
use rustc_symbol_mangling::mangle_internal_symbol;
15-
use rustc_target::spec::{
16-
Arch, FramePointer, LlvmAbi, SanitizerSet, StackProbeType, StackProtector,
17-
};
15+
use rustc_target::spec::{Arch, FramePointer, SanitizerSet, StackProbeType, StackProtector};
1816
use smallvec::SmallVec;
1917

20-
use crate::common::pauth_fn_attrs;
2118
use crate::context::SimpleCx;
2219
use crate::errors::{PackedStackBackchainNeedsSoftfloat, SanitizerMemtagRequiresMte};
2320
use crate::llvm::AttributePlace::Function;
@@ -668,8 +665,9 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
668665
}
669666
}
670667

671-
if sess.target.llvm_abiname == LlvmAbi::Pauthtest {
672-
for &ptrauth_attr in pauth_fn_attrs() {
668+
if sess.pointer_authentication() {
669+
let cfg = sess.pointer_auth_config.as_ref().unwrap();
670+
for ptrauth_attr in cfg.fn_attrs() {
673671
to_add.push(llvm::CreateAttrString(cx.llcx, ptrauth_attr));
674672
}
675673
}

compiler/rustc_codegen_llvm/src/base.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ use rustc_middle::mono::Visibility;
2525
use rustc_middle::ty::TyCtxt;
2626
use rustc_session::config::{DebugInfo, Offload};
2727
use rustc_span::Symbol;
28-
use rustc_target::spec::{LlvmAbi, SanitizerSet};
28+
use rustc_target::spec::SanitizerSet;
2929

3030
use super::ModuleLlvm;
3131
use crate::attributes;
3232
use crate::builder::Builder;
3333
use crate::builder::gpu_offload::OffloadGlobals;
34-
use crate::common::pauth_fn_attrs;
3534
use crate::context::CodegenCx;
3635
use crate::llvm::{self, Value};
3736

@@ -137,8 +136,9 @@ pub(crate) fn compile_codegen_unit(
137136
// FIXME(jchlanda) If it ever becomes necessary to ensure that all compiler
138137
// generated functions receive the ptrauth-* attributes, `declare_fn` or
139138
// `declare_raw_fn` could be used to provide those.
140-
if cx.sess().target.llvm_abiname == LlvmAbi::Pauthtest {
141-
for &ptrauth_attr in pauth_fn_attrs() {
139+
if cx.sess().pointer_authentication() {
140+
let cfg = cx.sess().pointer_auth_config.as_ref().unwrap();
141+
for ptrauth_attr in cfg.fn_attrs() {
142142
attrs.push(llvm::CreateAttrString(cx.llcx, ptrauth_attr));
143143
}
144144
}
@@ -158,28 +158,22 @@ pub(crate) fn compile_codegen_unit(
158158
cx.add_objc_module_flags();
159159
}
160160

161-
if cx.sess().target.llvm_abiname == LlvmAbi::Pauthtest {
162-
// FIXME(jchlanda): In LLVM/Clang, there are also `aarch64-elf-pauthabi-platform`
163-
// and `aarch64-elf-pauthabi-version` module flags. These are emitted into the
164-
// PAuth core info section of the resulting ELF, which the linker uses to enforce
165-
// binary compatibility.
166-
//
167-
// We intentionally do not emit these flags now, since only a subset of features
168-
// included in clang's pauthtest is currently supported. By default, the absence of
169-
// this info is treated as compatible with any binary.
170-
//
171-
// Please note, that this would cause compatibility issues, specifically runtime
172-
// crashes due to authentication failures (while compiling and linking
173-
// successfully) when linking against binaries that support larger set of features
174-
// (for example, signing of C++ member function pointers, virtual function
175-
// pointers, virtual table pointers).
176-
//
177-
// Link to PAuth core info documentation:
178-
// <https://github.com/ARM-software/abi-aa/blob/2025Q4/pauthabielf64/pauthabielf64.rst#core-information>
179-
if cx.sess().opts.unstable_opts.ptrauth_elf_got {
161+
if cx.sess().pointer_authentication() {
162+
let cfg = cx.sess().pointer_auth_config.as_ref().unwrap();
163+
164+
let aarch64_elf_pauthabi_version =
165+
cfg.calculate_pauth_abi_version(&cx.sess().target);
166+
if aarch64_elf_pauthabi_version != 0 {
167+
cx.add_ptrauth_pauthabi_version_and_platform_flags(
168+
aarch64_elf_pauthabi_version,
169+
);
170+
}
171+
if cfg.elf_got {
180172
cx.add_ptrauth_elf_got_flag();
181173
}
182-
cx.add_ptrauth_sign_personality_flag();
174+
if cx.sess().pointer_authentication_functions().is_some() {
175+
cx.add_ptrauth_sign_personality_flag();
176+
}
183177
}
184178

185179
// Finalize code coverage by injecting the coverage map. Note, the coverage map will

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_sanitizers::{cfi, kcfi};
2626
use rustc_session::config::OptLevel;
2727
use rustc_span::Span;
2828
use rustc_target::callconv::{FnAbi, PassMode};
29-
use rustc_target::spec::{Arch, HasTargetSpec, LlvmAbi, SanitizerSet, Target};
29+
use rustc_target::spec::{Arch, HasTargetSpec, SanitizerSet, Target};
3030
use smallvec::SmallVec;
3131
use tracing::{debug, instrument};
3232

@@ -2039,7 +2039,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
20392039
llfn: &'ll Value,
20402040
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
20412041
) -> Option<llvm::OperandBundleBox<'ll>> {
2042-
if self.sess().target.llvm_abiname != LlvmAbi::Pauthtest {
2042+
if self.sess().pointer_authentication_functions().is_none() {
20432043
return None;
20442044
}
20452045
// Pointer authentication support is currently limited to extern "C" calls; filter out other

compiler/rustc_codegen_llvm/src/common.rs

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::bug;
1616
use rustc_middle::mir::interpret::{GlobalAlloc, PointerArithmetic, Scalar};
1717
use rustc_middle::ty::{Instance, TyCtxt};
1818
use rustc_session::cstore::DllImport;
19-
use rustc_target::spec::LlvmAbi;
19+
use rustc_session::{PointerAuthAddressDiscriminator, PointerAuthSchema};
2020
use tracing::debug;
2121

2222
use crate::consts::{IsInitOrFini, IsStatic, const_alloc_to_llvm};
@@ -26,27 +26,13 @@ use crate::llvm::{
2626
self, BasicBlock, ConstantInt, FALSE, TRUE, ToLlvmBool, Type, Value, const_ptr_auth,
2727
};
2828

29-
#[inline]
30-
pub(crate) fn pauth_fn_attrs() -> &'static [&'static str] {
31-
// FIXME(jchlanda) This is not an exhaustive list of all `ptrauth`-related attributes, but only
32-
// those currently supported. The list is expected to grow as additional functionality is
33-
// implemented, particularly for C++ interoperability.
34-
&[
35-
"aarch64-jump-table-hardening",
36-
"ptrauth-indirect-gotos",
37-
"ptrauth-calls",
38-
"ptrauth-returns",
39-
"ptrauth-auth-traps",
40-
]
41-
}
42-
4329
pub(crate) fn maybe_sign_fn_ptr<'ll, 'tcx>(
4430
cx: &CodegenCx<'ll, '_>,
4531
instance: Instance<'tcx>,
4632
llfn: &'ll llvm::Value,
47-
pac: PacMetadata,
33+
schema: &PointerAuthSchema,
4834
) -> &'ll llvm::Value {
49-
if cx.sess().target.llvm_abiname != LlvmAbi::Pauthtest {
35+
if cx.tcx.sess.pointer_authentication_functions().is_none() {
5036
return llfn;
5137
}
5238

@@ -68,16 +54,16 @@ pub(crate) fn maybe_sign_fn_ptr<'ll, 'tcx>(
6854
return llfn;
6955
}
7056

71-
let addr_diversity = match pac.addr_diversity {
72-
AddressDiversity::None => None,
73-
AddressDiversity::Real => Some(llfn),
74-
AddressDiversity::Synthetic(val) => {
57+
let addr_diversity = match schema.is_address_discriminated {
58+
PointerAuthAddressDiscriminator::HardwareAddress(true) => Some(llfn),
59+
PointerAuthAddressDiscriminator::HardwareAddress(false) => None,
60+
PointerAuthAddressDiscriminator::Synthetic(val) => {
7561
let llval = cx.const_u64(val);
7662
let llty = cx.val_ty(llfn);
7763
Some(unsafe { llvm::LLVMConstIntToPtr(llval, llty) })
7864
}
7965
};
80-
const_ptr_auth(llfn, pac.key, pac.disc, addr_diversity)
66+
const_ptr_auth(llfn, schema.key as u32, schema.constant_discriminator as u64, addr_diversity)
8167
}
8268

8369
/*
@@ -331,7 +317,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
331317
cv: Scalar,
332318
layout: abi::Scalar,
333319
llty: &'ll Type,
334-
pac: Option<PacMetadata>,
320+
schema: Option<&PointerAuthSchema>,
335321
) -> &'ll Value {
336322
let bitsize = if layout.is_bool() { 1 } else { layout.size(self).bits() };
337323
match cv {
@@ -387,7 +373,7 @@ impl<'ll, 'tcx> ConstCodegenMethods for CodegenCx<'ll, 'tcx> {
387373
value
388374
}
389375
}
390-
GlobalAlloc::Function { instance, .. } => self.get_fn_addr(instance, pac),
376+
GlobalAlloc::Function { instance, .. } => self.get_fn_addr(instance, schema),
391377
GlobalAlloc::VTable(ty, dyn_ty) => {
392378
let alloc = self
393379
.tcx

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_middle::ty::layout::{HasTypingEnv, LayoutOf};
1717
use rustc_middle::ty::{self, Instance};
1818
use rustc_middle::{bug, span_bug};
1919
use rustc_span::Symbol;
20-
use rustc_target::spec::{Arch, LlvmAbi};
20+
use rustc_target::spec::Arch;
2121
use tracing::{debug, instrument, trace};
2222

2323
use crate::common::CodegenCx;
@@ -32,6 +32,7 @@ pub(crate) enum IsStatic {
3232
No,
3333
}
3434
/// Indicates whether a symbol is part of `.init_array` or `.fini_array`.
35+
#[derive(PartialEq)]
3536
pub(crate) enum IsInitOrFini {
3637
Yes,
3738
No,
@@ -120,31 +121,22 @@ pub(crate) fn const_alloc_to_llvm<'ll>(
120121
as u64;
121122

122123
let address_space = cx.tcx.global_alloc(prov.alloc_id()).address_space(cx);
123-
// Under pointer authentication, function pointers stored in init/fini arrays need special
124-
// handling.
125-
let pac_metadata = Some(
126-
if cx.sess().target.llvm_abiname == LlvmAbi::Pauthtest
127-
&& matches!(is_init_fini, IsInitOrFini::Yes)
128-
{
129-
PacMetadata {
130-
// Must correspond to ptrauth_key_init_fini_pointer from `ptrauth.h`.
131-
key: 0,
132-
// ptrauth_string_discriminator("init_fini")
133-
disc: 0xd9d4,
134-
addr_diversity: AddressDiversity::Synthetic(1),
135-
}
136-
} else {
137-
PacMetadata::default()
138-
},
139-
);
124+
let schema = if cx.sess().pointer_authentication() {
125+
match is_init_fini {
126+
IsInitOrFini::Yes => cx.sess().pointer_authentication_init_fini(),
127+
IsInitOrFini::No => cx.sess().pointer_authentication_functions(),
128+
}
129+
} else {
130+
None
131+
};
140132
llvals.push(cx.scalar_to_backend_with_pac(
141133
InterpScalar::from_pointer(Pointer::new(prov, Size::from_bytes(ptr_offset)), &cx.tcx),
142134
Scalar::Initialized {
143135
value: Primitive::Pointer(address_space),
144136
valid_range: WrappingRange::full(pointer_size),
145137
},
146138
cx.type_ptr_ext(address_space),
147-
pac_metadata,
139+
schema,
148140
));
149141
next_offset = offset + pointer_size_bytes;
150142
}
@@ -221,7 +213,7 @@ fn check_and_apply_linkage<'ll, 'tcx>(
221213
let fn_sig = sig.with(*header);
222214
let fn_abi = cx.fn_abi_of_fn_ptr(fn_sig, ty::List::empty());
223215
// Decide if the initializer needs to be signed
224-
if cx.sess().target.llvm_abiname == LlvmAbi::Pauthtest
216+
if cx.sess().pointer_authentication()
225217
&& matches!(fn_sig.abi(), ExternAbi::C { .. } | ExternAbi::System { .. })
226218
{
227219
should_sign = true;

0 commit comments

Comments
 (0)