mirror of
https://github.com/golang/go
synced 2024-11-14 08:50:22 -07:00
c5da4fb7ac
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>
53 lines
826 B
Go
53 lines
826 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.
|
|
|
|
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")
|
|
}
|
|
}
|