-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Description
Describe the bug
Linking picolibc's srand to esp32c3 causes startup fault
To Reproduce
Steps to reproduce the behavior:
- Modify hello_world sample : Call srand in the main function
int main(void)
{
srand(3);
printf("Hello World! %s\n", CONFIG_BOARD);
return 0;
}
- west build -b esp32c3_devkitm sample/hello_world
- west flash
- Reset run, you will find startup hang-up:
I (189) boot: Loaded app from partition at offset 0x10000
I (189) boot: Disabling RNG early entropy source...
Expected behavior
Linking picolibc's srand works fine on startup。
Impact
I can‘t use picolibc's C library properly on esp32c3
Logs and console output
Via jtag/gdb I found that the fault happens in prepare_multithreading->z_setup_new_thread->setup_thread_stack
, but I can‘t confirm the exact reason:
arch_system_halt (reason=reason@entry=0) at /home/frank/work/zpro/zephyr_zgp/zephyr/kernel/fatal.c:30
30 for (;;) {
(gdb) bt
#0 arch_system_halt (reason=reason@entry=0) at /home/frank/work/zpro/zephyr_zgp/zephyr/kernel/fatal.c:30
#1 0x403805cc in k_sys_fatal_error_handler (reason=reason@entry=0, esf=) at /home/frank/work/zpro/zephyr_zgp/zephyr/kernel/fatal.c:44
#2 0x403805e6 in z_fatal_error (reason=reason@entry=0, esf=) at /home/frank/work/zpro/zephyr_zgp/zephyr/kernel/fatal.c:118
#3 0x403804ca in z_riscv_fatal_error (esf=, reason=0) at /home/frank/work/zpro/zephyr_zgp/zephyr/arch/riscv/core/fatal.c:59
#4 _Fault (esf=) at /home/frank/work/zpro/zephyr_zgp/zephyr/arch/riscv/core/fatal.c:184
#5 0x403801ec in z_riscv_thread_start () at /home/frank/work/zpro/zephyr_zgp/zephyr/arch/riscv/core/isr.S:624
Backtrace stopped: frame did not save the PC
Additional context
But from the phenomenon, it seems that only linking picolibc's srand causes this phenomenon, if I switch to use newlibc it will work fine. I suspect it is related to -T${CMAKE_CURRENT_SOURCE_DIR}/../../components/esp_rom/esp32c3/ld/esp32c3.rom.newlib.ld
in modules/hal/espressif/zephyr/esp32c3/CMakeLists.txt
, but no further ideas.