diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-16 19:23:18 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-16 19:23:18 +0000 |
commit | 43a123c1ae6613b3efeed291fa552ecd909d3acf (patch) | |
tree | fd92518b7024bc74031f78a1cf9e454b65e73665 /misc/cgo/testplugin/testdata/issue53989 | |
parent | Initial commit. (diff) | |
download | golang-1.20-43a123c1ae6613b3efeed291fa552ecd909d3acf.tar.xz golang-1.20-43a123c1ae6613b3efeed291fa552ecd909d3acf.zip |
Adding upstream version 1.20.14.upstream/1.20.14upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'misc/cgo/testplugin/testdata/issue53989')
-rw-r--r-- | misc/cgo/testplugin/testdata/issue53989/main.go | 32 | ||||
-rw-r--r-- | misc/cgo/testplugin/testdata/issue53989/p/p.go | 52 | ||||
-rw-r--r-- | misc/cgo/testplugin/testdata/issue53989/plugin.go | 13 |
3 files changed, 97 insertions, 0 deletions
diff --git a/misc/cgo/testplugin/testdata/issue53989/main.go b/misc/cgo/testplugin/testdata/issue53989/main.go new file mode 100644 index 0000000..6907dfd --- /dev/null +++ b/misc/cgo/testplugin/testdata/issue53989/main.go @@ -0,0 +1,32 @@ +// 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 +} diff --git a/misc/cgo/testplugin/testdata/issue53989/p/p.go b/misc/cgo/testplugin/testdata/issue53989/p/p.go new file mode 100644 index 0000000..02567c1 --- /dev/null +++ b/misc/cgo/testplugin/testdata/issue53989/p/p.go @@ -0,0 +1,52 @@ +// 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") + } +} diff --git a/misc/cgo/testplugin/testdata/issue53989/plugin.go b/misc/cgo/testplugin/testdata/issue53989/plugin.go new file mode 100644 index 0000000..a753ee4 --- /dev/null +++ b/misc/cgo/testplugin/testdata/issue53989/plugin.go @@ -0,0 +1,13 @@ +// 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() {} |