Skip to content

Commit

Permalink
cmd/asm, cmd/link: use full objabi header
Browse files Browse the repository at this point in the history
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 <[email protected]>
Run-TryBot: Russ Cox <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Cherry Zhang <[email protected]>
  • Loading branch information
rsc committed Apr 23, 2021
1 parent 19470dc commit cef3a44
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
3 changes: 2 additions & 1 deletion src/cmd/asm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (

"cmd/internal/bio"
"cmd/internal/obj"
"cmd/internal/objabi"
)

func main() {
Expand Down Expand Up @@ -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")
}

Expand Down
22 changes: 4 additions & 18 deletions src/cmd/link/internal/ld/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit cef3a44

Please sign in to comment.