[llvm] [llvm-gsymutil] Read function symbols from .gnu_debugdata in gsymutil (PR #227159)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 2 00:56:01 PDT 2026


================
@@ -893,3 +896,56 @@ StringRef ELFObjectFileBase::getCrelDecodeProblem(SectionRef Sec) const {
     return Obj->getCrelDecodeProblem(Data);
   return cast<ELF64BEObjectFile>(this)->getCrelDecodeProblem(Data);
 }
+
+static constexpr StringLiteral GnuDebugDataSectionName = ".gnu_debugdata";
+
+static std::optional<SectionRef>
+findGnuDebugDataSection(const ELFObjectFileBase &Obj) {
+  for (SectionRef Sec : Obj.sections()) {
+    Expected<StringRef> NameOrErr = Sec.getName();
+    // Ignore malformed names so they do not prevent finding a valid section.
+    if (!NameOrErr) {
+      consumeError(NameOrErr.takeError());
+      continue;
+    }
+    if (*NameOrErr == GnuDebugDataSectionName)
+      return Sec;
+  }
+  return std::nullopt;
+}
+
+bool ELFObjectFileBase::hasGnuDebugDataSection() const {
+  return findGnuDebugDataSection(*this).has_value();
+}
+
+Expected<OwningBinary<ObjectFile>>
+ELFObjectFileBase::getGnuDebugDataObjectFile() const {
----------------
jh7370 wrote:

This is only used in one place. Does it need to be an `ELFObjectFileBase` member, or can it be done at the call site, thus not expanding the class interface unnecessarily?

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


More information about the llvm-commits mailing list