Skip to content

Commit fdf601e

Browse files
committed
auto merge of #6358 : crabtw/rust/mips-segstk, r=brson
I changed ```RED_ZONE_SIZE``` to ```RZ_MAC_32``` because of stack canary failure. Here is a LLVM patch for MIPS segmented stacks. http://people.cs.nctu.edu.tw/~jyyou/rust/mips-segstk.patch Current test results ``` failures: rand::tests::test_rng_seeded_custom_seed2 run::tests::test_forced_destroy_actually_kills run::tests::test_unforced_destroy_actually_kills time::tests::run_tests uv_ll::test::test_uv_ll_struct_size_addrinfo uv_ll::test::test_uv_ll_struct_size_uv_timer_t segfaults: rt::io::option::test::test_option_writer_error rt::local_services::test::unwind rt::sched::test_swap_tasks_then stackwalk::test_simple stackwalk::test_simple_deep ```
2 parents 6da2c98 + c2bf9bf commit fdf601e

File tree

8 files changed

+220
-10
lines changed

8 files changed

+220
-10
lines changed

mk/platform.mk

+2-2
Original file line numberDiff line numberDiff line change
@@ -247,12 +247,12 @@ AR_mips-unknown-linux-gnu=mips-linux-gnu-ar
247247
CFG_LIB_NAME_mips-unknown-linux-gnu=lib$(1).so
248248
CFG_LIB_GLOB_mips-unknown-linux-gnu=lib$(1)-*.so
249249
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
250+
CFG_GCCISH_CFLAGS_mips-unknown-linux-gnu := -Wall -g -fPIC -mips32r2 -msoft-float -mabi=32 -mno-compact-eh
251251
CFG_GCCISH_CXXFLAGS_mips-unknown-linux-gnu := -fno-rtti
252252
CFG_GCCISH_LINK_FLAGS_mips-unknown-linux-gnu := -shared -fPIC -g -mips32r2 -msoft-float -mabi=32
253253
CFG_GCCISH_DEF_FLAG_mips-unknown-linux-gnu := -Wl,--export-dynamic,--dynamic-list=
254254
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
255+
CFG_GCCISH_POST_LIB_FLAGS_mips-unknown-linux-gnu := -Wl,-no-whole-archive
256256
CFG_DEF_SUFFIX_mips-unknown-linux-gnu := .linux.def
257257
CFG_INSTALL_NAME_mips-unknown-linux-gnu =
258258
CFG_LIBUV_LINK_FLAGS_mips-unknown-linux-gnu =

src/libcore/libc.rs

