Skip to content

Commit

Permalink
Implement reading Build ID from Go ELF binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
tamird committed May 22, 2023
1 parent 2277754 commit 713569c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1835,6 +1835,10 @@ pub const NT_SOLARIS_PAGESIZE_HINT: u32 = 1;
/// GNU entries in the note section have this name.
pub const ELF_NOTE_GNU: &[u8] = b"GNU";

/// Go entries in the note section have this name.
// See https://go-review.googlesource.com/9520 and https://go-review.googlesource.com/10704.
pub const ELF_NOTE_GO: &[u8] = b"Go";

// Note types for `ELF_NOTE_GNU`.

/// ABI information.
Expand Down Expand Up @@ -1870,6 +1874,12 @@ pub const NT_GNU_HWCAP: u32 = 2;
/// The descriptor consists of any nonzero number of bytes.
pub const NT_GNU_BUILD_ID: u32 = 3;

/// Build ID bits as generated by Go's gc compiler.
///
/// The descriptor consists of any nonzero number of bytes.
// See https://go-review.googlesource.com/10707.
pub const NT_GO_BUILD_ID: u32 = 4;

/// Version note generated by GNU gold containing a version string.
pub const NT_GNU_GOLD_VERSION: u32 = 4;

Expand Down
10 changes: 6 additions & 4 deletions src/read/elf/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,12 @@ where
let mut notes = self.notes();
while let Some(mut notes) = notes.next().transpose()? {
while let Some(note) = notes.next()? {
if note.name() == elf::ELF_NOTE_GNU
&& note.n_type(self.endian) == elf::NT_GNU_BUILD_ID
{
return Ok(Some(note.desc()));
match (note.name(), note.n_type(self.endian())) {
(elf::ELF_NOTE_GNU, elf::NT_GNU_BUILD_ID)
| (elf::ELF_NOTE_GO, elf::NT_GO_BUILD_ID) => {
return Ok(Some(note.desc()));
}
_ => {}
}
}
}
Expand Down

0 comments on commit 713569c

Please sign in to comment.