Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion llvm/include/llvm/Object/ELFTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ class Elf_Note_Impl {

/// Get the note's descriptor.
ArrayRef<uint8_t> getDesc(size_t Align) const {
if (!Nhdr.n_descsz || !Align)
if (!Nhdr.n_descsz)
return ArrayRef<uint8_t>();
return ArrayRef<uint8_t>(
reinterpret_cast<const uint8_t *>(&Nhdr) +
Expand Down
30 changes: 17 additions & 13 deletions llvm/lib/Object/BuildID.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,27 @@ 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;
Error Err = Error::success();
for (auto N : Obj.notes(S, Err))
if (N.getType() == ELF::NT_GNU_BUILD_ID &&
N.getName() == ELF::ELF_NOTE_GNU)
return N.getDesc(S.sh_addralign);
consumeError(std::move(Err));
auto ShdrRes = findBuildID(S, S.sh_addralign);
if (ShdrRes)
return ShdrRes.value();
}
}

auto PhdrsOrErr = Obj.program_headers();
if (!PhdrsOrErr) {
consumeError(PhdrsOrErr.takeError());
Expand All @@ -46,12 +53,9 @@ 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));
auto PhdrRes = findBuildID(P, P.p_align);
if (PhdrRes)
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