Skip to content

Commit b9c7ee5

Browse files
committed
auto merge of #5647 : thestinger/rust/execstack, r=brson
Closes #5643
2 parents f336afd + c0be7df commit b9c7ee5

16 files changed

+94
-24
lines changed

mk/platform.mk

+3-5
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ ifdef CFG_VALGRIND
6161
endif
6262

6363
ifneq ($(findstring linux,$(CFG_OSTYPE)),)
64-
# -znoexecstack is here because librt is for some reason being created
65-
# with executable stack and Fedora (or SELinux) doesn't like that (#798)
6664
ifdef CFG_PERF
6765
ifneq ($(CFG_PERF_WITH_LOGFD),)
6866
CFG_PERF_TOOL := $(CFG_PERF) stat -r 3 --log-fd 2
@@ -126,7 +124,7 @@ CFG_GCCISH_CXXFLAGS_x86_64-unknown-linux-gnu := -fno-rtti
126124
CFG_GCCISH_LINK_FLAGS_x86_64-unknown-linux-gnu := -shared -fPIC -ldl -lpthread -lrt -g -m64
127125
CFG_GCCISH_DEF_FLAG_x86_64-unknown-linux-gnu := -Wl,--export-dynamic,--dynamic-list=
128126
CFG_GCCISH_PRE_LIB_FLAGS_x86_64-unknown-linux-gnu := -Wl,-whole-archive
129-
CFG_GCCISH_POST_LIB_FLAGS_x86_64-unknown-linux-gnu := -Wl,-no-whole-archive -Wl,-znoexecstack
127+
CFG_GCCISH_POST_LIB_FLAGS_x86_64-unknown-linux-gnu := -Wl,-no-whole-archive
130128
CFG_DEF_SUFFIX_x86_64-unknown-linux-gnu := .linux.def
131129
CFG_INSTALL_NAME_x86_64-unknown-linux-gnu =
132130
CFG_LIBUV_LINK_FLAGS_x86_64-unknown-linux-gnu =
@@ -152,7 +150,7 @@ CFG_GCCISH_CXXFLAGS_i686-unknown-linux-gnu := -fno-rtti
152150
CFG_GCCISH_LINK_FLAGS_i686-unknown-linux-gnu := -shared -fPIC -ldl -lpthread -lrt -g -m32
153151
CFG_GCCISH_DEF_FLAG_i686-unknown-linux-gnu := -Wl,--export-dynamic,--dynamic-list=
154152
CFG_GCCISH_PRE_LIB_FLAGS_i686-unknown-linux-gnu := -Wl,-whole-archive
155-
CFG_GCCISH_POST_LIB_FLAGS_i686-unknown-linux-gnu := -Wl,-no-whole-archive -Wl,-znoexecstack
153+
CFG_GCCISH_POST_LIB_FLAGS_i686-unknown-linux-gnu := -Wl,-no-whole-archive
156154
CFG_DEF_SUFFIX_i686-unknown-linux-gnu := .linux.def
157155
CFG_INSTALL_NAME_i686-unknown-linux-gnu =
158156
CFG_LIBUV_LINK_FLAGS_i686-unknown-linux-gnu =
@@ -228,7 +226,7 @@ CFG_GCCISH_CXXFLAGS_arm-linux-androideabi := -fno-rtti
228226
CFG_GCCISH_LINK_FLAGS_arm-linux-androideabi := -shared -fPIC -ldl -g -lm -lsupc++ -lgnustl_shared
229227
CFG_GCCISH_DEF_FLAG_arm-linux-androideabi := -Wl,--export-dynamic,--dynamic-list=
230228
CFG_GCCISH_PRE_LIB_FLAGS_arm-linux-androideabi := -Wl,-whole-archive
231-
CFG_GCCISH_POST_LIB_FLAGS_arm-linux-androideabi := -Wl,-no-whole-archive -Wl,-znoexecstack
229+
CFG_GCCISH_POST_LIB_FLAGS_arm-linux-androideabi := -Wl,-no-whole-archive
232230
CFG_DEF_SUFFIX_arm-linux-androideabi := .android.def
233231
CFG_INSTALL_NAME_arm-linux-androideabi =
234232
CFG_LIBUV_LINK_FLAGS_arm-linux-androideabi =

src/rt/arch/arm/_context.S

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Mark stack as non-executable
2+
#if defined(__linux__) && defined(__ELF__)
3+
.section .note.GNU-stack, "", @progbits
4+
#endif
5+
16
.text
27
.code 32
38
.arm
@@ -17,12 +22,12 @@ swap_registers:
1722
str r10, [r0, #40]
1823
str r11, [r0, #44]
1924
str r12, [r0, #48]
20-
str sp, [r0, #52]
25+
str sp, [r0, #52]
2126
str lr, [r0, #56]
2227

2328
mrs r2, cpsr
2429
str r2, [r0, #64]
25-
30+
2631

2732
ldr r0, [r1, #0]
2833
ldr r3, [r1, #12]
@@ -35,10 +40,10 @@ swap_registers:
3540
ldr r10, [r1, #40]
3641
ldr r11, [r1, #44]
3742
ldr r12, [r1, #48]
38-
43+
3944
ldr sp, [r1, #52]
4045
ldr lr, [r1, #56]
41-
46+
4247
ldr r2, [r1, #64]
4348
msr cpsr_cxsf, r2
4449

src/rt/arch/arm/ccall.S

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Mark stack as non-executable
2+
#if defined(__linux__) && defined(__ELF__)
3+
.section .note.GNU-stack, "", @progbits
4+
#endif
5+
16
.text
27
.code 32
38
.arm
@@ -19,4 +24,3 @@ __morestack:
1924
pop {r4, fp, lr}
2025
mov pc, lr
2126
.fnend
22-

src/rt/arch/arm/morestack.S

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Mark stack as non-executable
2+
#if defined(__linux__) && defined(__ELF__)
3+
.section .note.GNU-stack, "", @progbits
4+
#endif
5+
16
.text
27
.code 32
38
.arm

src/rt/arch/arm/record_sp.S

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Mark stack as non-executable
2+
#if defined(__linux__) && defined(__ELF__)
3+
.section .note.GNU-stack, "", @progbits
4+
#endif
5+
16
.text
27
.code 32
38
.arm
@@ -45,17 +50,17 @@ get_sp_limit:
4550
get_sp:
4651
mov r0, sp
4752
mov pc, lr
48-
53+
4954
.data
5055
my_cpu: .long 0
5156
.global my_array
52-
my_array:
57+
my_array:
58+
.long 0
5359
.long 0
5460
.long 0
5561
.long 0
5662
.long 0
5763
.long 0
5864
.long 0
5965
.long 0
60-
.long 0
6166
.end

src/rt/arch/i386/_context.S

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Mark stack as non-executable
2+
#if defined(__linux__) && defined(__ELF__)
3+
.section .note.GNU-stack, "", @progbits
4+
#endif
5+
16
.text
27

38
/*

src/rt/arch/i386/ccall.S

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Mark stack as non-executable
2+
#if defined(__linux__) && defined(__ELF__)
3+
.section .note.GNU-stack, "", @progbits
4+
#endif
5+
16
/*
27
The function for switching to the C stack. It is called
38
__morestack because gdb allows any frame with that name to

src/rt/arch/i386/morestack.S

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Mark stack as non-executable
2+
#if defined(__linux__) && defined(__ELF__)
3+
.section .note.GNU-stack, "", @progbits
4+
#endif
5+
16
/*
27
__morestack
38
@@ -218,11 +223,11 @@ MORESTACK:
218223
.L$bail:
219224
movl 32(%esp),%eax
220225
inc %eax
221-
226+
222227
addl $44, %esp
223228
popl %ebp
224229
addl $4+8,%esp
225-
230+
226231
jmpl *%eax
227232

228233
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__)
@@ -241,7 +246,7 @@ L_rust_get_task$stub:
241246
L_upcall_new_stack$stub:
242247
.indirect_symbol _upcall_new_stack
243248
.ascii "\364\364\364\364\364"
244-
249+
245250
L_upcall_del_stack$stub:
246251
.indirect_symbol _upcall_del_stack
247252
.ascii "\364\364\364\364\364"

src/rt/arch/i386/record_sp.S

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Mark stack as non-executable
2+
#if defined(__linux__) && defined(__ELF__)
3+
.section .note.GNU-stack, "", @progbits
4+
#endif

src/rt/arch/mips/_context.S

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Mark stack as non-executable
2+
#if defined(__linux__) && defined(__ELF__)
3+
.section .note.GNU-stack, "", @progbits
4+
#endif
5+
16
.text
27
.globl swap_registers
38
.align 2

src/rt/arch/mips/ccall.S

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Mark stack as non-executable
2+
#if defined(__linux__) && defined(__ELF__)
3+
.section .note.GNU-stack, "", @progbits
4+
#endif
5+
16
.text
27

38
.globl __morestack

src/rt/arch/mips/record_sp.S

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Mark stack as non-executable
2+
#if defined(__linux__) && defined(__ELF__)
3+
.section .note.GNU-stack, "", @progbits
4+
#endif
5+
16
.text
27

38
.globl record_sp_limit

src/rt/arch/x86_64/_context.S

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1+
// Mark stack as non-executable
2+
#if defined(__linux__) && defined(__ELF__)
3+
.section .note.GNU-stack, "", @progbits
4+
#endif
5+
16
#include "regs.h"
27
#define ARG0 RUSTRT_ARG0_S
38
#define ARG1 RUSTRT_ARG1_S
4-
9+
510
.text
611

712
/*
@@ -11,7 +16,7 @@ and Microsoft discussion at
1116
http://msdn.microsoft.com/en-US/library/9z1stfyw%28v=VS.80%29.aspx.
1217
1318
BOTH CALLING CONVENTIONS
14-
19+
1520
Callee save registers:
1621
R12--R15, RDI, RSI, RBX, RBP, RSP
1722
XMM0--XMM5
@@ -30,7 +35,7 @@ User flags have no specified role and are not preserved
3035
across calls, with the exception of DF in %rFLAGS,
3136
which must be clear (set to "forward" direction)
3237
on function entry and return.
33-
38+
3439
MICROSOFT CALLING CONVENTIONS
3540
3641
Return value: RAX
@@ -39,15 +44,15 @@ First four arguments:
3944
RCX, RDX, R8, R9
4045
XMM0, XMM1, XMM2, XMM3
4146
*/
42-
47+
4348
/*
4449
Stores current registers into arg0/RCX and restores
4550
registers found in arg1/RDX. This is used by our
4651
implementation of getcontext. Only saves/restores nonvolatile
4752
registers and the register used for the first argument.
4853
Volatile registers in general ought to be saved by the caller
4954
anyhow.
50-
*/
55+
*/
5156

5257
#if defined(__APPLE__) || defined(_WIN32)
5358
#define SWAP_REGISTERS _swap_registers

src/rt/arch/x86_64/ccall.S

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Mark stack as non-executable
2+
#if defined(__linux__) && defined(__ELF__)
3+
.section .note.GNU-stack, "", @progbits
4+
#endif
5+
16
/*
27
The function for switching to the C stack. It is called
38
__morestack because gdb allows any frame with that name to
@@ -10,7 +15,7 @@
1015
#define ARG0 RUSTRT_ARG0_S
1116
#define ARG1 RUSTRT_ARG1_S
1217
#define ARG2 RUSTRT_ARG2_S
13-
18+
1419
.text
1520

1621
#if defined(__APPLE__) || defined(_WIN32)

src/rt/arch/x86_64/morestack.S

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// Mark stack as non-executable
2+
#if defined(__linux__) && defined(__ELF__)
3+
.section .note.GNU-stack, "", @progbits
4+
#endif
5+
16
/*
27
__morestack
38
@@ -78,7 +83,7 @@ MORESTACK:
7883
movq %r11, %rdx // Size of stack arguments
7984
movq %rax, %rsi // Address of stack arguments
8085
movq %r10, %rdi // The amount of stack needed
81-
86+
8287
#ifdef __APPLE__
8388
call UPCALL_NEW_STACK
8489
#endif
@@ -132,7 +137,7 @@ MORESTACK:
132137
popq %rax // Restore the return value
133138
popq %rbp
134139
ret
135-
140+
136141
.cfi_endproc
137142

138143
#else

src/rt/arch/x86_64/record_sp.S

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Mark stack as non-executable
2+
#if defined(__linux__) && defined(__ELF__)
3+
.section .note.GNU-stack, "", @progbits
4+
#endif

0 commit comments

Comments
 (0)