rust-embedded/cortex-m

`__reset_vector` symbol placed incorrectly

jamesmunns opened this issue · 4 comments

link.x.in has this for placing the vector table members:

  .vector_table ORIGIN(FLASH) :
  {
    __vector_table = .;
 
    /* Initial Stack Pointer (SP) value. */
    LONG(_stack_start & 0xFFFFFFF8);
 
    /* Reset vector */
    KEEP(*(.vector_table.reset_vector));
    __reset_vector = .;

However when looking at the contents of the elf with nm, we see this at the start:

10000100 R __vector_table
10000104 00000004 R __RESET_VECTOR
10000108 00000038 R __EXCEPTIONS
10000108 R __reset_vector
10000140 00000080 R __INTERRUPTS

Here, __RESET_VECTOR is correctly placed at offset 4, but __reset_vector is placed at offset 8.

I tried adding an NMI (which should be at offset 8), and it was placed correctly, so I don't think there is any problem with layout, but the lowercase symbol is misleading.

Also this assert just looks wrong to me:

/* ## .vector_table */
ASSERT(__reset_vector == ADDR(.vector_table) + 0x8, "
BUG(cortex-m-rt): the reset vector is missing");

The vector table should be:

  • 0x0: Stack Pointer
  • 0x4: Reset Vector
  • 0x8: NMI Vector
  • ...

Tested with

active toolchain
----------------

nightly-2023-08-19-aarch64-apple-darwin
rustc 1.73.0-nightly (d06ca0ffa 2023-08-18)
[[package]]
name = "cortex-m-rt"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee84e813d593101b1723e13ec38b6ab6abbdbaaa4546553f5395ed274079ddb1"
dependencies = [
 "cortex-m-rt-macros",
]

Suggestion from @Dirbaio: we could rename this as __exceptions since this symbol actually tracks the start of exceptions (immediately after the reset vector)

AFAICT this symbol is just used as a check (in the assert) that the reset vector (and perhaps the vector table itself) exists.

Suggested names:

  • __ereset_vector
  • __reset_vector_end
  • __exceptions

General consensus from discussion:

  • Yes, probably fine to make this change
  • Prefer rename over remove
  • Probably fine to go in the 0.7.x train