[Openmp-commits] [PATCH] D138604: [OpenMP][libomptarget] Allow overriding function that gets ELF symbol info
Kevin Sala Penadés via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Sat Dec 3 12:51:54 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG4fde81679c78: [OpenMP][libomptarget] Allow overriding function that gets ELF symbol info (authored by kevinsala).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138604/new/
https://reviews.llvm.org/D138604
Files:
openmp/libomptarget/plugins-nextgen/common/PluginInterface/GlobalHandler.cpp
openmp/libomptarget/plugins-nextgen/common/PluginInterface/GlobalHandler.h
Index: openmp/libomptarget/plugins-nextgen/common/PluginInterface/GlobalHandler.h
===================================================================
--- openmp/libomptarget/plugins-nextgen/common/PluginInterface/GlobalHandler.h
+++ openmp/libomptarget/plugins-nextgen/common/PluginInterface/GlobalHandler.h
@@ -96,6 +96,12 @@
const ELF64LEObjectFile *
getOrCreateELFObjectFile(const GenericDeviceTy &Device, DeviceImageTy &Image);
+ /// Extract the global's information from the ELF image, section, and symbol.
+ virtual Error getGlobalMetadataFromELF(const DeviceImageTy &Image,
+ const ELF64LE::Sym &Symbol,
+ const ELF64LE::Shdr &Section,
+ GlobalTy &ImageGlobal);
+
/// Actually move memory between host and device. See readGlobalFromDevice and
/// writeGlobalToDevice for the interface description.
Error moveGlobalBetweenDeviceAndHost(GenericDeviceTy &Device,
Index: openmp/libomptarget/plugins-nextgen/common/PluginInterface/GlobalHandler.cpp
===================================================================
--- openmp/libomptarget/plugins-nextgen/common/PluginInterface/GlobalHandler.cpp
+++ openmp/libomptarget/plugins-nextgen/common/PluginInterface/GlobalHandler.cpp
@@ -46,6 +46,21 @@
return &Result.first->second;
}
+Error GenericGlobalHandlerTy::getGlobalMetadataFromELF(
+ const DeviceImageTy &Image, const ELF64LE::Sym &Symbol,
+ const ELF64LE::Shdr &Section, GlobalTy &ImageGlobal) {
+
+ // The global's address is computed as the image begin + the ELF section
+ // offset + the ELF symbol value.
+ ImageGlobal.setPtr((char *)Image.getStart() + Section.sh_offset +
+ Symbol.st_value);
+
+ // Set the global's size.
+ ImageGlobal.setSize(Symbol.st_size);
+
+ return Plugin::success();
+}
+
Error GenericGlobalHandlerTy::moveGlobalBetweenDeviceAndHost(
GenericDeviceTy &Device, DeviceImageTy &Image, const GlobalTy &HostGlobal,
bool Device2Host) {
@@ -111,19 +126,14 @@
ImageGlobal.getName().data());
// Get the section to which the symbol belongs.
- auto SymSecOrErr = ELFObj->getELFFile().getSection((*SymOrErr)->st_shndx);
- if (!SymSecOrErr)
+ auto SecOrErr = ELFObj->getELFFile().getSection((*SymOrErr)->st_shndx);
+ if (!SecOrErr)
return Plugin::error("Failed to get ELF section from global '%s': %s",
ImageGlobal.getName().data(),
- toString(SymOrErr.takeError()).data());
+ toString(SecOrErr.takeError()).data());
- // Save the global symbol's address and size. The address of the global is the
- // image base address + the section offset + the symbol value.
- ImageGlobal.setPtr((char *)Image.getStart() + (*SymSecOrErr)->sh_offset +
- (*SymOrErr)->st_value);
- ImageGlobal.setSize((*SymOrErr)->st_size);
-
- return Plugin::success();
+ // Setup the global symbol's address and size.
+ return getGlobalMetadataFromELF(Image, **SymOrErr, **SecOrErr, ImageGlobal);
}
Error GenericGlobalHandlerTy::readGlobalFromImage(GenericDeviceTy &Device,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138604.479863.patch
Type: text/x-patch
Size: 3203 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20221203/259c93cb/attachment.bin>
More information about the Openmp-commits
mailing list