From 00d8870a50effde1e631f953bef3930afa59c019 Mon Sep 17 00:00:00 2001 From: Noah Pendleton Date: Sun, 10 Sep 2023 19:33:11 -0400 Subject: [PATCH] debug: Set thread_info.c variables to const MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The variables are usually placed into an output region located in FLASH memory when linking, but the variables are not marked `const`, so the section ends up with `W` writeable section flag: ```bash ❯ arm-zephyr-eabi-readelf --section-headers build/zephyr/zephyr.elf | \ grep -E '(Section Headers:)|( \[Nr\])|(zephyr_dbg_info)' Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [10] zephyr_dbg_info PROGBITS 60012298 01238c 000040 00 WA 0 0 4 ``` Set them as const to set the output section to read-only: ```bash ❯ arm-zephyr-eabi-readelf --section-headers build/zephyr/zephyr.elf | \ grep -E '(Section Headers:)|( \[Nr\])|(zephyr_dbg_info)' Section Headers: [Nr] Name Type Addr Off Size ES Flg Lk Inf Al [10] zephyr_dbg_info PROGBITS 60012298 01238c 000040 00 A 0 0 4 ``` Signed-off-by: Noah Pendleton --- subsys/debug/thread_info.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/subsys/debug/thread_info.c b/subsys/debug/thread_info.c index dde7d1d2a20..742cbd59485 100644 --- a/subsys/debug/thread_info.c +++ b/subsys/debug/thread_info.c @@ -40,7 +40,7 @@ enum { * Only version 1 is backward compatible to version 0. */ __attribute__((used, section(".dbg_thread_info"))) -size_t _kernel_thread_info_offsets[] = { +const size_t _kernel_thread_info_offsets[] = { /* Version 0 starts */ [THREAD_INFO_OFFSET_VERSION] = 1, [THREAD_INFO_OFFSET_K_CURR_THREAD] = offsetof(struct _cpu, current), @@ -146,15 +146,15 @@ size_t _kernel_thread_info_offsets[] = { #endif /* CONFIG_ARC */ }; -extern size_t __attribute__((alias("_kernel_thread_info_offsets"))) +extern const size_t __attribute__((alias("_kernel_thread_info_offsets"))) _kernel_openocd_offsets; __attribute__((used, section(".dbg_thread_info"))) -size_t _kernel_thread_info_num_offsets = ARRAY_SIZE(_kernel_thread_info_offsets); -extern size_t __attribute__((alias("_kernel_thread_info_num_offsets"))) +const size_t _kernel_thread_info_num_offsets = ARRAY_SIZE(_kernel_thread_info_offsets); +extern const size_t __attribute__((alias("_kernel_thread_info_num_offsets"))) _kernel_openocd_num_offsets; __attribute__((used, section(".dbg_thread_info"))) -uint8_t _kernel_thread_info_size_t_size = (uint8_t)sizeof(size_t); -extern uint8_t __attribute__((alias("_kernel_thread_info_size_t_size"))) +const uint8_t _kernel_thread_info_size_t_size = (uint8_t)sizeof(size_t); +extern const uint8_t __attribute__((alias("_kernel_thread_info_size_t_size"))) _kernel_openocd_size_t_size;