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: Open panic on darwin/arm64 #63401

Closed
p8a opened this issue Oct 5, 2023 · 2 comments
Closed

plugin: Open panic on darwin/arm64 #63401

p8a opened this issue Oct 5, 2023 · 2 comments
Labels
OS-Darwin WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@p8a
Copy link

p8a commented Oct 5, 2023

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

$ go version
go version go1.21.1 darwin/arm64

Does this issue reproduce with the latest release?

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

> umname -v 
Darwin Kernel Version 22.6.0: Fri Sep 15 13:41:28 PDT 2023; root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T6020

> sw_vers
ProductName:		macOS
ProductVersion:		13.6
BuildVersion:		22G120
go env Output
$ go env
GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/p8a/Library/Caches/go-build'
GOENV='/Users/p8a/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/p8a/data/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/p8a/data/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.21.1/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.21.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.1'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/p8a/data/go/src//go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/_c/lqzcg3tj6s7595p2hzxm4qc40000gq/T/go-build1361766665=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

Loading a plugin that imports any package not in the standard library crashes the host. Plugins using only standard packages work fine.

What did you expect to see?

Clean run (plugin with no imports)

  • Plugin code without any imports
package main

type pluginFactory struct{}

func (p pluginFactory) Setup(cfg map[string]string) (interface{}, error) {
	return nil, nil
}

var PluginFactory pluginFactory
  • Build plugin: go build -buildmode=plugin
  • Host loading plugin :
package main

import (
	"fmt"
	"plugin"
)

type PluginFactory interface {
	Setup(ctx map[string]string) (interface{}, error)
}

func main() {
	pm, err := plugin.Open("./mock_plugin.so")
	if err != nil {
		panic(err)
	}

	pfs, err := pm.Lookup("PluginFactory")
	if err != nil {
		panic(err)
	}

	pf := pfs.(PluginFactory)

	fmt.Print(pf.Setup(nil))
}
  • run the host
> go run module_check.go
# command-line-arguments
ld: warning: -bind_at_load is deprecated on macOS
<nil> <nil>

What did you see instead?

Crash when loading plugin importing any package not in the standard library

  • Plugin code with one import
package main

import (
	"github.com/rs/zerolog/log"
)

type pluginFactory struct{}

func (p pluginFactory) Setup(cfg map[string]string) (interface{}, error) {
	log.Error().Msg("hello")
	return nil, nil
}

var PluginFactory pluginFactory
  • Build plugin: go build -buildmode=plugin
  • Host loading plugin :
package main

import (
	"fmt"
	"plugin"
)

type PluginFactory interface {
	Setup(ctx map[string]string) (interface{}, error)
}

func main() {
	pm, err := plugin.Open("./mock_plugin.so")
	if err != nil {
		panic(err)
	}

	pfs, err := pm.Lookup("PluginFactory")
	if err != nil {
		panic(err)
	}

	pf := pfs.(PluginFactory)

	fmt.Print(pf.Setup(nil))
}
  • run the host

> go run module_check.go
# command-line-arguments
ld: warning: -bind_at_load is deprecated on macOS
unexpected fault address 0xf0f0f0f0f0f0f0f0
fatal error: fault
[signal SIGSEGV: segmentation violation code=0x2 addr=0xf0f0f0f0f0f0f0f0 pc=0x1046fc0d0]

goroutine 1 [running]:
runtime.throw({0x104789067?, 0x1047d7e40?})
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/panic.go:1077 +0x40 fp=0x14000157a50 sp=0x14000157a20 pc=0x1046eaa80
runtime.sigpanic()
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/signal_unix.go:875 +0x22c fp=0x14000157ab0 sp=0x14000157a50 pc=0x10470173c
runtime.doInit1(0x1047cb201?)
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/proc.go:6712 +0x20 fp=0x14000157bf0 sp=0x14000157ac0 pc=0x1046fc0d0
runtime.doInit({0x104898c82, 0x19, 0x14000130000?})
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/proc.go:6707 +0x38 fp=0x14000157c10 sp=0x14000157bf0 pc=0x1046fc068
plugin.open({0x10478dd1f, 0x1f})
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/plugin/plugin_dlopen.go:95 +0x520 fp=0x14000157e90 sp=0x14000157c10 pc=0x1047879d0
plugin.Open(...)
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/plugin/plugin.go:80
main.main()
	/Users/p8a/data/go/src/stuff/test/module_check.go:14 +0x30 fp=0x14000157f30 sp=0x14000157e90 pc=0x104788100
