Skip to content

Commit e2dcc22

Browse files
committed
[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
1 parent 703240c commit e2dcc22

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

openmp/libomptarget/DeviceRTL/src/Mapping.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,10 @@ uint32_t mapping::getNumberOfProcessorElements() {
258258
/// Execution mode
259259
///
260260
///{
261-
static int SHARED(IsSPMDMode);
261+
262+
// TODO: This is a workaround for initialization coming from kernels outside of
263+
// the TU. We will need to solve this more correctly in the future.
264+
int __attribute__((used, retain, weak)) SHARED(IsSPMDMode);
262265

263266
void mapping::init(bool IsSPMD) {
264267
if (mapping::isInitialThreadInLevel0(IsSPMD))

0 commit comments

Comments
 (0)