Skip to content

Commit

Permalink
auto merge of #5431 : crabtw/rust/mips-rt, r=brson
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
bors committed Apr 4, 2013
2 parents 717ed51 + 4f1d8cb commit c08fb75
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 12 deletions.
25 changes: 25 additions & 0 deletions mk/platform.mk
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,31 @@ CFG_RUN_arm-linux-androideabi=
CFG_RUN_TARG_arm-linux-androideabi=
RUSTC_FLAGS_arm-linux-androideabi :=--android-cross-path=$(CFG_ANDROID_CROSS_PATH)

# mips-unknown-linux-gnu configuration
CC_mips-unknown-linux-gnu=mips-linux-gnu-gcc
CXX_mips-unknown-linux-gnu=mips-linux-gnu-g++
CPP_mips-unknown-linux-gnu=mips-linux-gnu-gcc -E
AR_mips-unknown-linux-gnu=mips-linux-gnu-ar
CFG_LIB_NAME_mips-unknown-linux-gnu=lib$(1).so
CFG_LIB_GLOB_mips-unknown-linux-gnu=lib$(1)-*.so
CFG_LIB_DSYM_GLOB_mips-unknown-linux-gnu=lib$(1)-*.dylib.dSYM
CFG_GCCISH_CFLAGS_mips-unknown-linux-gnu := -Wall -g -fPIC -mips32r2 -msoft-float -mabi=32
CFG_GCCISH_CXXFLAGS_mips-unknown-linux-gnu := -fno-rtti
CFG_GCCISH_LINK_FLAGS_mips-unknown-linux-gnu := -shared -fPIC -g -mips32r2 -msoft-float -mabi=32
CFG_GCCISH_DEF_FLAG_mips-unknown-linux-gnu := -Wl,--export-dynamic,--dynamic-list=
CFG_GCCISH_PRE_LIB_FLAGS_mips-unknown-linux-gnu := -Wl,-whole-archive
CFG_GCCISH_POST_LIB_FLAGS_mips-unknown-linux-gnu := -Wl,-no-whole-archive -Wl,-znoexecstack
CFG_DEF_SUFFIX_mips-unknown-linux-gnu := .linux.def
CFG_INSTALL_NAME_mips-unknown-linux-gnu =
CFG_LIBUV_LINK_FLAGS_mips-unknown-linux-gnu =
CFG_EXE_SUFFIX_mips-unknown-linux-gnu :=
CFG_WINDOWSY_mips-unknown-linux-gnu :=
CFG_UNIXY_mips-unknown-linux-gnu := 1
CFG_PATH_MUNGE_mips-unknown-linux-gnu := true
CFG_LDPATH_mips-unknown-linux-gnu :=
CFG_RUN_mips-unknown-linux-gnu=
CFG_RUN_TARG_mips-unknown-linux-gnu=

# i686-pc-mingw32 configuration
CC_i686-pc-mingw32=$(CC)
CXX_i686-pc-mingw32=$(CXX)
Expand Down
5 changes: 5 additions & 0 deletions mk/rt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
LIBUV_FLAGS_i386 = -m32 -fPIC
LIBUV_FLAGS_x86_64 = -m64 -fPIC
LIBUV_FLAGS_arm = -fPIC -DANDROID -std=gnu99
LIBUV_FLAGS_mips = -fPIC -mips32r2 -msoft-float -mabi=32

# when we're doing a snapshot build, we intentionally degrade as many
# features in libuv and the runtime as possible, to ease portability.
Expand Down Expand Up @@ -180,6 +181,10 @@ else
$$(LIBUV_LIB_$(1)): $$(LIBUV_DEPS)
$$(Q)$$(MAKE) -C $$(S)src/libuv/ \
CFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1))) $$(SNAP_DEFINES)" \
LDFLAGS="$$(LIBUV_FLAGS_$$(HOST_$(1)))" \
CC="$$(CC_$(1))" \
CXX="$$(CXX_$(1))" \
AR="$$(AR_$(1))" \
builddir_name="$$(CFG_BUILD_DIR)/rt/$(1)/libuv" \
V=$$(VERBOSE)
endif
Expand Down
1 change: 1 addition & 0 deletions src/libcore/rt/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ fn initialize_call_frame(regs: &mut Registers, fptr: *c_void, arg: *c_void, sp:

regs[4] = arg as uint;
regs[29] = sp as uint;
regs[25] = fptr as uint;
regs[31] = fptr as uint;
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn default_configuration(sess: Session, +argv0: ~str, input: input) ->
abi::X86 => (~"little",~"x86",~"32"),
abi::X86_64 => (~"little",~"x86_64",~"64"),
abi::Arm => (~"little",~"arm",~"32"),
abi::Mips => (~"little",~"arm",~"32")
abi::Mips => (~"big",~"mips",~"32")
};

return ~[ // Target bindings.
Expand Down
3 changes: 2 additions & 1 deletion src/rt/arch/mips/_context.S
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ swap_registers:
lw $2, 2 * 4($5)
lw $3, 3 * 4($5)
lw $4, 4 * 4($5)
lw $5, 5 * 4($5)
lw $6, 6 * 4($5)
lw $7, 7 * 4($5)

Expand Down Expand Up @@ -82,6 +81,8 @@ swap_registers:
lw $30, 30 * 4($5)
lw $31, 31 * 4($5)

lw $5, 5 * 4($5)

jr $31
nop
.end swap_registers
29 changes: 19 additions & 10 deletions src/rt/arch/mips/ccall.S
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,39 @@

.text

.align 2
.globl __morestack
.hidden __morestack
.align 2
.cfi_sections .eh_frame_entry
.cfi_startproc
.set nomips16
.ent __morestack
__morestack:
.set noreorder
.set nomacro
move $7, $29
move $29, $6

sw $7, 0($29)
sw $31, -4($29)
addiu $29, $29, -8
sw $31, 4($29)
sw $30, 0($29)

addiu $29, $29, -24
.cfi_def_cfa_offset 8
.cfi_offset 31, -4
.cfi_offset 30, -8

move $30, $29
.cfi_def_cfa_register 30

move $29, $6
move $25, $5
jalr $25
nop
addiu $29, $29, 24
move $29, $30

lw $31, -4($29)
lw $7, 0($29)
lw $30, 0($29)
lw $31, 4($29)
addiu $29, $29, 8

move $29, $7
jr $31
nop
.end __morestack
.cfi_endproc
1 change: 1 addition & 0 deletions src/rt/arch/mips/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ void context::call(void *f, void *arg, void *stack)

regs.data[4] = (uint32_t)arg;
regs.data[29] = (uint32_t)sp;
regs.data[25] = (uint32_t)f;
regs.data[31] = (uint32_t)f;

// Last base pointer on the stack should be 0
Expand Down
6 changes: 6 additions & 0 deletions src/rt/sync/rust_thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@


#include "rust_thread.h"
#include <limits.h>

const size_t default_stack_sz = 1024*1024;

Expand Down Expand Up @@ -41,6 +42,11 @@ rust_thread::start() {
#if defined(__WIN32__)
thread = CreateThread(NULL, stack_sz, rust_thread_start, this, 0, NULL);
#else
// PTHREAD_STACK_MIN of some system is larger than default size
// so we check stack_sz to prevent assertion failure.
if (stack_sz < PTHREAD_STACK_MIN) {
stack_sz = PTHREAD_STACK_MIN;
}
pthread_attr_t attr;
CHECKED(pthread_attr_init(&attr));
CHECKED(pthread_attr_setstacksize(&attr, stack_sz));
Expand Down

0 comments on commit c08fb75

Please sign in to comment.