Skip to content

Commit 0c96037

Browse files
committed
auto merge of #20980 : richo/rust/final-power, r=alexcrichton
Originally, this was going to be discussed and revisted, however I've been working on this for months, and a rebase on top of master was about 1 flight's worth of work so I just went ahead and did it. This gets you as far as being able to target powerpc with, eg: LD_LIBRARY_PATH=./x86_64-unknown-linux-gnu/stage2/lib/ x86_64-unknown-linux-gnu/stage2/bin/rustc -C linker=powerpc-linux-gnu-gcc --target powerpc-unknown-linux-gnu hello.rs Would really love to get this out before 1.0. r? @alexcrichton
2 parents 451e134 + 78278d0 commit 0c96037

File tree

26 files changed

+364
-42
lines changed

26 files changed

+364
-42
lines changed

configure

+6-2
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,10 @@ case $CFG_CPUTYPE in
448448
CFG_CPUTYPE=aarch64
449449
;;
450450

451+
powerpc)
452+
CFG_CPUTYPE=powerpc
453+
;;
454+
451455
x86_64 | x86-64 | x64 | amd64)
452456
CFG_CPUTYPE=x86_64
453457
;;
@@ -1004,7 +1008,7 @@ do
10041008
make_dir $t/rt/jemalloc
10051009
for i in \
10061010
isaac sync test \
1007-
arch/i386 arch/x86_64 arch/arm arch/aarch64 arch/mips
1011+
arch/i386 arch/x86_64 arch/arm arch/aarch64 arch/mips arch/powerpc
10081012
do
10091013
make_dir $t/rt/stage$s/$i
10101014
done
@@ -1169,7 +1173,7 @@ do
11691173

11701174
msg "configuring LLVM for $gnu_t"
11711175

1172-
LLVM_TARGETS="--enable-targets=x86,x86_64,arm,aarch64,mips"
1176+
LLVM_TARGETS="--enable-targets=x86,x86_64,arm,aarch64,mips,powerpc"
11731177
LLVM_BUILD="--build=$gnu_t"
11741178
LLVM_HOST="--host=$gnu_t"
11751179
LLVM_TARGET="--target=$gnu_t"

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

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# powerpc-unknown-linux-gnu configuration
2+
CROSS_PREFIX_powerpc-unknown-linux-gnu=powerpc-linux-gnu-
3+
CC_powerpc-unknown-linux-gnu=$(CC)
4+
CXX_powerpc-unknown-linux-gnu=$(CXX)
5+
CPP_powerpc-unknown-linux-gnu=$(CPP)
6+
AR_powerpc-unknown-linux-gnu=$(AR)
7+
CFG_LIB_NAME_powerpc-unknown-linux-gnu=lib$(1).so
8+
CFG_STATIC_LIB_NAME_powerpc-unknown-linux-gnu=lib$(1).a
9+
CFG_LIB_GLOB_powerpc-unknown-linux-gnu=lib$(1)-*.so
10+
CFG_LIB_DSYM_GLOB_powerpc-unknown-linux-gnu=lib$(1)-*.dylib.dSYM
11+
CFG_CFLAGS_powerpc-unknown-linux-gnu := -m32 $(CFLAGS)
12+
CFG_GCCISH_CFLAGS_powerpc-unknown-linux-gnu := -Wall -Werror -g -fPIC -m32 $(CFLAGS)
13+
CFG_GCCISH_CXXFLAGS_powerpc-unknown-linux-gnu := -fno-rtti $(CXXFLAGS)
14+
CFG_GCCISH_LINK_FLAGS_powerpc-unknown-linux-gnu := -shared -fPIC -ldl -pthread -lrt -g -m32
15+
CFG_GCCISH_DEF_FLAG_powerpc-unknown-linux-gnu := -Wl,--export-dynamic,--dynamic-list=
16+
CFG_GCCISH_PRE_LIB_FLAGS_powerpc-unknown-linux-gnu := -Wl,-whole-archive
17+
CFG_GCCISH_POST_LIB_FLAGS_powerpc-unknown-linux-gnu := -Wl,-no-whole-archive
18+
CFG_DEF_SUFFIX_powerpc-unknown-linux-gnu := .linux.def
19+
CFG_LLC_FLAGS_powerpc-unknown-linux-gnu :=
20+
CFG_INSTALL_NAME_powerpc-unknown-linux-gnu =
21+
CFG_EXE_SUFFIX_powerpc-unknown-linux-gnu =
22+
CFG_WINDOWSY_powerpc-unknown-linux-gnu :=
23+
CFG_UNIXY_powerpc-unknown-linux-gnu := 1
24+
CFG_PATH_MUNGE_powerpc-unknown-linux-gnu := true
25+
CFG_LDPATH_powerpc-unknown-linux-gnu :=
26+
CFG_RUN_powerpc-unknown-linux-gnu=$(2)
27+
CFG_RUN_TARG_powerpc-unknown-linux-gnu=$(call CFG_RUN_powerpc-unknown-linux-gnu,,$(2))
28+
CFG_GNU_TRIPLE_powerpc-unknown-linux-gnu := powerpc-unknown-linux-gnu

