Skip to content

Commit 3456328

Browse files
committed
Auto merge of #158593 - JonathanBrouwer:rollup-tGO5Zmu, r=JonathanBrouwer
Rollup of 11 pull requests Successful merges: - #155722 (Introduce aarch64-unknown-linux-pauthtest target) - #156230 (tests: check wasm compiler_builtins object architecture) - #156295 (Pass the whole `GenericArgs` to `Interner::for_each_relevant_impl()`) - #158375 (Support `DefKind::InlineConst` in `ConstKind::Unevaluated`) - #158556 (delegation: store child segment flag in `PathSegment`) - #158081 (trait-system: Recover deferred closure calls after errors) - #158468 (Include default-stability info in rustdoc JSON.) - #158543 (Note usage of documentation hard links in `core::io`) - #158564 (fix `-Z min-recursion-limit` unstable chapter name) - #158568 (llvm-wrapper: use accessors for private fields in LLVM 23+) - #158582 (Comment on needed RAM in huge-stacks.rs)
2 parents 0966944 + 9779110 commit 3456328

109 files changed

Lines changed: 2550 additions & 318 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/delegation.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ use rustc_span::def_id::{DefId, LocalDefId};
5555
use rustc_span::symbol::kw;
5656
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol};
5757

58-
use crate::delegation::generics::{GenericsGenerationResult, GenericsGenerationResults};
58+
use crate::delegation::generics::{
59+
GenericsGenerationResult, GenericsGenerationResults, GenericsPosition,
60+
};
5961
use crate::diagnostics::{
6062
CycleInDelegationSignatureResolution, DelegationAttemptedBlockWithDefsDeletion,
6163
DelegationBlockSpecifiedWhenNoParams, UnresolvedDelegationCallee,
@@ -505,6 +507,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
505507
res: Res::Local(param_id),
506508
args: None,
507509
infer_args: false,
510+
delegation_child_segment: false,
508511
}));
509512

510513
let path = self.arena.alloc(hir::Path { span, res: Res::Local(param_id), segments });
@@ -714,6 +717,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
714717
result.args_segment_id = segment.hir_id;
715718
result.use_for_sig_inheritance = !result.generics.is_trait_impl();
716719

720+
segment.delegation_child_segment = result.generics.pos() == GenericsPosition::Child;
721+
717722
segment
718723
}
719724

compiler/rustc_ast_lowering/src/delegation/generics.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc_span::{Ident, Span, sym};
1212
use crate::LoweringContext;
1313
use crate::diagnostics::DelegationInfersMismatch;
1414

15-
#[derive(Debug, Clone, Copy)]
15+
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
1616
pub(super) enum GenericsPosition {
1717
Parent,
1818
Child,
@@ -155,7 +155,7 @@ impl<'hir> DelegationGenericArgsIterator<'hir> {
155155
impl<'hir> HirOrTyGenerics<'hir> {
156156
pub(super) fn into_hir_generics(&mut self, ctx: &mut LoweringContext<'_, 'hir>, span: Span) {
157157
if let HirOrTyGenerics::Ty(ty) = self {
158-
let rename_self = matches!(ty.pos, GenericsPosition::Child);
158+
let rename_self = ty.pos == GenericsPosition::Child;
159159
let params = ctx.uplift_delegation_generic_params(span, &ty.data, rename_self);
160160

161161
*self = HirOrTyGenerics::Hir(DelegationGenerics {
@@ -218,6 +218,13 @@ impl<'hir> HirOrTyGenerics<'hir> {
218218
.expect("`Self` generic param is not found while expected"),
219219
}
220220
}
221+
222+
pub(crate) fn pos(&self) -> GenericsPosition {
223+
match self {
224+
HirOrTyGenerics::Ty(ty) => ty.pos,
225+
HirOrTyGenerics::Hir(hir) => hir.pos,
226+
}
227+
}
221228
}
222229

223230
impl<'hir> GenericsGenerationResult<'hir> {
@@ -590,6 +597,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
590597
ident: p.name.ident(),
591598
infer_args: false,
592599
res,
600+
delegation_child_segment: false,
593601
}]),
594602
res,
595603
span: p.span,

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10141014
res,
10151015
args,
10161016
infer_args: args.is_none(),
1017+
delegation_child_segment: false,
10171018
}]),
10181019
})
10191020
}
@@ -2791,7 +2792,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
27912792
}
27922793
ExprKind::ConstBlock(anon_const) => {
27932794
let def_id = self.local_def_id(anon_const.id);
2794-
assert_eq!(DefKind::AnonConst, self.tcx.def_kind(def_id));
2795+
assert_eq!(DefKind::InlineConst, self.tcx.def_kind(def_id));
27952796
self.lower_anon_const_to_const_arg(anon_const, span)
27962797
}
27972798
_ => overly_complex_const(self),

compiler/rustc_ast_lowering/src/path.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
412412
} else {
413413
Some(generic_args.into_generic_args(self))
414414
},
415+
delegation_child_segment: false,
415416
}
416417
}
417418

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
615615

616616
BodyOwnerKind::Const { .. } | BodyOwnerKind::Static(..) => {
617617
match tcx.def_kind(self.mir_def) {
618-
DefKind::InlineConst => {
618+
DefKind::InlineConst if !tcx.is_type_system_inline_const(self.mir_def) => {
619619
// This is required for `AscribeUserType` canonical query, which will call
620620
// `type_of(inline_const_def_id)`. That `type_of` would inject erased lifetimes
621621
// into borrowck, which is ICE #78174.

compiler/rustc_codegen_gcc/src/common.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ 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, StaticCodegenMethods,
5+
BaseTypeCodegenMethods, ConstCodegenMethods, MiscCodegenMethods, PacMetadata,
6+
StaticCodegenMethods,
67
};
78
use rustc_middle::mir::Mutability;
89
use rustc_middle::mir::interpret::{GlobalAlloc, PointerArithmetic, Scalar};
@@ -241,7 +242,13 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
241242
None
242243
}
243244

244-
fn scalar_to_backend(&self, cv: Scalar, layout: abi::Scalar, ty: Type<'gcc>) -> RValue<'gcc> {
245+
fn scalar_to_backend_with_pac(
246+
&self,
247+
cv: Scalar,
248+
layout: abi::Scalar,
249+
ty: Type<'gcc>,
250+
_pac: Option<PacMetadata>,
251+
) -> RValue<'gcc> {
245252
let bitsize = if layout.is_bool() { 1 } else { layout.size(self).bits() };
246253
match cv {
247254
Scalar::Int(int) => {
@@ -290,7 +297,7 @@ impl<'gcc, 'tcx> ConstCodegenMethods for CodegenCx<'gcc, 'tcx> {
290297
}
291298
value
292299
}
293-
GlobalAlloc::Function { instance, .. } => self.get_fn_addr(instance),
300+
GlobalAlloc::Function { instance, .. } => self.get_fn_addr(instance, None),
294301
GlobalAlloc::VTable(ty, dyn_ty) => {
295302
let alloc = self
296303
.tcx

compiler/rustc_codegen_gcc/src/context.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ 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::{BackendTypes, BaseTypeCodegenMethods, MiscCodegenMethods};
8+
use rustc_codegen_ssa::traits::{
9+
BackendTypes, BaseTypeCodegenMethods, MiscCodegenMethods, PacMetadata,
10+
};
911
use rustc_data_structures::base_n::{ALPHANUMERIC_ONLY, ToBaseN};
1012
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1113
use rustc_middle::mir::interpret::Allocation;
@@ -398,7 +400,7 @@ impl<'gcc, 'tcx> MiscCodegenMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
398400
get_fn(self, instance)
399401
}
400402

401-
fn get_fn_addr(&self, instance: Instance<'tcx>) -> RValue<'gcc> {
403+
fn get_fn_addr(&self, instance: Instance<'tcx>, _pac: Option<PacMetadata>) -> RValue<'gcc> {
402404
let func_name = self.tcx.symbol_name(instance).name;
403405

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

compiler/rustc_codegen_llvm/src/attributes.rs

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

20+
use crate::common::pauth_fn_attrs;
1821
use crate::context::SimpleCx;
1922
use crate::errors::{PackedStackBackchainNeedsSoftfloat, SanitizerMemtagRequiresMte};
2023
use crate::llvm::AttributePlace::Function;
@@ -643,6 +646,12 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
643646
}
644647
}
645648

649+
if sess.target.llvm_abiname == LlvmAbi::Pauthtest {
650+
for &ptrauth_attr in pauth_fn_attrs() {
651+
to_add.push(llvm::CreateAttrString(cx.llcx, ptrauth_attr));
652+
}
653+
}
654+
646655
to_add.extend(target_features_attr(cx, tcx, function_features));
647656

648657
attributes::apply_to_llfn(llfn, Function, &to_add);

compiler/rustc_codegen_llvm/src/base.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,13 @@ 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::SanitizerSet;
28+
use rustc_target::spec::{LlvmAbi, 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;
3435
use crate::context::CodegenCx;
3536
use crate::llvm::{self, Value};
3637

@@ -123,7 +124,18 @@ pub(crate) fn compile_codegen_unit(
123124
if let Some(entry) =
124125
maybe_create_entry_wrapper::<Builder<'_, '_, '_>>(&cx, cx.codegen_unit)
125126
{
126-
let attrs = attributes::sanitize_attrs(&cx, tcx, SanitizerFnAttrs::default());
127+
let mut attrs = attributes::sanitize_attrs(&cx, tcx, SanitizerFnAttrs::default());
128+
// When pointer authentication is enabled, ensure that the ptrauth-* attributes are
129+
// also attached to the entry wrapper.
130+
//
131+
// FIXME(jchlanda) If it ever becomes necessary to ensure that all compiler
132+
// generated functions receive the ptrauth-* attributes, `declare_fn` or
133+
// `declare_raw_fn` could be used to provide those.
134+
if cx.sess().target.llvm_abiname == LlvmAbi::Pauthtest {
135+
for &ptrauth_attr in pauth_fn_attrs() {
136+
attrs.push(llvm::CreateAttrString(cx.llcx, ptrauth_attr));
137+
}
138+
}
127139
attributes::apply_to_llfn(entry, llvm::AttributePlace::Function, &attrs);
128140
}
129141

@@ -140,6 +152,30 @@ pub(crate) fn compile_codegen_unit(
140152
cx.add_objc_module_flags();
141153
}
142154

155+
if cx.sess().target.llvm_abiname == LlvmAbi::Pauthtest {
156+
// FIXME(jchlanda): In LLVM/Clang, there are also `aarch64-elf-pauthabi-platform`
157+
// and `aarch64-elf-pauthabi-version` module flags. These are emitted into the
158+
// PAuth core info section of the resulting ELF, which the linker uses to enforce
159+
// binary compatibility.
160+
//
161+
// We intentionally do not emit these flags now, since only a subset of features
162+
// included in clang's pauthtest is currently supported. By default, the absence of
163+
// this info is treated as compatible with any binary.
164+
//
165+
// Please note, that this would cause compatibility issues, specifically runtime
166+
// crashes due to authentication failures (while compiling and linking
167+
// successfully) when linking against binaries that support larger set of features
168+
// (for example, signing of C++ member function pointers, virtual function
169+
// pointers, virtual table pointers).
170+
//
171+
// Link to PAuth core info documentation:
172+
// <https://github.com/ARM-software/abi-aa/blob/2025Q4/pauthabielf64/pauthabielf64.rst#core-information>
173+
if cx.sess().opts.unstable_opts.ptrauth_elf_got {
174+
cx.add_ptrauth_elf_got_flag();
175+
}
176+
cx.add_ptrauth_sign_personality_flag();
177+
}
178+
143179
// Finalize code coverage by injecting the coverage map. Note, the coverage map will
144180
// also be added to the `llvm.compiler.used` variable, created next.
145181
if cx.sess().instrument_coverage() {

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub(crate) mod autodiff;
77
pub(crate) mod gpu_offload;
88

99
use libc::{c_char, c_uint};
10-
use rustc_abi::{self as abi, Align, Size, WrappingRange};
10+
use rustc_abi::{self as abi, Align, CanonAbi, Size, WrappingRange};
1111
use rustc_codegen_ssa::MemFlags;
1212
use rustc_codegen_ssa::common::{IntPredicate, RealPredicate, SynchronizationScope, TypeKind};
1313
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
@@ -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, SanitizerSet, Target};
29+
use rustc_target::spec::{Arch, HasTargetSpec, LlvmAbi, SanitizerSet, Target};
3030
use smallvec::SmallVec;
3131
use tracing::{debug, instrument};
3232

@@ -475,6 +475,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
475475
bundles.push(kcfi_bundle);
476476
}
477477

478+
let pauth = self.ptrauth_operand_bundle(llfn, fn_abi);
479+
if let Some(p) = pauth.as_ref().map(|b| b.as_ref()) {
480+
bundles.push(p);
481+
}
482+
478483
let invoke = unsafe {
479484
llvm::LLVMBuildInvokeWithOperandBundles(
480485
self.llbuilder,
@@ -1472,6 +1477,11 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
14721477
bundles.push(kcfi_bundle);
14731478
}
14741479

1480+
let pauth = self.ptrauth_operand_bundle(llfn, fn_abi);
1481+
if let Some(p) = pauth.as_ref().map(|b| b.as_ref()) {
1482+
bundles.push(p);
1483+
}
1484+
14751485
let call = unsafe {
14761486
llvm::LLVMBuildCallWithOperandBundles(
14771487
self.llbuilder,
@@ -1902,6 +1912,11 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
19021912
bundles.push(kcfi_bundle);
19031913
}
19041914

1915+
let pauth = self.ptrauth_operand_bundle(llfn, fn_abi);
1916+
if let Some(p) = pauth.as_ref().map(|b| b.as_ref()) {
1917+
bundles.push(p);
1918+
}
1919+
19051920
let callbr = unsafe {
19061921
llvm::LLVMBuildCallBr(
19071922
self.llbuilder,
@@ -2021,6 +2036,40 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
20212036
kcfi_bundle
20222037
}
20232038

2039+
// Emits pauth operand bundle.
2040+
fn ptrauth_operand_bundle(
2041+
&mut self,
2042+
llfn: &'ll Value,
2043+
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
2044+
) -> Option<llvm::OperandBundleBox<'ll>> {
2045+
if self.sess().target.llvm_abiname != LlvmAbi::Pauthtest {
2046+
return None;
2047+
}
2048+
// Pointer authentication support is currently limited to extern "C" calls; filter out other
2049+
// ABIs.
2050+
if fn_abi?.conv != CanonAbi::C {
2051+
return None;
2052+
}
2053+
// Filter out LLVM intrinsics.
2054+
if llvm::get_value_name(llfn).starts_with(b"llvm.") {
2055+
return None;
2056+
}
2057+
2058+
// FIXME(jchlanda) Operand bundles should only be attached to indirect function calls.
2059+
// However, function pointer signing is currently performed in `get_fn_addr`, which causes
2060+
// the logic to be applied too broadly, including to function values (not just pointers).
2061+
// As a result, direct calls using signed function values must also receive operand
2062+
// bundles.
2063+
// Once this is resolved, we should analyze each call and skip direct calls. See the
2064+
// discussion in the rust-lang issue: <https://github.com/rust-lang/rust/issues/152532>
2065+
let key: u32 = 0;
2066+
let discriminator: u64 = 0;
2067+
Some(llvm::OperandBundleBox::new(
2068+
"ptrauth",
2069+
&[self.const_u32(key), self.const_u64(discriminator)],
2070+
))
2071+
}
2072+
20242073
/// Emits a call to `llvm.instrprof.increment`. Used by coverage instrumentation.
20252074
#[instrument(level = "debug", skip(self))]
20262075
pub(crate) fn instrprof_increment(

0 commit comments

Comments
 (0)