1
0
mirror of https://github.com/golang/go synced 2024-11-11 21:20:21 -07:00

cmd/asm, cmd/link: use full objabi header

The cmd/link check of the objabi header was a bit lax because
historically the assembler has not included the full version string.
And the assembler didn't do that because it didn't have access to it:
that was buried inside the compiler.

But now that we have cmd/internal/objabi, all the tools have full
access to the expected string, and they can use it, which simplifies
the cmd/link consistency check.

Do that.

Change-Id: I33bd2f9d36c373cc3c32ff02ec6368365088b011
Reviewed-on: https://go-review.googlesource.com/c/go/+/312030
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
Russ Cox 2021-04-20 14:08:58 -04:00
parent 19470dc535
commit cef3a442ea
2 changed files with 6 additions and 19 deletions

View File

@ -19,6 +19,7 @@ import (
"cmd/internal/bio"
"cmd/internal/obj"
"cmd/internal/objabi"
)
func main() {
@ -69,7 +70,7 @@ func main() {
defer buf.Close()
if !*flags.SymABIs {
fmt.Fprintf(buf, "go object %s %s %s\n", buildcfg.GOOS, buildcfg.GOARCH, buildcfg.Version)
buf.WriteString(objabi.HeaderString())
fmt.Fprintf(buf, "!\n")
}

View File

@ -1773,6 +1773,8 @@ func hostlinkArchArgs(arch *sys.Arch) []string {
return nil
}
var wantHdr = objabi.HeaderString()
// ldobj loads an input object. If it is a host object (an object
// compiled by a non-Go compiler) it returns the Hostobj pointer. If
// it is a Go object, it returns nil.
@ -1871,24 +1873,8 @@ func ldobj(ctxt *Link, f *bio.Reader, lib *sym.Library, length int64, pn string,
}
// First, check that the basic GOOS, GOARCH, and Version match.
t := fmt.Sprintf("%s %s %s ", buildcfg.GOOS, buildcfg.GOARCH, buildcfg.Version)
line = strings.TrimRight(line, "\n")
if !strings.HasPrefix(line[10:]+" ", t) && !*flagF {
Errorf(nil, "%s: object is [%s] expected [%s]", pn, line[10:], t)
return nil
}
// Second, check that longer lines match each other exactly,
// so that the Go compiler and write additional information
// that must be the same from run to run.
if len(line) >= len(t)+10 {
if theline == "" {
theline = line[10:]
} else if theline != line[10:] {
Errorf(nil, "%s: object is [%s] expected [%s]", pn, line[10:], theline)
return nil
}
if line != wantHdr {
Errorf(nil, "%s: linked object header mismatch:\nhave %q\nwant %q\n", pn, line, wantHdr)
}
// Skip over exports and other info -- ends with \n!\n.