-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linking picolibc's srand to esp32c3 causes startup fault #69708
Comments
This issue has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this issue will automatically be closed in 14 days. Note, that you can always re-open a closed issue at any time. |
This problem remains unresolved. Could someone provide assistance? |
Hum I thought it was solved already. Let me re-check tomorrow. |
Hrm. srand is a wrapper for srandom which stores to a thread local variable, _rand_next. I bet there's some thread local storage issue at play here. |
If this is a TLS specific issue, then building using newlib with TLS enabled should also fail (as that causes the kernel to use TLS for some internal operations). If this is specific to initialized TLS variables, then this should fail even with newlib:
|
Ok, got it. Reason it fails is because Seems esp32c3 linker file needs to be updated, which can be confirmed using the patch below, which makes it work by fixing the above mentioned address: diff --git a/include/zephyr/linker/thread-local-storage.ld b/include/zephyr/linker/thread-local-storage.ld
index 5a1313e1c8c..8444d1f082e 100644
--- a/include/zephyr/linker/thread-local-storage.ld
+++ b/include/zephyr/linker/thread-local-storage.ld
@@ -20,7 +20,7 @@
*/
#ifdef CONFIG_XIP
/* The "master copy" of tdata should be only in flash on XIP systems */
- PROVIDE(__tdata_start = LOADADDR(tdata));
+ PROVIDE(__tdata_start = ADDR(tdata));
#else
PROVIDE(__tdata_start = ADDR(tdata));
#endif @keith-packard Not sure if the PR linked to this issue is the final solution yet. PTAL if you can. I need to check whether we have more cases like this and/or evaluate if this is the correct fix. |
I commented in the PR -- I don't think this is right. |
@sylvioalves @keith-packard I have performed a simple verification on #72642 , and i seems that this issue can be resolved. But I have some doubts. The error with __tdata_start should have caused a fault during z_tls_copy. Why does the gdb trace show it happening in z_riscv_thread_start? |
I'll be able to do so later in case you can´t. |
In this case, where I am unable to see the "hello world" information, it is likely that a fault has occurred. However, since there is no JTAG connection available at the moment, it is not possible to further investigate and determine the exact location of the fault. |
@sylvioalves
However, I can confirm through single-step execution that the fault did occur when tls copying to the flash address within
|
The TLS initialized data lives in FLASH at 0x10ed0 and needs to be copied into each thread's TLS block so that the initialized TLS variables start with the right values. It seems that the processor cannot read from FLASH though, and so the system generates a fault when memcpy is called. Using the fake memory address of the tdata segment (possibly 0x3c000ed0?), which is what you'd get if you replace |
|
@lgl88911, correct. |
Describe the bug
Linking picolibc's srand to esp32c3 causes startup fault
To Reproduce
Steps to reproduce the behavior:
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: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
inmodules/hal/espressif/zephyr/esp32c3/CMakeLists.txt
, but no further ideas.The text was updated successfully, but these errors were encountered: