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

symbolication: allow symbol upload for Bazel-built Go binairies #57

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion libpf/pfelf/pfelf.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,18 @@ func GetGoBuildID(elfFile *elf.File) (string, error) {
}

// getGoBuildIDFromNotes returns the Go build ID from an ELF notes section data.
//
//nolint:lll
func getGoBuildIDFromNotes(notes []byte) (string, error) {
// 0x4 is the "Go Build ID" type. Not sure where this is standardized.
buildID, found, err := getNoteString(notes, "Go", 0x4)
if err != nil {
return "", fmt.Errorf("could not determine BuildID: %v", err)
}
if !found {
// When building Go binaries, Bazel explicitly sets their build ID to "redacted"
// see https://github.com/bazelbuild/rules_go/blob/199d8e4827f87d382a85febd0148c1b42fa949cc/go/private/actions/link.bzl#L174.
// In that case, we don't want to associate the build ID with the binary in the mapping.
if !found || buildID == "redacted" {
return "", ErrNoBuildID
}
return buildID, nil
Expand Down
20 changes: 8 additions & 12 deletions symbolication/datadog_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,7 @@ func (d *DatadogUploader) HandleExecutable(elfRef *pfelf.Reference, fileID libpf
return
}

e, err := newExecutableMetadata(fileName, ef, fileID)
if err != nil {
log.Debugf("Skipping symbol upload for executable %s: %v", fileName, err)
return
}
e := newExecutableMetadata(fileName, ef, fileID)

d.uploadCache.Add(fileID, struct{}{})
// TODO:
Expand Down Expand Up @@ -162,21 +158,21 @@ type executableMetadata struct {
}

func newExecutableMetadata(fileName string, elf *pfelf.File,
fileID libpf.FileID) (*executableMetadata, error) {
fileID libpf.FileID) *executableMetadata {
isGolang := elf.IsGolang()

buildID, err := elf.GetBuildID()
// Some Go executables don't have a GNU build ID, so we don't want to fail
// if we can't get it
if err != nil && !isGolang {
return nil, fmt.Errorf("failed to get build id: %w", err)
if err != nil {
log.Debugf(
"Unable to get GNU build ID for executable %s: %s", fileName, err)
}

goBuildID := ""
if isGolang {
goBuildID, err = elf.GetGoBuildID()
if err != nil {
return nil, fmt.Errorf("failed to get go build id: %w", err)
log.Debugf(
"Unable to get Go build ID for executable %s: %s", fileName, err)
}
}

Expand All @@ -191,7 +187,7 @@ func newExecutableMetadata(fileName string, elf *pfelf.File,
SymbolSource: "debug_info",
FileName: filepath.Base(fileName),
filePath: fileName,
}, nil
}
}

func (e *executableMetadata) String() string {
Expand Down
Loading