cmd/link: use sym.Symbol in addpersrc

addpersrc is called very late, after we have converted to
sym.Symbols and various fields in loader representation have been
dropped. Use the Symbol representation there.

Fixes #39658.

Change-Id: I616e838655b6f01554644171317e2cc5cefabf39
Reviewed-on: https://go-review.googlesource.com/c/go/+/238779
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
This commit is contained in:
Cherry Zhang 2020-06-18 18:05:10 -04:00
parent 27a0012bd6
commit f2bba30e40
4 changed files with 60 additions and 6 deletions

View file

@ -746,3 +746,37 @@ func TestIndexMismatch(t *testing.T) {
t.Errorf("did not see expected error message. out:\n%s", out)
}
}
func TestPErsrc(t *testing.T) {
// Test that PE rsrc section is handled correctly (issue 39658).
testenv.MustHaveGoBuild(t)
if runtime.GOARCH != "amd64" || runtime.GOOS != "windows" {
t.Skipf("this is a windows/amd64-only test")
}
tmpdir, err := ioutil.TempDir("", "TestPErsrc")
if err != nil {
t.Fatal(err)
}
defer os.RemoveAll(tmpdir)
pkgdir := filepath.Join("testdata", "testPErsrc")
exe := filepath.Join(tmpdir, "a.exe")
cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", exe)
cmd.Dir = pkgdir
// cmd.Env = append(os.Environ(), "GOOS=windows", "GOARCH=amd64") // uncomment if debugging in a cross-compiling environment
out, err := cmd.CombinedOutput()
if err != nil {
t.Fatalf("building failed: %v, output:\n%s", err, out)
}
// Check that the binary contains the rsrc data
b, err := ioutil.ReadFile(exe)
if err != nil {
t.Fatalf("reading output failed: %v", err)
}
if !bytes.Contains(b, []byte("Hello Gophers!")) {
t.Fatalf("binary does not contain expected content")
}
}