Skip to content

Commit e1279a0

Browse files
committed
Auto merge of #38726 - japaric:sparc64, r=sanxiyn
sparc64-linux support This is built on top of #38656 and depends on rust-lang/libc#483 Hello world works. The libc-test test suite passes. `panic!` doesn't fully work: ``` $ qemu-sparc64-static ./panic thread 'main' panicked at 'explicit panic', panic.rs:1 note: Run with `RUST_BACKTRACE=1` for a backtrace. Illegal instruction (core dumped) ``` Backtraces don't work either, probably related to the previous point: ``` $ export RUST_BACKTRACE=1 $ qemu-sparc64-static ./panic thread 'main' panicked at 'explicit panic', panic.rs:1 stack backtrace: Illegal instruction (core dumped) ``` r? @alexcrichton @jakllsch Does panicking / backtraces work on sparc64-netbsd? cc @glaubitz
2 parents e227433 + b14785d commit e1279a0

File tree

19 files changed

+291
-12
lines changed

19 files changed

+291
-12
lines changed

configure

+1-1
Original file line numberDiff line numberDiff line change
@@ -1822,7 +1822,7 @@ do
18221822
CMAKE_ARGS="$CMAKE_ARGS -DLLVM_ENABLE_ASSERTIONS=ON"
18231823
fi
18241824

1825-
CMAKE_ARGS="$CMAKE_ARGS -DLLVM_TARGETS_TO_BUILD='X86;ARM;AArch64;Mips;PowerPC;SystemZ;JSBackend;MSP430'"
1825+
CMAKE_ARGS="$CMAKE_ARGS -DLLVM_TARGETS_TO_BUILD='X86;ARM;AArch64;Mips;PowerPC;SystemZ;JSBackend;MSP430;Sparc'"
18261826
CMAKE_ARGS="$CMAKE_ARGS -G '$CFG_CMAKE_GENERATOR'"
18271827
CMAKE_ARGS="$CMAKE_ARGS $CFG_LLVM_SRC_DIR"
18281828

mk/cfg/sparc64-unknown-linux-gnu.mk

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# rustbuild-only target

mk/cfg/sparc64-unknown-netbsd.mk

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This file is intentially left empty to indicate that, while this target is
2+
# supported, it's not supported using plain GNU Make builds. Use a --rustbuild
3+
# instead.

mk/main.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ endif
285285
# LLVM macros
286286
######################################################################
287287

288-
LLVM_OPTIONAL_COMPONENTS=x86 arm aarch64 mips powerpc pnacl systemz jsbackend msp430
288+
LLVM_OPTIONAL_COMPONENTS=x86 arm aarch64 mips powerpc pnacl systemz jsbackend msp430 sparc
289289
LLVM_REQUIRED_COMPONENTS=ipo bitreader bitwriter linker asmparser mcjit \
290290
interpreter instrumentation
291291

src/liballoc_jemalloc/build.rs

+6
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ fn main() {
151151
cmd.arg(format!("--host={}", build_helper::gnu_target(&target)));
152152
cmd.arg(format!("--build={}", build_helper::gnu_target(&host)));
153153

154+
// for some reason, jemalloc configure doesn't detect this value
155+
// automatically for this target
156+
if target == "sparc64-unknown-linux-gnu" {
157+
cmd.arg("--with-lg-quantum=4");
158+
}
159+
154160
run(&mut cmd);
155161
let mut make = Command::new(build_helper::make(&host));
156162
make.current_dir(&build_dir)

src/liballoc_jemalloc/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ mod imp {
8484
target_arch = "aarch64",
8585
target_arch = "powerpc64",
8686
target_arch = "mips64",
87-
target_arch = "s390x")))]
87+
target_arch = "s390x",
88+
target_arch = "sparc64")))]
8889
const MIN_ALIGN: usize = 16;
8990

9091
// MALLOCX_ALIGN(a) macro

src/liballoc_system/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ const MIN_ALIGN: usize = 8;
3535
#[cfg(all(any(target_arch = "x86_64",
3636
target_arch = "aarch64",
3737
target_arch = "mips64",
38-
target_arch = "s390x")))]
38+
target_arch = "s390x",
39+
target_arch = "sparc64")))]
3940
const MIN_ALIGN: usize = 16;
4041

