cmd/go: look for __go_buildinfo section when looking for Mach-O version

This mirrors the ELF fix in CL 188957. TestScript/version failed on
darwin after that change.

Fixes #31861

Change-Id: I4ce953ebec8dd5fa47e26d373c59d7e290b75a34
Reviewed-on: https://go-review.googlesource.com/c/go/+/189159
Run-TryBot: Jay Conrod <jayconrod@google.com>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
Jay Conrod 2019-08-06 13:12:23 -04:00
parent 8e82624e69
commit 46f99ce7ea

View File

@ -213,7 +213,13 @@ func (x *machoExe) ReadData(addr, size uint64) ([]byte, error) {
} }
func (x *machoExe) DataStart() uint64 { func (x *machoExe) DataStart() uint64 {
// Assume data is first non-empty writable segment. // Look for section named "__go_buildinfo".
for _, sec := range x.f.Sections {
if sec.Name == "__go_buildinfo" {
return sec.Addr
}
}
// Try the first non-empty writable segment.
const RW = 3 const RW = 3
for _, load := range x.f.Loads { for _, load := range x.f.Loads {
seg, ok := load.(*macho.Segment) seg, ok := load.(*macho.Segment)