mk/main.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ endif
263263
######################################################################
264264

265265
# FIXME: x86-ism
266-
LLVM_COMPONENTS=x86 arm aarch64 mips ipo bitreader bitwriter linker asmparser mcjit \
266+
LLVM_COMPONENTS=x86 arm aarch64 mips powerpc ipo bitreader bitwriter linker asmparser mcjit \
267267
interpreter instrumentation
268268

269269
# Only build these LLVM tools

mk/platform.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ define CFG_MAKE_TOOLCHAIN
177177
$$(CFG_GCCISH_DEF_FLAG_$(1))$$(3) $$(2) \
178178
$$(call CFG_INSTALL_NAME_$(1),$$(4))
179179

180-
ifeq ($$(findstring $(HOST_$(1)),arm aarch64 mips mipsel),)
180+
ifeq ($$(findstring $(HOST_$(1)),arm aarch64 mips mipsel powerpc),)
181181

182182
# We're using llvm-mc as our assembler because it supports
183183
# .cfi pseudo-ops on mac
@@ -189,7 +189,7 @@ define CFG_MAKE_TOOLCHAIN
189189
-o=$$(1)
190190
else
191191

192-
# For the ARM, AARCH64 and MIPS crosses, use the toolchain assembler
192+
# For the ARM, AARCH64, MIPS and POWER crosses, use the toolchain assembler
193193
# FIXME: We should be able to use the LLVM assembler
194194
CFG_ASSEMBLE_$(1)=$$(CC_$(1)) $$(CFG_GCCISH_CFLAGS_$(1)) \
195195
$$(CFG_DEPEND_FLAGS) $$(2) -c -o $$(1)

src/doc/reference.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2170,7 +2170,7 @@ arbitrarily complex configurations through nesting.
21702170
The following configurations must be defined by the implementation:
21712171

21722172
* `target_arch = "..."`. Target CPU architecture, such as `"x86"`, `"x86_64"`
2173-
`"mips"`, `"arm"`, or `"aarch64"`.
2173+
`"mips"`, `"powerpc"`, `"arm"`, or `"aarch64"`.
21742174
* `target_endian = "..."`. Endianness of the target CPU, either `"little"` or
21752175
`"big"`.
21762176
* `target_family = "..."`. Operating system family of the target, e. g.

src/liballoc/heap.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ unsafe fn exchange_free(ptr: *mut u8, old_size: uint, align: uint) {
119119
not(feature = "external_crate"),
120120
any(target_arch = "arm",
121121
target_arch = "mips",
122-
target_arch = "mipsel")))]
122+
target_arch = "mipsel",
123+
target_arch = "powerpc")))]
123124
const MIN_ALIGN: uint = 8;
124125
#[cfg(all(not(feature = "external_funcs"),
125126
not(feature = "external_crate"),

src/libcoretest/mem.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,14 @@ fn size_of_basic() {
1919
}
2020

2121
#[test]
22-
#[cfg(any(target_arch = "x86",
23-
target_arch = "arm",
24-
target_arch = "mips",
25-
target_arch = "mipsel"))]
22+
#[cfg(target_pointer_width = "32")]
2623
fn size_of_32() {
2724
assert_eq!(size_of::<uint>(), 4u);
2825
assert_eq!(size_of::<*const uint>(), 4u);
2926
}
3027

3128
#[test]
32-
#[cfg(any(target_arch = "x86_64",
33-
target_arch = "aarch64"))]
29+
#[cfg(target_pointer_width = "64")]
3430
fn size_of_64() {
3531
assert_eq!(size_of::<uint>(), 8u);
3632
assert_eq!(size_of::<*const uint>(), 8u);
@@ -52,18 +48,14 @@ fn align_of_basic() {
5248
}
5349

5450
#[test]
55-
#[cfg(any(target_arch = "x86",
56-
target_arch = "arm",
57-
target_arch = "mips",
58-
target_arch = "mipsel"))]
51+
#[cfg(target_pointer_width = "32")]
5952
fn align_of_32() {
6053
assert_eq!(align_of::<uint>(), 4u);
6154
assert_eq!(align_of::<*const uint>(), 4u);
6255
}
6356

