This repository was archived by the owner on Jan 24, 2022. It is now read-only.
This repository was archived by the owner on Jan 24, 2022. It is now read-only.
null dereference before main is called #21
Closed
Description
STR
#![feature(used)]
#![no_std]
extern crate cortex_m_rt;
fn main() {}
#[used]
#[link_section = ".rodata.interrupts"]
static INTERRUPTS: [u32; 240] = [0; 240];
with cortex-m-quickstart v0.1.8 and cortex-m-rt v0.2.4.
Produces:
08000400 <cortex_m_rt::reset_handler>:
8000400: b580 push {r7, lr}
8000402: 466f mov r7, sp
8000404: f240 0000 movw r0, #0
8000408: f240 0100 movw r1, #0
800040c: f2c2 0000 movt r0, #8192 ; 0x2000
8000410: f2c2 0100 movt r1, #8192 ; 0x2000
8000414: 1a09 subs r1, r1, r0
8000416: f021 0103 bic.w r1, r1, #3
800041a: f000 f851 bl 80004c0 <__aeabi_memclr4>
800041e: f240 0000 movw r0, #0
8000422: f240 0100 movw r1, #0
8000426: f2c2 0000 movt r0, #8192 ; 0x2000
800042a: f2c2 0100 movt r1, #8192 ; 0x2000
800042e: 1a09 subs r1, r1, r0
8000430: f021 0203 bic.w r2, r1, #3
8000434: f240 41d4 movw r1, #1236 ; 0x4d4
8000438: f6c0 0100 movt r1, #2048 ; 0x800
800043c: f000 f836 bl 80004ac <__aeabi_memcpy4>
8000440: f240 0000 movw r0, #0
8000444: f2c0 0000 movt r0, #0
8000448: 7800 ldrb r0, [r0, #0]
800044a: bf30 wfi
800044c: e7fd b.n 800044a <cortex_m_rt::reset_handler+0x4a>
In this case there's no main to execute but this:
8000440: f240 0000 movw r0, #0
8000444: f2c0 0000 movt r0, #0
8000448: 7800 ldrb r0, [r0, #0]
is loading the byte stored at address 0x0. This doesn't crash on Cortex-M devices because that's a valid address (the start of the vector table).
I'm not exactly sure why that's being generated but it doesn't appear if I remove the start lang_item from cortex-m-rt and directly call a the binary crate main function.
cc @pftbest do you see something like this on msp430?
Metadata
Metadata
Assignees
Labels
No labels