Skip to content

Commit 29fd324

Browse files
Rollup merge of rust-lang#153857 - RalfJung:cfg-abi, r=Mark-Simulacrum
Rename `target.abi` to `target.cfg_abi` and enum-ify llvm_abiname See [Zulip](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/De-spaghettifying.20ABI.20controls/with/578893542) for more context. Discussed a bit in rust-lang#153769 (comment) too. This renames `target.abi` to `target.cfg_abi` to make it less likely that someone will use it to determine things about the actual ccABI, i.e. the calling convention used on the target. `target.abi` does not control that calling convention, it just *sometimes* informs the user about that calling convention (and also about other aspects of the ABI). Also turn llvm_abiname into an enum to make it more natural to match on. Cc @workingjubilee @madsmtm
2 parents 5114be8 + 4a0b264 commit 29fd324

181 files changed

Lines changed: 698 additions & 547 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_codegen_cranelift/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
4646
use rustc_session::Session;
4747
use rustc_session::config::OutputFilenames;
4848
use rustc_span::{Symbol, sym};
49-
use rustc_target::spec::{Abi, Arch, Env, Os};
49+
use rustc_target::spec::{Arch, CfgAbi, Env, Os};
5050

5151
pub use crate::config::*;
5252
use crate::prelude::*;
@@ -178,7 +178,7 @@ impl CodegenBackend for CraneliftCodegenBackend {
178178
let has_reliable_f16_f128 = !(sess.target.arch == Arch::X86_64
179179
&& sess.target.os == Os::Windows
180180
&& sess.target.env == Env::Gnu
181-
&& sess.target.abi != Abi::Llvm);
181+
&& sess.target.cfg_abi != CfgAbi::Llvm);
182182

