Skip to content

Commit c08fb75

Browse files
committed
auto merge of #5431 : crabtw/rust/mips-rt, r=brson
Because the PTHREAD_STACK_MIN of my system is larger than default size, I add the stack_sz check to prevent assertion failure. Besides, libuv has to be modified because some flags are different from other targets. Instead of using hardcoded numbers, I change them to predefined symbols. By the way, the toolchain I used is http://www.mentor.com/embedded-software/sourcery-tools/sourcery-codebench/editions/lite-edition/mips-gnu-linux libuv patch: http://people.cs.nctu.edu.tw/~jyyou/rust/mips-uv.patch Below is the current test result. * core test stackwalk tests can cause segfault so I ignored them. ``` failures: io::tests::test_read_be_int_n io::tests::test_read_buffer_big_enough io::tests::test_read_f32 io::tests::test_read_write_be io::tests::test_read_write_f32 io::tests::test_read_write_le io::tests::test_simple io::tests::test_write_empty rand::tests::rng_seeded_custom_seed2 unstable::uvll::test::test_uv_ll_struct_size_addrinfo unstable::uvll::test::test_uv_ll_struct_size_uv_timer_t result: FAILED. 596 passed; 11 failed; 49 ignored ``` * std test: ``` failures: time::tests::run_tests result: FAILED. 330 passed; 1 failed; 21 ignored ```
2 parents 717ed51 + 4f1d8cb commit c08fb75

File tree

8 files changed

+60
-12
lines changed

8 files changed

+60
-12
lines changed

Diff for: mk/platform.mk

+25
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,31 @@ CFG_RUN_arm-linux-androideabi=
239239
CFG_RUN_TARG_arm-linux-androideabi=
240240
RUSTC_FLAGS_arm-linux-androideabi :=--android-cross-path=$(CFG_ANDROID_CROSS_PATH)
241241

242+
# mips-unknown-linux-gnu configuration
243+
CC_mips-unknown-linux-gnu=mips-linux-gnu-gcc
244+
CXX_mips-unknown-linux-gnu=mips-linux-gnu-g++
245+
CPP_mips-unknown-linux-gnu=mips-linux-gnu-gcc -E
246+
AR_mips-unknown-linux-gnu=mips-linux-gnu-ar
247+
CFG_LIB_NAME_mips-unknown-linux-gnu=lib$(1).so
248+
CFG_LIB_GLOB_mips-unknown-linux-gnu=lib$(1)-*.so
249+
CFG_LIB_DSYM_GLOB_mips-unknown-linux-gnu=lib$(1)-*.dylib.dSYM
250+
CFG_GCCISH_CFLAGS_mips-unknown-linux-gnu := -Wall -g -fPIC -mips32r2 -msoft-float -mabi=32
251+
CFG_GCCISH_CXXFLAGS_mips-unknown-linux-gnu := -fno-rtti
252+
CFG_GCCISH_LINK_FLAGS_mips-unknown-linux-gnu := -shared -fPIC -g -mips32r2 -msoft-float -mabi=32
253+
CFG_GCCISH_DEF_FLAG_mips-unknown-linux-gnu := -Wl,--export-dynamic,--dynamic-list=
254+
CFG_GCCISH_PRE_LIB_FLAGS_mips-unknown-linux-gnu := -Wl,-whole-archive
255+
CFG_GCCISH_POST_LIB_FLAGS_mips-unknown-linux-gnu := -Wl,-no-whole-archive -Wl,-znoexecstack
256+
CFG_DEF_SUFFIX_mips-unknown-linux-gnu := .linux.def
257+
CFG_INSTALL_NAME_mips-unknown-linux-gnu =
258+
CFG_LIBUV_LINK_FLAGS_mips-unknown-linux-gnu =
259+
CFG_EXE_SUFFIX_mips-unknown-linux-gnu :=
260+
CFG_WINDOWSY_mips-unknown-linux-gnu :=
261+
CFG_UNIXY_mips-unknown-linux-gnu := 1
262+
CFG_PATH_MUNGE_mips-unknown-linux-gnu := true
263+
CFG_LDPATH_mips-unknown-linux-gnu :=
264+
CFG_RUN_mips-unknown-linux-gnu=
265+
CFG_RUN_TARG_mips-unknown-linux-gnu=
266+
242267
# i686-pc-mingw32 configuration
243268
CC_i686-pc-mingw32=$(CC)
244269
CXX_i686-pc-mingw32=$(CXX)

Diff for: mk/rt.mk

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
LIBUV_FLAGS_i386 = -m32 -fPIC
2828
LIBUV_FLAGS_x86_64 = -m64 -fPIC
2929
LIBUV_FLAGS_arm = -fPIC -DANDROID -std=gnu99
30+
LIBUV_FLAGS_mips = -fPIC -mips32r2 -msoft-float -mabi=32
3031

