1
0
mirror of https://github.com/golang/go synced 2024-09-30 13:28:38 -06:00
go/misc/cgo/testplugin/testdata/issue53989/main.go
Cherry Mui c5da4fb7ac cmd/compile: make jump table symbol local
When using plugins, if the plugin and the main executable both
have the same function, and if it uses jump table, currently the
jump table symbol have the same name so it will be deduplicated by
the dynamic linker. This causes a function in the plugin may (in
the middle of the function) jump to the function with the same name
in the main executable (or vice versa). But the function may be
compiled slightly differently, because the plugin needs to be PIC.
Jumping from the middle of one function to the other will not work.
Avoid this problem by marking the jump table symbol local to a DSO.

Fixes #53989.

Change-Id: I2b573b9dfc22401c8a09ffe9b9ea8bb83d3700ca
Reviewed-on: https://go-review.googlesource.com/c/go/+/418960
Reviewed-by: Keith Randall <khr@google.com>
Run-TryBot: Cherry Mui <cherryyz@google.com>
Reviewed-by: Than McIntosh <thanm@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-07-22 20:12:19 +00:00

33 lines
751 B
Go

// 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
}