summaryrefslogtreecommitdiffstats
path: root/openmp
diff options
context:
space:
mode:
authorAlexey Bataev <a.bataev@hotmail.com>2020-01-09 14:54:44 -0500
committerAlexey Bataev <a.bataev@hotmail.com>2020-01-10 09:45:27 -0500
commitb19c0810e56b552d31247dcff081643799fd97fb (patch)
treeade17da055bc7ebef9a7da2c8f8b150f73cac140 /openmp
parentbac995d97896c1e785d709da24c55f0e050eb899 (diff)
downloadbcm5719-llvm-b19c0810e56b552d31247dcff081643799fd97fb.tar.gz
bcm5719-llvm-b19c0810e56b552d31247dcff081643799fd97fb.zip
[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
Diffstat (limited to 'openmp')
-rw-r--r--openmp/libomptarget/src/rtl.cpp4
-rw-r--r--openmp/libomptarget/test/offloading/dynamic_module.c17
2 files changed, 21 insertions, 0 deletions
diff --git a/openmp/libomptarget/src/rtl.cpp b/openmp/libomptarget/src/rtl.cpp
index 35470f587b9..749f12c0773 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 00000000000..7f062b6d752
--- /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
OpenPOWER on IntegriCloud