[OMPT] Provide initialization for Mac OS X
authorJonas Hahnfeld <hahnjo@hahnjo.de>
Sat, 11 Nov 2017 13:59:48 +0000 (13:59 +0000)
committerJonas Hahnfeld <hahnjo@hahnjo.de>
Sat, 11 Nov 2017 13:59:48 +0000 (13:59 +0000)
commitd0ef19ef9b2c4c61ecd10b133632c795c3bc2d31
tree0887d4ea63782e1a28eaca6791a334261bbc6998
parent3acaa701adbb0820d968ffcd4886e443f9fe9ca3
[OMPT] Provide initialization for Mac OS X

Traditionally, the library had a weak symbol for ompt_start_tool()
that served as fallback and disabled OMPT if called. Tools could
provide their own version and replace the default implementation
to register callbacks and lookup functions. This mechanism has
worked reasonably well on Linux systems where this interface was
initially developed.

On Darwin / Mac OS X the situation is a bit more complicated and
the weak symbol doesn't work out-of-the-box. In my tests, the
library with the tool needed to link against the OpenMP runtime
to make the process work. This would effectively mean that a tool
needed to choose a runtime library whereas one design goal of the
interface was to allow tools that are agnostic of the runtime.

The solution is to use dlsym() with the argument RTLD_DEFAULT so
that static implementations of ompt_start_tool() are found in the
main executable. This works because the linker on Mac OS X includes
all symbols of an executable in the global symbol table by default.
To use the same code path on Linux, the application would need to
be built with -Wl,--export-dynamic. To avoid this restriction, we
continue to use weak symbols on Linux systems as before.

Finally this patch extends the existing test to cover all possible
ways of initializing the tool as described by the standard. It
also fixes ompt_finalize() to not call omp_get_thread_num() when
the library is shut down which resulted in hangs on Darwin.
The changes have been tested on Linux to make sure that it passes
the current tests as well as the newly extended one.

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

llvm-svn: 317980
openmp/runtime/cmake/config-ix.cmake
openmp/runtime/src/ompt-general.cpp
openmp/runtime/test/lit.cfg
openmp/runtime/test/ompt/loadtool/tool_available.c