Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build ID precedence #2775

Merged
merged 1 commit into from
May 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions pkg/buildid/elf.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ var ErrTextSectionNotFound = errors.New("could not find .text section")

// FromELF returns the build ID for an ELF binary.
func FromELF(ef *elf.File) (string, error) {
// First, try fast methods.
// We prefer the GNU build ID, so try that first. We want to try this first
// always as there are distros like Ubuntu that build Go binaries but set
// the GNU build ID, and their debuginfo is only find-able via debuginfod
// using the gnu build ID.
if id, err := fastGNU(ef); err == nil && len(id) > 0 {
return hex.EncodeToString(id), nil
}

// Then we try other fast methods.
hasGoBuildIDSection := false
for _, s := range ef.Sections {
if s.Name == goBuildIDSectionName {
Expand All @@ -42,11 +50,8 @@ func FromELF(ef *elf.File) (string, error) {
return hex.EncodeToString(id), nil
}
}
if id, err := fastGNU(ef); err == nil && len(id) > 0 {
return hex.EncodeToString(id), nil
}

// If that fails, try the slow methods.
// If all fast methods fails, we use the slow methods.
return buildid(ef)
}

Expand Down
Loading