Skip to content
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

runtime: Android shared lib panic #15856

Closed
gooid opened this issue May 27, 2016 · 3 comments
Closed

runtime: Android shared lib panic #15856

gooid opened this issue May 27, 2016 · 3 comments

Comments

@gooid
Copy link

gooid commented May 27, 2016

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)?
    go version devel +0e392c6 Thu May 26 09:27:08 2016 +0800 windows/amd64
  2. What operating system and processor architecture are you using (go env)?
    set GOARCH=arm
    set GOARM=7
    set GOOS=android
    set CGO_ENABLED=1
  3. What did you do?
    If possible, provide a recipe for reproducing the error.
    A complete runnable program is good.
    A link on play.golang.org is best.

armstack.go

package main

/*
typedef struct {
    int x,y,z;
    int a,b,c,d,e,f,g,h,i,j,k;
    } S1;

typedef struct {
    int a,b,c;
    S1  x,y,z[30];
    } S2;

extern void cgoCallback(S1* s1,S2* s2,int cnt);
*/
import "C"

import (
    "log"
)

type S1 C.S1
type S2 C.S2

//export cgoCallback
func cgoCallback(s1 *S1, s2 *S2, cnt C.int) {
    cnt++

    log.Println("cgoCallback1:", int(cnt), s1, s2)

    if cnt < 500 {
        s1 := &S1{}
        s2 := &S2{}
        cgoCallback(s1, s2, cnt)
    }
}

func main() {
    log.Println(".")
}

main.c

#include <stdio.h>
#include <stdlib.h>
#include "libarmstack.h"

int main(int argc, char** argv) {
    S1 o1 = {0};
    S2 o2 = {0};
    S1* s1= &o1;
    S2* s2= &o2;

    cgoCallback(s1,s2,0);

    cgoCallback(s1,s2,0);   

    //cgoCallback(s1,s2,0); 
    return 0;
}

go build -buildmode c-shared -o libarmstack.so armstack.go
gcc -marm main.c -o armstack -L. -larmstack
push to android 4.4 phone, then run.

result:

runtime: unexpected return pc for runtime.cgocallback_gofunc called from 0x0
fatal error: unknown caller pc

runtime stack:
runtime.throw(0xb6e97b9e, 0x11)
        D:/GoLang/goSource/go/src/runtime/panic.go:566 +0x80
runtime.gentraceback(0xb6e29ebc, 0x96dd43bc, 0x0, 0x96c143c0, 0x0, 0x0, 0x7fffffff, 0x868b5d04, 0x0, 0x0, ...)
        D:/GoLang/goSource/go/src/runtime/traceback.go:317 +0x1620
runtime.scanstack(0x96c143c0, 0x96c2292c)
        D:/GoLang/goSource/go/src/runtime/mgcmark.go:770 +0x344
runtime.scang(0x96c143c0, 0x96c2292c)
        D:/GoLang/goSource/go/src/runtime/proc.go:830 +0xb0
runtime.markroot.func1()
        D:/GoLang/goSource/go/src/runtime/mgcmark.go:234 +0xac
runtime.systemstack(0x96c22000)
        D:/GoLang/goSource/go/src/runtime/asm_arm.s:247 +0x8c
runtime.mstart()
        D:/GoLang/goSource/go/src/runtime/proc.go:1081

However, if you only once cgoCallback(s1,s2,0) is not panic.

@gooid gooid changed the title Android shared lib panic runtime: Android shared lib panic May 27, 2016
@eliasnaur
Copy link
Contributor

I'm also bitten by this in a gomobile project. Git bisect points to:

5f9a870bf1bf461ca3609502608b12cc4aab189a is the first bad commit
commit 5f9a870bf1bf461ca3609502608b12cc4aab189a
Author: Ian Lance Taylor <iant@golang.org>
Date:   Wed Apr 27 14:18:29 2016 -0700

    cmd/cgo, runtime, runtime/cgo: use cgo context function

(CL 22508). I tried to blindly apply the similar CL 22651 (for arm64), but failed.

CC @ianlancetaylor

I believe this is Go1.7 material, if not Go1.7Beta.

@ianlancetaylor ianlancetaylor added this to the Go1.7Beta milestone May 31, 2016
@ianlancetaylor
Copy link
Contributor

Sorry for the difficulties. Can you try https://golang.org/cl/23586 ?

@gopherbot
Copy link

CL https://golang.org/cl/23586 mentions this issue.

@golang golang locked and limited conversation to collaborators May 31, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants