Skip to content

Commit 374a011

Browse files
committed
PR feedback: Use target_env
1 parent 2624c23 commit 374a011

8 files changed

Lines changed: 22 additions & 18 deletions

File tree

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_session::config::{BranchProtection, FunctionReturn, OptLevel, PAuthKey
1010
use rustc_span::sym;
1111
use rustc_symbol_mangling::mangle_internal_symbol;
1212
use rustc_target::spec::{
13-
Arch, CfgAbi, FramePointer, SanitizerSet, StackProbeType, StackProtector,
13+
Arch, FramePointer, LlvmAbi, SanitizerSet, StackProbeType, StackProtector,
1414
};
1515
use smallvec::SmallVec;
1616

@@ -611,7 +611,7 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
611611
}
612612
}
613613

614-
if sess.target.cfg_abi == CfgAbi::Pauthtest {
614+
if sess.target.llvm_abiname == LlvmAbi::Pauthtest {
615615
for &ptrauth_attr in pauth_fn_attrs() {
616616
to_add.push(llvm::CreateAttrString(cx.llcx, ptrauth_attr));
617617
}

compiler/rustc_codegen_llvm/src/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ 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::{CfgAbi, SanitizerSet};
28+
use rustc_target::spec::{LlvmAbi, SanitizerSet};
2929

3030
use super::ModuleLlvm;
3131
use crate::attributes;
@@ -131,7 +131,7 @@ pub(crate) fn compile_codegen_unit(
131131
// FIXME(jchlanda) If it ever becomes necessary to ensure that all compiler
132132
// generated functions receive the ptrauth-* attributes, `declare_fn` or
133133
// `declare_raw_fn` could be used to provide those.
134-
if cx.sess().target.cfg_abi == CfgAbi::Pauthtest {
134+
if cx.sess().target.llvm_abiname == LlvmAbi::Pauthtest {
135135
for &ptrauth_attr in pauth_fn_attrs() {
136136
attrs.push(llvm::CreateAttrString(cx.llcx, ptrauth_attr));
137137
}
@@ -152,7 +152,7 @@ pub(crate) fn compile_codegen_unit(
152152
cx.add_objc_module_flags();
153153
}
154154

155-
if cx.sess().target.cfg_abi == CfgAbi::Pauthtest {
155+
if cx.sess().target.llvm_abiname == LlvmAbi::Pauthtest {
156156
// FIXME(jchlanda): In LLVM/Clang, there are also `aarch64-elf-pauthabi-platform`
157157
// and `aarch64-elf-pauthabi-version` module flags. These are emitted into the
158158
// PAuth core info section of the resulting ELF, which the linker uses to enforce

compiler/rustc_codegen_llvm/src/builder.rs

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

@@ -1992,7 +1992,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
19921992
llfn: &'ll Value,
19931993
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
19941994
) -> Option<llvm::OperandBundleBox<'ll>> {
1995-
if self.sess().target.cfg_abi != CfgAbi::Pauthtest {
1995+
if self.sess().target.llvm_abiname != LlvmAbi::Pauthtest {
19961996
return None;
19971997
}
19981998
// Pointer authentication support is currently limited to extern "C" calls; filter out other

compiler/rustc_codegen_llvm/src/common.rs

Lines changed: 2 additions & 2 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::CfgAbi;
19+
use rustc_target::spec::LlvmAbi;
2020
use tracing::debug;
2121

2222
use crate::consts::{IsInitOrFini, IsStatic, const_alloc_to_llvm};
@@ -46,7 +46,7 @@ pub(crate) fn maybe_sign_fn_ptr<'ll, 'tcx>(
4646
llfn: &'ll llvm::Value,
4747
pac: PacMetadata,
4848
) -> &'ll llvm::Value {
49-
if cx.sess().target.cfg_abi != CfgAbi::Pauthtest {
49+
if cx.sess().target.llvm_abiname != LlvmAbi::Pauthtest {
5050
return llfn;
5151
}
5252

compiler/rustc_codegen_llvm/src/consts.rs

Lines changed: 3 additions & 3 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, CfgAbi};
20+
use rustc_target::spec::{Arch, LlvmAbi};
2121
use tracing::{debug, instrument, trace};
2222

2323
use crate::common::CodegenCx;
@@ -123,7 +123,7 @@ pub(crate) fn const_alloc_to_llvm<'ll>(
123123
// Under pointer authentication, function pointers stored in init/fini arrays need special
124124
// handling.
125125
let pac_metadata = Some(
126-
if cx.sess().target.cfg_abi == CfgAbi::Pauthtest
126+
if cx.sess().target.llvm_abiname == LlvmAbi::Pauthtest
127127
&& matches!(is_init_fini, IsInitOrFini::Yes)
128128
{
129129
PacMetadata {
@@ -221,7 +221,7 @@ fn check_and_apply_linkage<'ll, 'tcx>(
221221
let fn_sig = sig.with(*header);
222222
let fn_abi = cx.fn_abi_of_fn_ptr(fn_sig, ty::List::empty());
223223
// Decide if the initializer needs to be signed
224-
if cx.sess().target.cfg_abi == CfgAbi::Pauthtest
224+
if cx.sess().target.llvm_abiname == LlvmAbi::Pauthtest
225225
&& matches!(fn_sig.abi(), ExternAbi::C { .. } | ExternAbi::System { .. })
226226
{
227227
should_sign = true;

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_session::lint::builtin::DEPRECATED_LLVM_INTRINSIC;
2828
use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};
2929
use rustc_symbol_mangling::{mangle_internal_symbol, symbol_name_for_instance_in_crate};
3030
use rustc_target::callconv::PassMode;
31-
use rustc_target::spec::{Arch, CfgAbi};
31+
use rustc_target::spec::{Arch, LlvmAbi};
3232
use tracing::debug;
3333

3434
use crate::abi::FnAbiLlvmExt;
@@ -1706,7 +1706,7 @@ fn get_rust_try_fn<'a, 'll, 'tcx>(
17061706
hir::Safety::Unsafe,
17071707
));
17081708
let rust_try = gen_fn(cx, "__rust_try", rust_fn_sig, codegen);
1709-
if cx.sess().target.cfg_abi == CfgAbi::Pauthtest {
1709+
if cx.sess().target.llvm_abiname == LlvmAbi::Pauthtest {
17101710
let attrs: Vec<&Attribute> =
17111711
pauth_fn_attrs().iter().map(|name| llvm::CreateAttrString(cx.llcx, name)).collect();
17121712
let (_ty, rust_try_fn) = rust_try;

compiler/rustc_target/src/spec/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,6 +2114,8 @@ crate::target_spec_enum! {
21142114
// PowerPC
21152115
ElfV1 = "elfv1",
21162116
ElfV2 = "elfv2",
2117+
// Pointer authentication: Pauthtest
2118+
Pauthtest = "pauthtest",
21172119

21182120
Unspecified = "",
21192121
}
@@ -3396,9 +3398,10 @@ impl Target {
33963398
)
33973399
}
33983400
Arch::AArch64 => {
3399-
check!(
3400-
self.llvm_abiname == LlvmAbi::Unspecified,
3401-
"`llvm_abiname` is unused on aarch64"
3401+
check_matches!(
3402+
self.llvm_abiname,
3403+
LlvmAbi::Unspecified | LlvmAbi::Pauthtest,
3404+
"invalid llvm ABI for aarch64"
34023405
);
34033406
check!(self.llvm_floatabi.is_none(), "`llvm_floatabi` is unused on aarch64");
34043407
// FIXME: Ensure that target_abi = "ilp32" correlates with actually using that ABI.

compiler/rustc_target/src/spec/targets/aarch64_unknown_linux_pauthtest.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::spec::{
2-
Arch, CfgAbi, Env, FramePointer, LinkSelfContainedDefault, StackProbeType, Target,
2+
Arch, CfgAbi, Env, FramePointer, LinkSelfContainedDefault, LlvmAbi, StackProbeType, Target,
33
TargetMetadata, TargetOptions, base,
44
};
55

@@ -19,6 +19,7 @@ pub(crate) fn target() -> Target {
1919
options: TargetOptions {
2020
env: Env::Musl,
2121
cfg_abi: CfgAbi::Pauthtest,
22+
llvm_abiname: LlvmAbi::Pauthtest,
2223
// `pauthtest` requires v8.3a, which includes lse, no need for outline-atomics
2324
features: "+v8.3a,+pauth".into(),
2425
max_atomic_width: Some(128),

0 commit comments

Comments
 (0)