Skip to content

Commit 2662303

Browse files
committed
mips: require LLVM ABI to be explicitly set, but also allow n32
1 parent c4fb58f commit 2662303

15 files changed

+26
-15
lines changed

‎compiler/rustc_codegen_ssa/src/back/metadata.rs‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -294,18 +294,13 @@ pub(super) fn elf_e_flags(architecture: Architecture, sess: &Session) -> u32 {
294294
_ => elf::EF_MIPS_ARCH_64R2,
295295
};
296296

297-
// If the ABI is explicitly given, use it, or default to O32 on 32-bit MIPS,
298-
// which is the only "true" 32-bit option that LLVM supports.
297+
// Use the explicitly given ABI.
299298
match sess.target.options.llvm_abiname.as_ref() {
300299
"o32" if is_32bit => e_flags |= elf::EF_MIPS_ABI_O32,
301300
"n32" if !is_32bit => e_flags |= elf::EF_MIPS_ABI2,
302301
"n64" if !is_32bit => {}
303-
"" if is_32bit => e_flags |= elf::EF_MIPS_ABI_O32,
304-
"" => sess.dcx().fatal("LLVM ABI must be specified for 64-bit MIPS targets"),
305-
s if is_32bit => {
306-
sess.dcx().fatal(format!("invalid LLVM ABI `{}` for 32-bit MIPS target", s))
307-
}
308-
s => sess.dcx().fatal(format!("invalid LLVM ABI `{}` for 64-bit MIPS target", s)),
302+
// The rest is invalid (which is already ensured by the target spec check).
303+
s => bug!("invalid LLVM ABI `{}` for MIPS target", s),
309304
};
310305

311306
if sess.target.options.relocation_model != RelocModel::Static {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3402,14 +3402,12 @@ impl Target {
34023402
self.abi,
34033403
);
34043404
}
3405-
Arch::Mips => {
3405+
Arch::Mips | Arch::Mips32r6 => {
34063406
check!(self.llvm_floatabi.is_none(), "`llvm_floatabi` is unused on MIPS");
34073407
check!(self.rustc_abi.is_none(), "`rustc_abi` is unused on MIPS");
34083408
check_matches!(
34093409
(&*self.llvm_abiname, &self.abi),
3410-
// FIXME: we should force it to always be non-empty.
3411-
("o32", Abi::Unspecified | Abi::Other(_))
3412-
| ("", Abi::Unspecified | Abi::Other(_)),
3410+
("o32", Abi::Unspecified | Abi::Other(_)),
34133411
"invalid MIPS ABI name and `cfg(target_abi)` combination:\n\
34143412
ABI name: {}\n\
34153413
cfg(target_abi): {}",
@@ -3422,7 +3420,9 @@ impl Target {
34223420
check!(self.rustc_abi.is_none(), "`rustc_abi` is unused on MIPS");
34233421
check_matches!(
34243422
(&*self.llvm_abiname, &self.abi),
3425-
("n64", Abi::Abi64),
3423+
// No in-tree targets use "n32" but at least for now we let out-of-tree targets
3424+
// experiment with that.
3425+
("n64", Abi::Abi64) | ("n32", Abi::Unspecified | Abi::Other(_)),
34263426
"invalid MIPS ABI name and `cfg(target_abi)` combination:\n\
34273427
ABI name: {}\n\
34283428
cfg(target_abi): {}",

‎compiler/rustc_target/src/spec/targets/mips_mti_none_elf.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub(crate) fn target() -> Target {
2424
endian: Endian::Big,
2525
cpu: "mips32r2".into(),
2626

27+
llvm_abiname: "o32".into(),
2728
max_atomic_width: Some(32),
2829

2930
features: "+mips32r2,+soft-float,+noabicalls".into(),

‎compiler/rustc_target/src/spec/targets/mips_unknown_linux_gnu.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub(crate) fn target() -> Target {
1818
endian: Endian::Big,
1919
cpu: "mips32r2".into(),
2020
features: "+mips32r2,+fpxx,+nooddspreg".into(),
21+
llvm_abiname: "o32".into(),
2122
max_atomic_width: Some(32),
2223
mcount: "_mcount".into(),
2324

‎compiler/rustc_target/src/spec/targets/mips_unknown_linux_musl.rs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ pub(crate) fn target() -> Target {
1818
pointer_width: 32,
1919
data_layout: "E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(),
2020
arch: Arch::Mips,
21-
options: TargetOptions { endian: Endian::Big, mcount: "_mcount".into(), ..base },
21+
options: TargetOptions {
22+
endian: Endian::Big,
23+
llvm_abiname: "o32".into(),
24+
mcount: "_mcount".into(),
25+
..base
26+
},
2227
}
2328
}

‎compiler/rustc_target/src/spec/targets/mips_unknown_linux_uclibc.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub(crate) fn target() -> Target {
1818
endian: Endian::Big,
1919
cpu: "mips32r2".into(),
2020
features: "+mips32r2,+soft-float".into(),
21+
llvm_abiname: "o32".into(),
2122
max_atomic_width: Some(32),
2223
mcount: "_mcount".into(),
2324

‎compiler/rustc_target/src/spec/targets/mipsel_mti_none_elf.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub(crate) fn target() -> Target {
2424
endian: Endian::Little,
2525
cpu: "mips32r2".into(),
2626

27+
llvm_abiname: "o32".into(),
2728
max_atomic_width: Some(32),
2829

2930
features: "+mips32r2,+soft-float,+noabicalls".into(),

‎compiler/rustc_target/src/spec/targets/mipsel_sony_psp.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub(crate) fn target() -> Target {
3636

3737
// PSP does not support trap-on-condition instructions.
3838
llvm_args: cvs!["-mno-check-zero-division"],
39+
llvm_abiname: "o32".into(),
3940
pre_link_args,
4041
link_script: Some(LINKER_SCRIPT.into()),
4142
..Default::default()

‎compiler/rustc_target/src/spec/targets/mipsel_unknown_linux_gnu.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pub(crate) fn target() -> Target {
1616
options: TargetOptions {
1717
cpu: "mips32r2".into(),
1818
features: "+mips32r2,+fpxx,+nooddspreg".into(),
19+
llvm_abiname: "o32".into(),
1920
max_atomic_width: Some(32),
2021
mcount: "_mcount".into(),
2122

‎compiler/rustc_target/src/spec/targets/mipsel_unknown_linux_musl.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@ pub(crate) fn target() -> Target {
1616
pointer_width: 32,
1717
data_layout: "e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64".into(),
1818
arch: Arch::Mips,
19-
options: TargetOptions { mcount: "_mcount".into(), ..base },
19+
options: TargetOptions { llvm_abiname: "o32".into(), mcount: "_mcount".into(), ..base },
2020
}
2121
}

0 commit comments

Comments
 (0)