+85-1
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,17 @@ pub mod types {
268268
pub type ssize_t = i32;
269269
}
270270
pub mod posix01 {
271-
use libc::types::os::arch::c95::{c_short, c_long, time_t};
271+
use libc::types::os::arch::c95::{c_short, c_long, c_ulong, time_t};
272272
use libc::types::os::arch::posix88::{dev_t, gid_t, ino_t};
273273
use libc::types::os::arch::posix88::{mode_t, off_t};
274274
use libc::types::os::arch::posix88::{uid_t};
275275

276276
pub type nlink_t = u32;
277277
pub type blksize_t = i32;
278278
pub type blkcnt_t = i32;
279+
280+
#[cfg(target_arch = "x86")]
281+
#[cfg(target_arch = "arm")]
279282
pub struct stat {
280283
st_dev: dev_t,
281284
__pad1: c_short,
@@ -298,6 +301,30 @@ pub mod types {
298301
__unused4: c_long,
299302
__unused5: c_long,
300303
}
304+
305+
#[cfg(target_arch = "mips")]
306+
pub struct stat {
307+
st_dev: c_ulong,
308+
st_pad1: [c_long, ..3],
309+
st_ino: ino_t,
310+
st_mode: mode_t,
311+
st_nlink: nlink_t,
312+
st_uid: uid_t,
313+
st_gid: gid_t,
314+
st_rdev: c_ulong,
315+
st_pad2: [c_long, ..2],
316+
st_size: off_t,
317+
st_pad3: c_long,
318+
st_atime: time_t,
319+
st_atime_nsec: c_long,
320+
st_mtime: time_t,
321+
st_mtime_nsec: c_long,
322+
st_ctime: time_t,
323+
st_ctime_nsec: c_long,
324+
st_blksize: blksize_t,
325+
st_blocks: blkcnt_t,
326+
st_pad5: [c_long, ..14],
327+
}
301328
}
302329
pub mod posix08 {}
303330
pub mod bsd44 {}
@@ -963,6 +990,9 @@ pub mod consts {
963990
}
964991
pub mod c99 {
965992
}
993+
#[cfg(target_arch = "x86")]
994+
#[cfg(target_arch = "x86_64")]
995+
#[cfg(target_arch = "arm")]
966996
pub mod posix88 {
967997
pub static O_RDONLY : int = 0;
968998
pub static O_WRONLY : int = 1;
@@ -1007,6 +1037,51 @@ pub mod consts {
10071037
pub static SIGALRM : int = 14;
10081038
pub static SIGTERM : int = 15;
10091039
}
1040+
#[cfg(target_arch = "mips")]
1041+
pub mod posix88 {
1042+
pub static O_RDONLY : int = 0;
1043+
pub static O_WRONLY : int = 1;
1044+
pub static O_RDWR : int = 2;
1045+
pub static O_APPEND : int = 8;
1046+
pub static O_CREAT : int = 256;
1047+
pub static O_EXCL : int = 1024;
1048+
pub static O_TRUNC : int = 512;
1049+
pub static S_IFIFO : int = 4096;
1050+
pub static S_IFCHR : int = 8192;
1051+
pub static S_IFBLK : int = 24576;
1052+
pub static S_IFDIR : int = 16384;
1053+
pub static S_IFREG : int = 32768;
1054+
pub static S_IFMT : int = 61440;
1055+
pub static S_IEXEC : int = 64;
1056+
pub static S_IWRITE : int = 128;
1057+
pub static S_IREAD : int = 256;
1058+
pub static S_IRWXU : int = 448;
1059+
pub static S_IXUSR : int = 64;
1060+
pub static S_IWUSR : int = 128;
1061+
pub static S_IRUSR : int = 256;
1062+
pub static F_OK : int = 0;
1063+
pub static R_OK : int = 4;
1064+
pub static W_OK : int = 2;
1065+
pub static X_OK : int = 1;
1066+
pub static STDIN_FILENO : int = 0;
1067+
pub static STDOUT_FILENO : int = 1;
1068+
pub static STDERR_FILENO : int = 2;
1069+
pub static F_LOCK : int = 1;
1070+
pub static F_TEST : int = 3;
1071+
pub static F_TLOCK : int = 2;
1072+
pub static F_ULOCK : int = 0;
1073+
pub static SIGHUP : int = 1;
1074+
pub static SIGINT : int = 2;
1075+
pub static SIGQUIT : int = 3;
1076+
pub static SIGILL : int = 4;
1077+
pub static SIGABRT : int = 6;
1078+
pub static SIGFPE : int = 8;
1079+
pub static SIGKILL : int = 9;
1080+
pub static SIGSEGV : int = 11;
1081+
pub static SIGPIPE : int = 13;
1082+
pub static SIGALRM : int = 14;
1083+
pub static SIGTERM : int = 15;
1084+
}
10101085
pub mod posix01 {
10111086
pub static SIGTRAP : int = 5;
10121087

@@ -1026,11 +1101,20 @@ pub mod consts {
10261101
}
10271102
pub mod bsd44 {
10281103
}
1104+
#[cfg(target_arch = "x86")]
1105+
#[cfg(target_arch = "x86_64")]
1106+
#[cfg(target_arch = "arm")]
10291107
pub mod extra {
10301108
pub static O_RSYNC : int = 1052672;
10311109
pub static O_DSYNC : int = 4096;
10321110
pub static O_SYNC : int = 1052672;
10331111
}
1112+
#[cfg(target_arch = "mips")]
1113+
pub mod extra {
1114+
pub static O_RSYNC : int = 16400;
1115+
pub static O_DSYNC : int = 16;
1116+
pub static O_SYNC : int = 16400;
1117+
}
10341118
}
10351119

10361120
#[cfg(target_os = "freebsd")]

src/libcore/path.rs

+30-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ pub trait GenericPath {
122122
mod stat {
123123
#[cfg(target_arch = "x86")]
124124
#[cfg(target_arch = "arm")]
125-
#[cfg(target_arch = "mips")]
126125
pub mod arch {
127126
use libc;
128127

@@ -152,6 +151,36 @@ mod stat {
152151
}
153152
}
154153

154+
#[cfg(target_arch = "mips")]
155+
pub mod arch {
156+
use libc;
157+
158+
pub fn default_stat() -> libc::stat {
159+
libc::stat {
160+
st_dev: 0,
161+
st_pad1: [0, ..3],
162+
st_ino: 0,
163+
st_mode: 0,
164+
st_nlink: 0,
165+
st_uid: 0,
166+
st_gid: 0,
167+
st_rdev: 0,
168+
st_pad2: [0, ..2],
169+
st_size: 0,
170+
st_pad3: 0,
171+
st_atime: 0,
172+
st_atime_nsec: 0,
173+
st_mtime: 0,
174+
st_mtime_nsec: 0,
175+
st_ctime: 0,
176+
st_ctime_nsec: 0,
177+
st_blksize: 0,
178+
st_blocks: 0,
179+
st_pad5: [0, ..14],
180+
}
181+
}
182+
}
183+
155184
#[cfg(target_arch = "x86_64")]
156185
pub mod arch {
157186
use libc;

src/libstd/ebml.rs

+1
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ pub mod reader {
157157
}
158158
159159
#[cfg(target_arch = "arm")]
160+
#[cfg(target_arch = "mips")]
160161
pub fn vuint_at(data: &[u8], start: uint) -> Res {
161162
vuint_at_slow(data, start)
162163
}

src/rt/arch/mips/ccall.S

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
.align 2
99
.globl __morestack
1010
.hidden __morestack
11-
.cfi_sections .eh_frame_entry
1211
.cfi_startproc
1312
.set nomips16
1413
.ent __morestack

src/rt/arch/mips/morestack.S

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
// Mark stack as non-executable
2+
#if defined(__linux__) && defined(__ELF__)
3+
.section .note.GNU-stack, "", @progbits
4+
#endif
5+
6+
.text
7+
8+
.globl upcall_new_stack
9+
.globl upcall_del_stack
10+
.globl __morestack
11+
12+
.hidden __morestack
13+
14+
.cfi_startproc
15+
.set nomips16
16+
.ent __morestack
17+
__morestack:
18+
.set noreorder
19+
.set nomacro
20+
21+
addiu $29, $29, -12
22+
sw $31, 8($29)
23+
sw $30, 4($29)
24+
sw $23, 0($29)
25+
26+
// 24 = 12 (current) + 12 (previous)
27+
.cfi_def_cfa_offset 24
28+
.cfi_offset 31, -4
29+
.cfi_offset 30, -20
30+
.cfi_offset 23, -24
31+
32+
move $23, $28
33+
move $30, $29
34+
.cfi_def_cfa_register 30
35+
36+
// Save argument registers of the original function
37+
addiu $29, $29, -32
38+
sw $4, 16($29)
39+
sw $5, 20($29)
40+
sw $6, 24($29)
41+
sw $7, 28($29)
42+
43+
move $4, $14 // Size of stack arguments
44+
addu $5, $30, 24 // Address of stack arguments
45+
move $6, $15 // The amount of stack needed
46+
47+
move $28, $23
48+
lw $25, %call16(upcall_new_stack)($23)
49+
jalr $25
50+
nop
51+
52+
// Pop the saved arguments
53+
lw $4, 16($29)
54+
lw $5, 20($29)
55+
lw $6, 24($29)
56+
lw $7, 28($29)
57+
addiu $29, $29, 32
58+
59+
lw $24, 8($30) // Grab the return pointer.
60+
addiu $24, $24, 12 // Skip past the `lw`, `jr`, `addiu` in our parent frame
61+
move $29, $2 // Switch to the new stack.
62+
63+
// for PIC
64+
lw $2, 12($30)
65+
lw $25, 16($30)
66+
67+
move $28, $23
68+
jalr $24 // Reenter the caller function
69+
nop
70+
71+
// Switch back to the rust stack
72+
move $29, $30
73+
74+
// Save the return value
75+
addiu $29, $29, -24
76+
sw $2, 16($29)
77+
sw $3, 20($29)
78+
79+
move $28, $23
80+
lw $25, %call16(upcall_del_stack)($23)
81+
jalr $25
82+
nop
83+
84+
// Restore the return value
85+
lw $2, 16($29)
86+
lw $3, 20($29)
87+
addiu $29, $29, 24
88+
89+
lw $31, 8($29)
90+
lw $30, 4($29)
91+
lw $23, 0($29)
92+
addiu $29, $29, 12
93+
94+
jr $31
95+
nop
96+
.end __morestack
97+
.cfi_endproc

src/rt/arch/mips/record_sp.S

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ record_sp_limit:
1616
.set mips32r2
1717
rdhwr $3, $29
1818
.set pop
19-
addiu $3, $3, -0x7008
20-
sw $4, 4($3)
19+
addiu $3, $3, -0x7004
20+
sw $4, 0($3)
2121
jr $31
2222
nop
2323
.end record_sp_limit
@@ -33,8 +33,8 @@ get_sp_limit:
3333
.set mips32r2
3434
rdhwr $3, $29
3535
.set pop
36-
addiu $3, $3, -0x7008
37-
lw $2, 4($3)
36+
addiu $3, $3, -0x7004
37+
lw $2, 0($3)
3838
jr $31
3939
nop
4040
.end get_sp_limit

src/rt/rust_task.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
#define RED_ZONE_SIZE RZ_LINUX_64
145145
#endif
146146
#ifdef __mips__
147-
#define RED_ZONE_SIZE RZ_LINUX_32
147+
#define RED_ZONE_SIZE RZ_MAC_32
148148
#endif
149149
#endif
150150
#ifdef __APPLE__

0 commit comments

Comments
 (0)