4142
#[no_mangle]

src/libpanic_unwind/gcc.rs

+3
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ const UNWIND_DATA_REG: (i32, i32) = (3, 4); // R3, R4 / X3, X4
133133
#[cfg(target_arch = "s390x")]
134134
const UNWIND_DATA_REG: (i32, i32) = (6, 7); // R6, R7
135135

136+
#[cfg(target_arch = "sparc64")]
137+
const UNWIND_DATA_REG: (i32, i32) = (24, 25); // I0, I1
138+
136139
// The following code is based on GCC's C and C++ personality routines. For reference, see:
137140
// https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/libsupc++/eh_personality.cc
138141
// https://github.com/gcc-mirror/gcc/blob/trunk/libgcc/unwind-c.c

src/librustc_back/target/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ supported_targets! {
158158
("mips-unknown-linux-uclibc", mips_unknown_linux_uclibc),
159159
("mipsel-unknown-linux-uclibc", mipsel_unknown_linux_uclibc),
160160

161+
("sparc64-unknown-linux-gnu", sparc64_unknown_linux_gnu),
162+
161163
("i686-linux-android", i686_linux_android),
162164
("arm-linux-androideabi", arm_linux_androideabi),
163165
("armv7-linux-androideabi", armv7_linux_androideabi),
@@ -174,6 +176,7 @@ supported_targets! {
174176
("i686-unknown-openbsd", i686_unknown_openbsd),
175177
("x86_64-unknown-openbsd", x86_64_unknown_openbsd),
176178

179+
("sparc64-unknown-netbsd", sparc64_unknown_netbsd),
177180
("x86_64-unknown-netbsd", x86_64_unknown_netbsd),
178181
("x86_64-rumprun-netbsd", x86_64_rumprun_netbsd),
179182

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use target::{Target, TargetResult};
12+
13+
pub fn target() -> TargetResult {
14+
let mut base = super::linux_base::opts();
15+
base.cpu = "v9".to_string();
16+
base.max_atomic_width = Some(64);
17+
base.exe_allocation_crate = "alloc_system".to_string();
18+
19+
Ok(Target {
20+
llvm_target: "sparc64-unknown-linux-gnu".to_string(),
21+
target_endian: "big".to_string(),
22+
target_pointer_width: "64".to_string(),
23+
data_layout: "E-m:e-i64:64-n32:64-S128".to_string(),
24+
arch: "sparc64".to_string(),
25+
target_os: "linux".to_string(),
26+
target_env: "gnu".to_string(),
27+
target_vendor: "unknown".to_string(),
28+
options: base,
29+
})
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use target::{Target, TargetResult};
12+
13+
pub fn target() -> TargetResult {
14+
let mut base = super::netbsd_base::opts();
15+
base.cpu = "v9".to_string();
16+
base.pre_link_args.push("-m64".to_string());
17+
base.max_atomic_width = Some(64);
18+
19+
Ok(Target {
20+
llvm_target: "sparc64-unknown-netbsd".to_string(),
21+
target_endian: "big".to_string(),
22+
target_pointer_width: "64".to_string(),
23+
data_layout: "E-m:e-i64:64-n32:64-S128".to_string(),
24+
arch: "sparc64".to_string(),
25+
target_os: "netbsd".to_string(),
26+
target_env: "".to_string(),
27+
target_vendor: "unknown".to_string(),
28+
options: base,
29+
})
30+
}

src/librustc_trans/abi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use cabi_mips64;
2525
use cabi_asmjs;
2626
use cabi_msp430;
2727
use cabi_sparc;
28+
use cabi_sparc64;
2829
use cabi_nvptx;
2930
use cabi_nvptx64;
3031
use machine::{llalign_of_min, llsize_of, llsize_of_alloc};
@@ -614,6 +615,7 @@ impl FnType {
614615
"wasm32" => cabi_asmjs::compute_abi_info(ccx, self),
615616
"msp430" => cabi_msp430::compute_abi_info(ccx, self),
616617
"sparc" => cabi_sparc::compute_abi_info(ccx, self),
618+
"sparc64" => cabi_sparc64::compute_abi_info(ccx, self),
617619
"nvptx" => cabi_nvptx::compute_abi_info(ccx, self),
618620
"nvptx64" => cabi_nvptx64::compute_abi_info(ccx, self),
619621
a => ccx.sess().fatal(&format!("unrecognized arch \"{}\" in target specification", a))

src/librustc_trans/cabi_sparc64.rs

+185
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
// Copyright 2014-2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// FIXME: This needs an audit for correctness and completeness.
12+
13+
use llvm::{Integer, Pointer, Float, Double, Struct, Vector, Array};
14+
use abi::{self, FnType, ArgType};
15+
use context::CrateContext;
16+
use type_::Type;
17+
18+
fn ty_size(ty: Type) -> usize {
19+
if ty.kind() == Vector {
20+
bug!("ty_size: unhandled type")
21+
} else {
22+
abi::ty_size(ty, 8)
23+
}
24+
}
25+
26+
fn is_homogenous_aggregate_ty(ty: Type) -> Option<(Type, u64)> {
27+
fn check_array(ty: Type) -> Option<(Type, u64)> {
28+
let len = ty.array_length() as u64;
29+
if len == 0 {
30+
return None
31+
}
32+
let elt = ty.element_type();
33+
34+
// if our element is an HFA/HVA, so are we; multiply members by our len
35+
is_homogenous_aggregate_ty(elt).map(|(base_ty, members)| (base_ty, len * members))
36+
}
37+
38+
fn check_struct(ty: Type) -> Option<(Type, u64)> {
39+
let str_tys = ty.field_types();
40+
if str_tys.len() == 0 {
41+
return None
42+
}
43+
44+
let mut prev_base_ty = None;
45+
let mut members = 0;
46+
for opt_homog_agg in str_tys.iter().map(|t| is_homogenous_aggregate_ty(*t)) {
47+
match (prev_base_ty, opt_homog_agg) {
48+
// field isn't itself an HFA, so we aren't either
49+
(_, None) => return None,
50+
51+
// first field - store its type and number of members
52+
(None, Some((field_ty, field_members))) => {
53+
prev_base_ty = Some(field_ty);
54+
members = field_members;
55+
},
56+
57+
// 2nd or later field - give up if it's a different type; otherwise incr. members
58+
(Some(prev_ty), Some((field_ty, field_members))) => {
59+
if prev_ty != field_ty {
60+
return None;
61+
}
62+
members += field_members;
63+
}
64+
}
65+
}
66+
67+
// Because of previous checks, we know prev_base_ty is Some(...) because
68+
// 1. str_tys has at least one element; and
69+
// 2. prev_base_ty was filled in (or we would've returned early)
70+
let (base_ty, members) = (prev_base_ty.unwrap(), members);
71+
72+
// Ensure there is no padding.
73+
if ty_size(ty) == ty_size(base_ty) * (members as usize) {
74+
Some((base_ty, members))
75+
} else {
76+
None
77+
}
78+
}
79+
80+
let homog_agg = match ty.kind() {
81+
Float => Some((ty, 1)),
82+
Double => Some((ty, 1)),
83+
Array => check_array(ty),
84+
Struct => check_struct(ty),
85+
_ => None
86+
};
87+
88+
// Ensure we have at most eight uniquely addressable members
89+
homog_agg.and_then(|(base_ty, members)| {
90+
if members > 0 && members <= 8 {
91+
Some((base_ty, members))
92+
} else {
93+
None
94+
}
95+
})
96+
}
97+
98+
fn classify_ret_ty(ccx: &CrateContext, ret: &mut ArgType) {
99+
if is_reg_ty(ret.ty) {
100+
ret.extend_integer_width_to(64);
101+
return;
102+
}
103+
104+
// don't return aggregates in registers
105+
ret.make_indirect(ccx);
106+
107+
if let Some((base_ty, members)) = is_homogenous_aggregate_ty(ret.ty) {
108+
ret.cast = Some(Type::array(&base_ty, members));
109+
return;
110+
}
111+
let size = ty_size(ret.ty);
112+
if size <= 16 {
113+
let llty = if size <= 1 {
114+
Type::i8(ccx)
115+
} else if size <= 2 {
116+
Type::i16(ccx)
117+
} else if size <= 4 {
118+
Type::i32(ccx)
119+
} else if size <= 8 {
120+
Type::i64(ccx)
121+
} else {
122+
Type::array(&Type::i64(ccx), ((size + 7 ) / 8 ) as u64)
123+
};
124+
ret.cast = Some(llty);
125+
return;
126+
}
127+
}
128+
129+
fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType) {
130+
if is_reg_ty(arg.ty) {
131+
arg.extend_integer_width_to(64);
132+
return;
133+
}
134+
135+
if let Some((base_ty, members)) = is_homogenous_aggregate_ty(arg.ty) {
136+
arg.cast = Some(Type::array(&base_ty, members));
137+
return;
138+
}
139+
140+
arg.cast = Some(struct_ty(ccx, arg.ty));
141+
}
142+
143+
fn is_reg_ty(ty: Type) -> bool {
144+
match ty.kind() {
145+
Integer
146+
| Pointer
147+
| Float
148+
| Double => true,
149+
_ => false
150+
}
151+
}
152+
153+
fn coerce_to_long(ccx: &CrateContext, size: usize) -> Vec<Type> {
154+
let long_ty = Type::i64(ccx);
155+
let mut args = Vec::new();
156+
157+
let mut n = size / 64;
158+
while n > 0 {
159+
args.push(long_ty);
160+
n -= 1;
161+
}
162+
163+
let r = size % 64;
164+
if r > 0 {
165+
args.push(Type::ix(ccx, r as u64));
166+
}
167+
168+
args
169+
}
170+
171+
fn struct_ty(ccx: &CrateContext, ty: Type) -> Type {
172+
let size = ty_size(ty) * 8;
173+
Type::struct_(ccx, &coerce_to_long(ccx, size), false)
174+
}
175+
176+
pub fn compute_abi_info(ccx: &CrateContext, fty: &mut FnType) {
177+
if !fty.ret.is_ignore() {
178+
classify_ret_ty(ccx, &mut fty.ret);
179+
}
180+
181+
for arg in &mut fty.args {
182+
if arg.is_ignore() { continue; }
183+
classify_arg_ty(ccx, arg);
184+
}
185+
}

src/librustc_trans/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ mod cabi_powerpc;
110110
mod cabi_powerpc64;
111111
mod cabi_s390x;
112112
mod cabi_sparc;
113+
mod cabi_sparc64;
113114
mod cabi_x86;
114115
mod cabi_x86_64;
115116
mod cabi_x86_win64;

src/libstd/env.rs

+6
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ pub mod consts {
712712
/// - powerpc
713713
/// - powerpc64
714714
/// - s390x
715+
/// - sparc64
715716
#[stable(feature = "env", since = "1.0.0")]
716717
pub const ARCH: &'static str = super::arch::ARCH;
717718

@@ -843,6 +844,11 @@ mod arch {
843844
pub const ARCH: &'static str = "s390x";
844845
}
845846

847+
#[cfg(target_arch = "sparc64")]
848+
mod arch {
849+
pub const ARCH: &'static str = "sparc64";
850+
}
851+
846852
#[cfg(target_arch = "le32")]
847853
mod arch {
848854
pub const ARCH: &'static str = "le32";

src/libstd/os/linux/raw.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,9 @@ mod arch {
157157
}
158158
}
159159

160-
#[cfg(target_arch = "mips64")]
161-
mod arch {
162-
pub use libc::{off_t, ino_t, nlink_t, blksize_t, blkcnt_t, stat, time_t};
163-
}
164-
165-
#[cfg(target_arch = "s390x")]
160+
#[cfg(any(target_arch = "mips64",
161+
target_arch = "s390x",
162+
target_arch = "sparc64"))]
166163
mod arch {
167164
pub use libc::{off_t, ino_t, nlink_t, blksize_t, blkcnt_t, stat, time_t};
168165
}

0 commit comments

Comments
 (0)