aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--src/host/imxrt-link.x72
-rw-r--r--src/target.rs2
-rw-r--r--tests/inspect_elf.rs96
4 files changed, 94 insertions, 78 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 49b1683..4bdd956 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,6 +22,8 @@ Add a `.bootrom_reservation` section in OCRAM. If you need to reserve this
OCRAM allocation, you may allocate your own `MaybeUninit` buffer sized for
your boot ROM's requirements.
+All sections now have a 8 byte alignment minimum.
+
### FlexRAM bank layouts
The runtime builder lets users specify the _layout_, or assignment, of FlexRAM
diff --git a/src/host/imxrt-link.x b/src/host/imxrt-link.x
index f07601b..c04e3d4 100644
--- a/src/host/imxrt-link.x
+++ b/src/host/imxrt-link.x
@@ -54,6 +54,7 @@ SECTIONS
.vector_table : ALIGN(1024)
{
FILL(0xff);
+ . = ALIGN(8);
__vector_table = .;
__svector_table = .;
@@ -70,12 +71,14 @@ SECTIONS
/* Device specific interrupts */
KEEP(*(.vector_table.interrupts)); /* this is the `__INTERRUPTS` symbol */
+
+ . = ALIGN(8);
__evector_table = .;
} > REGION_VTABLE AT> REGION_LOAD_VTABLE
__sivector_table = LOADADDR(.vector_table);
/* This section guarantees VMA = LMA to allow the execute-in-place entry point to be inside the image. */
- .xip : ALIGN(4)
+ .xip : ALIGN(8)
{
/* Included here if not otherwise included in the boot header. */
*(.Reset);
@@ -83,7 +86,7 @@ SECTIONS
*(.xip .xip.*);
} > REGION_LOAD_TEXT
- .text : ALIGN(4)
+ .text : ALIGN(8)
{
FILL(0xff);
__stext = .;
@@ -92,60 +95,56 @@ SECTIONS
so must be placed close to it. */
*(.HardFaultTrampoline);
*(.HardFault.*);
- . = ALIGN(4); /* Pad .text to the alignment to workaround overlapping load section bug in old lld */
+ . = ALIGN(8);
__etext = .;
} > REGION_TEXT AT> REGION_LOAD_TEXT
__sitext = LOADADDR(.text);
- .rodata : ALIGN(4)
+ .rodata : ALIGN(8)
{
FILL(0xff);
- . = ALIGN(4);
+ . = ALIGN(8);
__srodata = .;
*(.rodata .rodata.*);
-
- /* 4-byte align the end (VMA) of this section.
- This is required by LLD to ensure the LMA of the following .data
- section will have the correct alignment. */
- . = ALIGN(4);
+ . = ALIGN(8);
__erodata = .;
} > REGION_RODATA AT> REGION_LOAD_RODATA
__sirodata = LOADADDR(.rodata);
- .data : ALIGN(4)
+ .data : ALIGN(8)
{
FILL(0xff);
- . = ALIGN(4);
+ . = ALIGN(8);
__sdata = .;
*(.data .data.*);
- . = ALIGN(4); /* 4-byte align the end (VMA) of this section */
+ . = ALIGN(8);
__edata = .;
} > REGION_DATA AT> REGION_LOAD_DATA
__sidata = LOADADDR(.data);
- .bss (NOLOAD) : ALIGN(4)
+ .bss (NOLOAD) : ALIGN(8)
{
- . = ALIGN(4);
+ . = ALIGN(8);
__sbss = .;
*(.bss .bss.*);
*(COMMON); /* Uninitialized C statics */
- . = ALIGN(4); /* 4-byte align the end (VMA) of this section */
+ . = ALIGN(8);
__ebss = .;
} > REGION_BSS
- .uninit (NOLOAD) : ALIGN(4)
+ .uninit (NOLOAD) : ALIGN(8)
{
- . = ALIGN(4);
+ . = ALIGN(8);
__suninit = .;
*(.uninit .uninit.*);
- . = ALIGN(4);
+ . = ALIGN(8);
__euninit = .;
} > REGION_UNINIT
- .heap (NOLOAD) : ALIGN(4)
+ .heap (NOLOAD) : ALIGN(8)
{
__sheap = .;
- . += ALIGN(__heap_size, 4);
+ . += ALIGN(__heap_size, 8);
__eheap = .;
} > REGION_HEAP
@@ -171,17 +170,32 @@ SECTIONS
ASSERT(__sstack % 8 == 0 && __estack % 8 == 0, "
BUG(imxrt-rt): .stack is not 8-byte aligned");
-ASSERT(__sdata % 4 == 0 && __edata % 4 == 0, "
-BUG(imxrt-rt): .data is not 4-byte aligned");
+ASSERT(__stext % 8 == 0 && __etext % 8 == 0, "
+BUG(imxrt-rt): .text is not 8-byte aligned");
+
+ASSERT(__sitext % 8 == 0, "
+BUG(imxrt-rt): the LMA of .text is not 8-byte aligned");
+
+ASSERT(__srodata % 8 == 0 && __erodata % 8 == 0, "
+BUG(imxrt-rt): .rodata is not 8-byte aligned");
+
+ASSERT(__sirodata % 8 == 0, "
+BUG(imxrt-rt): the LMA of .rodata is not 8-byte aligned");
+
+ASSERT(__sdata % 8 == 0 && __edata % 8 == 0, "
+BUG(imxrt-rt): .data is not 8-byte aligned");
+
+ASSERT(__sidata % 8 == 0, "
+BUG(imxrt-rt): the LMA of .data is not 8-byte aligned");
-ASSERT(__sidata % 4 == 0, "
-BUG(imxrt-rt): the LMA of .data is not 4-byte aligned");
+ASSERT(__sbss % 8 == 0 && __ebss % 8 == 0, "
+BUG(imxrt-rt): .bss is not 8-byte aligned");
-ASSERT(__sbss % 4 == 0 && __ebss % 4 == 0, "
-BUG(imxrt-rt): .bss is not 4-byte aligned");
+ASSERT(__suninit % 8 == 0 && __euninit % 8 == 0, "
+BUG(imxrt-rt): .uninit is not 8-byte aligned");
-ASSERT(__sheap % 4 == 0, "
-BUG(imxrt-rt): start of .heap is not 4-byte aligned");
+ASSERT(__sheap % 8 == 0 && __eheap % 8 == 0, "
+BUG(imxrt-rt): .heap is not 8-byte aligned");
/* # Position checks */
diff --git a/src/target.rs b/src/target.rs
index 4515934..bfe6e7e 100644
--- a/src/target.rs
+++ b/src/target.rs
@@ -159,7 +159,7 @@ __pre_init:
/// Returns a pointer to the end of the heap.
///
-/// The returned pointer is guaranteed to be 4-byte aligned.
+/// The returned pointer is guaranteed to be 8-byte aligned.
#[inline]
pub fn heap_end() -> *mut u32 {
unsafe extern "C" {
diff --git a/tests/inspect_elf.rs b/tests/inspect_elf.rs
index d3c5ae1..177bf50 100644
--- a/tests/inspect_elf.rs
+++ b/tests/inspect_elf.rs
@@ -313,14 +313,14 @@ fn imxrt1010evk() {
assert_eq!(text.address, ITCM, "text");
assert_eq!(
binary.section_lma(".text"),
- aligned(0x6000_2000 + vector_table.size + xip.size, 4),
+ aligned(0x6000_2000 + vector_table.size + xip.size, 8),
"text VMA expected behind vector table"
);
let rodata = binary.section(".rodata").unwrap();
assert_eq!(
rodata.address,
- aligned(0x6000_2000 + vector_table.size + text.size + xip.size, 4),
+ aligned(0x6000_2000 + vector_table.size + text.size + xip.size, 8),
"rodata LMA & VMA expected behind text"
);
assert_eq!(rodata.address, binary.section_lma(".rodata"));
@@ -328,19 +328,19 @@ fn imxrt1010evk() {
let data = binary.section(".data").unwrap();
assert_eq!(data.address, 0x2020_0000, "data VMA in OCRAM");
assert_eq!(
- data.size, 4,
- "blink-rtic expected to have a single static mut u32"
+ data.size, 8,
+ "blink-rtic expected to have a single static mut u32, padded to 8 bytes"
);
assert_eq!(
binary.section_lma(".data"),
- rodata.address + aligned(rodata.size, 4),
+ rodata.address + aligned(rodata.size, 8),
"data LMA starts behind rodata"
);
let bss = binary.section(".bss").unwrap();
assert_eq!(
bss.address,
- data.address + aligned(data.size, 4),
+ data.address + aligned(data.size, 8),
"bss in OCRAM behind data"
);
assert_eq!(binary.section_lma(".bss"), bss.address, "bss is NOLOAD");
@@ -348,7 +348,7 @@ fn imxrt1010evk() {
let uninit = binary.section(".uninit").unwrap();
assert_eq!(
uninit.address,
- bss.address + aligned(bss.size, 4),
+ bss.address + aligned(bss.size, 8),
"uninit in OCRAM behind bss"
);
assert_eq!(
@@ -425,10 +425,10 @@ fn imxrt1010evk_ram() {
let xip = binary.section(".xip").unwrap();
let text = binary.section(".text").unwrap();
- assert_eq!(text.address, aligned(ITCM + xip.size, 4), "text");
+ assert_eq!(text.address, aligned(ITCM + xip.size, 8), "text");
assert_eq!(
binary.section_lma(".text"),
- aligned(ITCM + xip.size, 4),
+ aligned(ITCM + xip.size, 8),
"text LMA == VMA for RAM boot"
);
@@ -443,23 +443,23 @@ fn imxrt1010evk_ram() {
let data = binary.section(".data").unwrap();
assert_eq!(
data.address,
- rodata.address + aligned(rodata.size, 4),
+ rodata.address + aligned(rodata.size, 8),
"data VMA in OCRAM behind rodata"
);
assert_eq!(
- data.size, 4,
- "blink-rtic expected to have a single static mut u32"
+ data.size, 8,
+ "blink-rtic expected to have a single static mut u32, padded to 8 bytes"
);
assert_eq!(
binary.section_lma(".data"),
- rodata.address + aligned(rodata.size, 4),
+ rodata.address + aligned(rodata.size, 8),
"data LMA == VMA for RAM boot"
);
let bss = binary.section(".bss").unwrap();
assert_eq!(
bss.address,
- data.address + aligned(data.size, 4),
+ data.address + aligned(data.size, 8),
"bss in OCRAM behind data"
);
assert_eq!(binary.section_lma(".bss"), bss.address, "bss is NOLOAD");
@@ -467,7 +467,7 @@ fn imxrt1010evk_ram() {
let uninit = binary.section(".uninit").unwrap();
assert_eq!(
uninit.address,
- bss.address + aligned(bss.size, 4),
+ bss.address + aligned(bss.size, 8),
"uninit in OCRAM behind bss"
);
assert_eq!(
@@ -554,12 +554,12 @@ fn baseline_teensy4(
let text = binary.section(".text").unwrap();
let expected_text_address = aligned(
binary.section_lma(".vector_table") + vector_table.size + xip.size,
- 4,
+ 8,
);
assert_eq!(text.address, expected_text_address, "text");
assert_eq!(
binary.section_lma(".text"),
- aligned(0x6000_2000 + vector_table.size + xip.size, 4),
+ aligned(0x6000_2000 + vector_table.size + xip.size, 8),
"text VMA expected behind vector table"
);
@@ -569,7 +569,7 @@ fn baseline_teensy4(
vector_table.address + vector_table.size,
"rodata LMA & VMA expected behind text"
);
- assert!(binary.section_lma(".rodata") >= binary.section_lma(".text") + aligned(text.size, 4));
+ assert!(binary.section_lma(".rodata") >= binary.section_lma(".text") + aligned(text.size, 8));
let data = binary.section(".data").unwrap();
assert_eq!(
@@ -578,19 +578,19 @@ fn baseline_teensy4(
"data VMA in DTCM behind rodata"
);
assert_eq!(
- data.size, 4,
- "blink-rtic expected to have a single static mut u32"
+ data.size, 8,
+ "blink-rtic expected to have a single static mut u32, padded to 8 bytes"
);
assert_eq!(
binary.section_lma(".data"),
- binary.section_lma(".rodata") + aligned(rodata.size, 4),
+ binary.section_lma(".rodata") + aligned(rodata.size, 8),
"data LMA starts behind rodata"
);
let bss = binary.section(".bss").unwrap();
assert_eq!(
bss.address,
- data.address + aligned(data.size, 4),
+ data.address + aligned(data.size, 8),
"bss in DTCM behind data"
);
assert_eq!(binary.section_lma(".bss"), bss.address, "bss is NOLOAD");
@@ -598,7 +598,7 @@ fn baseline_teensy4(
let uninit = binary.section(".uninit").unwrap();
assert_eq!(
uninit.address,
- bss.address + aligned(bss.size, 4),
+ bss.address + aligned(bss.size, 8),
"uninit in DTCM behind bss"
);
assert_eq!(
@@ -610,7 +610,7 @@ fn baseline_teensy4(
let heap = binary.section(".heap").unwrap();
assert_eq!(
Section {
- address: uninit.address + aligned(uninit.size, 4),
+ address: uninit.address + aligned(uninit.size, 8),
size: heap_size
},
heap,
@@ -801,7 +801,7 @@ fn imxrt1170evk_cm7() {
assert_eq!(text.address, ITCM, "text");
assert_eq!(
binary.section_lma(".text"),
- aligned(0x3000_2000 + vector_table.size + xip.size, 4),
+ aligned(0x3000_2000 + vector_table.size + xip.size, 8),
"text VMA expected behind vector table"
);
@@ -812,25 +812,25 @@ fn imxrt1170evk_cm7() {
"rodata moved to DTCM behind vector table"
);
assert!(
- binary.section_lma(".rodata") >= 0x3000_2000 + vector_table.size + aligned(text.size, 4),
+ binary.section_lma(".rodata") >= 0x3000_2000 + vector_table.size + aligned(text.size, 8),
);
let data = binary.section(".data").unwrap();
assert_eq!(data.address, 0x2024_0000, "data VMA in OCRAM");
assert_eq!(
- data.size, 4,
- "blink-rtic expected to have a single static mut u32"
+ data.size, 8,
+ "blink-rtic expected to have a single static mut u32, padded to 8 bytes"
);
assert_eq!(
binary.section_lma(".data"),
- binary.section_lma(".rodata") + aligned(rodata.size, 4),
+ binary.section_lma(".rodata") + aligned(rodata.size, 8),
"data LMA starts behind rodata"
);
let bss = binary.section(".bss").unwrap();
assert_eq!(
bss.address,
- data.address + aligned(data.size, 4),
+ data.address + aligned(data.size, 8),
"bss in OCRAM behind data"
);
assert_eq!(binary.section_lma(".bss"), bss.address, "bss is NOLOAD");
@@ -838,7 +838,7 @@ fn imxrt1170evk_cm7() {
let uninit = binary.section(".uninit").unwrap();
assert_eq!(
uninit.address,
- bss.address + aligned(bss.size, 4),
+ bss.address + aligned(bss.size, 8),
"uninit in OCRAM behind bss"
);
assert_eq!(
@@ -850,7 +850,7 @@ fn imxrt1170evk_cm7() {
let heap = binary.section(".heap").unwrap();
assert_eq!(
Section {
- address: rodata.address + aligned(rodata.size, 4),
+ address: rodata.address + aligned(rodata.size, 8),
size: 0,
},
heap,
@@ -943,7 +943,7 @@ fn imxrt1170evk_cm7_nonboot() {
assert_eq!(text.address, ITCM, "text");
assert_eq!(
binary.section_lma(".text"),
- 0x3000_0000 + IMAGE_OFFSET + aligned(xip.size, 4) + vector_table.size,
+ 0x3000_0000 + IMAGE_OFFSET + aligned(xip.size, 8) + vector_table.size,
"text VMA expected behind vector table"
);
@@ -954,25 +954,25 @@ fn imxrt1170evk_cm7_nonboot() {
"rodata moved to DTCM behind vector table"
);
assert!(
- binary.section_lma(".rodata") >= 0x3000_2000 + vector_table.size + aligned(text.size, 4),
+ binary.section_lma(".rodata") >= 0x3000_2000 + vector_table.size + aligned(text.size, 8),
);
let data = binary.section(".data").unwrap();
assert_eq!(data.address, 0x2024_0000, "data VMA in OCRAM");
assert_eq!(
- data.size, 4,
- "blink-rtic expected to have a single static mut u32"
+ data.size, 8,
+ "blink-rtic expected to have a single static mut u32, padded to 8 bytes"
);
assert_eq!(
binary.section_lma(".data"),
- binary.section_lma(".rodata") + aligned(rodata.size, 4),
+ binary.section_lma(".rodata") + aligned(rodata.size, 8),
"data LMA starts behind rodata"
);
let bss = binary.section(".bss").unwrap();
assert_eq!(
bss.address,
- data.address + aligned(data.size, 4),
+ data.address + aligned(data.size, 8),
"bss in OCRAM behind data"
);
assert_eq!(binary.section_lma(".bss"), bss.address, "bss is NOLOAD");
@@ -980,7 +980,7 @@ fn imxrt1170evk_cm7_nonboot() {
let uninit = binary.section(".uninit").unwrap();
assert_eq!(
uninit.address,
- bss.address + aligned(bss.size, 4),
+ bss.address + aligned(bss.size, 8),
"uninit in OCRAM behind bss"
);
assert_eq!(
@@ -992,7 +992,7 @@ fn imxrt1170evk_cm7_nonboot() {
let heap = binary.section(".heap").unwrap();
assert_eq!(
Section {
- address: rodata.address + aligned(rodata.size, 4),
+ address: rodata.address + aligned(rodata.size, 8),
size: 0,
},
heap,
@@ -1075,7 +1075,7 @@ fn imxrt1170evk_cm7_secondary() {
assert_eq!(text.address, ITCM, "text");
assert_eq!(
binary.section_lma(".text"),
- aligned(0x3000_2000 + IMAGE_OFFSET + vector_table.size + xip.size, 4),
+ aligned(0x3000_2000 + IMAGE_OFFSET + vector_table.size + xip.size, 8),
"text VMA expected behind vector table"
);
@@ -1087,25 +1087,25 @@ fn imxrt1170evk_cm7_secondary() {
);
assert!(
binary.section_lma(".rodata")
- >= 0x3000_2000 + IMAGE_OFFSET + vector_table.size + aligned(text.size, 4),
+ >= 0x3000_2000 + IMAGE_OFFSET + vector_table.size + aligned(text.size, 8),
);
let data = binary.section(".data").unwrap();
assert_eq!(data.address, 0x2024_0000, "data VMA in OCRAM");
assert_eq!(
- data.size, 4,
- "blink-rtic expected to have a single static mut u32"
+ data.size, 8,
+ "blink-rtic expected to have a single static mut u32, padded to 8 bytes"
);
assert_eq!(
binary.section_lma(".data"),
- binary.section_lma(".rodata") + aligned(rodata.size, 4),
+ binary.section_lma(".rodata") + aligned(rodata.size, 8),
"data LMA starts behind rodata"
);
let bss = binary.section(".bss").unwrap();
assert_eq!(
bss.address,
- data.address + aligned(data.size, 4),
+ data.address + aligned(data.size, 8),
"bss in OCRAM behind data"
);
assert_eq!(binary.section_lma(".bss"), bss.address, "bss is NOLOAD");
@@ -1113,7 +1113,7 @@ fn imxrt1170evk_cm7_secondary() {
let uninit = binary.section(".uninit").unwrap();
assert_eq!(
uninit.address,
- bss.address + aligned(bss.size, 4),
+ bss.address + aligned(bss.size, 8),
"uninit in OCRAM behind bss"
);
assert_eq!(
@@ -1125,7 +1125,7 @@ fn imxrt1170evk_cm7_secondary() {
let heap = binary.section(".heap").unwrap();
assert_eq!(
Section {
- address: rodata.address + aligned(rodata.size, 4),
+ address: rodata.address + aligned(rodata.size, 8),
size: 0,
},
heap,