]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/asm, cmd/link: use full objabi header
authorRuss Cox <rsc@golang.org>
Tue, 20 Apr 2021 18:08:58 +0000 (14:08 -0400)
committerRuss Cox <rsc@golang.org>
Fri, 23 Apr 2021 21:42:54 +0000 (21:42 +0000)
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>
src/cmd/asm/main.go
src/cmd/link/internal/ld/lib.go

index e5a9ee565ed29d655f24ddfa55c1dc14fe8b4b1c..043bc696e58ae2fb0fdd74bcc0e5cdcfe9bb7a39 100644 (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")
        }
 
index c840e5ea516be0ae8577ad10617fce468e9857ba..d2dc3fb175ba46b9781c1fa998d3484ca95eacd3 100644 (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.