From 8b3961264120d188c3c9739370826e346d8748c2 Mon Sep 17 00:00:00 2001 From: Nikola Jokic Date: Mon, 6 Mar 2023 09:52:12 +0100 Subject: [PATCH] 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 Auto-Submit: Ian Lance Taylor Run-TryBot: Ian Lance Taylor Reviewed-by: Carlos Amedee Reviewed-by: Ian Lance Taylor --- src/debug/buildinfo/buildinfo.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/debug/buildinfo/buildinfo.go b/src/debug/buildinfo/buildinfo.go index a7019a666e..3409356f01 100644 --- a/src/debug/buildinfo/buildinfo.go +++ b/src/debug/buildinfo/buildinfo.go @@ -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") - }