-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: bind with go1.22.5,1.22.6 leads to: fatal error: runtime: stack split at bad time #68760
Comments
cc @cherrymui @golang/runtime |
This is presumably a bug in https://go.googlesource.com/go/+/3560cf0afb3c29300a6c88ccd98256949ca7a6f6, which is in go1.22.5. @xcolwell could you test with this commit reverted? Something like this should do the trick:
Then build with the toolchain in |
@prattmic that worked. I changed the installed go to the patched on with the below, and verified that the gomobile build worked when using the patched go, and failed when using 1.22.5.
As a summary of what the mobile code looks like, we have a gomobile lib that lets us register callbacks from Kotlin. There is a sequence like below. When the Kotlin callback is called from within the gomobile lib, the first function call back into the gomobile lib crashes with the error.
|
Can confirm. We see the same error but in go1.23: celzero/firestack#84 |
What did you do?Build a native aar for Android with cmd :
Go version
1. This code cause error only with go > 1.22.4Gomobile go codevar ReqLauncher = IToBeImplemented.Generate
// instanciated by mobile
type IToBeImplemented interface {
Generate(test ITest)
}
type IGoImpl interface {
TriggerGoAndLaunchTest()
}
type GoImpl struct {
impl IToBeImplemented
}
func InstanceGetter(mobileImpl IToBeImplemented) IGoImpl {
return GoImpl{impl: mobileImpl}
}
func (i GoImpl) TriggerGoAndLaunchTest() {
ReqLauncher(i.impl, TestImplemented{valueExample: "the go lib is on " + runtime.Version()})
}
type ITest interface {
Info() string
}
type TestImplemented struct {
valueExample string
}
func (t TestImplemented) Info() string {
return t.valueExample
} Gomobile android codevar res by remember { mutableStateOf("") }
val inst = Cmd.instanceGetter(object : IToBeImplemented {
override fun generate(test: ITest) {
res = test.info()
}
})
Surface(modifier = Modifier.fillMaxSize()) {
Column(verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally) {
Text(text = res)
Button(onClick = {inst.triggerGoAndLaunchTest()}) { Text("call go") }
}
} Error
2. This code work as expected (tested on go 1.22.4 & 1.22.5 & 1.22.6 & 1.23.2)Gomobile go code (ok)var ReqLauncher = IToBeImplemented.Generate
// instanciated by mobile
type IToBeImplemented interface {
Generate(test string)
}
type IGoImpl interface {
TriggerGoAndLaunchTest()
}
type GoImpl struct {
impl IToBeImplemented
}
func InstanceGetter(mobileImpl IToBeImplemented) IGoImpl {
return GoImpl{impl: mobileImpl}
}
func (i GoImpl) TriggerGoAndLaunchTest() {
ReqLauncher(i.impl, TestImplemented{}.Info())
}
type ITest interface {
Info() string
}
type TestImplemented struct{}
func (t TestImplemented) Info() string {
return "the go lib is on " + runtime.Version()
} Gomobile android code (ok)var res by remember { mutableStateOf("") }
val inst = Cmd.instanceGetter(object : IToBeImplemented {
override fun generate(test: String) {
res = test
}
})
Surface(modifier = Modifier.fillMaxSize()) {
Column(verticalArrangement = Arrangement.Center, horizontalAlignment = Alignment.CenterHorizontally) {
Text(text = res)
Button(onClick = {inst.triggerGoAndLaunchTest()}) { Text("call go") }
}
} The change between 2 testsThe only change is passing
Error potential causeWhen calling Kotlin ( |
how can I fix it? Is there any follow-up... |
The way we fixed it was by making all (JNI) calls into Kotlin from a (separate) go routine. - Kotlin.func1()
# use sync.WaitGroup or chans to await
# on return Kotlin.func1's value
+ go Kotlin.func1() |
Could you try building with Go tip (master branch)? It includes CL 600296, which fixes some similar issues related to https://go.googlesource.com/go/+/3560cf0afb3c29300a6c88ccd98256949ca7a6f6 . Thanks |
Is this confirmed to be the fix? |
Hey @cherrymui, you may know whether this may fix #46893 a stack alignment issue on darwin as well? |
@cherrymui I just built However, the referenced fix commit 1ffc296 is also in the branch
It looks like there are more changes in |
Any update on this? How can I use this with go mobile? |
@jigar-f A patched 1.23 works for us with gomobile. Follow the steps in #68760 (comment) but use branch
|
Go version
go version go1.22.5 darwin/arm64
Output of
go env
in your module/workspace:What did you do?
Build a native aar for Android as:
The code has interface callbacks that call from Go -> Kotlin -> Go.
What did you see happen?
Works up to go 1.22.4. On 1.22.5, the interface callback raises the error below. This happens in a Kotlin interface implementation called from Go, that is making another call to Go.
What did you expect to see?
No error.
The text was updated successfully, but these errors were encountered: