]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: look for __go_buildinfo section when looking for Mach-O version
authorJay Conrod <jayconrod@google.com>
Tue, 6 Aug 2019 17:12:23 +0000 (13:12 -0400)
committerJay Conrod <jayconrod@google.com>
Tue, 6 Aug 2019 18:00:31 +0000 (18:00 +0000)
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>

src/cmd/go/internal/version/exe.go

index 528433e325f015b64bf738cf0cd6710bacd296a5..0e7deef1491a9c4d022ff0ff6b86341d4a7b0cb4 100644 (file)
@@ -213,7 +213,13 @@ func (x *machoExe) ReadData(addr, size uint64) ([]byte, error) {
 }
 
 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
        for _, load := range x.f.Loads {
                seg, ok := load.(*macho.Segment)