-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
x/mobile: fatal error: bulkBarrierPreWrite: unaligned arguments #46893
Comments
I've encountered this problem as well in the past, issue started with Go 1.16 (1.15 seems unaffected). In my case I had a function signature |
I had the same issue using Go 1.16. Reverted to Go 1.13 and it works fine. Also just affected a few users and couldn't reproduce it consistently. |
I have experienced the same issue using https://github.com/ProtonMail/gopenpgp in an iOS app (with gomobile). |
Can consistently repro with 1.17.x on iOS. It occurs when calling into Go from C. The stack frame C sets up for Go is four-byte aligned, which makes it likely that the address of the results aren't properly aligned, and therefore casues I think this is a |
An update: we patched |
@elagergren-spideroak when should we expect a release that fixes it, do you have any idea? |
I am not a member of the Go team, so I am not the person to ask. However, I'm going to submit a CL with the patch to get things started. |
Bump - just ran into this: |
@elagergren-spideroak just to know if I/we can assist in any way, the current status is what exactly? Thanks for letting us know how you fixed it! |
@elagergren-spideroak thanks for looking into this! Did you get a chance to make the CL? If you didn't, I'd really appreciate a gist so I can patch locally for the time being. I just got a new batch of ocurrences of this I can't seem to sidestep :( |
How we've fixed it for our iOS builds is by replacing Line 1005 in 97e740e
|
Thanks @elagergren-spideroak! Just tested it out and works great 👌 |
@elagergren-spideroak Where you able to create a CL? If so can you share the link to follow here. |
Irregularly typedmemmove and bulkBarrierPreWrite crashes on unaligned arguments. By aligning the arguments on 8 bytes this is fixed. Fixes golang#46893
Change https://go.dev/cl/408395 mentions this issue: |
Thanks for the fix. It fixed our |
I just started using Golang. Can anyone tell me if I need to recompile the Golang or just need to rebuild my project after I change the source code |
@gopherbot fatal error: bulkBarrierPreWrite: unaligned arguments goroutine 17 [running, locked to thread]: goroutine 21 [GC worker (idle)]: goroutine 2 [force gc (idle)]: goroutine 3 [GC sweep wait]: goroutine 4 [GC scavenge wait]: goroutine 18 [finalizer wait]: goroutine 19 [select, locked to thread]: goroutine 20 [syscall]: goroutine 35 [runnable]: goroutine 36 [GC worker (idle)]: goroutine 5 [GC worker (idle)]: goroutine 37 [GC worker (idle)]: goroutine 38 [GC worker (idle)]: |
I don't think this has actually been fixed yet. There is a CL (https://go-review.googlesource.com/c/go/+/408395) but it hasn't been checked in yet. |
Irregularly typedmemmove and bulkBarrierPreWrite crashes on unaligned arguments. By aligning the arguments on 8 bytes this is fixed. Fixes golang#46893 (cherry picked from commit f0cb9ff)
Irregularly typedmemmove and bulkBarrierPreWrite crashes on unaligned arguments. By aligning the arguments on 8 bytes this is fixed. Fixes golang#46893 (cherry picked from commit f0cb9ff) (cherry picked from commit 5c35f52)
This issue persist on 1.21.5. A slightly simpler repro of the issue (
Not able to repro with the suggested cgo alignment fix |
I ran into the same issue for the Go library we are writing: random crashes on iOS, with similar error messages. I can confirm that a build done with a Go toolchain that includes the suggested fix does not crash. |
Irregularly typedmemmove and bulkBarrierPreWrite crashes on unaligned arguments. By aligning the arguments on 8 bytes this is fixed. Fixes golang#46893 (cherry picked from commit f0cb9ff) (cherry picked from commit 5c35f52)
Irregularly typedmemmove and bulkBarrierPreWrite crashes on unaligned arguments. By aligning the arguments on 8 bytes this is fixed. Fixes golang#46893 (cherry picked from commit f0cb9ff) (cherry picked from commit 5c35f52)
This is still an issue with the latest go 1.22.1 on arm64. We've been running the suggested patch for some time, with no adverse effects, so why we can't just get it merged in is a complete mystery. Is anyone watching these issues? |
The patch was never finished by the author. |
@randall77 this is completely perfect as a fix:
|
Sure, it works, but that doesn't mean the patch is perfect. |
Change https://go.dev/cl/571375 mentions this issue: |
Our users can confirm this is a showstopper for us using GoMobile. Our apps
renders useless without that patch. Have no idea how to express it in a
test or fix it for 32-bits, though
ons. 13. mars 2024 kl. 20:25 skrev GopherBot ***@***.***>:
… Change https://go.dev/cl/571375 mentions this issue: cmd/cgo: fix
unaligned arguments typedmemmove crash on iOS
—
Reply to this email directly, view it on GitHub
<#46893 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAJRBNRFEVHHQHNGE742JW3YYCR23AVCNFSM47GHEIEKU5DIOJSWCZC7NNSXTN2JONZXKZKDN5WW2ZLOOQ5TCOJZGU2DQNBUHA2Q>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Although the patch seems to focus on forcing the alignment of a variable in cgo-generated code, the problem seems to be that the stack is not aligned to what Go expects. Is that correct? That suggests that a better fix would be to align the stack pointer when calling from C to Go. |
On iOS arm64, irregular typedmemmove and bulkBarrierPreWrite crashes on unaligned arguments. By aligning the arguments on `PtrSize` bytes this is fixed. The included test attempts to reproduce with golang#46893 (comment). Fixes golang#46893
Irregularly typedmemmove and bulkBarrierPreWrite crashes on unaligned arguments. By aligning the arguments on 8 bytes this is fixed. Fixes golang#46893 (cherry picked from commit f0cb9ff) (cherry picked from commit 5c35f52)
To bump this issue: we ran into it in our first few days of experimenting with gomobile for our iOS project. As noted above, this (abandoned?) fix resolves the problem: https://go-review.googlesource.com/c/go/+/571375/5/src/cmd/cgo/out.go I would not have expected to need to modify and compile the toolchain, but it seems like gomobile doesn't work without this for iOS. We're not doing anything special as far as I can tell, just a |
Irregularly typedmemmove and bulkBarrierPreWrite crashes on unaligned arguments. By aligning the arguments on 8 bytes this is fixed. Fixes golang#46893 (cherry picked from commit f0cb9ff) (cherry picked from commit 5c35f52)
Irregularly typedmemmove and bulkBarrierPreWrite crashes on unaligned arguments. By aligning the arguments on 8 bytes this is fixed. Fixes golang#46893 (cherry picked from commit f0cb9ff) (cherry picked from commit 5c35f52) (cherry picked from commit 0003a64)
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?
I have an iOS project using a go library via gomobile:
[]byte
The golang code is simple:
And on swift:
A full working reproduction project is at https://github.com/champo/gomobile_panic
What did you expect to see?
No crash.
What did you see instead?
It sometimes crashes inside
bulkBarrierPreWrite
:I tried exposing a free function with a similar signature but no crashers there. Removing the paramters or return values seems to avoid the crash too.
The text was updated successfully, but these errors were encountered: