From 4974bc01370d779ad67c082491d4ceecb47b20b8 Mon Sep 17 00:00:00 2001 From: Laurentiu Mihalcea Date: Mon, 23 Oct 2023 18:48:50 +0300 Subject: [PATCH] linker: common-rom: Keep z_shared_isr regardless of dynamic interrupts Currently, the z_shared_isr symbol is only kept if CONFIG_DYNAMIC_INTERRUPTS=n. Whenever CONFG_DYNAMIC_INTERRUPTS is set to 'y', said symbol gets dropped when zephyr_pre0.elf is created. This is wrong because dropping/keeping z_shared_isr shouldn't be influenced by enabling/disabling support for the dynamic interrupts. This commit fixes the aforementioned issue by removing the dependency on CONFIG_DYNAMIC_INTERRUPTS. Signed-off-by: Laurentiu Mihalcea --- .../common-rom/common-rom-kernel-devices.ld | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/include/zephyr/linker/common-rom/common-rom-kernel-devices.ld b/include/zephyr/linker/common-rom/common-rom-kernel-devices.ld index 8adcaf5b1fb6a2..cd5c610d3f6ab8 100644 --- a/include/zephyr/linker/common-rom/common-rom-kernel-devices.ld +++ b/include/zephyr/linker/common-rom/common-rom-kernel-devices.ld @@ -22,6 +22,26 @@ ITERABLE_SECTION_ROM_NUMERIC(device, 4) +#if defined(CONFIG_GEN_SW_ISR_TABLE) && defined(CONFIG_SHARED_INTERRUPTS) + /* since z_shared_isr() is not referenced anywhere when + * zephyr_pre0.elf is built, the linker will end up dropping it. + * Later on, during the second linking stage (when zephyr.elf is + * built), the symbol will be added to the text section since it's + * now being referenced (thanks to isr_tables.c). This is very + * problematic because adding the z_shared_isr symbol between + * the linking stages will end up shifting the addresses of the + * functions, which, in turn, will end up messing the ISR table + * (as the entries from _sw_isr_table will end up pointing to + * old addresses of the registered ISRs). To prevent this from + * happening, instruct the linker to avoid dropping z_shared_isr + * if it's not being referenced anywhere. + */ + SECTION_PROLOGUE(.text.z_shared_isr,,) + { + KEEP(*(.text.z_shared_isr)) + } GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) +#endif + #if defined(CONFIG_GEN_SW_ISR_TABLE) && !defined(CONFIG_DYNAMIC_INTERRUPTS) SECTION_PROLOGUE(sw_isr_table,,) { @@ -40,11 +60,6 @@ /* TODO: does this section require alignment? */ KEEP(*(_SHARED_SW_ISR_TABLE_SECTION_SYMS)) } GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) - - SECTION_PROLOGUE(.text.z_shared_isr,,) - { - KEEP(*(.text.z_shared_isr)) - } GROUP_ROM_LINK_IN(RAMABLE_REGION, ROMABLE_REGION) #endif #endif