Skip to content

runtime: Android shared lib panic #15856

Closed
@gooid

Description

@gooid

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.

Activity

changed the title [-]Android shared lib panic[/-] [+]runtime: Android shared lib panic[/+] on May 27, 2016
eliasnaur

eliasnaur commented on May 31, 2016

@eliasnaur
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.

added this to the Go1.7Beta milestone on May 31, 2016
ianlancetaylor

ianlancetaylor commented on May 31, 2016

@ianlancetaylor
Contributor

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

gopherbot

gopherbot commented on May 31, 2016

@gopherbot
Contributor

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

locked and limited conversation to collaborators on May 31, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @eliasnaur@ianlancetaylor@gopherbot@gooid

        Issue actions

          runtime: Android shared lib panic · Issue #15856 · golang/go