-
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
Hard fault on boot w/ GCC 14 on Cortex-M #80542
Comments
cc @stephanosio in case you know something about this already (ARM + GCC 14) |
@ithinuel could you look into it? We bumped into the issue as well and also verified that removing that line is an effective workaround |
As far as I can tell from reading the gist, It looks like The difference that concerns me though is that in GCC 14, it does not set
in the first listing is actually the address of |
Note that this is also reproducible with GCC 14 on |
It was pointed to me that I'm afraid this might be a bit too cutting edge for the system I'm working from (NixOS). developer.arm.com only has 13.3. If you know how to get gcc14 for arm-none-eabi available in NixOS please let me know. |
@ithinuel I have a setup to test, did this change index fa500032d3c..00d31c05ee3 100644
--- a/arch/arm/core/cortex_m/thread.c
+++ b/arch/arm/core/cortex_m/thread.c
@@ -559,6 +559,8 @@ void arch_switch_to_main_thread(struct k_thread *main_thread, char *stack_ptr,
#endif
#endif /* CONFIG_BUILTIN_STACK_GUARD */
+ volatile k_thread_entry_t __main = _main;
+
/*
* Set PSP to the highest address of the main stack
* before enabling interrupts and jumping to main.
@@ -586,7 +588,7 @@ void arch_switch_to_main_thread(struct k_thread *main_thread, char *stack_ptr,
"mov r3, #0\n"
"ldr r4, =z_thread_entry\n"
"bx r4\n" /* We don’t intend to return, so there is no need to link. */
- : "+r" (_main)
+ : "+r" (__main)
: "r" (stack_ptr)
: "r0", "r1", "r2", "r3", "r4", "ip", "lr"); and it worked, though I won't try to pretend I understand why :-) does it make any sense? |
index fa500032d3c..695e216a43c 100644
--- a/arch/arm/core/cortex_m/thread.c
+++ b/arch/arm/core/cortex_m/thread.c
@@ -588,7 +588,7 @@ void arch_switch_to_main_thread(struct k_thread *main_thread, char *stack_ptr,
"bx r4\n" /* We don’t intend to return, so there is no need to link. */
: "+r" (_main)
: "r" (stack_ptr)
- : "r0", "r1", "r2", "r3", "r4", "ip", "lr");
+ : "r0", "r1", "r2", "r3", "r4", "ip", "lr", "memory");
CODE_UNREACHABLE;
} this alwo works (suggested by @ithinuel over discord) |
index fa500032d3c..6cd7144e79d 100644
--- a/arch/arm/core/cortex_m/thread.c
+++ b/arch/arm/core/cortex_m/thread.c
@@ -586,9 +586,9 @@ void arch_switch_to_main_thread(struct k_thread *main_thread, char *stack_ptr,
"mov r3, #0\n"
"ldr r4, =z_thread_entry\n"
"bx r4\n" /* We don’t intend to return, so there is no need to link. */
- : "+r" (_main)
- : "r" (stack_ptr)
- : "r0", "r1", "r2", "r3", "r4", "ip", "lr");
+ :
+ : "r" (_main), "r" (stack_ptr)
+ : "r0", "r1", "r2", "r3", "r4", "ip", "lr", "memory");
CODE_UNREACHABLE;
} this also works |
Seems to be the best solution. |
Discussed in #74379
Originally posted by agesome June 17, 2024
Hi. When building Zephyr with GCC 14.1.0 (arch linux package), it seems that on startup,
z_thread_entry
is called withentry = NULL
, when normally it would= _main
, which leads to a fault.zephyr/lib/os/thread_entry.c
Line 48 in 4d0a8c1
If we break in
arch_switch_to_main_thread
, it looks like this,_main
(which is passed toz_thread_entry
asentry
) is OK:but if we then break in
z_thread_entry
, it looks as ifarch_switch_to_main_thread
had_main = 0
After some experimenting, I fixed this by commenting
zephyr/arch/arm/core/cortex_m/thread.c
Line 593 in 4d0a8c1
With GCC 12 included in Zephyr SDK, this problem does not appear.
So at this point I'm not sure if it's some incompatible change 12->14, or a bug in 14. Any advice?
I also made a comparison of assembly on GCC 14 with/without
CODE_UNREACHABLE
and GCC 12: https://gist.github.com/agesome/bfc1e15b561df353fd5f340c0413e348The text was updated successfully, but these errors were encountered: