File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
7
7
8
8
## [ Unreleased]
9
9
10
+ - A linker error is generated if the initial stack pointer is not 8-byte aligned
11
+ - The initial stack pointer is now forced to be 8-byte aligned in the linker script,
12
+ to defend against it being overridden outside of the cortex-m-rt linker script
13
+
10
14
## [ v0.7.2]
11
15
12
16
- MSRV is now Rust 1.59.
Original file line number Diff line number Diff line change @@ -68,8 +68,12 @@ SECTIONS
68
68
{
69
69
__vector_table = .;
70
70
71
- /* Initial Stack Pointer (SP) value */
72
- LONG(_stack_start);
71
+ /* Initial Stack Pointer (SP) value.
72
+ * We mask the bottom three bits to force 8-byte alignment.
73
+ * Despite having an assert for this later, it's possible that a separate
74
+ * linker script could override _stack_start after the assert is checked.
75
+ */
76
+ LONG(_stack_start & 0xFFFFFFF8);
73
77
74
78
/* Reset vector */
75
79
KEEP(*(.vector_table.reset_vector)); /* this is the `__RESET_VECTOR` symbol */
Original file line number Diff line number Diff line change 56
56
//!
57
57
//! This optional symbol can be used to indicate where the call stack of the program should be
58
58
//! placed. If this symbol is not used then the stack will be placed at the *end* of the `RAM`
59
- //! region -- the stack grows downwards towards smaller address. This symbol can be used to place
60
- //! the stack in a different memory region, for example:
59
+ //! region -- the stack grows downwards towards smaller address.
60
+ //!
61
+ //! For Cortex-M, the `_stack_start` must always be aligned to 8 bytes, which is enforced by
62
+ //! the linker script. If you override it, ensure that whatever value you set is a multiple
63
+ //! of 8 bytes.
64
+ //!
65
+ //! This symbol can be used to place the stack in a different memory region, for example:
61
66
//!
62
67
//! ```text
63
68
//! /* Linker script for the STM32F303VCT6 */
You can’t perform that action at this time.
0 commit comments