Commit 41fd4c88 authored by Alex Brainman's avatar Alex Brainman

cmd/link: do not use _GLOBAL_OFFSET_TABLE_ on windows/386

When building windows/386 executable that imports "plugin" package,
cmd/link adds reference to DLL with blank name. Running

objdump -x a.exe

reports

...
The Import Tables (interpreted .idata section contents)
...
DLL Name:
vma:  Hint/Ord Member-Name Bound-To
25308a     0  _GLOBAL_OFFSET_TABLE_
...

So, obviously, executable cannot run, because Windows complains
that it cannot find DLL when trying to run it.

Stop using _GLOBAL_OFFSET_TABLE_ on windows/386.

Fixes #28789

Change-Id: Idd489eafd998f6e329f40c5d90a2a8965ab1d873
Reviewed-on: https://go-review.googlesource.com/c/151139
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 440368da
...@@ -588,8 +588,8 @@ func (ctxt *Link) loadlib() { ...@@ -588,8 +588,8 @@ func (ctxt *Link) loadlib() {
} }
} }
if ctxt.Arch == sys.Arch386 { if ctxt.Arch == sys.Arch386 && ctxt.HeadType != objabi.Hwindows {
if (ctxt.BuildMode == BuildModeCArchive && ctxt.IsELF) || (ctxt.BuildMode == BuildModeCShared && ctxt.HeadType != objabi.Hwindows) || ctxt.BuildMode == BuildModePIE || ctxt.DynlinkingGo() { if (ctxt.BuildMode == BuildModeCArchive && ctxt.IsELF) || ctxt.BuildMode == BuildModeCShared || ctxt.BuildMode == BuildModePIE || ctxt.DynlinkingGo() {
got := ctxt.Syms.Lookup("_GLOBAL_OFFSET_TABLE_", 0) got := ctxt.Syms.Lookup("_GLOBAL_OFFSET_TABLE_", 0)
got.Type = sym.SDYNIMPORT got.Type = sym.SDYNIMPORT
got.Attr |= sym.AttrReachable got.Attr |= sym.AttrReachable
......
// Copyright 2018 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.
// +build !nacl
package plugin_test
import (
_ "plugin"
"testing"
)
func TestPlugin(t *testing.T) {
// This test makes sure that executable that imports plugin
// package can actually run. See issue #28789 for details.
}
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