Skip to content

Commit e0c6f73

Browse files
committed
Use target_env = "musl" & target_abi = "pauthtest"
1 parent e98f285 commit e0c6f73

15 files changed

Lines changed: 36 additions & 31 deletions

File tree

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ use rustc_middle::ty::{self, TyCtxt};
99
use rustc_session::config::{BranchProtection, FunctionReturn, OptLevel, PAuthKey, PacRet};
1010
use rustc_span::sym;
1111
use rustc_symbol_mangling::mangle_internal_symbol;
12-
use rustc_target::spec::{Arch, Env, FramePointer, SanitizerSet, StackProbeType, StackProtector};
12+
use rustc_target::spec::{
13+
Arch, CfgAbi, FramePointer, SanitizerSet, StackProbeType, StackProtector,
14+
};
1315
use smallvec::SmallVec;
1416

1517
use crate::common::pauth_fn_attrs;
@@ -606,7 +608,7 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
606608
}
607609
}
608610

609-
if sess.target.env == Env::Pauthtest {
611+
if sess.target.cfg_abi == CfgAbi::Pauthtest {
610612
for &ptrauth_attr in pauth_fn_attrs() {
611613
to_add.push(llvm::CreateAttrString(cx.llcx, ptrauth_attr));
612614
}

compiler/rustc_codegen_llvm/src/base.rs

Lines changed: 4 additions & 4 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::{Env, SanitizerSet};
28+
use rustc_target::spec::{CfgAbi, SanitizerSet};
2929

3030
use super::ModuleLlvm;
3131
use crate::attributes;
@@ -127,7 +127,7 @@ pub(crate) fn compile_codegen_unit(
127127
let mut attrs = attributes::sanitize_attrs(&cx, tcx, SanitizerFnAttrs::default());
128128
// When pointer authentication is enabled, ensure that the ptrauth-* attributes are
129129
// also attached to the entry wrapper.
130-
if cx.sess().target.env == Env::Pauthtest {
130+
if cx.sess().target.cfg_abi == CfgAbi::Pauthtest {
131131
for &ptrauth_attr in pauth_fn_attrs() {
132132
attrs.push(llvm::CreateAttrString(cx.llcx, ptrauth_attr));
133133
}
@@ -148,14 +148,14 @@ pub(crate) fn compile_codegen_unit(
148148
cx.add_objc_module_flags();
149149
}
150150

151-
if cx.sess().target.env == Env::Pauthtest {
151+
if cx.sess().target.cfg_abi == CfgAbi::Pauthtest {
152152
// FIXME(jchlanda): In LLVM/Clang, there are also `aarch64-elf-pauthabi-platform`
153153
// and `aarch64-elf-pauthabi-version` module flags. These are emitted into the
154154
// PAuth core info section of the resulting ELF, which the linker uses to enforce
155155
// binary compatibility.
156156
//
157157
// We intentionally do not emit these flags now, since only a subset of features
158-
// included in pauthtest ABI is currently supported. By default, the absence of
158+
// included in clang's pauthtest is currently supported. By default, the absence of
159159
// this info is treated as compatible with any binary.
160160
//
161161
// Please note, that this would cause compatibility issues, specifically runtime

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, Env, HasTargetSpec, SanitizerSet, Target};
28+
use rustc_target::spec::{Arch, CfgAbi, HasTargetSpec, SanitizerSet, Target};
2929
use smallvec::SmallVec;
3030
use tracing::{debug, instrument};
3131

@@ -1987,7 +1987,7 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
19871987
llfn: &'ll Value,
19881988
fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>,
19891989
) -> Option<llvm::OperandBundleBox<'ll>> {
1990-
if self.sess().target.env != Env::Pauthtest {
1990+
if self.sess().target.cfg_abi != CfgAbi::Pauthtest {
19911991
return None;
19921992
}
19931993
// 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::Env;
19+
use rustc_target::spec::CfgAbi;
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.env != Env::Pauthtest {
49+
if cx.sess().target.cfg_abi != CfgAbi::Pauthtest {
5050
return llfn;
5151
}
5252

compiler/rustc_codegen_llvm/src/consts.rs

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

2323
use crate::common::CodegenCx;
@@ -123,7 +123,9 @@ 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.env == Env::Pauthtest && matches!(is_init_fini, IsInitOrFini::Yes) {
126+
if cx.sess().target.cfg_abi == CfgAbi::Pauthtest
127+
&& matches!(is_init_fini, IsInitOrFini::Yes)
128+
{
127129
PacMetadata {
128130
// Must correspond to ptrauth_key_init_fini_pointer from `ptrauth.h`.
129131
key: 0,
@@ -217,7 +219,7 @@ fn check_and_apply_linkage<'ll, 'tcx>(
217219
let fn_sig = sig.with(*header);
218220
let fn_abi = cx.fn_abi_of_fn_ptr(fn_sig, ty::List::empty());
219221
// Decide if the initializer needs to be signed
220-
if cx.sess().target.env == Env::Pauthtest
222+
if cx.sess().target.cfg_abi == CfgAbi::Pauthtest
221223
&& matches!(fn_sig.abi(), ExternAbi::C { .. } | ExternAbi::System { .. })
222224
{
223225
should_sign = true;

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use rustc_session::lint::builtin::DEPRECATED_LLVM_INTRINSIC;
2626
use rustc_span::{Span, Symbol, sym};
2727
use rustc_symbol_mangling::{mangle_internal_symbol, symbol_name_for_instance_in_crate};
2828
use rustc_target::callconv::PassMode;
29-
use rustc_target::spec::{Arch, Env, Os};
29+
use rustc_target::spec::{Arch, CfgAbi, Os};
3030
use tracing::debug;
3131

3232
use crate::abi::FnAbiLlvmExt;
@@ -1760,7 +1760,7 @@ fn get_rust_try_fn<'a, 'll, 'tcx>(
17601760
hir::Safety::Unsafe,
17611761
));
17621762
let rust_try = gen_fn(cx, "__rust_try", rust_fn_sig, codegen);
1763-
if cx.sess().target.env == Env::Pauthtest {
1763+
if cx.sess().target.cfg_abi == CfgAbi::Pauthtest {
17641764
let attrs: Vec<&Attribute> =
17651765
pauth_fn_attrs().iter().map(|name| llvm::CreateAttrString(cx.llcx, name)).collect();
17661766
let (_ty, rust_try_fn) = rust_try;

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,8 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
424424
// (ld is `f64`), anything other than Linux (Windows and MacOS use `f64`), and `x86`
425425
// (ld is 80-bit extended precision).
426426
//
427-
// musl and pauthtest do not implement the symbols required for f128 math at all.
428-
_ if (*target_env == Env::Musl || *target_env == Env::Pauthtest) => false,
427+
// musl does not implement the symbols required for f128 math at all.
428+
_ if *target_env == Env::Musl => false,
429429
(Arch::X86_64, _) => false,
430430
(_, Os::Linux) if target_pointer_width == 64 => true,
431431
_ => false,

compiler/rustc_metadata/src/native_libs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ pub(crate) fn collect(tcx: TyCtxt<'_>, LocalCrate: LocalCrate) -> Vec<NativeLib>
193193
}
194194
collector.process_command_line();
195195
for lib in &mut collector.libs {
196-
if tcx.sess.target.env == Env::Pauthtest {
196+
if tcx.sess.target.cfg_abi == CfgAbi::Pauthtest {
197197
if let NativeLibKind::Static { .. } = lib.kind {
198198
if !tcx.sess.opts.unstable_opts.ui_testing {
199199
let diag = if lib.foreign_module.is_none() {

compiler/rustc_session/src/session.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ use rustc_span::source_map::{FilePathMapping, SourceMap};
2929
use rustc_span::{RealFileName, Span, Symbol};
3030
use rustc_target::asm::InlineAsmArch;
3131
use rustc_target::spec::{
32-
Arch, CodeModel, DebuginfoKind, Env, Os, PanicStrategy, RelocModel, RelroLevel, SanitizerSet,
33-
SmallDataThresholdSupport, SplitDebuginfo, StackProtector, SymbolVisibility, Target,
34-
TargetTuple, TlsModel, apple,
32+
Arch, CfgAbi, CodeModel, DebuginfoKind, Os, PanicStrategy, RelocModel, RelroLevel,
33+
SanitizerSet, SmallDataThresholdSupport, SplitDebuginfo, StackProtector, SymbolVisibility,
34+
Target, TargetTuple, TlsModel, apple,
3535
};
3636

3737
use crate::code_stats::CodeStats;
@@ -1211,7 +1211,7 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
12111211
}
12121212

12131213
// Using static linking is prohibited on pauthtest target
1214-
if sess.crt_static(None) && sess.target.env == Env::Pauthtest {
1214+
if sess.crt_static(None) && sess.target.cfg_abi == CfgAbi::Pauthtest {
12151215
sess.dcx().emit_err(errors::CannotEnableCrtStaticPointerAuth);
12161216
}
12171217

compiler/rustc_target/src/spec/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,6 @@ crate::target_spec_enum! {
20592059
P1 = "p1",
20602060
P2 = "p2",
20612061
P3 = "p3",
2062-
Pauthtest = "pauthtest",
20632062
Uclibc = "uclibc",
20642063
V5 = "v5",
20652064
Unspecified = "",
@@ -2090,6 +2089,7 @@ crate::target_spec_enum! {
20902089
Ilp32e = "ilp32e",
20912090
Llvm = "llvm",
20922091
MacAbi = "macabi",
2092+
Pauthtest = "pauthtest",
20932093
Sim = "sim",
20942094
SoftFloat = "softfloat",
20952095
Spe = "spe",
@@ -3429,6 +3429,7 @@ impl Target {
34293429
CfgAbi::Ilp32
34303430
| CfgAbi::Llvm
34313431
| CfgAbi::MacAbi
3432+
| CfgAbi::Pauthtest
34323433
| CfgAbi::Sim
34333434
| CfgAbi::Uwp
34343435
| CfgAbi::Unspecified

0 commit comments

Comments
 (0)