Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 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
28 changes: 22 additions & 6 deletions llvm/lib/Object/BuildID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,26 @@ using namespace llvm::object;
namespace {

template <typename ELFT> BuildIDRef getBuildID(const ELFFile<ELFT> &Obj) {
auto findBuildID = [&Obj](const auto &ShdrOrPhdr,
uint64_t Alignment) -> std::optional<BuildIDRef> {
Error Err = Error::success();
for (auto N : Obj.notes(ShdrOrPhdr, Err))
if (N.getType() == ELF::NT_GNU_BUILD_ID &&
N.getName() == ELF::ELF_NOTE_GNU)
return N.getDesc(Alignment);
consumeError(std::move(Err));
return std::nullopt;
};

auto Sections = cantFail(Obj.sections());
if (!Sections.empty()) {
for (const auto &S : Sections) {
if (S.sh_type != ELF::SHT_NOTE)
continue;
if (std::optional<BuildIDRef> ShdrRes = findBuildID(S, S.sh_addralign))
return ShdrRes.value();
}
}
auto PhdrsOrErr = Obj.program_headers();
if (!PhdrsOrErr) {
consumeError(PhdrsOrErr.takeError());
Expand All @@ -32,12 +52,8 @@ template <typename ELFT> BuildIDRef getBuildID(const ELFFile<ELFT> &Obj) {
for (const auto &P : *PhdrsOrErr) {
if (P.p_type != ELF::PT_NOTE)
continue;
Error Err = Error::success();
for (auto N : Obj.notes(P, Err))
if (N.getType() == ELF::NT_GNU_BUILD_ID &&
N.getName() == ELF::ELF_NOTE_GNU)
return N.getDesc(P.p_align);
consumeError(std::move(Err));
if (std::optional<BuildIDRef> PhdrRes = findBuildID(P, P.p_align))
return PhdrRes.value();
}
return {};
}
Expand Down
1 change: 1 addition & 0 deletions llvm/test/DebugInfo/symbolize-build-id.test
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Sections:
Type: SHT_NOTE
Flags: [ SHF_ALLOC ]
Content: 040000000800000003000000474e5500abb50d82b6bdc861
AddressAlign: 4
ProgramHeaders:
- Type: PT_NOTE
Flags: [ PF_R ]
Expand Down