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

plugin: darwin support is still fragile #23369

Closed
hirochachacha opened this issue Jan 8, 2018 · 3 comments
Closed

plugin: darwin support is still fragile #23369

hirochachacha opened this issue Jan 8, 2018 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@hirochachacha
Copy link
Contributor

Please answer these questions before submitting your issue. Thanks!

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.

a.go

package main

func F() {
	b := make([]byte, 10000)
	_ = b
}

z.go

package main

import "plugin"

type A struct {
	a string
}

func NewA() *A {
	return &A{a: "a"}
}

func (a *A) Lookup() (plugin.Symbol, error) {
	so, err := plugin.Open("a.so")
	if err != nil {
		return nil, err
	}
	return so.Lookup("F")
}

func main() {
	a := NewA()

	sym, err := a.Lookup()
	if err != nil {
		panic(err)
	}

	(sym.(func()))()
}

Then,

$ go build -buildmode=plugin a.go
$ go run z.go

What did you expect to see?

no errors.

What did you see instead?

runtime: bad pointer in frame main.main at 0xc4200a5f70: 0x1
fatal error: invalid pointer found on stack

runtime stack:
runtime.throw(0x44625c6, 0x1e)
	/Users/hiro/go/src/runtime/panic.go:616 +0x81 fp=0x7ffeefbfef10 sp=0x7ffeefbfeef0 pc=0x441df81
runtime.adjustpointers(0xc4200a5f70, 0x7ffeefbff008, 0x7ffeefbff3b8, 0x40b4c48, 0x40b6a40)
	/Users/hiro/go/src/runtime/stack.go:592 +0x23e fp=0x7ffeefbfef80 sp=0x7ffeefbfef10 pc=0x443061e
runtime.adjustframe(0x7ffeefbff2c8, 0x7ffeefbff3b8, 0x40b6a40)
	/Users/hiro/go/src/runtime/stack.go:663 +0x32c fp=0x7ffeefbff038 sp=0x7ffeefbfef80 pc=0x443096c
runtime.gentraceback(0xffffffffffffffff, 0xffffffffffffffff, 0x0, 0xc420000180, 0x0, 0x0, 0x7fffffff, 0x4463e68, 0x7ffeefbff3b8, 0x0, ...)
	/Users/hiro/go/src/runtime/traceback.go:339 +0x1334 fp=0x7ffeefbff330 sp=0x7ffeefbff038 pc=0x44372a4
runtime.copystack(0xc420000180, 0x4000, 0x7ffeefbff501)
	/Users/hiro/go/src/runtime/stack.go:891 +0x26e fp=0x7ffeefbff4e8 sp=0x7ffeefbff330 pc=0x443145e
runtime.newstack()
	/Users/hiro/go/src/runtime/stack.go:1063 +0x310 fp=0x7ffeefbff678 sp=0x7ffeefbff4e8 pc=0x4431870
runtime.morestack()
	/Users/hiro/go/src/runtime/asm_amd64.s:480 +0x89 fp=0x7ffeefbff680 sp=0x7ffeefbff678 pc=0x443c6d9

goroutine 1 [copystack]:
plugin/unnamed-a6bc9850fd4dfe51568f68acc0d0e4139a9ff822.F()
	/Users/hiro/a.go:3 +0x63 fp=0xc4200a5f40 sp=0xc4200a5f38 pc=0x44436a3
main.main()
	/Users/hiro/z.go:29 +0x7a fp=0xc4200a5f88 sp=0xc4200a5f40 pc=0x40554ba
runtime.main()
	/Users/hiro/go/src/runtime/proc.go:198 +0x212 fp=0xc4200a5fe0 sp=0xc4200a5f88 pc=0x4028582
runtime.goexit()
	/Users/hiro/go/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc4200a5fe8 sp=0xc4200a5fe0 pc=0x404c3e1

goroutine 2 [force gc (idle)]:
runtime.gopark(0x407b828, 0x40b8cb0, 0x40773e6, 0xf, 0x407b714, 0x1)
	/Users/hiro/go/src/runtime/proc.go:291 +0x11a fp=0xc420036768 sp=0xc420036748 pc=0x40289ca
runtime.goparkunlock(0x40b8cb0, 0x40773e6, 0xf, 0x14, 0x1)
	/Users/hiro/go/src/runtime/proc.go:297 +0x5e fp=0xc4200367a8 sp=0xc420036768 pc=0x4028a7e
runtime.forcegchelper()
	/Users/hiro/go/src/runtime/proc.go:248 +0xcc fp=0xc4200367e0 sp=0xc4200367a8 pc=0x402880c
runtime.goexit()
	/Users/hiro/go/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc4200367e8 sp=0xc4200367e0 pc=0x404c3e1
created by runtime.init.4
	/Users/hiro/go/src/runtime/proc.go:237 +0x35

goroutine 3 [GC sweep wait]:
runtime.gopark(0x407b828, 0x40b8da0, 0x40770e3, 0xd, 0x401c714, 0x1)
	/Users/hiro/go/src/runtime/proc.go:291 +0x11a fp=0xc420036f60 sp=0xc420036f40 pc=0x40289ca
runtime.goparkunlock(0x40b8da0, 0x40770e3, 0xd, 0x14, 0x1)
	/Users/hiro/go/src/runtime/proc.go:297 +0x5e fp=0xc420036fa0 sp=0xc420036f60 pc=0x4028a7e
runtime.bgsweep(0xc420020070)
	/Users/hiro/go/src/runtime/mgcsweep.go:52 +0xa3 fp=0xc420036fd8 sp=0xc420036fa0 pc=0x401c813
runtime.goexit()
	/Users/hiro/go/src/runtime/asm_amd64.s:2361 +0x1 fp=0xc420036fe0 sp=0xc420036fd8 pc=0x404c3e1
created by runtime.gcenable
	/Users/hiro/go/src/runtime/mgc.go:216 +0x58
exit status 2

Does this issue reproduce with the latest release (go1.9.2)?

System details

go version devel +46850212af Sat Jan 6 18:23:45 2018 +0900 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hiro/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hiro/.go"
GORACE=""
GOROOT="/Users/hiro/go"
GOTMPDIR=""
GOTOOLDIR="/Users/hiro/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/wq/dwn8hs0x7njbzty9f68y61700000gn/T/go-build520323770=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version devel +46850212af Sat Jan 6 18:23:45 2018 +0900 darwin/amd64
GOROOT/bin/go tool compile -V: compile version devel +46850212af Sat Jan 6 18:23:45 2018 +0900
uname -v: Darwin Kernel Version 17.3.0: Thu Nov  9 18:09:22 PST 2017; root:xnu-4570.31.3~1/RELEASE_X86_64
ProductName:	Mac OS X
ProductVersion:	10.13.2
BuildVersion:	17C88
lldb --version: lldb-900.0.64
  Swift-4.0
gdb --version: GNU gdb (GDB) 8.0.1
@hirochachacha
Copy link
Contributor Author

Fixed by 08304e8

@akamensky
Copy link

Works on the tip, but will it be cherry-picked to 1.10.2? Currently impossible to to debug plugins that are meant for Linux on macOS.

@randall77
Copy link
Contributor

I've started the backport to 1.9 and 1.10.
Issues #26202 and #26203

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants