I want to build the weshnet as a shared library so that I can call it from NodeJS.
package main
import (
"C"
"berty.tech/weshnet"
)
//export NewPersistentServiceClient
func NewPersistentServiceClient() {
weshnet.NewPersistentServiceClient("data1")
}
func main() {} // Required for c-shared build mode
# command-line-arguments
ld: warning: -bind_at_load is deprecated on macOS
ld: warning: ignoring duplicate libraries: '-lobjc'
ld: warning: '/private/var/folders/_9/zt66nrqx6rg37b3mvyxflk740000gn/T/go-link-1036805785/go.o' has malformed LC_DYSYMTAB, expected 140 undefined symbols to start at index 169421, found 237 undefined symbols starting at index 133
Stanislaws-MacBook-Pro:app stanbar$ yarn start
yarn run v1.22.19
$ npx ts-node ./src/main.ts
unexpected fault address 0x2407ef5512a0
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x2 addr=0x2407ef5512a0 pc=0x1664a551c]
goroutine 17 [running, locked to thread]:
runtime.throw({0x1667604ed?, 0x0?})
/Users/stanbar/sdk/go1.19.13/src/runtime/panic.go:1047 +0x40 fp=0x1400009eba0 sp=0x1400009eb70 pc=0x165161520
runtime.sigpanic()
/Users/stanbar/sdk/go1.19.13/src/runtime/signal_unix.go:846 +0x1a0 fp=0x1400009ebd0 sp=0x1400009eba0 pc=0x1651795d0
path/filepath.Split(...)
/Users/stanbar/sdk/go1.19.13/src/path/filepath/path.go:212
berty.tech/weshnet/pkg/ipfsutil.LoadRepoFromPath({0x11b84ee48?, 0x0?})
/Users/stanbar/sandbox/weshnet/pkg/ipfsutil/repo.go:62 +0x2c fp=0x1400009ec30 sp=0x1400009ebe0 pc=0x1664a551c
berty.tech/weshnet.NewPersistentServiceClient({0x11b84ee48, 0x2406d3d02459})
/Users/stanbar/sandbox/weshnet/service_client.go:91 +0x48 fp=0x1400009ede0 sp=0x1400009ec30 pc=0x166595a78
main.NewPersistentServiceClient(...)
/Users/stanbar/sandbox/weshnet/wrapper/wrapper.go:10
_cgoexp_a96eb3496c92_NewPersistentServiceClient(0x1673dc3e8?)
_cgo_gotypes.go:40 +0x28 fp=0x1400009ee00 sp=0x1400009ede0 pc=0x1665c2638
runtime.cgocallbackg1(0x1665c2610, 0x0?, 0x0)
/Users/stanbar/sdk/go1.19.13/src/runtime/cgocall.go:316 +0x244 fp=0x1400009eef0 sp=0x1400009ee00 pc=0x165129c74
runtime.cgocallbackg(0x0?, 0x0?, 0x0?)
/Users/stanbar/sdk/go1.19.13/src/runtime/cgocall.go:235 +0xd8 fp=0x1400009ef80 sp=0x1400009eef0 pc=0x1651299a8
runtime.cgocallbackg(0x1665c2610, 0x16da530c0, 0x0)
<autogenerated>:1 +0x1c fp=0x1400009efb0 sp=0x1400009ef80 pc=0x165196a9c
runtime.cgocallback(0x0, 0x0, 0x0)
/Users/stanbar/sdk/go1.19.13/src/runtime/asm_arm64.s:1094 +0xa0 fp=0x1400009efe0 sp=0x1400009efb0 pc=0x165195220
runtime.goexit()
/Users/stanbar/sdk/go1.19.13/src/runtime/asm_arm64.s:1172 +0x4 fp=0x1400009efe0 sp=0x1400009efe0 pc=0x1651952f4
goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:363 +0xe4 fp=0x1400008cfa0 sp=0x1400008cf80 pc=0x165164124
runtime.goparkunlock(...)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:369
runtime.forcegchelper()
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:302 +0xb4 fp=0x1400008cfd0 sp=0x1400008cfa0 pc=0x165163fb4
runtime.goexit()
/Users/stanbar/sdk/go1.19.13/src/runtime/asm_arm64.s:1172 +0x4 fp=0x1400008cfd0 sp=0x1400008cfd0 pc=0x1651952f4
created by runtime.init.6
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:290 +0x24
goroutine 18 [GC sweep wait]:
runtime.gopark(0x1?, 0x0?, 0x0?, 0x0?, 0x0?)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:363 +0xe4 fp=0x14000088770 sp=0x14000088750 pc=0x165164124
runtime.goparkunlock(...)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:369
runtime.bgsweep(0x0?)
/Users/stanbar/sdk/go1.19.13/src/runtime/mgcsweep.go:297 +0x10c fp=0x140000887b0 sp=0x14000088770 pc=0x16514d62c
runtime.gcenable.func1()
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:178 +0x28 fp=0x140000887d0 sp=0x140000887b0 pc=0x1651418d8
runtime.goexit()
/Users/stanbar/sdk/go1.19.13/src/runtime/asm_arm64.s:1172 +0x4 fp=0x140000887d0 sp=0x140000887d0 pc=0x1651952f4
created by runtime.gcenable
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:178 +0x70
goroutine 19 [GC scavenge wait]:
runtime.gopark(0x1400010e000?, 0x166e180a8?, 0x0?, 0x0?, 0x0?)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:363 +0xe4 fp=0x14000088f50 sp=0x14000088f30 pc=0x165164124
runtime.goparkunlock(...)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:369
runtime.(*scavengerState).park(0x1686e8b60)
/Users/stanbar/sdk/go1.19.13/src/runtime/mgcscavenge.go:389 +0x5c fp=0x14000088f80 sp=0x14000088f50 pc=0x16514b4ac
runtime.bgscavenge(0x0?)
/Users/stanbar/sdk/go1.19.13/src/runtime/mgcscavenge.go:622 +0xac fp=0x14000088fb0 sp=0x14000088f80 pc=0x16514bacc
runtime.gcenable.func2()
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:179 +0x28 fp=0x14000088fd0 sp=0x14000088fb0 pc=0x165141878
runtime.goexit()
/Users/stanbar/sdk/go1.19.13/src/runtime/asm_arm64.s:1172 +0x4 fp=0x14000088fd0 sp=0x14000088fd0 pc=0x1651952f4
created by runtime.gcenable
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:179 +0xb4
goroutine 34 [finalizer wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:363 +0xe4 fp=0x140001b6580 sp=0x140001b6560 pc=0x165164124
runtime.goparkunlock(...)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:369
runtime.runfinq()
/Users/stanbar/sdk/go1.19.13/src/runtime/mfinal.go:180 +0x128 fp=0x140001b67d0 sp=0x140001b6580 pc=0x165140af8
runtime.goexit()
/Users/stanbar/sdk/go1.19.13/src/runtime/asm_arm64.s:1172 +0x4 fp=0x140001b67d0 sp=0x140001b67d0 pc=0x1651952f4
created by runtime.createfing
/Users/stanbar/sdk/go1.19.13/src/runtime/mfinal.go:157 +0x94
goroutine 35 [select]:
runtime.gopark(0x140001b6f80?, 0x2?, 0x0?, 0x0?, 0x140001b6f14?)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:363 +0xe4 fp=0x140001b6d90 sp=0x140001b6d70 pc=0x165164124
runtime.selectgo(0x140001b6f80, 0x140001b6f10, 0x0?, 0x0, 0x0?, 0x1)
/Users/stanbar/sdk/go1.19.13/src/runtime/select.go:328 +0x6b4 fp=0x140001b6ea0 sp=0x140001b6d90 pc=0x165175414
github.com/ipfs/go-log/writer.(*MirrorWriter).logRoutine(0x140003cc6f0)
/Users/stanbar/go/pkg/mod/github.com/ipfs/[email protected]/writer/writer.go:71 +0xb4 fp=0x140001b6fb0 sp=0x140001b6ea0 pc=0x165655f24
github.com/ipfs/go-log/writer.NewMirrorWriter.func1()
/Users/stanbar/go/pkg/mod/github.com/ipfs/[email protected]/writer/writer.go:36 +0x28 fp=0x140001b6fd0 sp=0x140001b6fb0 pc=0x165655ca8
runtime.goexit()
/Users/stanbar/sdk/go1.19.13/src/runtime/asm_arm64.s:1172 +0x4 fp=0x140001b6fd0 sp=0x140001b6fd0 pc=0x1651952f4
created by github.com/ipfs/go-log/writer.NewMirrorWriter
/Users/stanbar/go/pkg/mod/github.com/ipfs/[email protected]/writer/writer.go:36 +0xd0
goroutine 20 [GC worker (idle)]:
runtime.gopark(0x140001b0840?, 0x14000185ba0?, 0x98?, 0x77?, 0x1657a6578?)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:363 +0xe4 fp=0x140001b7740 sp=0x140001b7720 pc=0x165164124
runtime.gcBgMarkWorker()
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:1235 +0xec fp=0x140001b77d0 sp=0x140001b7740 pc=0x165143d5c
runtime.goexit()
/Users/stanbar/sdk/go1.19.13/src/runtime/asm_arm64.s:1172 +0x4 fp=0x140001b77d0 sp=0x140001b77d0 pc=0x1651952f4
created by runtime.gcBgMarkStartWorkers
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:1159 +0x28
goroutine 50 [GC worker (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:363 +0xe4 fp=0x140001b2740 sp=0x140001b2720 pc=0x165164124
runtime.gcBgMarkWorker()
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:1235 +0xec fp=0x140001b27d0 sp=0x140001b2740 pc=0x165143d5c
runtime.goexit()
/Users/stanbar/sdk/go1.19.13/src/runtime/asm_arm64.s:1172 +0x4 fp=0x140001b27d0 sp=0x140001b27d0 pc=0x1651952f4
created by runtime.gcBgMarkStartWorkers
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:1159 +0x28
goroutine 38 [GC worker (idle)]:
runtime.gopark(0x3a9851c75b172?, 0x3?, 0x64?, 0x89?, 0x0?)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:363 +0xe4 fp=0x140001b7f40 sp=0x140001b7f20 pc=0x165164124
runtime.gcBgMarkWorker()
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:1235 +0xec fp=0x140001b7fd0 sp=0x140001b7f40 pc=0x165143d5c
runtime.goexit()
/Users/stanbar/sdk/go1.19.13/src/runtime/asm_arm64.s:1172 +0x4 fp=0x140001b7fd0 sp=0x140001b7fd0 pc=0x1651952f4
created by runtime.gcBgMarkStartWorkers
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:1159 +0x28
goroutine 21 [GC worker (idle)]:
runtime.gopark(0x3a9851c75d882?, 0x2?, 0x20?, 0x50?, 0x1400010e000?)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:363 +0xe4 fp=0x1400008c740 sp=0x1400008c720 pc=0x165164124
runtime.gcBgMarkWorker()
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:1235 +0xec fp=0x1400008c7d0 sp=0x1400008c740 pc=0x165143d5c
runtime.goexit()
/Users/stanbar/sdk/go1.19.13/src/runtime/asm_arm64.s:1172 +0x4 fp=0x1400008c7d0 sp=0x1400008c7d0 pc=0x1651952f4
created by runtime.gcBgMarkStartWorkers
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:1159 +0x28
goroutine 51 [GC worker (idle)]:
runtime.gopark(0x1687225c0?, 0x3?, 0x4d?, 0x71?, 0x0?)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:363 +0xe4 fp=0x140001b2f40 sp=0x140001b2f20 pc=0x165164124
runtime.gcBgMarkWorker()
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:1235 +0xec fp=0x140001b2fd0 sp=0x140001b2f40 pc=0x165143d5c
runtime.goexit()
/Users/stanbar/sdk/go1.19.13/src/runtime/asm_arm64.s:1172 +0x4 fp=0x140001b2fd0 sp=0x140001b2fd0 pc=0x1651952f4
created by runtime.gcBgMarkStartWorkers
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:1159 +0x28
goroutine 39 [GC worker (idle)]:
runtime.gopark(0x3a9851c75f9b6?, 0x0?, 0x0?, 0x0?, 0x0?)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:363 +0xe4 fp=0x140001b8740 sp=0x140001b8720 pc=0x165164124
runtime.gcBgMarkWorker()
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:1235 +0xec fp=0x140001b87d0 sp=0x140001b8740 pc=0x165143d5c
runtime.goexit()
/Users/stanbar/sdk/go1.19.13/src/runtime/asm_arm64.s:1172 +0x4 fp=0x140001b87d0 sp=0x140001b87d0 pc=0x1651952f4
created by runtime.gcBgMarkStartWorkers
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:1159 +0x28
goroutine 22 [GC worker (idle)]:
runtime.gopark(0x3a9851c75af01?, 0x0?, 0x0?, 0x0?, 0x0?)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:363 +0xe4 fp=0x14000089740 sp=0x14000089720 pc=0x165164124
runtime.gcBgMarkWorker()
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:1235 +0xec fp=0x140000897d0 sp=0x14000089740 pc=0x165143d5c
runtime.goexit()
/Users/stanbar/sdk/go1.19.13/src/runtime/asm_arm64.s:1172 +0x4 fp=0x140000897d0 sp=0x140000897d0 pc=0x1651952f4
created by runtime.gcBgMarkStartWorkers
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:1159 +0x28
goroutine 52 [GC worker (idle)]:
runtime.gopark(0x1687225c0?, 0x1?, 0xd6?, 0xcf?, 0x0?)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:363 +0xe4 fp=0x140001b3740 sp=0x140001b3720 pc=0x165164124
runtime.gcBgMarkWorker()
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:1235 +0xec fp=0x140001b37d0 sp=0x140001b3740 pc=0x165143d5c
runtime.goexit()
/Users/stanbar/sdk/go1.19.13/src/runtime/asm_arm64.s:1172 +0x4 fp=0x140001b37d0 sp=0x140001b37d0 pc=0x1651952f4
created by runtime.gcBgMarkStartWorkers
/Users/stanbar/sdk/go1.19.13/src/runtime/mgc.go:1159 +0x28
goroutine 23 [select]:
runtime.gopark(0x1400009bf78?, 0x3?, 0xc6?, 0xa5?, 0x1400009bf62?)
/Users/stanbar/sdk/go1.19.13/src/runtime/proc.go:363 +0xe4 fp=0x1400009be10 sp=0x1400009bdf0 pc=0x165164124
runtime.selectgo(0x1400009bf78, 0x1400009bf5c, 0x1400004e380?, 0x0, 0x0?, 0x1)
/Users/stanbar/sdk/go1.19.13/src/runtime/select.go:328 +0x6b4 fp=0x1400009bf20 sp=0x1400009be10 pc=0x165175414
go.opencensus.io/stats/view.(*worker).start(0x1400004e380)
/Users/stanbar/go/pkg/mod/[email protected]/stats/view/worker.go:292 +0x88 fp=0x1400009bfb0 sp=0x1400009bf20 pc=0x165be1248
go.opencensus.io/stats/view.init.0.func1()
/Users/stanbar/go/pkg/mod/[email protected]/stats/view/worker.go:34 +0x28 fp=0x1400009bfd0 sp=0x1400009bfb0 pc=0x165be03e8
runtime.goexit()
/Users/stanbar/sdk/go1.19.13/src/runtime/asm_arm64.s:1172 +0x4 fp=0x1400009bfd0 sp=0x1400009bfd0 pc=0x1651952f4
created by go.opencensus.io/stats/view.init.0
/Users/stanbar/go/pkg/mod/[email protected]/stats/view/worker.go:34 +0xa4
The problem is with macOS (probably only on Apple M1 Pro). The same procedure on Linux machine (x86_64) produces a shared library without any warnings/errors. And invokes the function from NodeJS without any errors.