arm: cortex_m: add vector table padding for null pointer detection

Padding inserted after the (first-stage) vector table,
so that the Zephyr image does not attempt to use the
area which we reserve to detect null pointer dereferencing
(0x0 - <size>). If the end of the vector table section is
higher than the upper end of the reserved area, no padding
 will be added. Note also that the padding will be added
only once, to the first stage vector table, even if the current
snipped is included multiple times (this is for a corner case,
when we want to use this feature together with SW Vector Relaying
on MCUs without VTOR but with an MPU present).

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
This commit is contained in:
Ioannis Glaropoulos 2021-01-21 11:44:10 +01:00 committed by Carles Cufí
parent 0bac92db96
commit 66ef96fded
3 changed files with 25 additions and 0 deletions

View file

@ -30,3 +30,5 @@
KEEP(*(.vector_relay_table))
KEEP(*(".vector_relay_table.*"))
#include "vector_table_pad.ld"

View file

@ -0,0 +1,21 @@
/*
* Copyright (c) 2019 - 2021 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
/*
* Padding inserted after the (first-stage) vector table, so that the
* Zephyr image does not attempt to use the area which we reserve to
* detect null pointer dereferencing (0x0 - <size>). If the end of the
* vector table section is higher than the upper end of the reserved
* area, we add no padding.
*
* Note that even if the following linker script snippet is included
* multiple times, the padding will only be added at most once, to the
* first stage vector table.
*/
#if defined(CONFIG_CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION)
. = MAX(ABSOLUTE(.), CONFIG_CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION_PAGE_SIZE);
#endif /* CONFIG_CORTEX_M_DEBUG_NULL_POINTER_EXCEPTION */

View file

@ -40,3 +40,5 @@ _vector_end = .;
KEEP(*(.openocd_dbg))
KEEP(*(".openocd_dbg.*"))
#include "cortex_m/vector_table_pad.ld"