[Openmp-commits] [openmp] [Libomptarget] Move ELF symbol extraction to the ELF utility (PR #74717)

Joseph Huber via Openmp-commits openmp-commits at lists.llvm.org
Wed Dec 13 07:30:50 PST 2023


================
@@ -261,3 +261,27 @@ utils::elf::getSymbol(const ELFObjectFile<ELF64LE> &ELFObj, StringRef Name) {
 
   return nullptr;
 }
+
+Expected<const void *> utils::elf::getSymbolAddress(
+    const object::ELFObjectFile<object::ELF64LE> &ELFObj,
+    const object::ELF64LE::Sym &Symbol) {
+  const ELFFile<ELF64LE> &ELFFile = ELFObj.getELFFile();
+
+  auto SecOrErr = ELFFile.getSection(Symbol.st_shndx);
+  if (!SecOrErr)
+    return SecOrErr.takeError();
+  const auto &Section = *SecOrErr;
+
+  // A section with SHT_NOBITS occupies no space in the file and has no offset.
+  if (Section->sh_type == ELF::SHT_NOBITS)
+    return createError(
+        "invalid sh_type for symbol lookup, cannot be SHT_NOBITS");
----------------
jhuber6 wrote:

That's freely available with `Sym->st_size`. We could make a nicer looking helper if that's needed.

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


More information about the Openmp-commits mailing list