Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 22ad668

Browse files
committedFeb 6, 2025
Remove all support for wasm's legacy ABI
1 parent 5958825 commit 22ad668

File tree

11 files changed

+24
-168
lines changed

11 files changed

+24
-168
lines changed
 

‎compiler/rustc_codegen_gcc/src/builder.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
3030
use rustc_span::Span;
3131
use rustc_span::def_id::DefId;
3232
use rustc_target::callconv::FnAbi;
33-
use rustc_target::spec::{HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, Target, WasmCAbi, X86Abi};
33+
use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, X86Abi};
3434

3535
use crate::common::{SignType, TypeReflection, type_is_pointer};
3636
use crate::context::CodegenCx;
@@ -2363,12 +2363,6 @@ impl<'tcx> HasTargetSpec for Builder<'_, '_, 'tcx> {
23632363
}
23642364
}
23652365

2366-
impl<'tcx> HasWasmCAbiOpt for Builder<'_, '_, 'tcx> {
2367-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
2368-
self.cx.wasm_c_abi_opt()
2369-
}
2370-
}
2371-
23722366
impl<'tcx> HasX86AbiOpt for Builder<'_, '_, 'tcx> {
23732367
fn x86_abi_opt(&self) -> X86Abi {
23742368
self.cx.x86_abi_opt()

‎compiler/rustc_codegen_gcc/src/context.rs

+1-9
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ use rustc_middle::ty::{self, ExistentialTraitRef, Instance, Ty, TyCtxt};
1919
use rustc_session::Session;
2020
use rustc_span::source_map::respan;
2121
use rustc_span::{DUMMY_SP, Span};
22-
use rustc_target::spec::{
23-
HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, Target, TlsModel, WasmCAbi, X86Abi,
24-
};
22+
use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, Target, TlsModel, X86Abi};
2523

2624
use crate::callee::get_fn;
2725
use crate::common::SignType;
@@ -536,12 +534,6 @@ impl<'gcc, 'tcx> HasTargetSpec for CodegenCx<'gcc, 'tcx> {
536534
}
537535
}
538536

539-
impl<'gcc, 'tcx> HasWasmCAbiOpt for CodegenCx<'gcc, 'tcx> {
540-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
541-
self.tcx.sess.opts.unstable_opts.wasm_c_abi
542-
}
543-
}
544-
545537
impl<'gcc, 'tcx> HasX86AbiOpt for CodegenCx<'gcc, 'tcx> {
546538
fn x86_abi_opt(&self) -> X86Abi {
547539
X86Abi {

‎compiler/rustc_codegen_ssa/src/mir/naked_asm.rs

+6-38
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use rustc_abi::{BackendRepr, Float, Integer, Primitive, RegKind};
22
use rustc_attr_parsing::InstructionSetAttr;
3-
use rustc_hir::def_id::DefId;
43
use rustc_middle::mir::mono::{Linkage, MonoItem, MonoItemData, Visibility};
54
use rustc_middle::mir::{Body, InlineAsmOperand};
65
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt, HasTypingEnv, LayoutOf};
76
use rustc_middle::ty::{Instance, Ty, TyCtxt};
8-
use rustc_middle::{bug, span_bug, ty};
7+
use rustc_middle::{bug, ty};
98
use rustc_span::sym;
109
use rustc_target::callconv::{ArgAbi, FnAbi, PassMode};
11-
use rustc_target::spec::WasmCAbi;
1210

1311
use crate::common;
1412
use crate::traits::{AsmCodegenMethods, BuilderMethods, GlobalAsmOperandRef, MiscCodegenMethods};
@@ -287,12 +285,7 @@ fn prefix_and_suffix<'tcx>(
287285
writeln!(begin, "{}", arch_prefix).unwrap();
288286
}
289287
writeln!(begin, "{asm_name}:").unwrap();
290-
writeln!(
291-
begin,
292-
".functype {asm_name} {}",
293-
wasm_functype(tcx, fn_abi, instance.def_id())
294-
)
295-
.unwrap();
288+
writeln!(begin, ".functype {asm_name} {}", wasm_functype(tcx, fn_abi)).unwrap();
296289

297290
writeln!(end).unwrap();
298291
// .size is ignored for function symbols, so we can skip it
@@ -306,7 +299,7 @@ fn prefix_and_suffix<'tcx>(
306299
/// The webassembly type signature for the given function.
307300
///
308301
/// Used by the `.functype` directive on wasm targets.
309-
fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id: DefId) -> String {
302+
fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>) -> String {
310303
let mut signature = String::with_capacity(64);
311304

312305
let ptr_type = match tcx.data_layout.pointer_size.bits() {
@@ -315,17 +308,6 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id
315308
other => bug!("wasm pointer size cannot be {other} bits"),
316309
};
317310

318-
// FIXME: remove this once the wasm32-unknown-unknown ABI is fixed
319-
// please also add `wasm32-unknown-unknown` back in `tests/assembly/wasm32-naked-fn.rs`
320-
// basically the commit introducing this comment should be reverted
321-
if let PassMode::Pair { .. } = fn_abi.ret.mode {
322-
let _ = WasmCAbi::Legacy;
323-
span_bug!(
324-
tcx.def_span(def_id),
325-
"cannot return a pair (the wasm32-unknown-unknown ABI is broken, see https://github.com/rust-lang/rust/issues/115666"
326-
);
327-
}
328-
329311
let hidden_return = matches!(fn_abi.ret.mode, PassMode::Indirect { .. });
330312

331313
signature.push('(');
@@ -339,7 +321,7 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id
339321

340322
let mut it = fn_abi.args.iter().peekable();
341323
while let Some(arg_abi) = it.next() {
342-
wasm_type(tcx, &mut signature, arg_abi, ptr_type, def_id);
324+
wasm_type(&mut signature, arg_abi, ptr_type);
343325
if it.peek().is_some() {
344326
signature.push_str(", ");
345327
}
@@ -348,35 +330,21 @@ fn wasm_functype<'tcx>(tcx: TyCtxt<'tcx>, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, def_id
348330
signature.push_str(") -> (");
349331

350332
if !hidden_return {
351-
wasm_type(tcx, &mut signature, &fn_abi.ret, ptr_type, def_id);
333+
wasm_type(&mut signature, &fn_abi.ret, ptr_type);
352334
}
353335

354336
signature.push(')');
355337

356338
signature
357339
}
358340

359-
fn wasm_type<'tcx>(
360-
tcx: TyCtxt<'tcx>,
361-
signature: &mut String,
362-
arg_abi: &ArgAbi<'_, Ty<'tcx>>,
363-
ptr_type: &'static str,
364-
def_id: DefId,
365-
) {
341+
fn wasm_type<'tcx>(signature: &mut String, arg_abi: &ArgAbi<'_, Ty<'tcx>>, ptr_type: &'static str) {
366342
match arg_abi.mode {
367343
PassMode::Ignore => { /* do nothing */ }
368344
PassMode::Direct(_) => {
369345
let direct_type = match arg_abi.layout.backend_repr {
370346
BackendRepr::Scalar(scalar) => wasm_primitive(scalar.primitive(), ptr_type),
371347
BackendRepr::Vector { .. } => "v128",
372-
BackendRepr::Memory { .. } => {
373-
// FIXME: remove this branch once the wasm32-unknown-unknown ABI is fixed
374-
let _ = WasmCAbi::Legacy;
375-
span_bug!(
376-
tcx.def_span(def_id),
377-
"cannot use memory args (the wasm32-unknown-unknown ABI is broken, see https://github.com/rust-lang/rust/issues/115666"
378-
);
379-
}
380348
other => unreachable!("unexpected BackendRepr: {:?}", other),
381349
};
382350

‎compiler/rustc_interface/src/tests.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use rustc_span::{FileName, SourceFileHashAlgorithm, sym};
2727
use rustc_target::abi::Align;
2828
use rustc_target::spec::{
2929
CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy,
30-
RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel, WasmCAbi,
30+
RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, TlsModel,
3131
};
3232

3333
use crate::interface::{initialize_checked_jobserver, parse_cfg};
@@ -875,7 +875,6 @@ fn test_unstable_options_tracking_hash() {
875875
tracked!(verify_llvm_ir, true);
876876
tracked!(virtual_function_elimination, true);
877877
tracked!(wasi_exec_model, Some(WasiExecModel::Reactor));
878-
tracked!(wasm_c_abi, WasmCAbi::Spec);
879878
// tidy-alphabetical-end
880879

881880
macro_rules! tracked_no_crate_hash {

‎compiler/rustc_middle/src/ty/layout.rs

+1-15
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ use rustc_macros::{HashStable, TyDecodable, TyEncodable, extension};
1818
use rustc_session::config::OptLevel;
1919
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span, Symbol, sym};
2020
use rustc_target::callconv::FnAbi;
21-
use rustc_target::spec::{
22-
HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, PanicStrategy, Target, WasmCAbi, X86Abi,
23-
};
21+
use rustc_target::spec::{HasTargetSpec, HasX86AbiOpt, PanicStrategy, Target, X86Abi};
2422
use tracing::debug;
2523
use {rustc_abi as abi, rustc_hir as hir};
2624

@@ -552,12 +550,6 @@ impl<'tcx> HasTargetSpec for TyCtxt<'tcx> {
552550
}
553551
}
554552

555-
impl<'tcx> HasWasmCAbiOpt for TyCtxt<'tcx> {
556-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
557-
self.sess.opts.unstable_opts.wasm_c_abi
558-
}
559-
}
560-
561553
impl<'tcx> HasX86AbiOpt for TyCtxt<'tcx> {
562554
fn x86_abi_opt(&self) -> X86Abi {
563555
X86Abi {
@@ -612,12 +604,6 @@ impl<'tcx> HasTargetSpec for LayoutCx<'tcx> {
612604
}
613605
}
614606

615-
impl<'tcx> HasWasmCAbiOpt for LayoutCx<'tcx> {
616-
fn wasm_c_abi_opt(&self) -> WasmCAbi {
617-
self.calc.cx.wasm_c_abi_opt()
618-
}
619-
}
620-
621607
impl<'tcx> HasX86AbiOpt for LayoutCx<'tcx> {
622608
fn x86_abi_opt(&self) -> X86Abi {
623609
self.calc.cx.x86_abi_opt()

‎compiler/rustc_session/src/config.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2936,7 +2936,7 @@ pub(crate) mod dep_tracking {
29362936
use rustc_target::spec::{
29372937
CodeModel, FramePointer, MergeFunctions, OnBrokenPipe, PanicStrategy, RelocModel,
29382938
RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility, TargetTuple,
2939-
TlsModel, WasmCAbi,
2939+
TlsModel,
29402940
};
29412941

29422942
use super::{
@@ -3047,7 +3047,6 @@ pub(crate) mod dep_tracking {
30473047
Polonius,
30483048
InliningThreshold,
30493049
FunctionReturn,
3050-
WasmCAbi,
30513050
Align,
30523051
);
30533052

‎compiler/rustc_session/src/options.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use rustc_span::{RealFileName, SourceFileHashAlgorithm};
1616
use rustc_target::spec::{
1717
CodeModel, FramePointer, LinkerFlavorCli, MergeFunctions, OnBrokenPipe, PanicStrategy,
1818
RelocModel, RelroLevel, SanitizerSet, SplitDebuginfo, StackProtector, SymbolVisibility,
19-
TargetTuple, TlsModel, WasmCAbi,
19+
TargetTuple, TlsModel,
2020
};
2121

2222
use crate::config::*;
@@ -790,7 +790,6 @@ mod desc {
790790
"either a boolean (`yes`, `no`, `on`, `off`, etc), or a non-negative number";
791791
pub(crate) const parse_llvm_module_flag: &str = "<key>:<type>:<value>:<behavior>. Type must currently be `u32`. Behavior should be one of (`error`, `warning`, `require`, `override`, `append`, `appendunique`, `max`, `min`)";
792792
pub(crate) const parse_function_return: &str = "`keep` or `thunk-extern`";
793-
pub(crate) const parse_wasm_c_abi: &str = "`legacy` or `spec`";
794793
pub(crate) const parse_mir_include_spans: &str =
795794
"either a boolean (`yes`, `no`, `on`, `off`, etc), or `nll` (default: `nll`)";
796795
pub(crate) const parse_align: &str = "a number that is a power of 2 between 1 and 2^29";
@@ -1886,15 +1885,6 @@ pub mod parse {
18861885
true
18871886
}
18881887

1889-
pub(crate) fn parse_wasm_c_abi(slot: &mut WasmCAbi, v: Option<&str>) -> bool {
1890-
match v {
1891-
Some("spec") => *slot = WasmCAbi::Spec,
1892-
Some("legacy") => *slot = WasmCAbi::Legacy,
1893-
_ => return false,
1894-
}
1895-
true
1896-
}
1897-
18981888
pub(crate) fn parse_mir_include_spans(slot: &mut MirIncludeSpans, v: Option<&str>) -> bool {
18991889
*slot = match v {
19001890
Some("on" | "yes" | "y" | "true") | None => MirIncludeSpans::On,
@@ -2604,8 +2594,6 @@ written to standard error output)"),
26042594
Requires `-Clto[=[fat,yes]]`"),
26052595
wasi_exec_model: Option<WasiExecModel> = (None, parse_wasi_exec_model, [TRACKED],
26062596
"whether to build a wasi command or reactor"),
2607-
wasm_c_abi: WasmCAbi = (WasmCAbi::Legacy, parse_wasm_c_abi, [TRACKED],
2608-
"use spec-compliant C ABI for `wasm32-unknown-unknown` (default: legacy)"),
26092597
write_long_types_to_disk: bool = (true, parse_bool, [UNTRACKED],
26102598
"whether long type names should be written to files instead of being printed in errors"),
26112599
// tidy-alphabetical-end

‎compiler/rustc_target/src/callconv/mod.rs

+3-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::abi::{
99
self, AddressSpace, Align, BackendRepr, HasDataLayout, Pointer, Size, TyAbiInterface,
1010
TyAndLayout,
1111
};
12-
use crate::spec::{HasTargetSpec, HasWasmCAbiOpt, HasX86AbiOpt, WasmCAbi};
12+
use crate::spec::{HasTargetSpec, HasX86AbiOpt};
1313

1414
mod aarch64;
1515
mod amdgpu;
@@ -639,7 +639,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
639639
) -> Result<(), AdjustForForeignAbiError>
640640
where
641641
Ty: TyAbiInterface<'a, C> + Copy,
642-
C: HasDataLayout + HasTargetSpec + HasWasmCAbiOpt + HasX86AbiOpt,
642+
C: HasDataLayout + HasTargetSpec + HasX86AbiOpt,
643643
{
644644
if abi == ExternAbi::X86Interrupt {
645645
if let Some(arg) = self.args.first_mut() {
@@ -711,14 +711,7 @@ impl<'a, Ty> FnAbi<'a, Ty> {
711711
"hexagon" => hexagon::compute_abi_info(self),
712712
"xtensa" => xtensa::compute_abi_info(cx, self),
713713
"riscv32" | "riscv64" => riscv::compute_abi_info(cx, self),
714-
"wasm32" => {
715-
if spec.os == "unknown" && cx.wasm_c_abi_opt() == WasmCAbi::Legacy {
716-
wasm::compute_wasm_abi_info(self)
717-
} else {
718-
wasm::compute_c_abi_info(cx, self)
719-
}
720-
}
721-
"wasm64" => wasm::compute_c_abi_info(cx, self),
714+
"wasm32" | "wasm64" => wasm::compute_abi_info(cx, self),
722715
"bpf" => bpf::compute_abi_info(self),
723716
arch => {
724717
return Err(AdjustForForeignAbiError::Unsupported {

‎compiler/rustc_target/src/callconv/wasm.rs

+1-41
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ where
5757
}
5858

5959
/// The purpose of this ABI is to match the C ABI (aka clang) exactly.
60-
pub(crate) fn compute_c_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
60+
pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>)
6161
where
6262
Ty: TyAbiInterface<'a, C> + Copy,
6363
C: HasDataLayout,
@@ -73,43 +73,3 @@ where
7373
classify_arg(cx, arg);
7474
}
7575
}
76-
77-
/// The purpose of this ABI is for matching the WebAssembly standard. This
78-
/// intentionally diverges from the C ABI and is specifically crafted to take
79-
/// advantage of LLVM's support of multiple returns in WebAssembly.
80-
///
81-
/// This ABI is *bad*! It uses `PassMode::Direct` for `abi::Aggregate` types, which leaks LLVM
82-
/// implementation details into the ABI. It's just hard to fix because ABIs are hard to change.
83-
/// Also see <https://github.com/rust-lang/rust/issues/115666>.
84-
pub(crate) fn compute_wasm_abi_info<Ty>(fn_abi: &mut FnAbi<'_, Ty>) {
85-
if !fn_abi.ret.is_ignore() {
86-
classify_ret_wasm_abi(&mut fn_abi.ret);
87-
}
88-
89-
for arg in fn_abi.args.iter_mut() {
90-
if arg.is_ignore() {
91-
continue;
92-
}
93-
classify_arg_wasm_abi(arg);
94-
}
95-
96-
fn classify_ret_wasm_abi<Ty>(ret: &mut ArgAbi<'_, Ty>) {
97-
if !ret.layout.is_sized() {
98-
// Not touching this...
99-
return;
100-
}
101-
// FIXME: this is bad! https://github.com/rust-lang/rust/issues/115666
102-
ret.make_direct_deprecated();
103-
ret.extend_integer_width_to(32);
104-
}
105-
106-
fn classify_arg_wasm_abi<Ty>(arg: &mut ArgAbi<'_, Ty>) {
107-
if !arg.layout.is_sized() {
108-
// Not touching this...
109-
return;
110-
}
111-
// FIXME: this is bad! https://github.com/rust-lang/rust/issues/115666
112-
arg.make_direct_deprecated();
113-
arg.extend_integer_width_to(32);
114-
}
115-
}

‎compiler/rustc_target/src/spec/mod.rs

-13
Original file line numberDiff line numberDiff line change
@@ -2168,19 +2168,6 @@ impl HasTargetSpec for Target {
21682168
}
21692169
}
21702170

2171-
/// Which C ABI to use for `wasm32-unknown-unknown`.
2172-
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
2173-
pub enum WasmCAbi {
2174-
/// Spec-compliant C ABI.
2175-
Spec,
2176-
/// Legacy ABI. Which is non-spec-compliant.
2177-
Legacy,
2178-
}
2179-
2180-
pub trait HasWasmCAbiOpt {
2181-
fn wasm_c_abi_opt(&self) -> WasmCAbi;
2182-
}
2183-
21842171
/// x86 (32-bit) abi options.
21852172
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)]
21862173
pub struct X86Abi {

‎compiler/rustc_ty_utils/src/abi.rs

+8-18
Original file line numberDiff line numberDiff line change
@@ -482,28 +482,18 @@ fn fn_abi_sanity_check<'tcx>(
482482
// For an unsized type we'd only pass the sized prefix, so there is no universe
483483
// in which we ever want to allow this.
484484
assert!(sized, "`PassMode::Direct` for unsized type in ABI: {:#?}", fn_abi);
485+
485486
// This really shouldn't happen even for sized aggregates, since
486487
// `immediate_llvm_type` will use `layout.fields` to turn this Rust type into an
487488
// LLVM type. This means all sorts of Rust type details leak into the ABI.
488-
// However wasm sadly *does* currently use this mode for it's "C" ABI so we
489-
// have to allow it -- but we absolutely shouldn't let any more targets do
490-
// that. (Also see <https://github.com/rust-lang/rust/issues/115666>.)
491-
//
492-
// The unadjusted ABI also uses Direct for all args and is ill-specified,
489+
// The unadjusted ABI however uses Direct for all args. It is ill-specified,
493490
// but unfortunately we need it for calling certain LLVM intrinsics.
494-
495-
match spec_abi {
496-
ExternAbi::Unadjusted => {}
497-
ExternAbi::C { unwind: _ }
498-
if matches!(&*tcx.sess.target.arch, "wasm32" | "wasm64") => {}
499-
_ => {
500-
panic!(
501-
"`PassMode::Direct` for aggregates only allowed for \"unadjusted\" functions and on wasm\n\
502-
Problematic type: {:#?}",
503-
arg.layout,
504-
);
505-
}
506-
}
491+
assert!(
492+
matches!(spec_abi, ExternAbi::Unadjusted),
493+
"`PassMode::Direct` for aggregates only allowed for \"unadjusted\"\n\
494+
Problematic type: {:#?}",
495+
arg.layout,
496+
);
507497
}
508498
}
509499
}

0 commit comments

Comments
 (0)
Please sign in to comment.