mirror of
https://github.com/golang/go
synced 2024-11-13 12:20:26 -07:00
cmd/internal/buildid: skip over GNU build ID from buildid computation
This is similar to CL 618597, but for GNU build ID on ELF. This makes it possible to enable "-B gobuildid" by default on ELF. Updates #41004. For #63934. Change-Id: I4e663a27a2f7824bce994c783fe6d9ce8d1a395a Reviewed-on: https://go-review.googlesource.com/c/go/+/618600 Reviewed-by: Than McIntosh <thanm@golang.org> Reviewed-by: Michael Knyszek <mknyszek@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
c15e589733
commit
00034fa796
@ -9,6 +9,7 @@ import (
|
||||
"cmd/internal/codesign"
|
||||
imacho "cmd/internal/macho"
|
||||
"crypto/sha256"
|
||||
"debug/elf"
|
||||
"debug/macho"
|
||||
"fmt"
|
||||
"io"
|
||||
@ -185,14 +186,26 @@ func findHostBuildID(r io.Reader) (offset int64, size int64, ok bool) {
|
||||
if !ok {
|
||||
return 0, 0, false
|
||||
}
|
||||
// TODO: handle ELF GNU build ID.
|
||||
f, err := macho.NewFile(ra)
|
||||
|
||||
ef, err := elf.NewFile(ra)
|
||||
if err == nil {
|
||||
// ELF file. Find GNU build ID section.
|
||||
sect := ef.Section(".note.gnu.build-id")
|
||||
if sect == nil {
|
||||
return 0, 0, false
|
||||
}
|
||||
// Skip over the 3-word note "header" and "GNU\x00".
|
||||
return int64(sect.Offset + 16), int64(sect.Size - 16), true
|
||||
}
|
||||
|
||||
mf, err := macho.NewFile(ra)
|
||||
if err != nil {
|
||||
return 0, 0, false
|
||||
}
|
||||
|
||||
reader := imacho.NewLoadCmdReader(io.NewSectionReader(ra, 0, 1<<63-1), f.ByteOrder, imacho.FileHeaderSize(f))
|
||||
for i := uint32(0); i < f.Ncmd; i++ {
|
||||
// Mach-O file. Find LC_UUID load command.
|
||||
reader := imacho.NewLoadCmdReader(io.NewSectionReader(ra, 0, 1<<63-1), mf.ByteOrder, imacho.FileHeaderSize(mf))
|
||||
for i := uint32(0); i < mf.Ncmd; i++ {
|
||||
cmd, err := reader.Next()
|
||||
if err != nil {
|
||||
break
|
||||
|
Loading…
Reference in New Issue
Block a user