Skip to content

Commit 60561f6

Browse files
sawenzelclaude
andcommitted
Report why a simulation setup library cannot be loaded
This replaces the asserts in execFromPlugin by fatal messages with the reason. - A failed dlopen of libO2G4Setup and friends stopped at assert(libHandle), without the error from dlerror(). - The message now gives the dlopen error, e.g. a missing static TLS reserve for Geant4 built with the initial-exec TLS model. - The library is opened once, with the platform suffix from DLLoaderBase.h. - A fair::FatalException follows the fatal message, since LOG(fatal) ends the process only when a fatal handler is installed. https://its.cern.ch/jira/browse/O2-7305 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a8a2a45 commit 60561f6

1 file changed

Lines changed: 14 additions & 19 deletions

File tree

‎Detectors/gconfig/src/SimSetup.cxx‎

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,9 @@
1414
#include "TVirtualMC.h"
1515
#include <fairlogger/Logger.h>
1616
#include "SetCuts.h"
17+
#include "CommonUtils/DLLoaderBase.h"
1718
#include <dlfcn.h>
18-
#ifdef NDEBUG
19-
#undef NDEBUG
20-
#endif
21-
#include <cassert>
22-
#include <sstream>
19+
#include <string>
2320

2421
namespace o2
2522
{
@@ -28,23 +25,21 @@ typedef void (*setup_fnc)();
2825

2926
void execFromPlugin(const char* libname, const char* funcname)
3027
{
31-
auto libHandle = dlopen(libname, RTLD_NOW);
32-
// try to make the library loading a bit more portable:
28+
const std::string filename = std::string(libname) + DLLOADER_MAC_LINUX(".dylib", ".so");
29+
auto libHandle = dlopen(filename.c_str(), RTLD_NOW);
3330
if (!libHandle) {
34-
// try appending *.so
35-
std::stringstream stream;
36-
stream << libname << ".so";
37-
libHandle = dlopen(stream.str().c_str(), RTLD_NOW);
31+
const char* error = dlerror();
32+
LOG(fatal) << "Cannot load " << filename << ": " << (error ? error : "unknown error");
33+
// LOG(fatal) ends the process only when a fatal handler is installed
34+
throw fair::FatalException("Cannot load " + filename);
3835
}
39-
if (!libHandle) {
40-
// try appending *.dylib
41-
std::stringstream stream;
42-
stream << libname << ".dylib";
43-
libHandle = dlopen(stream.str().c_str(), RTLD_NOW);
44-
}
45-
assert(libHandle);
36+
dlerror(); // clear any pending error before dlsym
4637
auto func = (setup_fnc)dlsym(libHandle, funcname);
47-
assert(func);
38+
if (!func) {
39+
const char* error = dlerror();
40+
LOG(fatal) << "Cannot find " << funcname << " in " << filename << ": " << (error ? error : "the symbol is null");
41+
throw fair::FatalException("Cannot find " + std::string(funcname) + " in " + filename);
42+
}
4843
func();
4944
}
5045

0 commit comments

Comments
 (0)