Skip to content

Conversation

tpambor
Copy link
Contributor

@tpambor tpambor commented Sep 30, 2025

Explicitly link with libgcc_s to work around a race condition in glibc when dynamically loading libgcc_s in multiple threads.

The race condition was observed in the past in #87987 (comment) when running native_sim with CONFIG_REBOOT=y and CONFIG_NATIVE_SIM_REBOOT=y and rebooting quickly
from main(). As well as in the new boards.native_sim.reset_hw_info test that was temporarily disabled in #96765.

Most likely, this is caused by pthread_exit() and vprintf loading libgcc_s in two threads at the same time. The program then crashes with

libgcc_s.so.1 must be installed for pthread_exit to work
Aborted (core dumped)

With this PR, no crashes were observed for the following example (without sleeping) based on #87987 (comment):

diff --git a/samples/hello_world/prj.conf b/samples/hello_world/prj.conf
index b2a4ba59104..36d8008a72b 100644
--- a/samples/hello_world/prj.conf
+++ b/samples/hello_world/prj.conf
@@ -1 +1,3 @@
 # nothing here
+CONFIG_REBOOT=y
+CONFIG_NATIVE_SIM_REBOOT=y
\ No newline at end of file
diff --git a/samples/hello_world/src/main.c b/samples/hello_world/src/main.c
index c550ab461cb..4c3b037d42e 100644
--- a/samples/hello_world/src/main.c
+++ b/samples/hello_world/src/main.c
@@ -5,10 +5,14 @@
  */
 
 #include <stdio.h>
+#include <zephyr/kernel.h>
+#include <zephyr/sys/reboot.h>
 
 int main(void)
 {
        printf("Hello World! %s\n", CONFIG_BOARD_TARGET);
 
+       sys_reboot(SYS_REBOOT_WARM);
+
        return 0;
 }

@tpambor
Copy link
Contributor Author

tpambor commented Sep 30, 2025

/cc @koalatux

@zephyrbot zephyrbot added area: Tests Issues related to a particular existing or missing test area: native port Host native arch port (native_sim) labels Sep 30, 2025
@tpambor tpambor force-pushed the native-sim-reboot-fix branch from a45da52 to 37f5fd6 Compare September 30, 2025 10:01
Explicitly link with libgcc_s to work around a race condition
in glibc when dynamically loading libgcc_s in multiple threads.

The race condition was observed when running native_sim with
CONFIG_REBOOT=y and CONFIG_NATIVE_SIM_REBOOT=y and rebooting quickly
from main().

Signed-off-by: Tim Pambor <[email protected]>
The issue has been fixed, so re-enable the test.

This reverts commit 8d7c2e1.

Signed-off-by: Tim Pambor <[email protected]>
@tpambor tpambor force-pushed the native-sim-reboot-fix branch from 37f5fd6 to 085b7cd Compare September 30, 2025 13:33
@tpambor tpambor marked this pull request as draft September 30, 2025 13:34
Copy link

@tpambor
Copy link
Contributor Author

tpambor commented Oct 8, 2025

Closing this in favor of #96812

@tpambor tpambor closed this Oct 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Boards/SoCs area: native port Host native arch port (native_sim) area: Tests Issues related to a particular existing or missing test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants