mirror of
https://github.com/golang/go
synced 2024-11-05 18:36:08 +00:00
cmd/internal/goobj: add test case for object file reader
Add test in which a input Go object file contains a very large number of relocations (more than 1<<20). Updates #41621. Change-Id: If1ebf3c4fefbf55ddec4e05c5299e7c48fc697d8 Reviewed-on: https://go-review.googlesource.com/c/go/+/278493 Run-TryBot: Than McIntosh <thanm@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com> Trust: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
c9d9b40b13
commit
b7f62daa59
1 changed files with 62 additions and 0 deletions
|
@ -9,6 +9,11 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"cmd/internal/bio"
|
"cmd/internal/bio"
|
||||||
"cmd/internal/objabi"
|
"cmd/internal/objabi"
|
||||||
|
"fmt"
|
||||||
|
"internal/testenv"
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -69,3 +74,60 @@ func TestReadWrite(t *testing.T) {
|
||||||
t.Errorf("read Aux2 mismatch: got %v %v", a2.Type(), a2.Sym())
|
t.Errorf("read Aux2 mismatch: got %v %v", a2.Type(), a2.Sym())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var issue41621prolog = `
|
||||||
|
package main
|
||||||
|
var lines = []string{
|
||||||
|
`
|
||||||
|
|
||||||
|
var issue41621epilog = `
|
||||||
|
}
|
||||||
|
func getLines() []string {
|
||||||
|
return lines
|
||||||
|
}
|
||||||
|
func main() {
|
||||||
|
println(getLines())
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
func TestIssue41621LargeNumberOfRelocations(t *testing.T) {
|
||||||
|
if testing.Short() || (objabi.GOARCH != "amd64") {
|
||||||
|
t.Skipf("Skipping large number of relocations test in short mode or on %s", objabi.GOARCH)
|
||||||
|
}
|
||||||
|
testenv.MustHaveGoBuild(t)
|
||||||
|
|
||||||
|
tmpdir, err := ioutil.TempDir("", "lotsofrelocs")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("can't create temp directory: %v\n", err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
|
// Emit testcase.
|
||||||
|
var w bytes.Buffer
|
||||||
|
fmt.Fprintf(&w, issue41621prolog)
|
||||||
|
for i := 0; i < 1048576+13; i++ {
|
||||||
|
fmt.Fprintf(&w, "\t\"%d\",\n", i)
|
||||||
|
}
|
||||||
|
fmt.Fprintf(&w, issue41621epilog)
|
||||||
|
err = ioutil.WriteFile(tmpdir+"/large.go", w.Bytes(), 0666)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("can't write output: %v\n", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Emit go.mod
|
||||||
|
w.Reset()
|
||||||
|
fmt.Fprintf(&w, "module issue41621\n\ngo 1.12\n")
|
||||||
|
err = ioutil.WriteFile(tmpdir+"/go.mod", w.Bytes(), 0666)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("can't write output: %v\n", err)
|
||||||
|
}
|
||||||
|
w.Reset()
|
||||||
|
|
||||||
|
// Build.
|
||||||
|
cmd := exec.Command(testenv.GoToolPath(t), "build", "-o", "large")
|
||||||
|
cmd.Dir = tmpdir
|
||||||
|
out, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Build failed: %v, output: %s", err, out)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue