1
0
mirror of https://github.com/golang/go synced 2024-11-19 04:34:39 -07:00

cmd/go: make asm the first assembler

verifyAsm is still on, but this CL changes the order to asm then 6a.
Before, it was 6a then asm, but that meant that any bugs in asm
for bad input would be prevented from happening because 6a would
catch them. Now asm gets first crack, as it must.

Also implement the -trimpath flag in asm. It's necessary and trivial.

Change-Id: Ifb2ab870de1aa1b53dec76a78ac697a0d36fa80a
Reviewed-on: https://go-review.googlesource.com/5850
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
Rob Pike 2015-02-24 14:28:49 -08:00
parent 3e9e9b4822
commit 4100f7d95c
3 changed files with 5 additions and 4 deletions

View File

@ -17,7 +17,7 @@ var (
Debug = flag.Bool("debug", false, "dump instructions as they are parsed") Debug = flag.Bool("debug", false, "dump instructions as they are parsed")
OutputFile = flag.String("o", "", "output file; default foo.6 for /a/b/c/foo.s on amd64") OutputFile = flag.String("o", "", "output file; default foo.6 for /a/b/c/foo.s on amd64")
PrintOut = flag.Bool("S", false, "print assembly and machine code") PrintOut = flag.Bool("S", false, "print assembly and machine code")
TrimPath = flag.String("trimpath", "", "remove prefix from recorded source file paths (unused TODO)") TrimPath = flag.String("trimpath", "", "remove prefix from recorded source file paths")
) )
var ( var (

View File

@ -40,6 +40,7 @@ func main() {
if *flags.PrintOut { if *flags.PrintOut {
ctxt.Debugasm = 1 ctxt.Debugasm = 1
} }
ctxt.Trimpath = *flags.TrimPath
ctxt.Bso = obj.Binitw(os.Stdout) ctxt.Bso = obj.Binitw(os.Stdout)
defer obj.Bflush(ctxt.Bso) defer obj.Bflush(ctxt.Bso)
ctxt.Diag = log.Fatalf ctxt.Diag = log.Fatalf

View File

@ -1703,7 +1703,7 @@ func (gcToolchain) gc(b *builder, p *Package, archive, obj string, asmhdr bool,
} }
// verifyAsm specifies whether to check the assemblers written in Go // verifyAsm specifies whether to check the assemblers written in Go
// against the assemblers written in C. If set, asm will run both (say) 6a and new6a // against the assemblers written in C. If set, asm will run both asm and (say) 6a
// and fail if the two produce different output files. // and fail if the two produce different output files.
const verifyAsm = true const verifyAsm = true
@ -1711,12 +1711,12 @@ func (gcToolchain) asm(b *builder, p *Package, obj, ofile, sfile string) error {
// Add -I pkg/GOOS_GOARCH so #include "textflag.h" works in .s files. // Add -I pkg/GOOS_GOARCH so #include "textflag.h" works in .s files.
inc := filepath.Join(goroot, "pkg", fmt.Sprintf("%s_%s", goos, goarch)) inc := filepath.Join(goroot, "pkg", fmt.Sprintf("%s_%s", goos, goarch))
sfile = mkAbs(p.Dir, sfile) sfile = mkAbs(p.Dir, sfile)
args := []interface{}{buildToolExec, tool(archChar + "a"), "-o", ofile, "-trimpath", b.work, "-I", obj, "-I", inc, "-D", "GOOS_" + goos, "-D", "GOARCH_" + goarch, sfile} args := []interface{}{buildToolExec, tool("asm"), "-o", ofile, "-trimpath", b.work, "-I", obj, "-I", inc, "-D", "GOOS_" + goos, "-D", "GOARCH_" + goarch, sfile}
if err := b.run(p.Dir, p.ImportPath, nil, args...); err != nil { if err := b.run(p.Dir, p.ImportPath, nil, args...); err != nil {
return err return err
} }
if verifyAsm { if verifyAsm {
if err := toolVerify(b, p, "asm", ofile, args); err != nil { if err := toolVerify(b, p, archChar+"a", ofile, args); err != nil {
return err return err
} }
} }