]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/link, cmd/oldlink: detect object file format mismatch
authorCherry Zhang <cherryyz@google.com>
Wed, 25 Mar 2020 16:06:59 +0000 (12:06 -0400)
committerCherry Zhang <cherryyz@google.com>
Mon, 30 Mar 2020 13:52:55 +0000 (13:52 +0000)
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>
src/cmd/link/internal/loader/loader.go
src/cmd/oldlink/internal/objfile/objfile.go

index 3b77a4bff3372c8848e22d5ae778e5278d2cfdd1..c04cc03b3e24ecd6febcebdb77311c98549b931e 100644 (file)
@@ -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()
index 83b931ddef217189d92d2bbeadb5efada739a49e..7be433ad40278a9d1a6c3e5f87aee122170b3249 100644 (file)
@@ -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])
        }