go: x/mobile: Binding go mobile framework on iOS 9 with golang1.7rc6 crash when call debug.FreeOSMemory()

Please answer these questions before submitting your issue. Thanks!

  1. What version of Go are you using (go version)? go version go1.7rc5 darwin/amd64
  2. What operating system and processor architecture are you using (go env)? GOARCH=“amd64” GOBIN=“” GOEXE=“” GOHOSTARCH=“amd64” GOHOSTOS=“darwin” GOOS=“darwin” GOPATH=“” GORACE=“” GOROOT=“/usr/local/go” GOTOOLDIR=“/usr/local/go/pkg/tool/darwin_amd64” CC=“clang” GOGCCFLAGS=“-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/m9/qtbxkp6s3p96fk54rln7qhj80000gp/T/go-build097177340=/tmp/go-build -gno-record-gcc-switches -fno-common” CXX=“clang++” CGO_ENABLED=“1”
  3. What did you do? I create a simple one page ios project. I write a simple package with follow code:
package iosGomobileLib

import (
    "runtime/debug"
    "fmt"
)

func RunFromGo(){
    fmt.Println("before debug.FreeOSMemory()")
    debug.FreeOSMemory()
    fmt.Println("after debug.FreeOSMemory()")
}

change the ViewController.m with follow code:

#import "ViewController.h"
@import IosGomobileLib;

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    GoIosGomobileLibRunFromGo();
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

I build the framework with follow code(the kmg stuff should be easy to understand):

package main

import (
    "github.com/bronze1man/kmg/kmgCmd"
    "github.com/bronze1man/kmg/kmgConfig"
    "os"
)

func main(){
    goPath := kmgConfig.DefaultEnv().GOPATHToString()
    androidSdkPath := "/usr/local/AndroidSdk"
    kmgCmd.CmdString("gomobile bind -target ios -o client/ios-gomobile/ufr/iosGomobileLib.framework make/tplIosGomobile/iosGomobileLib").
    MustSetEnvMap(map[string]string{
        "GOPATH":                     "/usr/local/gopath:"+goPath,
        "PATH":                           os.Getenv("PATH"),
        "ANDROID_HOME":               androidSdkPath,
        "IPHONEOS_DEPLOYMENT_TARGET": "8.0",
    }).
    RunAndReturnOutput()
}
  1. What did you expect to see? see following in ios console:
before debug.FreeOSMemory()
after debug.FreeOSMemory()
  1. What did you see instead? see following in ios console:
before debug.FreeOSMemory()

and crash with EXC_BAD_ACCESS

* thread #1: tid = 0x6dd76, 0x00000001000c8cec ufr`notok + 4, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
    frame #0: 0x00000001000c8cec ufr`notok + 4
    frame #1: 0x00000001000c8e48 ufr`runtime.madvise + 32
    frame #2: 0x0000000100080fdc ufr`runtime.sysUnused + 52
    frame #3: 0x00000001000901c4 ufr`runtime.scavengelist + 332
    frame #4: 0x000000010009027c ufr`runtime.(*mheap).scavenge + 132
    frame #5: 0x00000001000bfd68 ufr`runtime.runtime_debug_freeOSMemory.func1 + 64
    frame #6: 0x00000001000c6178 ufr`runtime.systemstack + 144
    frame #7: 0x000000010009d8e8 ufr`runtime.startTheWorldWithSema + 800
    frame #8: 0x0000000100101dbc ufr`GoIosGomobileLibRunFromGo + 12
  * frame #9: 0x000000010006bba8 ufr`-[ViewController viewDidLoad](self=0x0000000127da0c70, _cmd="viewDidLoad") + 72 at ViewController.m:20
    frame #10: 0x00000001898bf610 UIKit`-[UIViewController loadViewIfRequired] + 1124
    frame #11: 0x00000001898bf194 UIKit`-[UIViewController view] + 28
    frame #12: 0x00000001898c5f70 UIKit`-[UIWindow addRootViewControllerViewIfPossible] + 76
    frame #13: 0x00000001898c3454 UIKit`-[UIWindow _setHidden:forced:] + 264
    frame #14: 0x000000018993775c UIKit`-[UIWindow makeKeyAndVisible] + 48
    frame #15: 0x0000000189b5c088 UIKit`-[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 3456
    frame #16: 0x0000000189b601a4 UIKit`-[UIApplication _runWithMainScene:transitionContext:completion:] + 1660
    frame #17: 0x0000000189b5d2e4 UIKit`-[UIApplication workspaceDidEndTransaction:] + 168
    frame #18: 0x000000018e3f77ec FrontBoardServices`-[FBSSerialQueue _performNext] + 184
    frame #19: 0x000000018e3f7b6c FrontBoardServices`-[FBSSerialQueue _performNextFromRunLoopSource] + 56
    frame #20: 0x00000001843205a4 CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
    frame #21: 0x0000000184320038 CoreFoundation`__CFRunLoopDoSources0 + 540
    frame #22: 0x000000018431dd38 CoreFoundation`__CFRunLoopRun + 724
    frame #23: 0x000000018424cdc0 CoreFoundation`CFRunLoopRunSpecific + 384
    frame #24: 0x000000018992c0ac UIKit`-[UIApplication _run] + 460
    frame #25: 0x0000000189926f44 UIKit`UIApplicationMain + 204
    frame #26: 0x000000010006bf40 ufr`main(argc=1, argv=0x000000016fd9bb18) + 124 at main.m:14
    frame #27: 0x000000019a0768b8 libdyld.dylib`start + 4

gomobile version

gomobile version +8ab5dbb Thu Aug 4 01:15:58 2016 +0000 (android,ios); androidSDK=

ios version: 9.0.2 ios device name: iphone 6s

It works ok with golang1.6. I have uploaded several apps with gomobile and golang1.6 to apple app store.

I can use golang1.6 to work around this problem. This issue may be same as https://github.com/golang/go/issues/16598

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 32 (24 by maintainers)

Commits related to this issue

Most upvoted comments

I’m seeing a random crash from time to time as well. I’ll confirm if it is the same. /cc @crawshaw