mirror of
https://github.com/golang/go
synced 2024-11-11 22:30:21 -07:00
cmd/compile,cmd/internal/objabi: abstract out object header string
Change-Id: Idbbb4cb7127b93afa34a8aa18bbdaad1f206ab6a Reviewed-on: https://go-review.googlesource.com/c/go/+/308090 Trust: Austin Clements <austin@google.com> Run-TryBot: Austin Clements <austin@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
b675e52e95
commit
89ca1ce9a8
@ -70,7 +70,7 @@ func dumpobj1(outfile string, mode int) {
|
||||
}
|
||||
|
||||
func printObjHeader(bout *bio.Writer) {
|
||||
fmt.Fprintf(bout, "go object %s %s %s %s\n", objabi.GOOS, objabi.GOARCH, objabi.Version, objabi.Expstring())
|
||||
bout.WriteString(objabi.HeaderString())
|
||||
if base.Flag.BuildID != "" {
|
||||
fmt.Fprintf(bout, "build id %q\n", base.Flag.BuildID)
|
||||
}
|
||||
|
@ -243,9 +243,9 @@ func importfile(decl *syntax.ImportDecl) *types.Pkg {
|
||||
base.Errorf("import %s: not a go object file: %s", file, p)
|
||||
base.ErrorExit()
|
||||
}
|
||||
q := fmt.Sprintf("%s %s %s %s\n", objabi.GOOS, objabi.GOARCH, objabi.Version, objabi.Expstring())
|
||||
if p[10:] != q {
|
||||
base.Errorf("import %s: object is [%s] expected [%s]", file, p[10:], q)
|
||||
q := objabi.HeaderString()
|
||||
if p != q {
|
||||
base.Errorf("import %s: object is [%s] expected [%s]", file, p, q)
|
||||
base.ErrorExit()
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
package objabi
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
@ -121,3 +122,11 @@ func gowasm() (f gowasmFeatures) {
|
||||
func Getgoextlinkenabled() string {
|
||||
return envOr("GO_EXTLINK_ENABLED", defaultGO_EXTLINK_ENABLED)
|
||||
}
|
||||
|
||||
// HeaderString returns the toolchain configuration string written in
|
||||
// Go object headers. This string ensures we don't attempt to import
|
||||
// or link object files that are incompatible with each other. This
|
||||
// string always starts with "go object ".
|
||||
func HeaderString() string {
|
||||
return fmt.Sprintf("go object %s %s %s %s\n", GOOS, GOARCH, Version, Expstring())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user