6457
#[test]
65-
#[cfg(any(target_arch = "x86_64",
66-
target_arch = "aarch64"))]
58+
#[cfg(target_pointer_width = "64")]
6759
fn align_of_64() {
6860
assert_eq!(align_of::<uint>(), 8u);
6961
assert_eq!(align_of::<*const uint>(), 8u);

src/liblibc/lib.rs

+18-7
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,8 @@ pub mod types {
497497
#[cfg(any(target_arch = "x86",
498498
target_arch = "arm",
499499
target_arch = "mips",
500-
target_arch = "mipsel"))]
500+
target_arch = "mipsel",
501+
target_arch = "powerpc"))]
501502
pub mod arch {
502503
pub mod c95 {
503504
pub type c_char = i8;
@@ -528,7 +529,8 @@ pub mod types {
528529
}
529530
#[cfg(any(target_arch = "x86",
530531
target_arch = "mips",
531-
target_arch = "mipsel"))]
532+
target_arch = "mipsel",
533+
target_arch = "powerpc"))]
532534
pub mod posix88 {
533535
pub type off_t = i32;
534536
pub type dev_t = u64;
@@ -642,7 +644,9 @@ pub mod types {
642644
pub __size: [u32; 9]
643645
}
644646
}
645-
#[cfg(any(target_arch = "mips", target_arch = "mipsel"))]
647+
#[cfg(any(target_arch = "mips",
648+
target_arch = "mipsel",
649+
target_arch = "powerpc"))]
646650
pub mod posix01 {
647651
use types::os::arch::c95::{c_long, c_ulong, time_t};
648652
use types::os::arch::posix88::{gid_t, ino_t};
@@ -2697,7 +2701,9 @@ pub mod consts {
26972701
pub const EHWPOISON: c_int = 133;
26982702
}
26992703

2700-
#[cfg(any(target_arch = "mips", target_arch = "mipsel"))]
2704+
#[cfg(any(target_arch = "mips",
2705+
target_arch = "mipsel",
2706+
target_arch = "powerpc"))]
27012707
pub mod posix88 {
27022708
use types::os::arch::c95::c_int;
27032709
use types::common::c95::c_void;
@@ -2982,7 +2988,8 @@ pub mod consts {
29822988
#[cfg(all(target_os = "linux",
29832989
any(target_arch = "mips",
29842990
target_arch = "mipsel",
2985-
target_arch = "aarch64")))]
2991+
target_arch = "aarch64",
2992+
target_arch = "powerpc")))]
29862993
pub const PTHREAD_STACK_MIN: size_t = 131072;
29872994

