zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.54k stars 6.46k forks source link

Consider marking vector tables as `const` when CONFIG_DYNAMIC_INTERRUPTS=0 #17517

Open chrisc11 opened 5 years ago

chrisc11 commented 5 years ago

Is your enhancement proposal related to a problem? Please describe.

The elf section with the vector table gets marked as (W)ritable even if it's placed in FLASH, i.e

arm-none-eabi-readelf -S build/zephyr/zephyr.elf | grep text
  [ 1] text              PROGBITS        00000000 0000b4 000100 00 WAX  0   0  4

This happens because the vector tables created in gen_isr_tables.py are not defined with a const qualifier. If non-const data is placed in a read-only MEMORY section, the gnu linker will auto-promote the section to have the SHF_WRITE bit set.

While this does not cause any runtime issues, it does:

Describe the solution you'd like

I think sw_isr_table.h, isr_tables.c, & gen_isr_tables.py could simply be patched to add a const qualifier to _irq_vector_table & _sw_isr_table when the vector table is not dynamic

Additional context

Here's an example output of the west -v build -b nrf52840_pca10056 samples/basic/threads/ before/after a patch marking the sections as const was made:

Before:

arm-none-eabi-readelf -S build/zephyr/zephyr.elf | grep text
  [ 1] text              PROGBITS        00000000 0000b4 000100 00 WAX  0   0  4

arm-none-eabi-size build/zephyr/zephyr.elf
   text    data     bss     dec     hex filename
  22576     864    7453   30893    78ad build/zephyr/zephyr.elf

After:

# arm-none-eabi-size build/zephyr/zephyr.elf
   text    data     bss     dec     hex filename
  22960     480    7453   30893    78ad build/zephyr/zephyr.elf

arm-none-eabi-readelf -S build/zephyr/zephyr.elf | grep text
  [ 1] text              PROGBITS        00000000 0000b4 000100 00  AX  0   0  4

(NB: It also looks like the structs placed in .devconfig.init are also not marked as const but are placed in ROM. For similar reasons might be nice to mark those structures as const but that's probably outside the scope of this issue)

aescolar commented 5 years ago

CC @andrewboie @ioannisg

zephyrbot commented 7 months ago

Hi @nashif,

This issue, marked as an Enhancement, was opened a while ago and did not get any traction. It was just assigned to you based on the labels. If you don't consider yourself the right person to address this issue, please re-assing it to the right person.

Please take a moment to review if the issue is still relevant to the project. If it is, please provide feedback and direction on how to move forward. If it is not, has already been addressed, is a duplicate, or is no longer relevant, please close it with a short comment explaining the reason.

@chrisc11 you are also encouraged to help moving this issue forward by providing additional information and confirming this request/issue is still relevant to you.

Thanks!