mirror of
https://github.com/golang/go
synced 2024-11-23 18:20:04 -07:00
[dev.link] cmd/link, cmd/oldlink: detect object file format mismatch
When using the new(old) linker but an old(new) object file is found, give a better error message. Change-Id: I94786f1a4b527c15c4f5b00457eab60d215a72a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/225457 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
7716d7fc1b
commit
3e6ff18247
@ -1667,6 +1667,9 @@ func (l *Loader) Preload(syms *sym.Symbols, f *bio.Reader, lib *sym.Library, uni
|
||||
}
|
||||
r := goobj2.NewReaderFromBytes(roObject, readonly)
|
||||
if r == nil {
|
||||
if len(roObject) >= 8 && bytes.Equal(roObject[:8], []byte("\x00go114ld")) {
|
||||
log.Fatalf("found object file %s in old format, but -go115newobj is true\nset -go115newobj consistently in all -gcflags, -asmflags, and -ldflags", f.File().Name())
|
||||
}
|
||||
panic("cannot read object file")
|
||||
}
|
||||
localSymVersion := syms.IncVersion()
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"bytes"
|
||||
"cmd/internal/bio"
|
||||
"cmd/internal/dwarf"
|
||||
"cmd/internal/goobj2"
|
||||
"cmd/internal/obj"
|
||||
"cmd/internal/objabi"
|
||||
"cmd/internal/sys"
|
||||
@ -117,6 +118,9 @@ func (r *objReader) loadObjFile() {
|
||||
var buf [8]uint8
|
||||
r.readFull(buf[:])
|
||||
if string(buf[:]) != startmagic {
|
||||
if string(buf[:]) == goobj2.Magic {
|
||||
log.Fatalf("found object file %s in new format, but -go115newobj is false\nset -go115newobj consistently in all -gcflags, -asmflags, and -ldflags", r.pn)
|
||||
}
|
||||
log.Fatalf("%s: invalid file start %x %x %x %x %x %x %x %x", r.pn, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7])
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user