Skip to content

Commit

Permalink
[Libomptarget] Work around bug in initialization of libomptarget
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jhuber6 committed Mar 4, 2022
1 parent 703240c commit e2dcc22
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion openmp/libomptarget/DeviceRTL/src/Mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit e2dcc22

Please sign in to comment.