Файловый менеджер - Редактировать - /var/www/html/testplugin.zip
Ðазад
PK ! �a�� � ! altpath/testdata/common/common.gonu �[��� // Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package common var X int func init() { X = 4 } PK ! R�4� � ( altpath/testdata/plugin-mismatch/main.gonu �[��� // Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main // // No C code required. import "C" // The common package imported here does not match the common package // imported by plugin1. A program that attempts to load plugin1 and // plugin-mismatch should produce an error. import "testplugin/common" func ReadCommonX() int { return common.X } PK ! ��U*_2 _2 plugin_test.gonu �[��� // Copyright 2019 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package plugin_test import ( "bytes" "cmd/cgo/internal/cgotest" "context" "flag" "fmt" "internal/platform" "internal/testenv" "log" "os" "os/exec" "path/filepath" "runtime" "strings" "testing" "time" ) var globalSkip = func(t *testing.T) {} var gcflags string = os.Getenv("GO_GCFLAGS") var goroot string func TestMain(m *testing.M) { flag.Parse() log.SetFlags(log.Lshortfile) os.Exit(testMain(m)) } // tmpDir is used to cleanup logged commands -- s/tmpDir/$TMPDIR/ var tmpDir string // prettyPrintf prints lines with tmpDir sanitized. func prettyPrintf(format string, args ...interface{}) { s := fmt.Sprintf(format, args...) if tmpDir != "" { s = strings.ReplaceAll(s, tmpDir, "$TMPDIR") } fmt.Print(s) } func testMain(m *testing.M) int { if testing.Short() && os.Getenv("GO_BUILDER_NAME") == "" { globalSkip = func(t *testing.T) { t.Skip("short mode and $GO_BUILDER_NAME not set") } return m.Run() } if !platform.BuildModeSupported(runtime.Compiler, "plugin", runtime.GOOS, runtime.GOARCH) { globalSkip = func(t *testing.T) { t.Skip("plugin build mode not supported") } return m.Run() } if !testenv.HasCGO() { globalSkip = func(t *testing.T) { t.Skip("cgo not supported") } return m.Run() } cwd, err := os.Getwd() if err != nil { log.Fatal(err) } goroot = filepath.Join(cwd, "../../../../..") // Copy testdata into GOPATH/src/testplugin, along with a go.mod file // declaring the same path. GOPATH, err := os.MkdirTemp("", "plugin_test") if err != nil { log.Panic(err) } defer os.RemoveAll(GOPATH) tmpDir = GOPATH fmt.Printf("TMPDIR=%s\n", tmpDir) modRoot := filepath.Join(GOPATH, "src", "testplugin") altRoot := filepath.Join(GOPATH, "alt", "src", "testplugin") for srcRoot, dstRoot := range map[string]string{ "testdata": modRoot, filepath.Join("altpath", "testdata"): altRoot, } { if err := cgotest.OverlayDir(dstRoot, srcRoot); err != nil { log.Panic(err) } prettyPrintf("mkdir -p %s\n", dstRoot) prettyPrintf("rsync -a %s/ %s\n", srcRoot, dstRoot) if err := os.WriteFile(filepath.Join(dstRoot, "go.mod"), []byte("module testplugin\n"), 0666); err != nil { log.Panic(err) } prettyPrintf("echo 'module testplugin' > %s/go.mod\n", dstRoot) } os.Setenv("GOPATH", filepath.Join(GOPATH, "alt")) if err := os.Chdir(altRoot); err != nil { log.Panic(err) } else { prettyPrintf("cd %s\n", altRoot) } os.Setenv("PWD", altRoot) goCmd(nil, "build", "-buildmode=plugin", "-o", filepath.Join(modRoot, "plugin-mismatch.so"), "./plugin-mismatch") os.Setenv("GOPATH", GOPATH) if err := os.Chdir(modRoot); err != nil { log.Panic(err) } else { prettyPrintf("cd %s\n", modRoot) } os.Setenv("PWD", modRoot) os.Setenv("LD_LIBRARY_PATH", modRoot) goCmd(nil, "build", "-buildmode=plugin", "./plugin1") goCmd(nil, "build", "-buildmode=plugin", "./plugin2") so, err := os.ReadFile("plugin2.so") if err != nil { log.Panic(err) } if err := os.WriteFile("plugin2-dup.so", so, 0444); err != nil { log.Panic(err) } prettyPrintf("cp plugin2.so plugin2-dup.so\n") goCmd(nil, "build", "-buildmode=plugin", "-o=sub/plugin1.so", "./sub/plugin1") goCmd(nil, "build", "-buildmode=plugin", "-o=unnamed1.so", "./unnamed1/main.go") goCmd(nil, "build", "-buildmode=plugin", "-o=unnamed2.so", "./unnamed2/main.go") goCmd(nil, "build", "-o", "host.exe", "./host") return m.Run() } func goCmd(t *testing.T, op string, args ...string) string { if t != nil { t.Helper() } var flags []string if op != "tool" { flags = []string{"-gcflags", gcflags} } return run(t, filepath.Join(goroot, "bin", "go"), append(append([]string{op}, flags...), args...)...) } // escape converts a string to something suitable for a shell command line. func escape(s string) string { s = strings.Replace(s, "\\", "\\\\", -1) s = strings.Replace(s, "'", "\\'", -1) // Conservative guess at characters that will force quoting if s == "" || strings.ContainsAny(s, "\\ ;#*&$~?!|[]()<>{}`") { s = "'" + s + "'" } return s } // asCommandLine renders cmd as something that could be copy-and-pasted into a command line func asCommandLine(cwd string, cmd *exec.Cmd) string { s := "(" if cmd.Dir != "" && cmd.Dir != cwd { s += "cd" + escape(cmd.Dir) + ";" } for _, e := range cmd.Env { if !strings.HasPrefix(e, "PATH=") && !strings.HasPrefix(e, "HOME=") && !strings.HasPrefix(e, "USER=") && !strings.HasPrefix(e, "SHELL=") { s += " " s += escape(e) } } // These EVs are relevant to this test. for _, e := range os.Environ() { if strings.HasPrefix(e, "PWD=") || strings.HasPrefix(e, "GOPATH=") || strings.HasPrefix(e, "LD_LIBRARY_PATH=") { s += " " s += escape(e) } } for _, a := range cmd.Args { s += " " s += escape(a) } s += " )" return s } func run(t *testing.T, bin string, args ...string) string { cmd := exec.Command(bin, args...) cmdLine := asCommandLine(".", cmd) prettyPrintf("%s\n", cmdLine) cmd.Stderr = new(strings.Builder) out, err := cmd.Output() if err != nil { if t == nil { log.Panicf("%s: %v\n%s", strings.Join(cmd.Args, " "), err, cmd.Stderr) } else { t.Helper() t.Fatalf("%s: %v\n%s", strings.Join(cmd.Args, " "), err, cmd.Stderr) } } return string(bytes.TrimSpace(out)) } func TestDWARFSections(t *testing.T) { // test that DWARF sections are emitted for plugins and programs importing "plugin" globalSkip(t) goCmd(t, "run", "./checkdwarf/main.go", "plugin2.so", "plugin2.UnexportedNameReuse") goCmd(t, "run", "./checkdwarf/main.go", "./host.exe", "main.main") } func TestBuildID(t *testing.T) { // check that plugin has build ID. globalSkip(t) b := goCmd(t, "tool", "buildid", "plugin1.so") if len(b) == 0 { t.Errorf("build id not found") } } func TestRunHost(t *testing.T) { globalSkip(t) run(t, "./host.exe") } func TestUniqueTypesAndItabs(t *testing.T) { globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "./iface_a") goCmd(t, "build", "-buildmode=plugin", "./iface_b") goCmd(t, "build", "-o", "iface.exe", "./iface") run(t, "./iface.exe") } func TestIssue18676(t *testing.T) { // make sure we don't add the same itab twice. // The buggy code hangs forever, so use a timeout to check for that. globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "plugin.so", "./issue18676/plugin.go") goCmd(t, "build", "-o", "issue18676.exe", "./issue18676/main.go") ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() cmd := exec.CommandContext(ctx, "./issue18676.exe") out, err := cmd.CombinedOutput() if err != nil { t.Fatalf("%s: %v\n%s", strings.Join(cmd.Args, " "), err, out) } } func TestIssue19534(t *testing.T) { // Test that we can load a plugin built in a path with non-alpha characters. globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-gcflags=-p=issue.19534", "-ldflags=-pluginpath=issue.19534", "-o", "plugin.so", "./issue19534/plugin.go") goCmd(t, "build", "-o", "issue19534.exe", "./issue19534/main.go") run(t, "./issue19534.exe") } func TestIssue18584(t *testing.T) { globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "plugin.so", "./issue18584/plugin.go") goCmd(t, "build", "-o", "issue18584.exe", "./issue18584/main.go") run(t, "./issue18584.exe") } func TestIssue19418(t *testing.T) { globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-ldflags=-X main.Val=linkstr", "-o", "plugin.so", "./issue19418/plugin.go") goCmd(t, "build", "-o", "issue19418.exe", "./issue19418/main.go") run(t, "./issue19418.exe") } func TestIssue19529(t *testing.T) { globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "plugin.so", "./issue19529/plugin.go") } func TestIssue22175(t *testing.T) { globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "issue22175_plugin1.so", "./issue22175/plugin1.go") goCmd(t, "build", "-buildmode=plugin", "-o", "issue22175_plugin2.so", "./issue22175/plugin2.go") goCmd(t, "build", "-o", "issue22175.exe", "./issue22175/main.go") run(t, "./issue22175.exe") } func TestIssue22295(t *testing.T) { globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "issue.22295.so", "./issue22295.pkg") goCmd(t, "build", "-o", "issue22295.exe", "./issue22295.pkg/main.go") run(t, "./issue22295.exe") } func TestIssue24351(t *testing.T) { globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "issue24351.so", "./issue24351/plugin.go") goCmd(t, "build", "-o", "issue24351.exe", "./issue24351/main.go") run(t, "./issue24351.exe") } func TestIssue25756(t *testing.T) { globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "life.so", "./issue25756/plugin") goCmd(t, "build", "-o", "issue25756.exe", "./issue25756/main.go") // Fails intermittently, but 20 runs should cause the failure for n := 20; n > 0; n-- { t.Run(fmt.Sprint(n), func(t *testing.T) { t.Parallel() run(t, "./issue25756.exe") }) } } // Test with main using -buildmode=pie with plugin for issue #43228 func TestIssue25756pie(t *testing.T) { globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "life.so", "./issue25756/plugin") goCmd(t, "build", "-buildmode=pie", "-o", "issue25756pie.exe", "./issue25756/main.go") run(t, "./issue25756pie.exe") } func TestMethod(t *testing.T) { // Exported symbol's method must be live. globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "plugin.so", "./method/plugin.go") goCmd(t, "build", "-o", "method.exe", "./method/main.go") run(t, "./method.exe") } func TestMethod2(t *testing.T) { globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "method2.so", "./method2/plugin.go") goCmd(t, "build", "-o", "method2.exe", "./method2/main.go") run(t, "./method2.exe") } func TestMethod3(t *testing.T) { globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "method3.so", "./method3/plugin.go") goCmd(t, "build", "-o", "method3.exe", "./method3/main.go") run(t, "./method3.exe") } func TestIssue44956(t *testing.T) { globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "issue44956p1.so", "./issue44956/plugin1.go") goCmd(t, "build", "-buildmode=plugin", "-o", "issue44956p2.so", "./issue44956/plugin2.go") goCmd(t, "build", "-o", "issue44956.exe", "./issue44956/main.go") run(t, "./issue44956.exe") } func TestIssue52937(t *testing.T) { globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "issue52937.so", "./issue52937/main.go") } func TestIssue53989(t *testing.T) { globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "issue53989.so", "./issue53989/plugin.go") goCmd(t, "build", "-o", "issue53989.exe", "./issue53989/main.go") run(t, "./issue53989.exe") } func TestForkExec(t *testing.T) { // Issue 38824: importing the plugin package causes it hang in forkExec on darwin. globalSkip(t) t.Parallel() goCmd(t, "build", "-o", "forkexec.exe", "./forkexec/main.go") for i := 0; i < 100; i++ { cmd := testenv.Command(t, "./forkexec.exe", "1") err := cmd.Run() if err != nil { if ee, ok := err.(*exec.ExitError); ok && len(ee.Stderr) > 0 { t.Logf("stderr:\n%s", ee.Stderr) } t.Errorf("running command failed: %v", err) break } } } func TestSymbolNameMangle(t *testing.T) { // Issue 58800: generic function name may contain weird characters // that confuse the external linker. // Issue 62098: the name mangling code doesn't handle some string // symbols correctly. globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "mangle.so", "./mangle/plugin.go") } func TestIssue62430(t *testing.T) { globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "issue62430.so", "./issue62430/plugin.go") goCmd(t, "build", "-o", "issue62430.exe", "./issue62430/main.go") run(t, "./issue62430.exe") } func TestTextSectionSplit(t *testing.T) { globalSkip(t) if runtime.GOOS != "darwin" || runtime.GOARCH != "arm64" { t.Skipf("text section splitting is not done in %s/%s", runtime.GOOS, runtime.GOARCH) } // Use -ldflags=-debugtextsize=262144 to let the linker split text section // at a smaller size threshold, so it actually splits for the test binary. goCmd(nil, "build", "-ldflags=-debugtextsize=262144", "-o", "host-split.exe", "./host") run(t, "./host-split.exe") // Check that we did split text sections. syms := goCmd(nil, "tool", "nm", "host-split.exe") if !strings.Contains(syms, "runtime.text.1") { t.Errorf("runtime.text.1 not found, text section not split?") } } func TestIssue67976(t *testing.T) { // Issue 67976: build failure with loading a dynimport variable (the runtime/pprof // package does this on darwin) in a plugin on darwin/amd64. // The test program uses runtime/pprof in a plugin. globalSkip(t) goCmd(t, "build", "-buildmode=plugin", "-o", "issue67976.so", "./issue67976/plugin.go") } PK ! ��՛ � testdata/issue19534/main.gonu �[��� // Copyright 2017 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import "plugin" func main() { p, err := plugin.Open("plugin.so") if err != nil { panic(err) } sym, err := p.Lookup("Foo") if err != nil { panic(err) } f := sym.(func() int) if f() != 42 { panic("expected f() == 42") } } PK ! oitI� � testdata/issue19534/plugin.gonu �[��� // Copyright 2017 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main func Foo() int { return 42 } PK ! �r�n n testdata/unnamed2/main.gonu �[��� // Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build ignore package main // // No C code required. import "C" func FuncInt() int { return 2 } func FuncRecursive() X { return X{} } type Y struct { X *X } type X struct { Y Y } func main() {} PK ! C��� � testdata/host/host.gonu �[��� // Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "fmt" "log" "path/filepath" "plugin" "strings" "testplugin/common" ) func init() { common.X *= 5 } // testUnnamed tests that two plugins built with .go files passed on // the command line do not have overlapping symbols. That is, // unnamed1.so/FuncInt and unnamed2.so/FuncInt should be distinct functions. func testUnnamed() { p, err := plugin.Open("unnamed1.so") if err != nil { log.Fatalf(`plugin.Open("unnamed1.so"): %v`, err) } fn, err := p.Lookup("FuncInt") if err != nil { log.Fatalf(`unnamed1.so: Lookup("FuncInt") failed: %v`, err) } if got, want := fn.(func() int)(), 1; got != want { log.Fatalf("unnamed1.so: FuncInt()=%d, want %d", got, want) } p, err = plugin.Open("unnamed2.so") if err != nil { log.Fatalf(`plugin.Open("unnamed2.so"): %v`, err) } fn, err = p.Lookup("FuncInt") if err != nil { log.Fatalf(`unnamed2.so: Lookup("FuncInt") failed: %v`, err) } if got, want := fn.(func() int)(), 2; got != want { log.Fatalf("unnamed2.so: FuncInt()=%d, want %d", got, want) } } func main() { if got, want := common.X, 3*5; got != want { log.Fatalf("before plugin load common.X=%d, want %d", got, want) } p, err := plugin.Open("plugin1.so") if err != nil { log.Fatalf("plugin.Open failed: %v", err) } const wantX = 3 * 5 * 7 if got := common.X; got != wantX { log.Fatalf("after plugin load common.X=%d, want %d", got, wantX) } seven, err := p.Lookup("Seven") if err != nil { log.Fatalf(`Lookup("Seven") failed: %v`, err) } if got, want := *seven.(*int), 7; got != want { log.Fatalf("plugin1.Seven=%d, want %d", got, want) } readFunc, err := p.Lookup("ReadCommonX") if err != nil { log.Fatalf(`plugin1.Lookup("ReadCommonX") failed: %v`, err) } if got := readFunc.(func() int)(); got != wantX { log.Fatalf("plugin1.ReadCommonX()=%d, want %d", got, wantX) } // sub/plugin1.so is a different plugin with the same name as // the already loaded plugin. It also depends on common. Test // that we can load the different plugin, it is actually // different, and that it sees the same common package. subpPath, err := filepath.Abs("sub/plugin1.so") if err != nil { log.Fatalf("filepath.Abs(%q) failed: %v", subpPath, err) } subp, err := plugin.Open(subpPath) if err != nil { log.Fatalf("plugin.Open(%q) failed: %v", subpPath, err) } funcVar, err := subp.Lookup("FuncVar") if err != nil { log.Fatalf(`sub/plugin1.Lookup("FuncVar") failed: %v`, err) } called := false *funcVar.(*func()) = func() { called = true } readFunc, err = subp.Lookup("ReadCommonX") if err != nil { log.Fatalf(`sub/plugin1.Lookup("ReadCommonX") failed: %v`, err) } if got := readFunc.(func() int)(); got != wantX { log.Fatalf("sub/plugin1.ReadCommonX()=%d, want %d", got, wantX) } if !called { log.Fatal("calling ReadCommonX did not call FuncVar") } subf, err := subp.Lookup("F") if err != nil { log.Fatalf(`sub/plugin1.Lookup("F") failed: %v`, err) } if gotf := subf.(func() int)(); gotf != 17 { log.Fatalf(`sub/plugin1.F()=%d, want 17`, gotf) } f, err := p.Lookup("F") if err != nil { log.Fatalf(`plugin1.Lookup("F") failed: %v`, err) } if gotf := f.(func() int)(); gotf != 3 { log.Fatalf(`plugin1.F()=%d, want 17`, gotf) } p2, err := plugin.Open("plugin2.so") if err != nil { log.Fatalf("plugin.Open failed: %v", err) } // Check that plugin2's init function was called, and // that it modifies the same global variable as the host. if got, want := common.X, 2; got != want { log.Fatalf("after loading plugin2, common.X=%d, want %d", got, want) } _, err = plugin.Open("plugin2-dup.so") if err == nil { log.Fatal(`plugin.Open("plugin2-dup.so"): duplicate open should have failed`) } if s := err.Error(); !strings.Contains(s, "already loaded") { log.Fatal(`plugin.Open("plugin2.so"): error does not mention "already loaded"`) } _, err = plugin.Open("plugin-mismatch.so") if err == nil { log.Fatal(`plugin.Open("plugin-mismatch.so"): should have failed`) } if s := err.Error(); !strings.Contains(s, "different version") { log.Fatalf(`plugin.Open("plugin-mismatch.so"): error does not mention "different version": %v`, s) } _, err = plugin.Open("plugin2-dup.so") if err == nil { log.Fatal(`plugin.Open("plugin2-dup.so"): duplicate open after bad plugin should have failed`) } _, err = plugin.Open("plugin2.so") if err != nil { log.Fatalf(`plugin.Open("plugin2.so"): second open with same name failed: %v`, err) } // Test that unexported types with the same names in // different plugins do not interfere with each other. // // See Issue #21386. UnexportedNameReuse, _ := p.Lookup("UnexportedNameReuse") UnexportedNameReuse.(func())() UnexportedNameReuse, _ = p2.Lookup("UnexportedNameReuse") UnexportedNameReuse.(func())() testUnnamed() fmt.Println("PASS") } PK ! �H testdata/iface/main.gonu �[��� // Copyright 2017 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "log" "plugin" "testplugin/iface_i" ) func main() { a, err := plugin.Open("iface_a.so") if err != nil { log.Fatalf(`plugin.Open("iface_a.so"): %v`, err) } b, err := plugin.Open("iface_b.so") if err != nil { log.Fatalf(`plugin.Open("iface_b.so"): %v`, err) } af, err := a.Lookup("F") if err != nil { log.Fatalf(`a.Lookup("F") failed: %v`, err) } bf, err := b.Lookup("F") if err != nil { log.Fatalf(`b.Lookup("F") failed: %v`, err) } if af.(func() interface{})() != bf.(func() interface{})() { panic("empty interfaces not equal") } ag, err := a.Lookup("G") if err != nil { log.Fatalf(`a.Lookup("G") failed: %v`, err) } bg, err := b.Lookup("G") if err != nil { log.Fatalf(`b.Lookup("G") failed: %v`, err) } if ag.(func() iface_i.I)() != bg.(func() iface_i.I)() { panic("nonempty interfaces not equal") } } PK ! �o�Z 4 testdata/issue18676/dynamodbstreamsevt/definition.gonu �[��� // Copyright 2017 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package dynamodbstreamsevt import "encoding/json" var foo json.RawMessage type Event struct{} func (e *Event) Dummy() {} PK ! TP߇� � testdata/issue18676/main.gonu �[��� // Copyright 2017 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // The bug happened like this: // 1. The main binary adds an itab for *json.UnsupportedValueError / error // (concrete type / interface type). This itab goes in hash bucket 0x111. // 2. The plugin adds that same itab again. That makes a cycle in the itab // chain rooted at hash bucket 0x111. // 3. The main binary then asks for the itab for *dynamodbstreamsevt.Event / // json.Unmarshaler. This itab happens to also live in bucket 0x111. // The lookup code goes into an infinite loop searching for this itab. // // The code is carefully crafted so that the two itabs are both from the // same bucket, and so that the second itab doesn't exist in // the itab hashmap yet (so the entire linked list must be searched). package main import ( "encoding/json" "plugin" "testplugin/issue18676/dynamodbstreamsevt" ) func main() { plugin.Open("plugin.so") var x interface{} = (*dynamodbstreamsevt.Event)(nil) if _, ok := x.(json.Unmarshaler); !ok { println("something") } } PK ! �g[� testdata/issue18676/plugin.gonu �[��� // Copyright 2017 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import "C" import "testplugin/issue18676/dynamodbstreamsevt" func F(evt *dynamodbstreamsevt.Event) {} PK ! _�/� � testdata/issue22295.pkg/main.gonu �[��� // Copyright 2017 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build ignore package main import ( "log" "plugin" ) func main() { p, err := plugin.Open("issue.22295.so") if err != nil { log.Fatal(err) } f, err := p.Lookup("F") if err != nil { log.Fatal(err) } const want = 2503 got := f.(func() int)() if got != want { log.Fatalf("got %d, want %d", got, want) } } PK ! �-ը ! testdata/issue22295.pkg/plugin.gonu �[��� // Copyright 2017 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main var f *int func init() { f = new(int) *f = 2503 } func F() int { return *f } func main() {} PK ! �&|ը � testdata/issue18584/main.gonu �[��� // Copyright 2017 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import "plugin" func main() { p, err := plugin.Open("plugin.so") if err != nil { panic(err) } sym, err := p.Lookup("G") if err != nil { panic(err) } g := sym.(func() bool) if !g() { panic("expected types to match, Issue #18584") } } PK ! ��ZF F testdata/issue18584/plugin.gonu �[��� // Copyright 2017 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import "reflect" type C struct { } func F(c *C) *C { return nil } func G() bool { var c *C return reflect.TypeOf(F).Out(0) == reflect.TypeOf(c) } PK ! �+ƣ� � testdata/issue22175/plugin1.gonu �[��� // Copyright 2017 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import "plugin" func F() int { p2, err := plugin.Open("issue22175_plugin2.so") if err != nil { panic(err) } g, err := p2.Lookup("G") if err != nil { panic(err) } return g.(func() int)() } func main() {} PK ! �h��� � testdata/issue22175/plugin2.gonu �[��� // Copyright 2017 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main func G() int { return 971 } func main() {} PK ! &]�h� � testdata/issue22175/main.gonu �[��� // Copyright 2017 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "fmt" "os" "plugin" ) func main() { p2, err := plugin.Open("issue22175_plugin1.so") if err != nil { panic(err) } f, err := p2.Lookup("F") if err != nil { panic(err) } got := f.(func() int)() const want = 971 if got != want { fmt.Fprintf(os.Stderr, "issue22175: F()=%d, want %d", got, want) os.Exit(1) } } PK ! 9V�4 4 testdata/plugin1/plugin1.gonu �[��� // Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main // // No C code required. import "C" import ( "reflect" "testplugin/common" ) func F() int { _ = make([]byte, 1<<21) // trigger stack unwind, Issue #18190. return 3 } func ReadCommonX() int { return common.X } var Seven int func call(fn func()) { fn() } func g() { common.X *= Seven } func init() { Seven = 7 call(g) } type sameNameReusedInPlugins struct { X string } type sameNameHolder struct { F *sameNameReusedInPlugins } func UnexportedNameReuse() { h := sameNameHolder{} v := reflect.ValueOf(&h).Elem().Field(0) newval := reflect.New(v.Type().Elem()) v.Set(newval) } func main() { panic("plugin1.main called") } PK ! �e��: : testdata/issue53989/p/p.gonu �[��� // Copyright 2022 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package p import ( "fmt" "runtime" ) var y int //go:noinline func Square(x int) { var pc0, pc1 [1]uintptr runtime.Callers(1, pc0[:]) // get PC at entry // a switch using jump table switch x { case 1: y = 1 case 2: y = 4 case 3: y = 9 case 4: y = 16 case 5: y = 25 case 6: y = 36 case 7: y = 49 case 8: y = 64 default: panic("too large") } // check PC is in the same function runtime.Callers(1, pc1[:]) if pc1[0] < pc0[0] || pc1[0] > pc0[0]+1000000 { fmt.Printf("jump across DSO boundary. pc0=%x, pc1=%x\n", pc0[0], pc1[0]) panic("FAIL") } if y != x*x { fmt.Printf("x=%d y=%d!=%d\n", x, y, x*x) panic("FAIL") } } PK ! �ǭ�� � testdata/issue53989/main.gonu �[��� // Copyright 2022 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Issue 53989: the use of jump table caused a function // from the plugin jumps in the middle of the function // to the function with the same name in the main // executable. As these two functions may be compiled // differently as plugin needs to be PIC, this causes // crash. package main import ( "plugin" "testplugin/issue53989/p" ) func main() { p.Square(7) // call the function in main executable p, err := plugin.Open("issue53989.so") if err != nil { panic(err) } f, err := p.Lookup("Square") if err != nil { panic(err) } f.(func(int))(7) // call the plugin one } PK ! ��]� testdata/issue53989/plugin.gonu �[��� // Copyright 2022 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import "testplugin/issue53989/p" func Square(x int) { // export Square for plugin p.Square(x) } func main() {} PK ! b� � testdata/issue44956/plugin1.gonu �[��� // Copyright 2021 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import _ "testplugin/issue44956/base" func main() {} PK ! �춉 testdata/issue44956/plugin2.gonu �[��� // Copyright 2021 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import "testplugin/issue44956/base" func F() *map[int]int { return base.X } func main() {} PK ! D 2�� � testdata/issue44956/base/base.gonu �[��� // Copyright 2021 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package base var X = &map[int]int{123: 456} PK ! Ob� � testdata/issue44956/main.gonu �[��� // Copyright 2021 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Issue 44956: writable static temp is not exported correctly. // In the test below, package base is // // X = &map{...} // // which compiles to // // X = &stmp // static // stmp = makemap(...) // in init function // // plugin1 and plugin2 both import base. plugin1 doesn't use // base.X, so that symbol is deadcoded in plugin1. // // plugin1 is loaded first. base.init runs at that point, which // initialize base.stmp. // // plugin2 is then loaded. base.init already ran, so it doesn't run // again. When base.stmp is not exported, plugin2's base.X points to // its own private base.stmp, which is not initialized, fail. package main import "plugin" func main() { _, err := plugin.Open("issue44956p1.so") if err != nil { panic("FAIL") } p2, err := plugin.Open("issue44956p2.so") if err != nil { panic("FAIL") } f, err := p2.Lookup("F") if err != nil { panic("FAIL") } x := f.(func() *map[int]int)() if x == nil || (*x)[123] != 456 { panic("FAIL") } } PK ! _��� � testdata/common/common.gonu �[��� // Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package common var X int func init() { X = 3 } PK ! ނ% testdata/issue67976/plugin.gonu �[��� // Copyright 2024 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "io" "runtime/pprof" ) func main() {} func Start() { pprof.StartCPUProfile(io.Discard) } PK ! z�7k� � testdata/method/main.gonu �[��� // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Issue 42579: methods of symbols exported from plugin must be live. package main import ( "plugin" "reflect" ) func main() { p, err := plugin.Open("plugin.so") if err != nil { panic(err) } x, err := p.Lookup("X") if err != nil { panic(err) } reflect.ValueOf(x).Elem().MethodByName("M").Call(nil) } PK ! v�Q� � testdata/method/plugin.gonu �[��� // Copyright 2020 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main func main() {} type T int func (T) M() { println("M") } var X T PK ! N���� � testdata/issue52937/main.gonu �[��� // Copyright 2022 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main func main() {} func F[T any]() {} func G[T any](T) {} PK ! 1C��� � testdata/unnamed1/main.gonu �[��� // Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build ignore package main // // No C code required. import "C" func FuncInt() int { return 1 } // Add a recursive type to check that type equality across plugins doesn't // crash. See https://golang.org/issues/19258 func FuncRecursive() X { return X{} } type Y struct { X *X } type X struct { Y Y } func main() {} PK ! �4�x� � testdata/mangle/plugin.gonu �[��� // Copyright 2023 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Test cases for symbol name mangling. package main import ( "fmt" "strings" ) // Issue 58800: // Instantiated function name may contain weird characters // that confuse the external linker, so it needs to be // mangled. type S struct { X int `parser:"|@@)"` } //go:noinline func F[T any]() {} func P() { F[S]() } // Issue 62098: the name mangling code doesn't handle some string // symbols correctly. func G(id string) error { if strings.ContainsAny(id, "&$@;/:+,?\\{^}%`]\">[~<#|") { return fmt.Errorf("invalid") } return nil } func main() {} PK ! �^�v$ $ ! testdata/issue25756/plugin/life.hnu �[��� // Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. extern void Step(int, int, int *, int *); extern void DoStep(int, int, int, int, int, int, int *, int *); extern const int MYCONST; PK ! Պ�ly y "