[Openmp-commits] [PATCH] D72472: [LIBOMPTARGET]Ignore empty target descriptors.
Alexey Bataev via Phabricator via Openmp-commits
openmp-commits at lists.llvm.org
Thu Jan 9 12:07:34 PST 2020
ABataev created this revision.
ABataev added a reviewer: grokos.
Herald added a reviewer: jdoerfert.
Herald added a project: OpenMP.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D72472
Files:
openmp/libomptarget/src/rtl.cpp
openmp/libomptarget/test/offloading/dynamic_module.c
Index: openmp/libomptarget/test/offloading/dynamic_module.c
===================================================================
--- /dev/null
+++ 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
Index: openmp/libomptarget/src/rtl.cpp
===================================================================
--- openmp/libomptarget/src/rtl.cpp
+++ openmp/libomptarget/src/rtl.cpp
@@ -234,6 +234,8 @@
// 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::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) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D72472.237150.patch
Type: text/x-patch
Size: 2102 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/openmp-commits/attachments/20200109/124d2de4/attachment.bin>
More information about the Openmp-commits
mailing list