]> Cypherpunks.ru repositories - gostls13.git/commitdiff
debug/buildinfo: recognize macOS fat binary in go version
authorNikola Jokic <jokicnikola07@gmail.com>
Mon, 6 Mar 2023 08:52:12 +0000 (09:52 +0100)
committerGopher Robot <gobot@golang.org>
Wed, 8 Mar 2023 15:57:58 +0000 (15:57 +0000)
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>
src/debug/buildinfo/buildinfo.go

index a7019a666e2aa4d12491ac936a99efb4c20ec3eb..3409356f017037c1be84c9de0f3187d1bc19607a 100644 (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")
-
 }