golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.99k stars 17.54k forks source link

x/mobile: building 2 independent xcframeworks for iOS Simulator, but crash when app start up #50594

Open pipi32167 opened 2 years ago

pipi32167 commented 2 years ago

What version of Go are you using (go version)?

$ go version
go version go1.17.6 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/x/Library/Caches/go-build"
GOENV="/Users/x/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/x/.gvm/pkgsets/go1.17.6/global/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/x/.gvm/pkgsets/go1.17.6/global"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/Users/x/.gvm/gos/go1.17.6"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/x/.gvm/gos/go1.17.6/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/private/tmp/golang-crash-test/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/vd/lrhd0qbn1t56jjs5ml_81_w00000gp/T/go-build4026723300=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Building 2 independent xcframeworks for iOS App to use.

gomobile bind -tags test1 -target=ios -o build/golang_crash_test1.xcframework ./crash
gomobile bind -tags test2 -target=ios -o build/golang_crash_test2.xcframework ./crash

And then use the xcframeworks in the Xcode project

What did you expect to see?

The iOS program is able to run properly.

What did you see instead?

The iOS program running crash with the callstack:

#0  0x000000010e814d55 in debugCall65536 ()
#1  0x000000010ed76899 in invocation function for block in dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const ()
#2  0x000000010ed92941 in invocation function for block in dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const ()
#3  0x000000010ed8be09 in invocation function for block in dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const ()
#4  0x000000010ed8af5f in dyld3::MachOFile::forEachLoadCommand(Diagnostics&, void (load_command const*, bool&) block_pointer) const ()
#5  0x000000010ed8bb93 in dyld3::MachOFile::forEachSection(void (dyld3::MachOFile::SectionInfo const&, bool, bool&) block_pointer) const ()
#6  0x000000010ed923a2 in dyld3::MachOAnalyzer::forEachInitializerPointerSection(Diagnostics&, void (unsigned int, unsigned int, unsigned char const*, bool&) block_pointer) const ()
#7  0x000000010ed925e4 in dyld3::MachOAnalyzer::forEachInitializer(Diagnostics&, dyld3::MachOAnalyzer::VMAddrConverter const&, void (unsigned int) block_pointer, void const*) const ()
#8  0x000000010ed767cc in dyld4::Loader::findAndRunAllInitializers(dyld4::RuntimeState&) const ()
#9  0x000000010ed76958 in dyld4::Loader::runInitializersBottomUp(dyld4::RuntimeState&, dyld3::Array<dyld4::Loader const*>&) const ()
#10 0x000000010ed769f6 in dyld4::Loader::runInitializersBottomUpPlusUpwardLinks(dyld4::RuntimeState&) const ()
#11 0x000000010ed852d8 in dyld4::APIs::runAllInitializersForMain() ()
#12 0x000000010ed69920 in dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) ()
#13 0x000000010ed69d3f in _dyld_sim_prepare ()
#14 0x00000001145fcb24 in dyld4::prepareSim(dyld4::RuntimeState&, char const*) ()
#15 0x00000001145fb6de in dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*) ()
#16 0x00000001145fb4b4 in start ()
dr2chase commented 2 years ago

@hyangah can you give this a look?

ydnar commented 2 years ago

@pipi32167 are both frameworks built from the same Go package? Does it crash if the two XCFrameworks are built from different Go packages?

CoderHarry commented 2 years ago

how to solve it? I build 2 xcframeworks also crash

pipi32167 commented 2 years ago

how to solve it? I build 2 xcframeworks also crash

I just merge 2 xcframeworks into 1.

OEA commented 2 years ago

I had also same problem. We have 2 independent go library and If I bind two libraries into two different xcframework, It causes a crash.

fatal error: minpc or maxpc invalid
runtime: panic before malloc heap initialized

runtime stack:
runtime.throw({0x102eafb8c?, 0x0?})
    /usr/local/go/src/runtime/panic.go:1047 +0x40 fp=0x17bbbee60 sp=0x17bbbee30 pc=0x10294a840
runtime.moduledataverify1(0x1034a2f20)
    /usr/local/go/src/runtime/symtab.go:636 +0x41c fp=0x17bbbef40 sp=0x17bbbee60 pc=0x102966ffc
runtime.moduledataverify(...)
    /usr/local/go/src/runtime/symtab.go:593
runtime.schedinit()
    /usr/local/go/src/runtime/proc.go:691 +0x40 fp=0x17bbbefa0 sp=0x17bbbef40 pc=0x10294dee0
runtime.rt0_go()
    /usr/local/go/src/runtime/asm_arm64.s:86 +0xd0 fp=0x17bbbefd0 sp=0x17bbbefa0 pc=0x102975c20

I used same sys package same dependencies but never succeed.

Merging 2 frameworks into 1 is solving problem but I think it needs further investigation

GavinZhang80 commented 1 year ago

I had also same problem.

minpc= 0x1022de450 min= 0x1022de450 maxpc= 0x10236a380 max= 0x10236a4b0
fatal error: minpc or maxpc invalid
runtime: panic before malloc heap initialized

runtime stack:
runtime.throw({0x102429860?, 0x0?})
    /usr/local/go/src/runtime/panic.go:1047 +0x40 fp=0x16dd52e60 sp=0x16dd52e30 pc=0x10230ef10
runtime.moduledataverify1(0x1025c2b60)
    /usr/local/go/src/runtime/symtab.go:636 +0x41c fp=0x16dd52f40 sp=0x16dd52e60 pc=0x10232b69c
runtime.moduledataverify(...)
    /usr/local/go/src/runtime/symtab.go:593
runtime.schedinit()
    /usr/local/go/src/runtime/proc.go:691 +0x40 fp=0x16dd52fa0 sp=0x16dd52f40 pc=0x1023125b0
runtime.rt0_go()
    /usr/local/go/src/runtime/asm_arm64.s:86 +0xd0 fp=0x16dd52fd0 sp=0x16dd52fa0 pc=0x102339c60
ghjdegithub commented 1 year ago

If you are using a dynamic link library (go export), this error will not occur. Once the static library is used, this error will be reported.

GavinZhang80 commented 1 year ago

If you are using a dynamic link library (go export), this error will not occur. Once the static library is used, this error will be reported.

Can you provide an example of a dynamic link library? Thank you!