Skip to content

Commit 536235f

Browse files
committed
Auto merge of #126907 - glaubitz:sparc-fixes, r=nagisa
Fixes for 32-bit SPARC on Linux This PR fixes a number of issues which previously prevented `rustc` from being built successfully for 32-bit SPARC using the `sparc-unknown-linux-gnu` triplet. In particular, it adds linking against `libatomic` where necessary, uses portable `AtomicU64` for `rustc_data_structures` and rewrites the spec for `sparc_unknown_linux_gnu` to use `TargetOptions` and replaces the previously used `-mv8plus` with the more portable `-mcpu=v9 -m32`. To make `rustc` build successfully, support for 32-bit SPARC needs to be added to the `object` crate as well as the `nix` crate which I will be sending out later as well. r? nagisa
2 parents 1def498 + e57bbb3 commit 536235f

File tree

6 files changed

+25
-18
lines changed

6 files changed

+25
-18
lines changed

compiler/rustc_data_structures/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ libc = "0.2"
5050
memmap2 = "0.2.1"
5151
# tidy-alphabetical-end
5252

53-
[target.'cfg(any(target_arch = "powerpc", target_arch = "mips"))'.dependencies]
53+
[target.'cfg(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc"))'.dependencies]
5454
portable-atomic = "1.5.1"
5555

5656
[features]

compiler/rustc_data_structures/src/marker.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,14 @@ cfg_match! {
147147
[crate::owned_slice::OwnedSlice]
148148
);
149149

150-
// PowerPC and MIPS platforms with 32-bit pointers do not
150+
// MIPS, PowerPC and SPARC platforms with 32-bit pointers do not
151151
// have AtomicU64 type.
152-
#[cfg(not(any(target_arch = "powerpc", target_arch = "mips")))]
152+
#[cfg(not(any(target_arch = "powerpc", target_arch = "powerpc", target_arch = "sparc")))]
153153
already_sync!(
154154
[std::sync::atomic::AtomicU64]
155155
);
156156

157-
#[cfg(any(target_arch = "powerpc", target_arch = "mips"))]
157+
#[cfg(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc"))]
158158
already_sync!(
159159
[portable_atomic::AtomicU64]
160160
);

compiler/rustc_data_structures/src/sync.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,12 @@ cfg_match! {
270270

271271
pub use std::sync::atomic::{AtomicBool, AtomicUsize, AtomicU32};
272272

273-
// PowerPC and MIPS platforms with 32-bit pointers do not
273+
// MIPS, PowerPC and SPARC platforms with 32-bit pointers do not
274274
// have AtomicU64 type.
275-
#[cfg(not(any(target_arch = "powerpc", target_arch = "mips")))]
275+
#[cfg(not(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc")))]
276276
pub use std::sync::atomic::AtomicU64;
277277

278-
#[cfg(any(target_arch = "powerpc", target_arch = "mips"))]
278+
#[cfg(any(target_arch = "mips", target_arch = "powerpc", target_arch = "sparc"))]
279279
pub use portable_atomic::AtomicU64;
280280

281281
pub use std::sync::Arc as Lrc;

compiler/rustc_llvm/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ fn main() {
235235
|| target.starts_with("mips-")
236236
|| target.starts_with("mipsel-")
237237
|| target.starts_with("powerpc-")
238+
|| target.starts_with("sparc-")
238239
{
239240
// 32-bit targets need to link libatomic.
240241
println!("cargo:rustc-link-lib=atomic");
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
use crate::abi::Endian;
2-
use crate::spec::{base, Cc, LinkerFlavor, Lld, Target};
2+
use crate::spec::{base, Cc, LinkerFlavor, Lld, Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
let mut base = base::linux_gnu::opts();
6-
base.endian = Endian::Big;
7-
base.cpu = "v9".into();
8-
base.max_atomic_width = Some(32);
9-
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-mv8plus"]);
10-
115
Target {
126
llvm_target: "sparc-unknown-linux-gnu".into(),
137
metadata: crate::spec::TargetMetadata {
@@ -19,6 +13,15 @@ pub fn target() -> Target {
1913
pointer_width: 32,
2014
data_layout: "E-m:e-p:32:32-i64:64-f128:64-n32-S64".into(),
2115
arch: "sparc".into(),
22-
options: base,
16+
options: TargetOptions {
17+
cpu: "v9".into(),
18+
endian: Endian::Big,
19+
late_link_args: TargetOptions::link_args(
20+
LinkerFlavor::Gnu(Cc::Yes, Lld::No),
21+
&["-mcpu=v9", "-m32"],
22+
),
23+
max_atomic_width: Some(32),
24+
..base::linux_gnu::opts()
25+
},
2326
}
2427
}

src/bootstrap/src/core/build_steps/llvm.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -407,18 +407,21 @@ impl Step for Llvm {
407407
cfg.define("LLVM_LINK_LLVM_DYLIB", "ON");
408408
}
409409

410-
if (target.starts_with("riscv") || target.starts_with("csky"))
410+
if (target.starts_with("csky")
411+
|| target.starts_with("riscv")
412+
|| target.starts_with("sparc-"))
411413
&& !target.contains("freebsd")
412414
&& !target.contains("openbsd")
413415
&& !target.contains("netbsd")
414416
{
415-
// RISC-V and CSKY GCC erroneously requires linking against
417+
// CSKY and RISC-V GCC erroneously requires linking against
416418
// `libatomic` when using 1-byte and 2-byte C++
417419
// atomics but the LLVM build system check cannot
418420
// detect this. Therefore it is set manually here.
419421
// Some BSD uses Clang as its system compiler and
420422
// provides no libatomic in its base system so does
421-
// not want this.
423+
// not want this. 32-bit SPARC requires linking against
424+
// libatomic as well.
422425
ldflags.exe.push(" -latomic");
423426
ldflags.shared.push(" -latomic");
424427
}

0 commit comments

Comments
 (0)