Storage duration of MPIHelper singleton
The following discussion from !1274 (closed) should be addressed:
-
@andreas.dedner started a discussion: (+4 comments) Just wanted to mention that we ran into problem with this singleton pattern with the python bindings - in fact the issue can come up with any code that combines multiple object files I believe. The issue has to do with 'semantic interposition` and leads to segfaults with clang:
Basically, clang did not guarantee that these singleton are unique between different units. So the variable would be initialized in one object file but there might be a separate version of the
singleton
in a different unit that was not initialized. That obviously leads to problems. I looked at this some time ago and by default gcc assumes semantic-interposition if not explicitly turned off (that is the ELF default). The version of clang that was available at the time (2y ago but don't have the version) provided no semantic-interposition by default and unfortunately had no flag to turn it on.We solved the problem in dune-fem by putting the singleton into
libdunefem
which all other modules link against. That makes the singleton truly unique. The hard ones we had were template dependent singletons...The following blog post that I found at the time has been updated in 2022 and apparently clang has a flag now to turn on
semantic interposition
: https://maskray.me/blog/2021-05-09-fno-semantic-interposition So we could probably require that flag for python bindings to avoid the issue or possibly the singleton can be instantiated inlibdunecommon
.