-
Notifications
You must be signed in to change notification settings - Fork 18k
runtime/cgo: dlopen shared library cause bus error in pthread_create with raspberry pi (Arch Linux) #58548
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
Comments
I'm experiencing the same issue after dlopen a golang built shared so into an ARM binary.
|
CC @golang/arm @golang/runtime In triage now, it looks like it's an unaligned 8 byte store, but it's not clear why this doesn't happen consistently on all Raspberry Pis. One theory is that it's this particular implementation of pthreads (which libc is this? glibc? musl?) expecting an aligned stack pointer. But it could just be a general issue on our side in failing to follow the C ABI fully. |
@randall77 points out that we do 8-byte align the stack on arm (regardless of what the CPU actually requires, if it requires less). |
I'm using the official build of arch linux arm (32bit). The glibc link is here. |
FWIW, I'm experiencing this issue using go1.19. And it was working fine previously when using go1.17 |
Can confirm that changing |
This issue is not specific to golang. Close and seek help from arch linux. |
@tmm1 How did you make that change? |
I did hit the same issue also with golang 1.19.4 + glibc 2.35. Fix is to patch go-runtime in following (as stated in original issue):
@dong-zeyu I've tried same code with glibc 2.35 and 2.36 and issue was still present until go-runtime was patched. |
@nandra thanks. Could you send a CL? (See https://go.dev/doc/contribute for how to contribute, if you haven't seen it.) Thanks. |
I think it may be that the original frame size was 104, but we add 4 byte for the stack slot to save the LR, which makes it not a multiple of 8. Changing to 108 makes it a multiple of 8 after adding the LR slot. (If you send a patch, a comment would be helpful. Thanks.) |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
The system is running on a raspberry pi model 3b+, with up to date Arch Linux ARM (32bit)
Create
main.go
Create
main.c
Build
libtest.so
and executable, and run the programWhat did you expect to see?
The program should exit normally
What did you see instead?
The program failed with Bus error
I suspect the problem is caused by the stack is misaligned, so I trace back the stack pointer and find the misalignment happens at
go/src/runtime/asm_arm.s
Line 31 in 40ed359
where the function
_rt0_arm_lib
applied for a stack size of 104. I changed it to 108 and this solves the issue.I don't have much knowledge in assembly and processor architecture, so I'm not sure why the misalignment happens here and what should be the correct way to solve this issue.
The text was updated successfully, but these errors were encountered: