Skip to content

Commit f0e2ce6

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 suffix of the platform as in DLLoaderBase. - A runtime_error follows the fatal message, since LOG(fatal) ends the process only when a fatal handler is installed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a8a2a45 commit f0e2ce6

1 file changed

Lines changed: 18 additions & 19 deletions

File tree

‎Detectors/gconfig/src/SimSetup.cxx‎

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
#include <fairlogger/Logger.h>
1616
#include "SetCuts.h"
1717
#include <dlfcn.h>
18-
#ifdef NDEBUG
19-
#undef NDEBUG
20-
#endif
21-
#include <cassert>
22-
#include <sstream>
18+
#include <stdexcept>
19+
#include <string>
2320

2421
namespace o2
2522
{
@@ -28,23 +25,25 @@ 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:
33-
if (!libHandle) {
34-
// try appending *.so
35-
std::stringstream stream;
36-
stream << libname << ".so";
37-
libHandle = dlopen(stream.str().c_str(), RTLD_NOW);
38-
}
28+
#if defined(__APPLE__)
29+
const std::string filename = std::string(libname) + ".dylib";
30+
#else
31+
const std::string filename = std::string(libname) + ".so";
32+
#endif
33+
auto libHandle = dlopen(filename.c_str(), RTLD_NOW);
3934
if (!libHandle) {
40-
// try appending *.dylib
41-
std::stringstream stream;
42-
stream << libname << ".dylib";
43-
libHandle = dlopen(stream.str().c_str(), RTLD_NOW);
35+
const char* error = dlerror();
36+
LOG(fatal) << "Cannot load " << libname << ": " << (error ? error : "unknown error");
37+
// LOG(fatal) ends the process only when a fatal handler is installed
38+
throw std::runtime_error("Cannot load " + filename);
4439
}
45-
assert(libHandle);
40+
dlerror(); // clear any pending error before dlsym
4641
auto func = (setup_fnc)dlsym(libHandle, funcname);
47-
assert(func);
42+
if (!func) {
43+
const char* error = dlerror();
44+
LOG(fatal) << "Cannot find " << funcname << " in " << filename << ": " << (error ? error : "the symbol is null");
45+
throw std::runtime_error("Cannot find " + std::string(funcname) + " in " + filename);
46+
}
4847
func();
4948
}
5049

0 commit comments

Comments
 (0)