[Libomptarget] Remove handling of old ctor / dtor entries (#80153)

Summary:
A previous patch removed creating these entries in clang in favor of the
backend emitting a callable kernel and having the runtime call that if
present. The support for the old style was kept around in LLVM 18.0 but
now that we have forked to 19.0 we should remove the support.

The effect of this would be that an application linking against a newer
libomptarget that still had the old constructors will no longer be
called. In that case, they can either recompile or use the
`libomptarget.so.18` that comes with the previous release.

GitOrigin-RevId: 254287658f4b3e413d47870c1cca422071b398ff
diff --git a/libomptarget/include/OffloadEntry.h b/libomptarget/include/OffloadEntry.h
index 5173841..da1de81 100644
--- a/libomptarget/include/OffloadEntry.h
+++ b/libomptarget/include/OffloadEntry.h
@@ -36,8 +36,6 @@
   const char *getNameAsCStr() const { return OffloadEntry.name; }
   __tgt_bin_desc *getBinaryDescription() const;
 
-  bool isCTor() const { return hasFlags(OMP_DECLARE_TARGET_CTOR); }
-  bool isDTor() const { return hasFlags(OMP_DECLARE_TARGET_DTOR); }
   bool isLink() const { return hasFlags(OMP_DECLARE_TARGET_LINK); }
 
   bool hasFlags(OpenMPOffloadingDeclareTargetFlags Flags) const {
diff --git a/libomptarget/include/PluginManager.h b/libomptarget/include/PluginManager.h
index a0499c3..ec5d98d 100644
--- a/libomptarget/include/PluginManager.h
+++ b/libomptarget/include/PluginManager.h
@@ -58,10 +58,6 @@
   /// user.
   int32_t getNumberOfUserDevices() const { return NumberOfUserDevices; }
 
-  /// Add all offload entries described by \p DI to the devices managed by this
-  /// plugin.
-  void addOffloadEntries(DeviceImageTy &DI);
-
   /// RTL index, index is the number of devices of other RTLs that were
   /// registered before, i.e. the OpenMP index of the first device to be
   /// registered with this RTL.
diff --git a/libomptarget/include/device.h b/libomptarget/include/device.h
index 1dc82e3..3b40de9 100644
--- a/libomptarget/include/device.h
+++ b/libomptarget/include/device.h
@@ -38,14 +38,6 @@
 struct __tgt_bin_desc;
 struct __tgt_target_table;
 
-///
-struct PendingCtorDtorListsTy {
-  std::list<void *> PendingCtors;
-  std::list<void *> PendingDtors;
-};
-typedef std::map<__tgt_bin_desc *, PendingCtorDtorListsTy>
-    PendingCtorsDtorsPerLibrary;
-
 struct DeviceTy {
   int32_t DeviceID;
   PluginAdaptorTy *RTL;
@@ -53,10 +45,6 @@
 
   bool HasMappedGlobalData = false;
 
-  PendingCtorsDtorsPerLibrary PendingCtorsDtors;
-
-  std::mutex PendingGlobalsMtx;
-
   DeviceTy(PluginAdaptorTy *RTL, int32_t DeviceID, int32_t RTLDeviceID);
   // DeviceTy is not copyable
   DeviceTy(const DeviceTy &D) = delete;
@@ -158,9 +146,6 @@
   int32_t destroyEvent(void *Event);
   /// }
 
-  /// Register \p Entry as an offload entry that is avalable on this device.
-  void addOffloadEntry(const OffloadEntryTy &Entry);
-
   /// Print all offload entries to stderr.
   void dumpOffloadEntries();
 
diff --git a/libomptarget/include/omptarget.h b/libomptarget/include/omptarget.h
index d5602ee..3016467 100644
--- a/libomptarget/include/omptarget.h
+++ b/libomptarget/include/omptarget.h
@@ -91,10 +91,6 @@
 enum OpenMPOffloadingDeclareTargetFlags {
   /// Mark the entry global as having a 'link' attribute.
   OMP_DECLARE_TARGET_LINK = 0x01,
-  /// Mark the entry kernel as being a global constructor.
-  OMP_DECLARE_TARGET_CTOR = 0x02,
-  /// Mark the entry kernel as being a global destructor.
-  OMP_DECLARE_TARGET_DTOR = 0x04,
   /// Mark the entry global as being an indirectly callable function.
   OMP_DECLARE_TARGET_INDIRECT = 0x08
 };
diff --git a/libomptarget/src/PluginManager.cpp b/libomptarget/src/PluginManager.cpp
index f65ffc4..0693d4b 100644
--- a/libomptarget/src/PluginManager.cpp
+++ b/libomptarget/src/PluginManager.cpp
@@ -89,19 +89,6 @@
   return Error::success();
 }
 
-void PluginAdaptorTy::addOffloadEntries(DeviceImageTy &DI) {
-  for (int32_t I = 0, E = getNumberOfUserDevices(); I < E; ++I) {
-    auto DeviceOrErr = PM->getDevice(DeviceOffset + I);
-    if (!DeviceOrErr)
-      FATAL_MESSAGE(DeviceOffset + I, "%s",
-                    toString(DeviceOrErr.takeError()).c_str());
-
-    DeviceTy &Device = *DeviceOrErr;
-    for (__tgt_offload_entry &Entry : DI.entries())
-      Device.addOffloadEntry(OffloadEntryTy(DI, Entry));
-  }
-}
-
 void PluginManager::init() {
   TIMESCOPE();
   DP("Loading RTLs...\n");
@@ -259,9 +246,6 @@
       PM->TrlTblMtx.unlock();
       FoundRTL = &R;
 
-      // Register all offload entries with the devices handled by the plugin.
-      R.addOffloadEntries(DI);
-
       // if an RTL was found we are done - proceed to register the next image
       break;
     }
@@ -302,34 +286,6 @@
 
       FoundRTL = &R;
 
-      // Execute dtors for static objects if the device has been used, i.e.
-      // if its PendingCtors list has been emptied.
-      for (int32_t I = 0; I < FoundRTL->getNumberOfUserDevices(); ++I) {
-        auto DeviceOrErr = PM->getDevice(FoundRTL->DeviceOffset + I);
-        if (!DeviceOrErr)
-          FATAL_MESSAGE(FoundRTL->DeviceOffset + I, "%s",
-                        toString(DeviceOrErr.takeError()).c_str());
-
-        DeviceTy &Device = *DeviceOrErr;
-        Device.PendingGlobalsMtx.lock();
-        if (Device.PendingCtorsDtors[Desc].PendingCtors.empty()) {
-          AsyncInfoTy AsyncInfo(Device);
-          for (auto &Dtor : Device.PendingCtorsDtors[Desc].PendingDtors) {
-            int Rc =
-                target(nullptr, Device, Dtor, CTorDTorKernelArgs, AsyncInfo);
-            if (Rc != OFFLOAD_SUCCESS) {
-              DP("Running destructor " DPxMOD " failed.\n", DPxPTR(Dtor));
-            }
-          }
-          // Remove this library's entry from PendingCtorsDtors
-          Device.PendingCtorsDtors.erase(Desc);
-          // All constructors have been issued, wait for them now.
-          if (AsyncInfo.synchronize() != OFFLOAD_SUCCESS)
-            DP("Failed synchronizing destructors kernels.\n");
-        }
-        Device.PendingGlobalsMtx.unlock();
-      }
-
       DP("Unregistered image " DPxMOD " from RTL " DPxMOD "!\n",
          DPxPTR(Img->ImageStart), DPxPTR(R.LibraryHandler.get()));
 
diff --git a/libomptarget/src/device.cpp b/libomptarget/src/device.cpp
index 9bdc6b7..67edc55 100644
--- a/libomptarget/src/device.cpp
+++ b/libomptarget/src/device.cpp
@@ -66,7 +66,7 @@
 
 DeviceTy::DeviceTy(PluginAdaptorTy *RTL, int32_t DeviceID, int32_t RTLDeviceID)
     : DeviceID(DeviceID), RTL(RTL), RTLDeviceID(RTLDeviceID),
-      PendingCtorsDtors(), PendingGlobalsMtx(), MappingInfo(*this) {}
+      MappingInfo(*this) {}
 
 DeviceTy::~DeviceTy() {
   if (DeviceID == -1 || !(getInfoLevel() & OMP_INFOTYPE_DUMP_TABLE))
@@ -297,48 +297,11 @@
   return OFFLOAD_SUCCESS;
 }
 
-void DeviceTy::addOffloadEntry(const OffloadEntryTy &Entry) {
-  std::lock_guard<decltype(PendingGlobalsMtx)> Lock(PendingGlobalsMtx);
-  DeviceOffloadEntries.getExclusiveAccessor()->insert({Entry.getName(), Entry});
-  if (Entry.isGlobal())
-    return;
-
-  if (Entry.isCTor()) {
-    DP("Adding ctor " DPxMOD " to the pending list.\n",
-       DPxPTR(Entry.getAddress()));
-    MESSAGE("WARNING: Calling deprecated constructor for entry %s will be "
-            "removed in a future release \n",
-            Entry.getNameAsCStr());
-    PendingCtorsDtors[Entry.getBinaryDescription()].PendingCtors.push_back(
-        Entry.getAddress());
-  } else if (Entry.isDTor()) {
-    // Dtors are pushed in reverse order so they are executed from end
-    // to beginning when unregistering the library!
-    DP("Adding dtor " DPxMOD " to the pending list.\n",
-       DPxPTR(Entry.getAddress()));
-    MESSAGE("WARNING: Calling deprecated destructor for entry %s will be "
-            "removed in a future release \n",
-            Entry.getNameAsCStr());
-    PendingCtorsDtors[Entry.getBinaryDescription()].PendingDtors.push_front(
-        Entry.getAddress());
-  }
-
-  if (Entry.isLink()) {
-    MESSAGE(
-        "WARNING: The \"link\" attribute is not yet supported for entry: %s!\n",
-        Entry.getNameAsCStr());
-  }
-}
-
 void DeviceTy::dumpOffloadEntries() {
   fprintf(stderr, "Device %i offload entries:\n", DeviceID);
   for (auto &It : *DeviceOffloadEntries.getExclusiveAccessor()) {
     const char *Kind = "kernel";
-    if (It.second.isCTor())
-      Kind = "constructor";
-    else if (It.second.isDTor())
-      Kind = "destructor";
-    else if (It.second.isLink())
+    if (It.second.isLink())
       Kind = "link";
     else if (It.second.isGlobal())
       Kind = "global var.";
diff --git a/libomptarget/src/omptarget.cpp b/libomptarget/src/omptarget.cpp
index 04490ab..5b85249 100644
--- a/libomptarget/src/omptarget.cpp
+++ b/libomptarget/src/omptarget.cpp
@@ -291,36 +291,9 @@
     }
   }
 
-  if (Rc != OFFLOAD_SUCCESS) {
+  if (Rc != OFFLOAD_SUCCESS)
     return Rc;
-  }
 
-  /*
-   * Run ctors for static objects
-   */
-  if (!Device.PendingCtorsDtors.empty()) {
-    AsyncInfoTy AsyncInfo(Device);
-    // Call all ctors for all libraries registered so far
-    for (auto &Lib : Device.PendingCtorsDtors) {
-      if (!Lib.second.PendingCtors.empty()) {
-        DP("Has pending ctors... call now\n");
-        for (auto &Entry : Lib.second.PendingCtors) {
-          void *Ctor = Entry;
-          int Rc = target(nullptr, Device, Ctor, CTorDTorKernelArgs, AsyncInfo);
-          if (Rc != OFFLOAD_SUCCESS) {
-            REPORT("Running ctor " DPxMOD " failed.\n", DPxPTR(Ctor));
-            return OFFLOAD_FAIL;
-          }
-        }
-        // Clear the list to indicate that this device has been used
-        Lib.second.PendingCtors.clear();
-        DP("Done with pending ctors for lib " DPxMOD "\n", DPxPTR(Lib.first));
-      }
-    }
-    // All constructors have been issued, wait for them now.
-    if (AsyncInfo.synchronize() != OFFLOAD_SUCCESS)
-      return OFFLOAD_FAIL;
-  }
   Device.HasMappedGlobalData = true;
 
   static Int32Envar DumpOffloadEntries =
@@ -435,14 +408,10 @@
     FATAL_MESSAGE(DeviceID, "%s", toString(DeviceOrErr.takeError()).data());
 
   // Check whether global data has been mapped for this device
-  {
-    std::lock_guard<decltype(DeviceOrErr->PendingGlobalsMtx)> LG(
-        DeviceOrErr->PendingGlobalsMtx);
-    if (initLibrary(*DeviceOrErr) != OFFLOAD_SUCCESS) {
-      REPORT("Failed to init globals on device %" PRId64 "\n", DeviceID);
-      handleTargetOutcome(false, Loc);
-      return true;
-    }
+  if (initLibrary(*DeviceOrErr) != OFFLOAD_SUCCESS) {
+    REPORT("Failed to init globals on device %" PRId64 "\n", DeviceID);
+    handleTargetOutcome(false, Loc);
+    return true;
   }
 
   return false;
diff --git a/libomptarget/test/offloading/ctor_dtor.cpp b/libomptarget/test/offloading/ctor_dtor.cpp
index 1d8b583..7f08798 100644
--- a/libomptarget/test/offloading/ctor_dtor.cpp
+++ b/libomptarget/test/offloading/ctor_dtor.cpp
@@ -1,13 +1,6 @@
 // RUN: %libomptarget-compilexx-run-and-check-generic
 // RUN: %libomptarget-compileoptxx-run-and-check-generic
-// RUN: %libomptarget-compilexx-generic && \
-// RUN: env OMPTARGET_DUMP_OFFLOAD_ENTRIES=0 %libomptarget-run-generic 2>&1 | \
-// RUN: %fcheck-generic --check-prefix=DUMP
-//
-// DUMP:     Device 0 offload entries:
-// DUMP-DAG:   global var.: s
-// DUMP-DAG:        kernel: __omp_offloading_{{.*}}_main_
-//
+
 #include <cstdio>
 struct S {
   S() : i(7) {}