29882995
pub const CLOCK_REALTIME: c_int = 0;
@@ -3040,7 +3047,9 @@ pub mod consts {
30403047
pub const SHUT_WR: c_int = 1;
30413048
pub const SHUT_RDWR: c_int = 2;
30423049
}
3043-
#[cfg(any(target_arch = "mips", target_arch = "mipsel"))]
3050+
#[cfg(any(target_arch = "mips",
3051+
target_arch = "mipsel",
3052+
target_arch = "powerpc"))]
30443053
pub mod bsd44 {
30453054
use types::os::arch::c95::c_int;
30463055

@@ -3115,7 +3124,9 @@ pub mod consts {
31153124
pub const MAP_NONBLOCK : c_int = 0x010000;
31163125
pub const MAP_STACK : c_int = 0x020000;
31173126
}
3118-
#[cfg(any(target_arch = "mips", target_arch = "mipsel"))]
3127+
#[cfg(any(target_arch = "mips",
3128+
target_arch = "mipsel",
3129+
target_arch = "powerpc"))]
31193130
pub mod extra {
31203131
use types::os::arch::c95::c_int;
31213132

src/librustc_back/target/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ mod i686_unknown_dragonfly;
7272
mod i686_unknown_linux_gnu;
7373
mod mips_unknown_linux_gnu;
7474
mod mipsel_unknown_linux_gnu;
75+
mod powerpc_unknown_linux_gnu;
7576
mod x86_64_apple_darwin;
7677
mod x86_64_apple_ios;
7778
mod x86_64_pc_windows_gnu;
@@ -95,7 +96,7 @@ pub struct Target {
9596
/// OS name to use for conditional compilation.
9697
pub target_os: String,
9798
/// Architecture to use for ABI considerations. Valid options: "x86", "x86_64", "arm",
98-
/// "aarch64", and "mips". "mips" includes "mipsel".
99+
/// "aarch64", "mips", and "powerpc". "mips" includes "mipsel".
99100
pub arch: String,
100101
/// Optional settings with defaults.
101102
pub options: TargetOptions,
@@ -339,6 +340,7 @@ impl Target {
339340
i686_unknown_linux_gnu,
340341
mips_unknown_linux_gnu,
341342
mipsel_unknown_linux_gnu,
343+
powerpc_unknown_linux_gnu,
342344
arm_linux_androideabi,
343345
arm_unknown_linux_gnueabi,
344346
arm_unknown_linux_gnueabihf,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2012 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;
12+
13+
pub fn target() -> Target {
14+
let mut base = super::linux_base::opts();
15+
base.pre_link_args.push("-m32".to_string());
16+
17+
Target {
18+
data_layout: "E-S8-p:32:32-f64:32:64-i64:32:64-f80:32:32-n8:16:32".to_string(),
19+
llvm_target: "powerpc-unknown-linux-gnu".to_string(),
20+
target_endian: "big".to_string(),
21+
target_pointer_width: "32".to_string(),
22+
arch: "powerpc".to_string(),
23+
target_os: "linux".to_string(),
24+
options: base,
25+
}
26+
}

src/librustc_llvm/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1974,6 +1974,11 @@ extern {
19741974
pub fn LLVMInitializeMipsTargetMC();
19751975
pub fn LLVMInitializeMipsAsmPrinter();
19761976
pub fn LLVMInitializeMipsAsmParser();
1977+
pub fn LLVMInitializePowerPCTargetInfo();
1978+
pub fn LLVMInitializePowerPCTarget();
1979+
pub fn LLVMInitializePowerPCTargetMC();
1980+
pub fn LLVMInitializePowerPCAsmPrinter();
1981+
pub fn LLVMInitializePowerPCAsmParser();
19771982

19781983
pub fn LLVMRustAddPass(PM: PassManagerRef, Pass: *const c_char) -> bool;
19791984
pub fn LLVMRustCreateTargetMachine(Triple: *const c_char,
@@ -2249,6 +2254,12 @@ pub unsafe fn static_link_hack_this_sucks() {
22492254
LLVMInitializeMipsAsmPrinter();
22502255
LLVMInitializeMipsAsmParser();
22512256

2257+
LLVMInitializePowerPCTargetInfo();
2258+
LLVMInitializePowerPCTarget();
2259+
LLVMInitializePowerPCTargetMC();
2260+
LLVMInitializePowerPCAsmPrinter();
2261+
LLVMInitializePowerPCAsmParser();
2262+
22522263
LLVMRustSetLLVMOptions(0 as c_int,
22532264
0 as *const _);
22542265

src/librustc_trans/back/write.rs

+6
Original file line numberDiff line numberDiff line change
@@ -1039,6 +1039,12 @@ unsafe fn configure_llvm(sess: &Session) {
10391039
llvm::LLVMInitializeMipsAsmPrinter();
10401040
llvm::LLVMInitializeMipsAsmParser();
10411041

1042+
llvm::LLVMInitializePowerPCTargetInfo();
1043+
llvm::LLVMInitializePowerPCTarget();
1044+
llvm::LLVMInitializePowerPCTargetMC();
1045+
llvm::LLVMInitializePowerPCAsmPrinter();
1046+
llvm::LLVMInitializePowerPCAsmParser();
1047+
10421048
llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int,
10431049
llvm_args.as_ptr());
10441050
});

src/librustc_trans/trans/asm.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -161,10 +161,7 @@ pub fn trans_inline_asm<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, ia: &ast::InlineAsm)
161161
// Default per-arch clobbers
162162
// Basically what clang does
163163

164-
#[cfg(any(target_arch = "arm",
165-
target_arch = "aarch64",
166-
target_arch = "mips",
167-
target_arch = "mipsel"))]
164+
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
168165
fn get_clobbers() -> String {
169166
"".to_string()
170167
}

src/librustc_trans/trans/cabi.rs

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use trans::cabi_x86_64;
1818
use trans::cabi_x86_win64;
1919
use trans::cabi_arm;
2020
use trans::cabi_aarch64;
21+
use trans::cabi_powerpc;
2122
use trans::cabi_mips;
2223
use trans::type_::Type;
2324

@@ -125,6 +126,7 @@ pub fn compute_abi_info(ccx: &CrateContext,
125126
cabi_arm::compute_abi_info(ccx, atys, rty, ret_def, flavor)
126127
},
127128
"mips" => cabi_mips::compute_abi_info(ccx, atys, rty, ret_def),
129+
"powerpc" => cabi_powerpc::compute_abi_info(ccx, atys, rty, ret_def),
128130
a => ccx.sess().fatal(&format!("unrecognized arch \"{}\" in target specification", a)
129131
[]),
130132
}

0 commit comments

Comments
 (0)