[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
Tue Dec 12 15:25:04 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:

I wasn't sure what the original intention was, as far as I could tell it would hit this error because there was a check for `nullptr` right after where we would look this up. That being said, even though we can check size and it exists, it still had no data associated with it so it seems kind of weird. If you want to look up a symbol you can use the other ELF Symbol lookup so that's my understanding.


More information about the Openmp-commits mailing list