cmd/link: fix export data truncation bug

Similar fix as in CL 60773 for fixing cmd/pack.

Fixes #21703.

Change-Id: I457ed8a3be828fd458abc5c8c1cc766a9f7aab13
Reviewed-on: https://go-review.googlesource.com/79135
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Matthew Dempsky 2017-11-21 11:27:20 -08:00
parent f100e0c228
commit 5e423ed855
2 changed files with 61 additions and 3 deletions

View file

@ -1,6 +1,13 @@
package main
import "testing"
import (
"internal/testenv"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"testing"
)
var AuthorPaidByTheColumnInch struct {
fog int `
@ -28,3 +35,38 @@ func TestLargeSymName(t *testing.T) {
// the bufio buffer. Issue #15104.
_ = AuthorPaidByTheColumnInch
}
func TestIssue21703(t *testing.T) {
testenv.MustHaveGoBuild(t)
const source = `
package main
const X = "\n!\n"
func main() {}
`
tmpdir, err := ioutil.TempDir("", "issue21703")
if err != nil {
t.Fatalf("failed to create temp dir: %v\n", err)
}
defer os.RemoveAll(tmpdir)
err = ioutil.WriteFile(filepath.Join(tmpdir, "main.go"), []byte(source), 0666)
if err != nil {
t.Fatalf("failed to write main.go: %v\n", err)
}
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "main.go")
cmd.Dir = tmpdir
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("failed to compile main.go: %v, output: %s\n", err, out)
}
cmd = exec.Command(testenv.GoToolPath(t), "tool", "link", "main.o")
cmd.Dir = tmpdir
out, err = cmd.CombinedOutput()
if err != nil {
t.Fatalf("failed to link main.o: %v, output: %s\n", err, out)
}
}