[llvm] [llvm-objdump][ELF]Add Shdr buildID check(#126418) (PR #126537)

via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 10 08:13:38 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-binary-utilities

Author: Ruoyu Qiu (cabbaken)

<details>
<summary>Changes</summary>

Add Section Header check for getBuildID, fix crash with invalid Program Header.

---
Full diff: https://github.com/llvm/llvm-project/pull/126537.diff


1 Files Affected:

- (modified) llvm/lib/Object/BuildID.cpp (+16) 


``````````diff
diff --git a/llvm/lib/Object/BuildID.cpp b/llvm/lib/Object/BuildID.cpp
index 89d6bc3ab550db8..8bb15c89e02e884 100644
--- a/llvm/lib/Object/BuildID.cpp
+++ b/llvm/lib/Object/BuildID.cpp
@@ -24,6 +24,22 @@ using namespace llvm::object;
 namespace {
 
 template <typename ELFT> BuildIDRef getBuildID(const ELFFile<ELFT> &Obj) {
+  auto ShdrsOrErr = Obj.sections();
+  if (!ShdrsOrErr) {
+    consumeError(ShdrsOrErr.takeError());
+    return {};
+  }
+  for (const auto &S : *ShdrsOrErr) {
+    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 PhdrsOrErr = Obj.program_headers();
   if (!PhdrsOrErr) {
     consumeError(PhdrsOrErr.takeError());

``````````

</details>


https://github.com/llvm/llvm-project/pull/126537


More information about the llvm-commits mailing list