183183
// FIXME(f128): f128 math operations need f128 math symbols, which currently aren't always
184184
// filled in by compiler-builtins. The only libc that provides these currently is glibc.

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ pub(crate) fn target_machine_factory(
225225
let triple = SmallCStr::new(&versioned_llvm_target(sess));
226226
let cpu = SmallCStr::new(llvm_util::target_cpu(sess));
227227
let features = CString::new(target_features.join(",")).unwrap();
228-
let abi = SmallCStr::new(&sess.target.llvm_abiname);
228+
let abi = SmallCStr::new(sess.target.llvm_abiname.desc());
229229
let trap_unreachable =
230230
sess.opts.unstable_opts.trap_unreachable.unwrap_or(sess.target.trap_unreachable);
231231
let emit_stack_size_section = sess.opts.unstable_opts.emit_stack_sizes;

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_session::config::{
2828
use rustc_span::{DUMMY_SP, Span, Spanned, Symbol};
2929
use rustc_symbol_mangling::mangle_internal_symbol;
3030
use rustc_target::spec::{
31-
Abi, Arch, Env, HasTargetSpec, Os, RelocModel, SmallDataThresholdSupport, Target, TlsModel,
31+
Arch, CfgAbi, Env, HasTargetSpec, Os, RelocModel, SmallDataThresholdSupport, Target, TlsModel,
3232
};
3333
use smallvec::SmallVec;
3434

@@ -344,7 +344,7 @@ pub(crate) unsafe fn create_module<'ll>(
344344
if sess.target.is_like_msvc
345345
|| (sess.target.options.os == Os::Windows
346346
&& sess.target.options.env == Env::Gnu
347-
&& sess.target.options.abi == Abi::Llvm)
347+
&& sess.target.options.cfg_abi == CfgAbi::Llvm)
348348
{
349349
match sess.opts.cg.control_flow_guard {
350350
CFGuard::Disabled => {}
@@ -509,14 +509,13 @@ pub(crate) unsafe fn create_module<'ll>(
509509
// to workaround lld as the LTO plugin not
510510
// correctly setting target-abi for the LTO object
511511
// FIXME: https://github.com/llvm/llvm-project/issues/50591
512-
// If llvm_abiname is empty, emit nothing.
513512
let llvm_abiname = &sess.target.options.llvm_abiname;
514-
if matches!(sess.target.arch, Arch::RiscV32 | Arch::RiscV64) && !llvm_abiname.is_empty() {
513+
if matches!(sess.target.arch, Arch::RiscV32 | Arch::RiscV64) {
515514
llvm::add_module_flag_str(
516515
llmod,
517516
llvm::ModuleFlagMergeBehavior::Error,
518517
"target-abi",
519-
llvm_abiname,
518+
llvm_abiname.desc(),
520519
);
521520
}
522521

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_middle::bug;
1616
use rustc_session::Session;
1717
use rustc_session::config::{PrintKind, PrintRequest};
1818
use rustc_target::spec::{
19-
Abi, Arch, Env, MergeFunctions, Os, PanicStrategy, SmallDataThresholdSupport,
19+
Arch, CfgAbi, Env, MergeFunctions, Os, PanicStrategy, SmallDataThresholdSupport,
2020
};
2121
use smallvec::{SmallVec, smallvec};
2222

@@ -362,7 +362,7 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
362362
let target_arch = &sess.target.arch;
363363
let target_os = &sess.target.options.os;
364364
let target_env = &sess.target.options.env;
365-
let target_abi = &sess.target.options.abi;
365+
let target_abi = &sess.target.options.cfg_abi;
366366
let target_pointer_width = sess.target.pointer_width;
367367
let version = get_version();
368368
let (major, _, _) = version;
@@ -371,7 +371,9 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
371371
// Unsupported <https://github.com/llvm/llvm-project/issues/94434> (fixed in llvm22)
372372
(Arch::Arm64EC, _) if major < 22 => false,
373373
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
374-
(Arch::X86_64, Os::Windows) if *target_env == Env::Gnu && *target_abi != Abi::Llvm => false,
374+
(Arch::X86_64, Os::Windows) if *target_env == Env::Gnu && *target_abi != CfgAbi::Llvm => {
375+
false
376+
}
375377
// Infinite recursion <https://github.com/llvm/llvm-project/issues/97981>
376378
(Arch::CSky, _) if major < 22 => false, // (fixed in llvm22)
377379
(Arch::PowerPC | Arch::PowerPC64, _) if major < 22 => false, // (fixed in llvm22)
@@ -397,7 +399,9 @@ fn update_target_reliable_float_cfg(sess: &Session, cfg: &mut TargetConfig) {
397399
// ABI unsupported <https://github.com/llvm/llvm-project/issues/41838> (fixed in llvm22)
398400
(Arch::Sparc, _) if major < 22 => false,
399401
// MinGW ABI bugs <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115054>
400-
(Arch::X86_64, Os::Windows) if *target_env == Env::Gnu && *target_abi != Abi::Llvm => false,
402+
(Arch::X86_64, Os::Windows) if *target_env == Env::Gnu && *target_abi != CfgAbi::Llvm => {
403+
false
404+
}
401405
// There are no known problems on other platforms, so the only requirement is that symbols
402406
// are available. `compiler-builtins` provides all symbols required for core `f128`
403407
// support, so this should work for everything else.

compiler/rustc_codegen_llvm/src/va_arg.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_codegen_ssa::traits::{
88
use rustc_middle::bug;
99
use rustc_middle::ty::Ty;
1010
use rustc_middle::ty::layout::{HasTyCtxt, LayoutOf, TyAndLayout};
11-
use rustc_target::spec::{Arch, Env, RustcAbi};
11+
use rustc_target::spec::{Arch, Env, LlvmAbi, RustcAbi};
1212

1313
use crate::builder::Builder;
1414
use crate::llvm::{Type, Value};
@@ -1077,7 +1077,7 @@ pub(super) fn emit_va_arg<'ll, 'tcx>(
10771077
AllowHigherAlign::Yes,
10781078
ForceRightAdjust::Yes,
10791079
),
1080-
Arch::RiscV32 if target.llvm_abiname == "ilp32e" => {
1080+
Arch::RiscV32 if target.llvm_abiname == LlvmAbi::Ilp32e => {
10811081
// FIXME: clang manually adjusts the alignment for this ABI. It notes:
10821082
//
10831083
// > To be compatible with GCC's behaviors, we force arguments with

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use rustc_session::{Session, filesearch};
4747
use rustc_span::Symbol;
4848
use rustc_target::spec::crt_objects::CrtObjects;
4949
use rustc_target::spec::{
50-
Abi, BinaryFormat, Cc, Env, LinkOutputKind, LinkSelfContainedComponents,
50+
BinaryFormat, Cc, CfgAbi, Env, LinkOutputKind, LinkSelfContainedComponents,
5151
LinkSelfContainedDefault, LinkerFeatures, LinkerFlavor, LinkerFlavorCli, Lld, Os, RelocModel,
5252
RelroLevel, SanitizerSet, SplitDebuginfo,
5353
};
@@ -1917,7 +1917,7 @@ fn self_contained_components(
19171917
LinkSelfContainedDefault::InferredForMusl => sess.crt_static(Some(crate_type)),
19181918
LinkSelfContainedDefault::InferredForMingw => {
19191919
sess.host == sess.target
1920-
&& sess.target.abi != Abi::Uwp
1920+
&& sess.target.cfg_abi != CfgAbi::Uwp
19211921
&& detect_self_contained_mingw(sess, linker)
19221922
}
19231923
}

compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::middle::exported_symbols::{
1818
use rustc_middle::ty::TyCtxt;
1919
use rustc_session::Session;
2020
use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip};
21-
use rustc_target::spec::{Abi, Arch, Cc, LinkOutputKind, LinkerFlavor, Lld, Os};
21+
use rustc_target::spec::{Arch, Cc, CfgAbi, LinkOutputKind, LinkerFlavor, Lld, Os};
2222
use tracing::{debug, warn};
2323

2424
use super::command::Command;
@@ -84,7 +84,7 @@ pub(crate) fn get_linker<'a>(
8484
// To comply with the Windows App Certification Kit,
8585
// MSVC needs to link with the Store versions of the runtime libraries (vcruntime, msvcrt, etc).
8686
let t = &sess.target;
87-
if matches!(flavor, LinkerFlavor::Msvc(..)) && t.abi == Abi::Uwp {
87+
if matches!(flavor, LinkerFlavor::Msvc(..)) && t.cfg_abi == CfgAbi::Uwp {
8888
if let Some(ref tool) = msvc_tool {
8989
let original_path = tool.path();
9090
if let Some(root_lib_path) = original_path.ancestors().nth(4) {
@@ -135,7 +135,7 @@ pub(crate) fn get_linker<'a>(
135135

136136
// FIXME: Move `/LIBPATH` addition for uwp targets from the linker construction
137137
// to the linker args construction.
138-
assert!(cmd.get_args().is_empty() || sess.target.abi == Abi::Uwp);
138+
assert!(cmd.get_args().is_empty() || sess.target.cfg_abi == CfgAbi::Uwp);
139139
match flavor {
140140
LinkerFlavor::Unix(Cc::No) if sess.target.os == Os::L4Re => {
141141
Box::new(L4Bender::new(cmd, sess)) as Box<dyn Linker>

compiler/rustc_codegen_ssa/src/back/metadata.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_metadata::fs::METADATA_FILENAME;
2020
use rustc_middle::bug;
2121
use rustc_session::Session;
2222
use rustc_span::sym;
23-
use rustc_target::spec::{Abi, Os, RelocModel, Target, ef_avr_arch};
23+
use rustc_target::spec::{CfgAbi, LlvmAbi, Os, RelocModel, Target, ef_avr_arch};
2424
use tracing::debug;
2525

2626
use super::apple;
@@ -295,10 +295,10 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
295295
};
296296

297297
// Use the explicitly given ABI.
298-
match sess.target.options.llvm_abiname.as_ref() {
299-
"o32" if is_32bit => e_flags |= elf::EF_MIPS_ABI_O32,
300-
"n32" if !is_32bit => e_flags |= elf::EF_MIPS_ABI2,
301-
"n64" if !is_32bit => {}
298+
match &sess.target.options.llvm_abiname {
299+
LlvmAbi::O32 if is_32bit => e_flags |= elf::EF_MIPS_ABI_O32,
300+
LlvmAbi::N32 if !is_32bit => e_flags |= elf::EF_MIPS_ABI2,
301+
LlvmAbi::N64 if !is_32bit => {}
302302
// The rest is invalid (which is already ensured by the target spec check).
303303
s => bug!("invalid LLVM ABI `{}` for MIPS target", s),
304304
};
@@ -336,12 +336,12 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
336336

337337
// Set the appropriate flag based on ABI
338338
// This needs to match LLVM `RISCVELFStreamer.cpp`
339-
match &*sess.target.llvm_abiname {
340-
"ilp32" | "lp64" => (),
341-
"ilp32f" | "lp64f" => e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE,
342-
"ilp32d" | "lp64d" => e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE,
339+
match &sess.target.llvm_abiname {
340+
LlvmAbi::Ilp32 | LlvmAbi::Lp64 => (),
341+
LlvmAbi::Ilp32f | LlvmAbi::Lp64f => e_flags |= elf::EF_RISCV_FLOAT_ABI_SINGLE,
342+
LlvmAbi::Ilp32d | LlvmAbi::Lp64d => e_flags |= elf::EF_RISCV_FLOAT_ABI_DOUBLE,
343343
// Note that the `lp64e` is still unstable as it's not (yet) part of the ELF psABI.
344-
"ilp32e" | "lp64e" => e_flags |= elf::EF_RISCV_RVE,
344+
LlvmAbi::Ilp32e | LlvmAbi::Lp64e => e_flags |= elf::EF_RISCV_RVE,
345345
_ => bug!("unknown RISC-V ABI name"),
346346
}
347347

@@ -353,10 +353,10 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
353353

354354
// Set the appropriate flag based on ABI
355355
// This needs to match LLVM `LoongArchELFStreamer.cpp`
356-
match &*sess.target.llvm_abiname {
357-
"ilp32s" | "lp64s" => e_flags |= elf::EF_LARCH_ABI_SOFT_FLOAT,
358-
"ilp32f" | "lp64f" => e_flags |= elf::EF_LARCH_ABI_SINGLE_FLOAT,
359-
"ilp32d" | "lp64d" => e_flags |= elf::EF_LARCH_ABI_DOUBLE_FLOAT,
356+
match &sess.target.llvm_abiname {
357+
LlvmAbi::Ilp32s | LlvmAbi::Lp64s => e_flags |= elf::EF_LARCH_ABI_SOFT_FLOAT,
358+
LlvmAbi::Ilp32f | LlvmAbi::Lp64f => e_flags |= elf::EF_LARCH_ABI_SINGLE_FLOAT,
359+
LlvmAbi::Ilp32d | LlvmAbi::Lp64d => e_flags |= elf::EF_LARCH_ABI_DOUBLE_FLOAT,
360360
_ => bug!("unknown LoongArch ABI name"),
361361
}
362362

@@ -372,7 +372,7 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
372372
}
373373
}
374374
Architecture::Csky => {
375-
if matches!(sess.target.options.abi, Abi::AbiV2) {
375+
if matches!(sess.target.options.cfg_abi, CfgAbi::AbiV2) {
376376
elf::EF_CSKY_ABIV2
377377
} else {
378378
elf::EF_CSKY_ABIV1
@@ -383,14 +383,14 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
383383
const EF_PPC64_ABI_ELF_V1: u32 = 1;
384384
const EF_PPC64_ABI_ELF_V2: u32 = 2;
385385

386-
match sess.target.options.llvm_abiname.as_ref() {
386+
match sess.target.options.llvm_abiname {
387387
// If the flags do not correctly indicate the ABI,
388388
// linkers such as ld.lld assume that the ppc64 object files are always ELFv2
389389
// which leads to broken binaries if ELFv1 is used for the object files.
390-
"elfv1" => EF_PPC64_ABI_ELF_V1,
391-
"elfv2" => EF_PPC64_ABI_ELF_V2,
392-
"" if sess.target.options.binary_format.to_object() == BinaryFormat::Elf => {
393-
bug!("No ABI specified for this PPC64 ELF target");
390+
LlvmAbi::ElfV1 => EF_PPC64_ABI_ELF_V1,
391+
LlvmAbi::ElfV2 => EF_PPC64_ABI_ELF_V2,
392+
_ if sess.target.options.binary_format.to_object() == BinaryFormat::Elf => {
393+
bug!("invalid ABI specified for this PPC64 ELF target");
394394
}
395395
// Fall back
396396
_ => EF_PPC64_ABI_UNKNOWN,

compiler/rustc_codegen_ssa/src/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::ty::{self, Instance, TyCtxt};
77
use rustc_middle::{bug, mir, span_bug};
88
use rustc_session::cstore::{DllCallingConvention, DllImport, DllImportSymbolType};
99
use rustc_span::Span;
10-
use rustc_target::spec::{Abi, Env, Os, Target};
10+
use rustc_target::spec::{CfgAbi, Env, Os, Target};
1111

1212
use crate::traits::*;
1313

@@ -171,7 +171,7 @@ pub fn asm_const_to_str<'tcx>(
171171
}
172172

173173
pub fn is_mingw_gnu_toolchain(target: &Target) -> bool {
174-
target.os == Os::Windows && target.env == Env::Gnu && target.abi == Abi::Unspecified
174+
target.os == Os::Windows && target.env == Env::Gnu && target.cfg_abi == CfgAbi::Unspecified
175175
}
176176

177177
pub fn i686_decorated_name(

compiler/rustc_metadata/src/native_libs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_session::cstore::{
1919
use rustc_session::search_paths::PathKind;
2020
use rustc_span::Symbol;
2121
use rustc_span::def_id::{DefId, LOCAL_CRATE};
22-
use rustc_target::spec::{Abi, Arch, BinaryFormat, Env, LinkSelfContainedComponents, Os};
22+
use rustc_target::spec::{Arch, BinaryFormat, CfgAbi, Env, LinkSelfContainedComponents, Os};
2323

2424
use crate::errors;
2525

@@ -73,14 +73,14 @@ pub fn walk_native_lib_search_dirs<R>(
7373
// FIXME: On AIX this also has the side-effect of making the list of library search paths
7474
// non-empty, which is needed or the linker may decide to record the LIBPATH env, if
7575
// defined, as the search path instead of appending the default search paths.
76-
if sess.target.abi == Abi::Fortanix
76+
if sess.target.cfg_abi == CfgAbi::Fortanix
7777
|| sess.target.os == Os::Linux
7878
|| sess.target.os == Os::Fuchsia
7979
|| sess.target.is_like_aix
8080
|| sess.target.is_like_darwin && !sess.sanitizers().is_empty()
8181
|| sess.target.os == Os::Windows
8282
&& sess.target.env == Env::Gnu
83-
&& sess.target.abi == Abi::Llvm
83+
&& sess.target.cfg_abi == CfgAbi::Llvm
8484
{
8585
f(&sess.target_tlib_path.dir, false)?;
8686
}

0 commit comments

Comments
 (0)