Commit 1134411a authored by Hiroshi Ioka's avatar Hiroshi Ioka Committed by David Crawshaw

cmd/go, cmd/link, cmd/dist: re-enable plugin mode on darwin/amd64

1. remove broken verification
   The runtime check assumes that no-pcln symbol entry have zero value,
   but the linker emit no entries if the symbol is no-pcln.
   As a result, if there are no-pcln symbols at the very end of pcln
   table, it will panic.
2. correct condition of export
   Handle special chracters in pluginpath correcty.
   Export "go.itab.*", so different plugins can share the same itab.

Fixes #18190

Change-Id: Ia4f9c51d83ce8488a9470520f1ee9432802cfc1d
Reviewed-on: https://go-review.googlesource.com/61091Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
Run-TryBot: David Crawshaw <crawshaw@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 1053ae5c
...@@ -40,11 +40,21 @@ GOPATH=$(pwd) go build -buildmode=plugin iface_b ...@@ -40,11 +40,21 @@ GOPATH=$(pwd) go build -buildmode=plugin iface_b
GOPATH=$(pwd) go build iface GOPATH=$(pwd) go build iface
LD_LIBRARY_PATH=$(pwd) ./iface LD_LIBRARY_PATH=$(pwd) ./iface
function _timeout() (
set -e
$2 &
p=$!
(sleep $1; kill $p 2>/dev/null) &
p2=$!
wait $p 2>/dev/null
kill -0 $p2 2>/dev/null
)
# Test for issue 18676 - make sure we don't add the same itab twice. # Test for issue 18676 - make sure we don't add the same itab twice.
# The buggy code hangs forever, so use a timeout to check for that. # The buggy code hangs forever, so use a timeout to check for that.
GOPATH=$(pwd) go build -buildmode=plugin -o plugin.so src/issue18676/plugin.go GOPATH=$(pwd) go build -buildmode=plugin -o plugin.so src/issue18676/plugin.go
GOPATH=$(pwd) go build -o issue18676 src/issue18676/main.go GOPATH=$(pwd) go build -o issue18676 src/issue18676/main.go
timeout 10s ./issue18676 _timeout 10 ./issue18676
# Test for issue 19534 - that we can load a plugin built in a path with non-alpha # Test for issue 19534 - that we can load a plugin built in a path with non-alpha
# characters # characters
......
...@@ -850,6 +850,8 @@ func (t *tester) supportedBuildmode(mode string) bool { ...@@ -850,6 +850,8 @@ func (t *tester) supportedBuildmode(mode string) bool {
switch pair { switch pair {
case "linux-386", "linux-amd64", "linux-arm", "linux-s390x": case "linux-386", "linux-amd64", "linux-arm", "linux-s390x":
return true return true
case "darwin-amd64":
return true
} }
return false return false
default: default:
......
...@@ -358,6 +358,9 @@ func BuildModeInit() { ...@@ -358,6 +358,9 @@ func BuildModeInit() {
switch platform { switch platform {
case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x",
"android/amd64", "android/arm", "android/arm64", "android/386": "android/amd64", "android/arm", "android/arm64", "android/386":
case "darwin/amd64":
// Skip DWARF generation due to #21647
cfg.BuildLdflags = append(cfg.BuildLdflags, "-w")
default: default:
base.Fatalf("-buildmode=plugin not supported on %s\n", platform) base.Fatalf("-buildmode=plugin not supported on %s\n", platform)
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package ld package ld
import ( import (
"cmd/internal/objabi"
"cmd/internal/sys" "cmd/internal/sys"
"sort" "sort"
"strings" "strings"
...@@ -746,7 +747,10 @@ func machoShouldExport(ctxt *Link, s *Symbol) bool { ...@@ -746,7 +747,10 @@ func machoShouldExport(ctxt *Link, s *Symbol) bool {
if !ctxt.DynlinkingGo() || s.Attr.Local() { if !ctxt.DynlinkingGo() || s.Attr.Local() {
return false return false
} }
if Buildmode == BuildmodePlugin && strings.HasPrefix(s.Extname, *flagPluginPath) { if Buildmode == BuildmodePlugin && strings.HasPrefix(s.Extname, objabi.PathToPrefix(*flagPluginPath)) {
return true
}
if strings.HasPrefix(s.Name, "go.itab.") {
return true return true
} }
if strings.HasPrefix(s.Name, "type.") && !strings.HasPrefix(s.Name, "type..") { if strings.HasPrefix(s.Name, "type.") && !strings.HasPrefix(s.Name, "type..") {
......
...@@ -526,7 +526,6 @@ func moduledataverify1(datap *moduledata) { ...@@ -526,7 +526,6 @@ func moduledataverify1(datap *moduledata) {
// ftab is lookup table for function by program counter. // ftab is lookup table for function by program counter.
nftab := len(datap.ftab) - 1 nftab := len(datap.ftab) - 1
var pcCache pcvalueCache
for i := 0; i < nftab; i++ { for i := 0; i < nftab; i++ {
// NOTE: ftab[nftab].entry is legal; it is the address beyond the final function. // NOTE: ftab[nftab].entry is legal; it is the address beyond the final function.
if datap.ftab[i].entry > datap.ftab[i+1].entry { if datap.ftab[i].entry > datap.ftab[i+1].entry {
...@@ -542,30 +541,6 @@ func moduledataverify1(datap *moduledata) { ...@@ -542,30 +541,6 @@ func moduledataverify1(datap *moduledata) {
} }
throw("invalid runtime symbol table") throw("invalid runtime symbol table")
} }
if debugPcln || nftab-i < 5 {
// Check a PC near but not at the very end.
// The very end might be just padding that is not covered by the tables.
// No architecture rounds function entries to more than 16 bytes,
// but if one came along we'd need to subtract more here.
// But don't use the next PC if it corresponds to a foreign object chunk
// (no pcln table, f2.pcln == 0). That chunk might have an alignment
// more than 16 bytes.
f := funcInfo{(*_func)(unsafe.Pointer(&datap.pclntable[datap.ftab[i].funcoff])), datap}
end := f.entry
if i+1 < nftab {
f2 := funcInfo{(*_func)(unsafe.Pointer(&datap.pclntable[datap.ftab[i+1].funcoff])), datap}
if f2.pcln != 0 {
end = f2.entry - 16
if end < f.entry {
end = f.entry
}
}
}
pcvalue(f, f.pcfile, end, &pcCache, true)
pcvalue(f, f.pcln, end, &pcCache, true)
pcvalue(f, f.pcsp, end, &pcCache, true)
}
} }
if datap.minpc != datap.ftab[0].entry || if datap.minpc != datap.ftab[0].entry ||
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment