Skip to content

Commit 6cc1bc2

Browse files
authored
Merge pull request #692 from Dirbaio/fix-text-align
rt: automatically align .text by default
2 parents 87d67dc + e1b7dd6 commit 6cc1bc2

3 files changed

Lines changed: 13 additions & 1 deletion

File tree

‎cortex-m-rt/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
- Align the default `_stext` to the alignment required by the `.text` section. Fixes
11+
the lld warning `address (...) of section .text is not a multiple of alignment (...)`.
12+
- Note: `_stext` is not auto-aligned if it's explicitly overridden by the user. It's their responsibility to align it, else the warning will show.
13+
1014
## [v0.7.6]
1115

1216
- Mark `pre_init` as deprecated

‎cortex-m-rt/link.x.in‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ SECTIONS
8989
KEEP(*(.vector_table.interrupts)); /* this is the `__INTERRUPTS` symbol */
9090
} > FLASH
9191

92-
PROVIDE(_stext = ADDR(.vector_table) + SIZEOF(.vector_table));
92+
/* The alignment of .text is the maximum alignment required by its input sections, which
93+
can be more than 4 (e.g. `.p2align` directives inside inline assembly). Since the
94+
start address of .text is set explicitly, the linker won't align it automatically, so do it
95+
here. */
96+
PROVIDE(_stext = ALIGN(ADDR(.vector_table) + SIZEOF(.vector_table), ALIGNOF(.text)));
9397

9498
/* ### .text */
9599
.text _stext :

‎cortex-m-rt/src/lib.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@
113113
//! _stext = ORIGIN(FLASH) + 0x40C;
114114
//! ```
115115
//!
116+
//! It is your responsibility to ensure `_stext` is aligned to what the `.text` section requires.
117+
//! This is typically 4 but can ocasionally be higher, such as when using `.p2align` directives inside ASM.
118+
//! If you fail to do so you will see a linker warning like `address (...) of section .text is not a multiple of alignment (...)`.
119+
//!
116120
//! # An example
117121
//!
118122
//! This section presents a minimal application built on top of `cortex-m-rt`. Apart from the

0 commit comments

Comments
 (0)