From 60561f68642c36764f5fbc9784b61a84626573ea Mon Sep 17 00:00:00 2001 From: Sandro Wenzel Date: Mon, 9 Nov 2026 13:25:46 +0100 Subject: [PATCH] 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 --- Detectors/gconfig/src/SimSetup.cxx | 33 +++++++++++++----------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/Detectors/gconfig/src/SimSetup.cxx b/Detectors/gconfig/src/SimSetup.cxx index aaec17d97ef10..12663eb1723df 100644 --- a/Detectors/gconfig/src/SimSetup.cxx +++ b/Detectors/gconfig/src/SimSetup.cxx @@ -14,12 +14,9 @@ #include "TVirtualMC.h" #include #include "SetCuts.h" +#include "CommonUtils/DLLoaderBase.h" #include -#ifdef NDEBUG -#undef NDEBUG -#endif -#include -#include +#include namespace o2 { @@ -28,23 +25,21 @@ typedef void (*setup_fnc)(); void execFromPlugin(const char* libname, const char* funcname) { - auto libHandle = dlopen(libname, RTLD_NOW); - // try to make the library loading a bit more portable: + const std::string filename = std::string(libname) + DLLOADER_MAC_LINUX(".dylib", ".so"); + auto libHandle = dlopen(filename.c_str(), RTLD_NOW); if (!libHandle) { - // try appending *.so - std::stringstream stream; - stream << libname << ".so"; - libHandle = dlopen(stream.str().c_str(), RTLD_NOW); + const char* error = dlerror(); + LOG(fatal) << "Cannot load " << filename << ": " << (error ? error : "unknown error"); + // LOG(fatal) ends the process only when a fatal handler is installed + throw fair::FatalException("Cannot load " + filename); } - if (!libHandle) { - // try appending *.dylib - std::stringstream stream; - stream << libname << ".dylib"; - libHandle = dlopen(stream.str().c_str(), RTLD_NOW); - } - assert(libHandle); + dlerror(); // clear any pending error before dlsym auto func = (setup_fnc)dlsym(libHandle, funcname); - assert(func); + if (!func) { + const char* error = dlerror(); + LOG(fatal) << "Cannot find " << funcname << " in " << filename << ": " << (error ? error : "the symbol is null"); + throw fair::FatalException("Cannot find " + std::string(funcname) + " in " + filename); + } func(); }