Skip to content

Commit

Permalink
debug/buildinfo: recognize macOS fat binary in go version
Browse files Browse the repository at this point in the history
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 golang#58796

Change-Id: I45cd26729352e46cc7ecfb13f2e9a8d96d62e0a0
Reviewed-on: https://go-review.googlesource.com/c/go/+/473615
TryBot-Result: Gopher Robot <[email protected]>
Auto-Submit: Ian Lance Taylor <[email protected]>
Run-TryBot: Ian Lance Taylor <[email protected]>
Reviewed-by: Carlos Amedee <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
  • Loading branch information
nikola-jokic authored and gopherbot committed Mar 8, 2023
1 parent 99f811e commit 8b39612
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/debug/buildinfo/buildinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -423,5 +429,4 @@ func (x *plan9objExe) ReadData(addr, size uint64) ([]byte, error) {
}
}
return nil, errors.New("address not mapped")

}

0 comments on commit 8b39612

Please sign in to comment.