[Openmp-commits] [openmp] e2dcc22 - [Libomptarget] Work around bug in initialization of libomptarget

Joseph Huber via Openmp-commits openmp-commits at lists.llvm.org
Fri Mar 4 10:13:43 PST 2022


Author: Joseph Huber
Date: 2022-03-04T13:13:31-05:00
New Revision: e2dcc2218c64ae1b6a774f52bd3aec87a6902b58

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

LOG: [Libomptarget] Work around bug in initialization of libomptarget

Libomptarget uses some shared variables to track certain internal stated
in the runtime. This causes problems when we have code that contains no
OpenMP kernels. These variables are normally initialized upon kernel
entry, but if there are no kernels we will see no initialization.
Currently we load the runtime into each source file when not running in
LTO mode, so these variables will be erroneously considered undefined or
dead and removed, causing miscompiles. This patch temporarily works
around the most obvious case, but others still exhibit this problem. We
will need to fix this more soundly later.

Fixes #54208.

Reviewed By: jdoerfert

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

Added: 
    

Modified: 
    openmp/libomptarget/DeviceRTL/src/Mapping.cpp

Removed: 
    


################################################################################
diff  --git a/openmp/libomptarget/DeviceRTL/src/Mapping.cpp b/openmp/libomptarget/DeviceRTL/src/Mapping.cpp
index 23615cb2f4ed1..21104be3d02eb 100644
--- a/openmp/libomptarget/DeviceRTL/src/Mapping.cpp
+++ b/openmp/libomptarget/DeviceRTL/src/Mapping.cpp
@@ -258,7 +258,10 @@ uint32_t mapping::getNumberOfProcessorElements() {
 /// Execution mode
 ///
 ///{
-static int SHARED(IsSPMDMode);
+
+// TODO: This is a workaround for initialization coming from kernels outside of
+//       the TU. We will need to solve this more correctly in the future.
+int __attribute__((used, retain, weak)) SHARED(IsSPMDMode);
 
 void mapping::init(bool IsSPMD) {
   if (mapping::isInitialThreadInLevel0(IsSPMD))


        


More information about the Openmp-commits mailing list