runtime.main()
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/proc.go:267 +0x2bc fp=0x14000157fd0 sp=0x14000157f30 pc=0x1046ee1fc
runtime.goexit()
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/asm_arm64.s:1197 +0x4 fp=0x14000157fd0 sp=0x14000157fd0 pc=0x10471c184

goroutine 2 [force gc (idle)]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/proc.go:398 +0xc8 fp=0x14000050f90 sp=0x14000050f70 pc=0x1046ee628
runtime.goparkunlock(...)
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/proc.go:404
runtime.forcegchelper()
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/proc.go:322 +0xb8 fp=0x14000050fd0 sp=0x14000050f90 pc=0x1046ee4b8
runtime.goexit()
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/asm_arm64.s:1197 +0x4 fp=0x14000050fd0 sp=0x14000050fd0 pc=0x10471c184
created by runtime.init.6 in goroutine 1
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/proc.go:310 +0x24

goroutine 18 [GC sweep wait]:
runtime.gopark(0x0?, 0x0?, 0x0?, 0x0?, 0x0?)
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/proc.go:398 +0xc8 fp=0x1400004c760 sp=0x1400004c740 pc=0x1046ee628
runtime.goparkunlock(...)
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/proc.go:404
runtime.bgsweep(0x0?)
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/mgcsweep.go:280 +0xa0 fp=0x1400004c7b0 sp=0x1400004c760 pc=0x1046d90b0
runtime.gcenable.func1()
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/mgc.go:200 +0x28 fp=0x1400004c7d0 sp=0x1400004c7b0 pc=0x1046cd9e8
runtime.goexit()
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/asm_arm64.s:1197 +0x4 fp=0x1400004c7d0 sp=0x1400004c7d0 pc=0x10471c184
created by runtime.gcenable in goroutine 1
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/mgc.go:200 +0x6c

goroutine 19 [GC scavenge wait]:
runtime.gopark(0x14000096000?, 0x1047b5408?, 0x1?, 0x0?, 0x1400008a4e0?)
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/proc.go:398 +0xc8 fp=0x1400004cf50 sp=0x1400004cf30 pc=0x1046ee628
runtime.goparkunlock(...)
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/proc.go:404
runtime.(*scavengerState).park(0x10489f540)
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/mgcscavenge.go:425 +0x5c fp=0x1400004cf80 sp=0x1400004cf50 pc=0x1046d67bc
runtime.bgscavenge(0x0?)
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/mgcscavenge.go:653 +0x44 fp=0x1400004cfb0 sp=0x1400004cf80 pc=0x1046d6d34
runtime.gcenable.func2()
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/mgc.go:201 +0x28 fp=0x1400004cfd0 sp=0x1400004cfb0 pc=0x1046cd988
runtime.goexit()
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/asm_arm64.s:1197 +0x4 fp=0x1400004cfd0 sp=0x1400004cfd0 pc=0x10471c184
created by runtime.gcenable in goroutine 1
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/mgc.go:201 +0xac

goroutine 34 [finalizer wait]:
runtime.gopark(0x32?, 0x0?, 0xe8?, 0x5?, 0x10472dcbc?)
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/proc.go:398 +0xc8 fp=0x14000050580 sp=0x14000050560 pc=0x1046ee628
runtime.runfinq()
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/mfinal.go:193 +0x108 fp=0x140000507d0 sp=0x14000050580 pc=0x1046ccad8
runtime.goexit()
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/asm_arm64.s:1197 +0x4 fp=0x140000507d0 sp=0x140000507d0 pc=0x10471c184
created by runtime.createfing in goroutine 1
	/opt/homebrew/Cellar/go/1.21.1/libexec/src/runtime/mfinal.go:163 +0x80
exit status 2
@seankhliao seankhliao changed the title plugin.Open panic on darwin/arm64 plugin: Open panic on darwin/arm64 Oct 6, 2023
@cherrymui
Copy link
Member

cherrymui commented Oct 6, 2023

What version of C toolchain are you using? Are you using Xcode 15? Please try Go 1.21.2, which is released yesterday and includes workarounds for bugs in the C linker. Thanks.

@seankhliao seankhliao added OS-Darwin WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. labels Oct 6, 2023
@p8a
Copy link
Author

p8a commented Oct 6, 2023

I am using Xcode 15 and indeed switching to 1.22.2 solved the crash - closing the issue.

@p8a p8a closed this as completed Oct 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-Darwin WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

3 participants