[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:31:36 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:
Potentially we could make `getMetadataFromImage` do the `nullptr` handling. I just think that it's correct to have the function that gets the associated data to error if no such data exists.
https://github.com/llvm/llvm-project/pull/74717
More information about the Openmp-commits
mailing list