From 6c74db40247737da2d3c3ffe1871d9cf67afd0a5 Mon Sep 17 00:00:00 2001 From: Mark Glines Date: Wed, 31 Jul 2019 03:46:15 +0000 Subject: [PATCH] cmd/go: look for .go.buildinfo section when looking for ELF version Based on original fix from Mark Glines in golang.org/cl/186737 Fixes #31861 Change-Id: Ibd583a3aa8f8b8eefade998aa2ac757b55140937 Reviewed-on: https://go-review.googlesource.com/c/go/+/188957 Run-TryBot: Andrew Bonventre TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/go/internal/version/exe.go | 5 +++++ src/cmd/go/testdata/script/version.txt | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/cmd/go/internal/version/exe.go b/src/cmd/go/internal/version/exe.go index 55da960c025..528433e325f 100644 --- a/src/cmd/go/internal/version/exe.go +++ b/src/cmd/go/internal/version/exe.go @@ -103,6 +103,11 @@ func (x *elfExe) ReadData(addr, size uint64) ([]byte, error) { } func (x *elfExe) DataStart() uint64 { + for _, s := range x.f.Sections { + if s.Name == ".go.buildinfo" { + return s.Addr + } + } for _, p := range x.f.Progs { if p.Type == elf.PT_LOAD && p.Flags&(elf.PF_X|elf.PF_W) == elf.PF_W { return p.Vaddr diff --git a/src/cmd/go/testdata/script/version.txt b/src/cmd/go/testdata/script/version.txt index cb4881f7a72..9086f047e4b 100644 --- a/src/cmd/go/testdata/script/version.txt +++ b/src/cmd/go/testdata/script/version.txt @@ -8,5 +8,12 @@ go version -m fortune.exe stdout '^\tpath\trsc.io/fortune' stdout '^\tmod\trsc.io/fortune\tv1.0.0' +go build -buildmode=pie -o external.exe rsc.io/fortune +go version external.exe +stdout '^external.exe: .+' +go version -m external.exe +stdout '^\tpath\trsc.io/fortune' +stdout '^\tmod\trsc.io/fortune\tv1.0.0' + -- go.mod -- module m