From: Russ Cox Date: Tue, 20 Apr 2021 18:08:58 +0000 (-0400) Subject: cmd/asm, cmd/link: use full objabi header X-Git-Tag: go1.17beta1~473 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=cef3a442eaa1f86b81bb67fb881c5bb9e446fb13;p=gostls13.git 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 Run-TryBot: Russ Cox TryBot-Result: Go Bot Reviewed-by: Cherry Zhang --- diff --git a/src/cmd/asm/main.go b/src/cmd/asm/main.go index e5a9ee565e..043bc696e5 100644 --- a/src/cmd/asm/main.go +++ b/src/cmd/asm/main.go @@ -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") } diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index c840e5ea51..d2dc3fb175 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -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.