-
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
kernel.threads.tls.userspace fails with SDK 0.12.0-beta on ARM Cortex-M #30393
Comments
@dcpleung can you please take a look at this, seeing failures when building with gcc-10.2 on ARM. |
I've traced it to the calling site of Under userspace, when creating the second thread ( Test NOT under userspace:
Test under userspace:
Maybe register |
Here is the disassembly of the for loop:
|
I was able to reproduce it even with TLS disabled: and the following modified
|
According to GCC manual regarding input operands in extended asm: Warning: Do not modify the contents of input-only operands (except for inputs tied to outputs). The compiler assumes that on exit from the asm statement these operands contain the same values as they had before executing the statement. It is not possible to use clobbers to inform the compiler that the values in these inputs are changing. This has been observed that after arch_syscall_invoke6(), r1 has its value set to zero instead of the value before syscall. Given the above warning, it seems that GCC does not automatically save and restore r1-r3. Since arch_syscall_invoke*() can be inlined without function prologue so r0-r3 may not be saved even though they are caller-save registers. So save and restore them manually on relevant arch_syscall_invoke*(). Fixes zephyrproject-rtos#30393 Signed-off-by: Daniel Leung <[email protected]>
I think there is something wrong with GCC's code generation here. If I add printk() at the beginning of the thread creation loop, it ran fine. Also setting |
@dcpleung what do you think the compiler bug is? |
I am not totally sure this is a compiler bug, but this looks like clobbered register are not handled correctly with inline assembly inside inline functions. When tracing through the syscall invoke inline functions (inside |
was there some particular registers that didn't seem to get save/restored? |
The registers declared as variables (i.e. They cannot be added to the clobber list as GCC complains ( |
The inline asm code was not conveying in all cases that registers r1-r3 would get clobbered by the SVC handler code. In the cases that we can't list r1-r3 in the clobber list the registers need to show up as outputs to know that they values are not preserved by the callee. Fixes zephyrproject-rtos#30393 Signed-off-by: Kumar Gala <[email protected]>
The inline asm code was not conveying in all cases that registers r1-r3 would get clobbered by the SVC handler code. In the cases that we can't list r1-r3 in the clobber list the registers need to show up as outputs to know that they values are not preserved by the callee. Fixes #30393 Signed-off-by: Kumar Gala <[email protected]>
tests/kernel/threads/tls/kernel.threads.tls.userspace fails to run on qemu for mps2_an521 & mps2_an385.
./scripts/sanitycheck -p mps2_an521 -p mps2_an385 -s tests/kernel/threads/tls/kernel.threads.tls.userspace
Get the following log:
The text was updated successfully, but these errors were encountered: