[llvm] [llvm][ELF]Add Shdr check for getBuildID(#126418) (PR #126537)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 11 01:28:15 PST 2025


================
@@ -24,6 +24,20 @@ using namespace llvm::object;
 namespace {
 
 template <typename ELFT> BuildIDRef getBuildID(const ELFFile<ELFT> &Obj) {
+  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));
----------------
jh7370 wrote:

I assume it is, but please check that `consumeError` is safe if `Err` is `Error::success()`.

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


More information about the llvm-commits mailing list