cmd/internal/objfile: emit better error for Go object of a different version

The Go object file format can change from version to version.
Tools like cmd/objdump and cmd/nm only onderstand the current
version of the object file. Currently, when it encounters an
object built with a different version of the toolchain, it emits
a generic error "unrecognized object file", which is not very
helpful for users. This CL makes it emit a clearer error. Now it
emits

objdump: open go116.o: go object of a different version: go116ld

Change-Id: I063c6078ed1da78f97cea65796779ae093a1a8cb
Reviewed-on: https://go-review.googlesource.com/c/go/+/315609
Trust: Cherry Zhang <cherryyz@google.com>
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
Cherry Zhang 2021-04-29 21:49:15 -04:00
parent a893682d83
commit 89bf297b24
4 changed files with 28 additions and 1 deletions

View file

@ -6,6 +6,7 @@
package objfile
import (
"cmd/internal/archive"
"debug/dwarf"
"debug/gosym"
"fmt"
@ -73,6 +74,8 @@ func Open(name string) (*File, error) {
}
if f, err := openGoFile(r); err == nil {
return f, nil
} else if _, ok := err.(archive.ErrGoObjOtherVersion); ok {
return nil, fmt.Errorf("open %s: %v", name, err)
}
for _, try := range openers {
if raw, err := try(r); err == nil {