1
0
mirror of https://github.com/golang/go synced 2024-11-19 07:14:45 -07:00

[dev.cc] cmd/go: add veryifyAsm test for the new assembler.

Enabled for adm64 and 386 only.

Depends on https://go-review.googlesource.com/4502

Change-Id: I61caf15f91297c12197b825dd70f750c4df02d3d
Reviewed-on: https://go-review.googlesource.com/4503
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Rob Pike 2015-02-10 17:10:40 -08:00
parent e59ed477c3
commit 7c604b0b7d

View File

@ -1689,28 +1689,43 @@ func (gcToolchain) asm(b *builder, p *Package, obj, ofile, sfile string) error {
return err
}
if verifyAsm {
newArgs := make([]interface{}, len(args))
copy(newArgs, args)
newArgs[1] = tool("new" + archChar + "a")
newArgs[3] = ofile + ".new" // x.6 becomes x.6.new
if err := b.run(p.Dir, p.ImportPath, nil, newArgs...); err != nil {
if err := asmVerify(b, p, "new"+archChar+"a", ofile, args); err != nil {
return err
}
data1, err := ioutil.ReadFile(ofile)
if err != nil {
return err
}
data2, err := ioutil.ReadFile(ofile + ".new")
if err != nil {
return err
}
if !bytes.Equal(data1, data2) {
return fmt.Errorf("%sa and new%sa produced different output files:\n%s\n%s", archChar, archChar, strings.Join(stringList(args...), " "), strings.Join(stringList(newArgs...), " "))
switch goarch {
case "386", "amd64": // Asm only supports these architectures so far.
if err := asmVerify(b, p, "asm", ofile, args); err != nil {
return err
}
}
}
return nil
}
// asmVerify checks that the assembly run for the specified assembler (asm) agrees
// with the C-implemented original assembly output, bit for bit.
func asmVerify(b *builder, p *Package, asm string, ofile string, args []interface{}) error {
newArgs := make([]interface{}, len(args))
copy(newArgs, args)
newArgs[1] = tool(asm)
newArgs[3] = ofile + ".new" // x.6 becomes x.6.new
if err := b.run(p.Dir, p.ImportPath, nil, newArgs...); err != nil {
return err
}
data1, err := ioutil.ReadFile(ofile)
if err != nil {
return err
}
data2, err := ioutil.ReadFile(ofile + ".new")
if err != nil {
return err
}
if !bytes.Equal(data1, data2) {
return fmt.Errorf("%sa and %s produced different output files:\n%s\n%s", archChar, asm, strings.Join(stringList(args...), " "), strings.Join(stringList(newArgs...), " "))
}
return nil
}
func (gcToolchain) pkgpath(basedir string, p *Package) string {
end := filepath.FromSlash(p.ImportPath + ".a")
return filepath.Join(basedir, end)