Skip to content

Commit 23704a8

Browse files
committed
fix stack corruptions in startup routine
1 parent 08998e9 commit 23704a8

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

compiler/rustc_target/src/spec/targets/armv7a_vex_v5_linker_script.ld

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,7 @@ MEMORY {
1111
}
1212

1313
__stack_length = 0x400000;
14-
/*
15-
It's currently unclear why subtracting anything is necessary, but it fixes memory permission errors.
16-
0x100 is an arbitrary number that works.
17-
*/
18-
__heap_end = __user_ram_end - __stack_length - 0x100;
14+
__heap_end = __user_ram_end - __stack_length;
1915

2016
SECTIONS {
2117
.text : {
@@ -55,4 +51,4 @@ SECTIONS {
5551
/DISCARD/ : {
5652
*(.ARM.exidx)
5753
}
58-
}
54+
}

library/std/src/sys/pal/vexos/mod.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,24 @@ pub mod stdio;
1818
pub mod thread;
1919
pub mod time;
2020

21-
use crate::arch::asm;
21+
use crate::arch::global_asm;
2222
use crate::hash::{DefaultHasher, Hasher};
2323
use crate::ptr::{self, addr_of_mut};
2424
use crate::time::{Duration, Instant};
2525

26+
global_asm!(
27+
r#"
28+
.section .boot, "ax"
29+
.global _boot
30+
31+
_boot:
32+
ldr sp, =__stack_top @ Set up the user stack.
33+
b _start @ Jump to the Rust entrypoint.
34+
"#
35+
);
36+
2637
#[cfg(not(test))]
2738
#[no_mangle]
28-
#[link_section = ".boot"]
2939
pub unsafe extern "C" fn _start() -> ! {
3040
extern "C" {
3141
static mut __bss_start: u8;
@@ -34,9 +44,6 @@ pub unsafe extern "C" fn _start() -> ! {
3444
fn main() -> i32;
3545
}
3646

37-
// Setup the stack
38-
asm!("ldr sp, =__stack_top", options(nostack));
39-
4047
// VEXos doesn't explicitly clean out .bss.
4148
ptr::slice_from_raw_parts_mut(
4249
addr_of_mut!(__bss_start),

0 commit comments

Comments
 (0)