Skip to content

SW ISR table gets mangled when enabling SHARED_INTERRUPTS #64110

@davedesro

Description

@davedesro

Describe the bug

tl;dr zephyr_pre0.elf does not have z_shared_isr() in its image, but should. See bottom for my work-around. Does the linker need modification?

When enabling the new shared interrupts feature (Great feature!! long overdue!! thank you!!) in v3.5.0-rc3, The interrupt pointers set in build/zephyr/isr_tables.c (generated by gen_isr_tables.py) are wrong.

After a bit of objdump'ing, I found that the linker for build/zephyr/zephyr_pre0.elf removes z_shared_isr() function since it's not used (due to a combo of -ffunction-sections at compile time, and -Wl,--gc-sections at link time). It's not used because zephyr_pre0.elf does not have isr_tables.c in it.

... however, build/zephyr/zephyr.elf does have build/zephyr/isr_tables.c, so z_shared_isr() is part of the final image.

This causes a shift of all ISR addresses when comparing zephyr_pre0.elf to zephyr.elf. When loaded, hang is bound to happen on the first couple of interrupts.

To Reproduce

Using the environment below,

  1. set CONFIG_SHARED_INTERRUPTS=y and CONFIG_ADC_STM32_SHARED_IRQ=n
  2. On NUCLEO_G474RE, enable &adc1 and &adc2 to exercise the new feature.
  3. flash it. You should see a hang pretty quickly.. likely on the first interrupt.

Impact

Without a fix, the feature is not usable at least with the setup below.

Environment (please complete the following information):**

  • Hardware: NUCLEO_G474RE
  • SDK: 0.16.3
  • Relevent config: CONFIG_SHARED_INTERRUPTS=y
  • Zephyr tag v3.5.0-rc3
  • Fedora Linux OS

Additional context

I'm working around this issue by modifying the linker.

Modify the linker to keep z_shared_isr() no matter what

> cat app/shared_irq.ld                                                                                                                       
SECTION_PROLOGUE(.text.z_shared_isr,,)                                                                                                                                                                                                  
{
    KEEP(*(.text.z_shared_isr))
} GROUP_ROM_LINK_IN(0, FLASH)

Add new .ld file to the build

> git diff app/CMakeLists.txt
diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt
index 38c15f6..0196245 100644
--- a/app/CMakeLists.txt
+++ b/app/CMakeLists.txt
@@ -9,3 +9,6 @@ add_dependencies(app app_version)

 add_subdirectory(src)
 add_subdirectory_ifdef(CONFIG_SHELL src/cli)
+
+zephyr_linker_sources(SECTIONS shared_irq.ld)
+

@LaurentiuM1234 @carlescufi

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions