From a7a69d38a466b1b8d7a1aa60d7ee3cb41822a482 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 25 Jan 2022 22:09:29 +0100 Subject: [PATCH] builder: prefer GNU build ID over Go build ID The GNU build ID covers the Go build ID, and probably some more. --- builder/buildid.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/builder/buildid.go b/builder/buildid.go index e23c75f5..e6527700 100644 --- a/builder/buildid.go +++ b/builder/buildid.go @@ -30,6 +30,7 @@ func ReadBuildID() ([]byte, error) { if err != nil { return nil, err } + var gnuID, goID []byte for _, section := range file.Sections { if section.Type != elf.SHT_NOTE || (section.Name != ".note.gnu.build-id" && section.Name != ".note.go.buildid") { @@ -40,7 +41,16 @@ func ReadBuildID() ([]byte, error) { if uint64(n) != section.Size || err != nil { return nil, fmt.Errorf("could not read build id: %w", err) } - return buf, nil + if section.Name == ".note.gnu.build-id" { + gnuID = buf + } else { + goID = buf + } + } + if gnuID != nil { + return gnuID, nil + } else if goID != nil { + return goID, nil } case "darwin": // Read the LC_UUID load command, which contains the equivalent of a