[Openmp-commits] [openmp] b19c081 - [LIBOMPTARGET]Ignore empty target descriptors.

Alexey Bataev via Openmp-commits openmp-commits at lists.llvm.org
Fri Jan 10 06:49:16 PST 2020


Author: Alexey Bataev
Date: 2020-01-10T09:45:27-05:00
New Revision: b19c0810e56b552d31247dcff081643799fd97fb

URL: https://github.com/llvm/llvm-project/commit/b19c0810e56b552d31247dcff081643799fd97fb
DIFF: https://github.com/llvm/llvm-project/commit/b19c0810e56b552d31247dcff081643799fd97fb.diff

LOG: [LIBOMPTARGET]Ignore empty target descriptors.

Summary:
If the dynamically loaded module has been compiled with -fopenmp-targets
and has no target regions, it has empty target descriptor. It leads to a
crash at the runtime if another module has at least one target region
and at least one entry in its descriptor. The runtime library is unable
to load the empty binary descriptor and terminates the execution.
Caused by a clang-offload-wrapper.

Reviewers: grokos, jdoerfert

Subscribers: caomhin, kkwli0, openmp-commits

Tags: #openmp

Differential Revision: https://reviews.llvm.org/D72472

Added: 
    openmp/libomptarget/test/offloading/dynamic_module.c

Modified: 
    openmp/libomptarget/src/rtl.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/src/rtl.cpp b/openmp/libomptarget/src/rtl.cpp
index 35470f587b96..749f12c0773b 100644
--- a/openmp/libomptarget/src/rtl.cpp
+++ b/openmp/libomptarget/src/rtl.cpp
@@ -234,6 +234,8 @@ void RTLsTy::RegisterLib(__tgt_bin_desc *desc) {
   // Attempt to load all plugins available in the system.
   std::call_once(initFlag, &RTLsTy::LoadRTLs, this);
 
+  if (desc->HostEntriesBegin == desc->HostEntriesEnd)
+    return;
   RTLsMtx.lock();
   // Register the images with the RTLs that understand them, if any.
   for (int32_t i = 0; i < desc->NumDeviceImages; ++i) {
@@ -320,6 +322,8 @@ void RTLsTy::RegisterLib(__tgt_bin_desc *desc) {
 void RTLsTy::UnregisterLib(__tgt_bin_desc *desc) {
   DP("Unloading target library!\n");
 
+  if (desc->HostEntriesBegin == desc->HostEntriesEnd)
+    return;
   RTLsMtx.lock();
   // Find which RTL understands each image, if any.
   for (int32_t i = 0; i < desc->NumDeviceImages; ++i) {

diff  --git a/openmp/libomptarget/test/offloading/dynamic_module.c b/openmp/libomptarget/test/offloading/dynamic_module.c
new file mode 100644
index 000000000000..7f062b6d752c
--- /dev/null
+++ b/openmp/libomptarget/test/offloading/dynamic_module.c
@@ -0,0 +1,17 @@
+// RUN: %libomptarget-compile-aarch64-unknown-linux-gnu -DSHARED -shared -o %t.so && %libomptarget-compile-aarch64-unknown-linux-gnu %t.so && %libomptarget-run-aarch64-unknown-linux-gnu 2>&1 | %fcheck-aarch64-unknown-linux-gnu
+// RUN: %libomptarget-compile-powerpc64-ibm-linux-gnu -DSHARED -shared -o %t.so && %libomptarget-compile-powerpc64-ibm-linux-gnu %t.so && %libomptarget-run-powerpc64-ibm-linux-gnu 2>&1 | %fcheck-powerpc64-ibm-linux-gnu
+// RUN: %libomptarget-compile-powerpc64le-ibm-linux-gnu -DSHARED -shared -o %t.so && %libomptarget-compile-powerpc64le-ibm-linux-gnu %t.so && %libomptarget-run-powerpc64le-ibm-linux-gnu 2>&1 | %fcheck-powerpc64le-ibm-linux-gnu
+// RUN: %libomptarget-compile-x86_64-pc-linux-gnu -DSHARED -shared -o %t.so && %libomptarget-compile-x86_64-pc-linux-gnu %t.so && %libomptarget-run-x86_64-pc-linux-gnu 2>&1 | %fcheck-x86_64-pc-linux-gnu
+
+#ifdef SHARED
+void foo() {}
+#else
+#include <stdio.h>
+int main() {
+#pragma omp target
+  ;
+  // CHECK: DONE.
+  printf("%s\n", "DONE.");
+  return 0;
+}
+#endif


        


More information about the Openmp-commits mailing list