From 66af40fa01b965be096bfc63489af2bb57f9a4d9 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 1 Oct 2025 15:22:40 +0200 Subject: [PATCH 1/2] variants/_ldscripts: Fix static thread data alignment. The _static_thread_data struct contains int64_t members that require 8-byte alignment. When placed in a 4-byte aligned section, it causes the linker to insert padding, which in turn causes __static_thread_data_list_start to point to the padding not to the first iterable. GNU ld automatically aligns output sections based on the strictest alignment requirement of input sections, so moving __static_thread_data_list to its own section fixes the problem. Signed-off-by: iabdalkader --- variants/_ldscripts/build-dynamic.ld | 6 ++++-- variants/_ldscripts/build-static.ld | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/variants/_ldscripts/build-dynamic.ld b/variants/_ldscripts/build-dynamic.ld index 47d353655..c5e8dc41e 100644 --- a/variants/_ldscripts/build-dynamic.ld +++ b/variants/_ldscripts/build-dynamic.ld @@ -34,9 +34,11 @@ SECTIONS { KEEP (*(.ctors)) KEEP (*(.dtors)) KEEP (*(.fini)) + } + .static_thread_data_area : { __static_thread_data_list_start = .; - KEEP(*(SORT_BY_NAME(.__static_thread_data.static.*))); + KEEP(*(.static_thread_data_area SORT_BY_NAME(.__static_thread_data.*))); __static_thread_data_list_end = .; } @@ -87,4 +89,4 @@ SECTIONS { .got : { KEEP(*(.got .got.* .got.plt .got.plt*)) } -} \ No newline at end of file +} diff --git a/variants/_ldscripts/build-static.ld b/variants/_ldscripts/build-static.ld index 7154ee9a4..3ed10654c 100644 --- a/variants/_ldscripts/build-static.ld +++ b/variants/_ldscripts/build-static.ld @@ -23,9 +23,11 @@ SECTIONS { KEEP (*(.ctors)) KEEP (*(.dtors)) KEEP (*(.fini)) + } >FLASH + .static_thread_data_area : { __static_thread_data_list_start = .; - KEEP(*(SORT_BY_NAME(.__static_thread_data.static.*))); + KEEP(*(.static_thread_data_area SORT_BY_NAME(.__static_thread_data.*))); __static_thread_data_list_end = .; } >FLASH From 6d9ef009fe271553f8fa817b3c9d9e45cfdfe9a2 Mon Sep 17 00:00:00 2001 From: iabdalkader Date: Wed, 1 Oct 2025 15:31:07 +0200 Subject: [PATCH 2/2] cores: Remove redundant k_thread_start() calls for static threads. According to Zephyr documentation, k_thread_create() both initializes and starts the thread. The second loop that was calling k_thread_start() on each static thread was redundant. Signed-off-by: iabdalkader --- cores/arduino/threads.cpp | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cores/arduino/threads.cpp b/cores/arduino/threads.cpp index f34a7f6d9..5a4e7a9b7 100644 --- a/cores/arduino/threads.cpp +++ b/cores/arduino/threads.cpp @@ -19,15 +19,5 @@ void start_static_threads() { k_thread_name_set(thread_data->init_thread, thread_data->init_name); thread_data->init_thread->init_data = thread_data; } - - /* - * Take a sched lock to prevent them from running - * until they are all started. - */ - k_sched_lock(); - _FOREACH_STATIC_THREAD(thread_data) { - k_thread_start(thread_data->init_thread); - } - k_sched_unlock(); } #endif