[Openmp-commits] [openmp] [Libomptarget] Add a utility function for checking existence of symbols (PR #74550)

Shilei Tian via Openmp-commits openmp-commits at lists.llvm.org
Tue Dec 5 20:21:30 PST 2023

@@ -105,6 +105,26 @@ Error GenericGlobalHandlerTy::moveGlobalBetweenDeviceAndHost(
   return Plugin::success();
+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.
+  const ELF64LEObjectFile *ELFObj = getOrCreateELFObjectFile(Device, Image);
+  if (!ELFObj)
+    return false;
+  // Search the ELF symbol using the symbol name.
+  auto SymOrErr = utils::elf::getSymbol(*ELFObj, SymName);
+  if (!SymOrErr) {
+    consumeError(SymOrErr.takeError());
shiltian wrote:

We always consume the error. It might be a good idea to print the error if debug is enabled, but of course it is out of the scope of this patch.


More information about the Openmp-commits mailing list