[Openmp-commits] [openmp] [libomptarget] Support BE ELF files in plugins-nextgen (PR #83976)
Joseph Huber via Openmp-commits
openmp-commits at lists.llvm.org
Tue Mar 5 20:42:20 PST 2024
================
@@ -81,55 +71,36 @@ Error GenericGlobalHandlerTy::moveGlobalBetweenDeviceAndHost(
bool GenericGlobalHandlerTy::isSymbolInImage(GenericDeviceTy &Device,
DeviceImageTy &Image,
StringRef SymName) {
- // Get the ELF object file for the image. Notice the ELF object may already
- // be created in previous calls, so we can reuse it. If this is unsuccessful
- // just return false as we couldn't find it.
- auto ELFObjOrErr = getELFObjectFile(Image);
- if (!ELFObjOrErr) {
- consumeError(ELFObjOrErr.takeError());
- return false;
- }
// Search the ELF symbol using the symbol name.
- auto SymOrErr = utils::elf::getSymbol(*ELFObjOrErr, SymName);
+ auto SymOrErr =
+ utils::elf::findSymbolInImage(Image.getMemoryBuffer(), SymName);
if (!SymOrErr) {
consumeError(SymOrErr.takeError());
return false;
}
- return *SymOrErr;
+ return !SymOrErr->empty();
}
Error GenericGlobalHandlerTy::getGlobalMetadataFromImage(
GenericDeviceTy &Device, DeviceImageTy &Image, GlobalTy &ImageGlobal) {
- // Get the ELF object file for the image. Notice the ELF object may already
- // be created in previous calls, so we can reuse it.
- auto ELFObj = getELFObjectFile(Image);
- if (!ELFObj)
- return ELFObj.takeError();
-
// Search the ELF symbol using the symbol name.
- auto SymOrErr = utils::elf::getSymbol(*ELFObj, ImageGlobal.getName());
+ auto SymOrErr = utils::elf::findSymbolInImage(Image.getMemoryBuffer(),
+ ImageGlobal.getName());
if (!SymOrErr)
return Plugin::error("Failed ELF lookup of global '%s': %s",
ImageGlobal.getName().data(),
toString(SymOrErr.takeError()).data());
- if (!*SymOrErr)
+ if (SymOrErr->empty())
return Plugin::error("Failed to find global symbol '%s' in the ELF image",
ImageGlobal.getName().data());
- auto AddrOrErr = utils::elf::getSymbolAddress(*ELFObj, **SymOrErr);
- // Get the section to which the symbol belongs.
- if (!AddrOrErr)
- return Plugin::error("Failed to get ELF symbol from global '%s': %s",
- ImageGlobal.getName().data(),
- toString(AddrOrErr.takeError()).data());
-
// Setup the global symbol's address and size.
- ImageGlobal.setPtr(const_cast<void *>(*AddrOrErr));
- ImageGlobal.setSize((*SymOrErr)->st_size);
+ ImageGlobal.setPtr((void *)(SymOrErr->data()));
----------------
jhuber6 wrote:
C++ casts please
https://github.com/llvm/llvm-project/pull/83976
More information about the Openmp-commits
mailing list