aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Object
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/Object')
-rw-r--r--llvm/lib/Object/BuildID.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/llvm/lib/Object/BuildID.cpp b/llvm/lib/Object/BuildID.cpp
index 89d6bc3..d1ee597 100644
--- a/llvm/lib/Object/BuildID.cpp
+++ b/llvm/lib/Object/BuildID.cpp
@@ -24,6 +24,24 @@ 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());
+ 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());
@@ -32,12 +50,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 {};
}