3132
# when we're doing a snapshot build, we intentionally degrade as many
3233
# features in libuv and the runtime as possible, to ease portability.
@@ -180,6 +181,10 @@ else
180181
$$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
181182
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
182183
CFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
184+
LDFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1)))" \
185+
CC="$$(CC_$(1))" \
186+
CXX="$$(CXX_$(1))" \
187+
AR="$$(AR_$(1))" \
183188
builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
184189
V=$$(VERBOSE)
185190
endif

Diff for: src/libcore/rt/context.rs

+1
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ fn initialize_call_frame(regs: &mut Registers, fptr: *c_void, arg: *c_void, sp:
189189

190190
regs[4] = arg as uint;
191191
regs[29] = sp as uint;
192+
regs[25] = fptr as uint;
192193
regs[31] = fptr as uint;
193194
}
194195

Diff for: src/librustc/driver/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ pub fn default_configuration(sess: Session, +argv0: ~str, input: input) ->
8989
abi::X86 => (~"little",~"x86",~"32"),
9090
abi::X86_64 => (~"little",~"x86_64",~"64"),
9191
abi::Arm => (~"little",~"arm",~"32"),
92-
abi::Mips => (~"little",~"arm",~"32")
92+
abi::Mips => (~"big",~"mips",~"32")
9393
};
9494

9595
return ~[ // Target bindings.

Diff for: src/rt/arch/mips/_context.S

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ swap_registers:
5151
lw $2, 2 * 4($5)
5252
lw $3, 3 * 4($5)
5353
lw $4, 4 * 4($5)
54-
lw $5, 5 * 4($5)
5554
lw $6, 6 * 4($5)
5655
lw $7, 7 * 4($5)
5756

@@ -82,6 +81,8 @@ swap_registers:
8281
lw $30, 30 * 4($5)
8382
lw $31, 31 * 4($5)
8483

84+
lw $5, 5 * 4($5)
85+
8586
jr $31
8687
nop
8788
.end swap_registers

Diff for: src/rt/arch/mips/ccall.S

+19-10
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,39 @@
55

66
.text
77

8+
.align 2
89
.globl __morestack
910
.hidden __morestack
10-
.align 2
11+
.cfi_sections .eh_frame_entry
12+
.cfi_startproc
1113
.set nomips16
1214
.ent __morestack
1315
__morestack:
1416
.set noreorder
1517
.set nomacro
16-
move $7, $29
17-
move $29, $6
1818

19-
sw $7, 0($29)
20-
sw $31, -4($29)
19+
addiu $29, $29, -8
20+
sw $31, 4($29)
21+
sw $30, 0($29)
2122

22-
addiu $29, $29, -24
23+
.cfi_def_cfa_offset 8
24+
.cfi_offset 31, -4
25+
.cfi_offset 30, -8
26+
27+
move $30, $29
28+
.cfi_def_cfa_register 30
29+
30+
move $29, $6
2331
move $25, $5
2432
jalr $25
2533
nop
26-
addiu $29, $29, 24
34+
move $29, $30
2735

28-
lw $31, -4($29)
29-
lw $7, 0($29)
36+
lw $30, 0($29)
37+
lw $31, 4($29)
38+
addiu $29, $29, 8
3039

31-
move $29, $7
3240
jr $31
3341
nop
3442
.end __morestack
43+
.cfi_endproc

Diff for: src/rt/arch/mips/context.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ void context::call(void *f, void *arg, void *stack)
4040

4141
regs.data[4] = (uint32_t)arg;
4242
regs.data[29] = (uint32_t)sp;
43+
regs.data[25] = (uint32_t)f;
4344
regs.data[31] = (uint32_t)f;
4445

4546
// Last base pointer on the stack should be 0

Diff for: src/rt/sync/rust_thread.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111

1212
#include "rust_thread.h"
13+
#include <limits.h>
1314

1415
const size_t default_stack_sz = 1024*1024;
1516

@@ -41,6 +42,11 @@ rust_thread::start() {
4142
#if defined(__WIN32__)
4243
thread = CreateThread(NULL, stack_sz, rust_thread_start, this, 0, NULL);
4344
#else
45+
// PTHREAD_STACK_MIN of some system is larger than default size
46+
// so we check stack_sz to prevent assertion failure.
47+
if (stack_sz < PTHREAD_STACK_MIN) {
48+
stack_sz = PTHREAD_STACK_MIN;
49+
}
4450
pthread_attr_t attr;
4551
CHECKED(pthread_attr_init(&attr));
4652
CHECKED(pthread_attr_setstacksize(&attr, stack_sz));

0 commit comments

Comments
 (0)