1
0
mirror of https://github.com/golang/go synced 2024-09-29 21:24:30 -06:00

debug/buildinfo: recognize macOS fat binary in go version

buildinfo did not check for fat magic, which caused go version to report
unrecognized file format.

This change reads the fat file and passes the first arch file to machoExe.

Fixes #58796

Change-Id: I45cd26729352e46cc7ecfb13f2e9a8d96d62e0a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/473615
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
Nikola Jokic 2023-03-06 09:52:12 +01:00 committed by Gopher Robot
parent 99f811ecca
commit 8b39612641

View File

@ -126,6 +126,12 @@ func readRawBuildInfo(r io.ReaderAt) (vers, mod string, err error) {
return "", "", errUnrecognizedFormat
}
x = &machoExe{f}
case bytes.HasPrefix(ident, []byte("\xCA\xFE\xBA\xBE")) || bytes.HasPrefix(ident, []byte("\xCA\xFE\xBA\xBF")):
f, err := macho.NewFatFile(r)
if err != nil || len(f.Arches) == 0 {
return "", "", errUnrecognizedFormat
}
x = &machoExe{f.Arches[0].File}
case bytes.HasPrefix(ident, []byte{0x01, 0xDF}) || bytes.HasPrefix(ident, []byte{0x01, 0xF7}):
f, err := xcoff.NewFile(r)
if err != nil {
@ -423,5 +429,4 @@ func (x *plan9objExe) ReadData(addr, size uint64) ([]byte, error) {
}
}
return nil, errors.New("address not mapped")
}