[Openmp-commits] [openmp] [OpenMP][FIX] Ensure we do not read outside the device image (PR #74669)

Joseph Huber via Openmp-commits openmp-commits at lists.llvm.org
Wed Dec 6 14:47:41 PST 2023

@@ -53,9 +57,15 @@ Error GenericGlobalHandlerTy::getGlobalMetadataFromELF(
     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(advanceVoidPtr(
-      Image.getStart(), Section.sh_offset - Section.sh_addr + Symbol.st_value));
+  // offset + the ELF symbol value except for NOBITS sections that, as the name
+  // suggests, have no bits in the image. We still record the size and use
+  // nullptr to indicate there is no location.
+  if (Section.sh_type == ELF::SHT_NOBITS)
jhuber6 wrote:

Not directly related, but could we remove this function from `GenericGlobalHandlerTy` and just make this a utility in `Elf.cpp` like `getSymbolAddr` that returns said void pointer?


More information about the Openmp-commits mailing list