Skip to content

Commit 4ffbcee

Browse files
committed
Improve shared library loading path output
Fix logger debug outout showing which actual files are loaded after path resolution. Without this not useful for debugging misconfigured systems. Signed-off-by: Russell McGuire <russell.w.mcguire@intel.com>
1 parent 79ab38c commit 4ffbcee

1 file changed

Lines changed: 60 additions & 7 deletions

File tree

source/loader/ze_loader.cpp

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,19 @@ namespace loader
511511
auto handle = LOAD_DRIVER_LIBRARY( driver.name.c_str() );
512512
if( NULL != handle )
513513
{
514+
if (debugTraceEnabled) {
515+
#if !defined(_WIN32) && !defined(ANDROID)
516+
struct link_map *dlinfo_map;
517+
if (dlinfo(handle, RTLD_DI_LINKMAP, &dlinfo_map) == 0) {
518+
debug_trace_message("init driver " + driver.name + " resolved path: ", std::string(dlinfo_map->l_name));
519+
}
520+
#elif defined(_WIN32)
521+
char resolved[MAX_PATH];
522+
if (GetModuleFileNameA(static_cast<HMODULE>(handle), resolved, MAX_PATH)) {
523+
debug_trace_message("init driver " + driver.name + " resolved path: ", std::string(resolved));
524+
}
525+
#endif
526+
}
514527
driver.handle = handle;
515528
} else {
516529
std::string loadLibraryErrorValue;
@@ -662,19 +675,31 @@ namespace loader
662675
if( getenv_tobool( "ZE_ENABLE_NULL_DRIVER" ) )
663676
{
664677
zel_logger->log_info("Enabling Null Driver");
665-
auto handle = LOAD_DRIVER_LIBRARY( create_library_path( MAKE_LIBRARY_NAME( "ze_null", L0_LOADER_VERSION ), loaderLibraryPath.c_str()).c_str());
666-
if (debugTraceEnabled) {
667-
std::string message = "ze_null Driver Init";
668-
debug_trace_message(message, "");
669-
}
678+
std::string nullDriverPath = create_library_path( MAKE_LIBRARY_NAME( "ze_null", L0_LOADER_VERSION ), loaderLibraryPath.c_str());
679+
if (debugTraceEnabled)
680+
debug_trace_message("Null Driver Library Path (requested): ", nullDriverPath);
681+
auto handle = LOAD_DRIVER_LIBRARY( nullDriverPath.c_str() );
670682
if( NULL != handle )
671683
{
684+
if (debugTraceEnabled) {
685+
#if !defined(_WIN32) && !defined(ANDROID)
686+
struct link_map *dlinfo_map;
687+
if (dlinfo(handle, RTLD_DI_LINKMAP, &dlinfo_map) == 0) {
688+
debug_trace_message("Null Driver Library Path (resolved): ", std::string(dlinfo_map->l_name));
689+
}
690+
#elif defined(_WIN32)
691+
char resolved[MAX_PATH];
692+
if (GetModuleFileNameA(static_cast<HMODULE>(handle), resolved, MAX_PATH)) {
693+
debug_trace_message("Null Driver Library Path (resolved): ", std::string(resolved));
694+
}
695+
#endif
696+
}
672697
allDrivers.emplace_back();
673698
allDrivers.rbegin()->handle = handle;
674699
allDrivers.rbegin()->name = "ze_null";
675700
} else if (debugTraceEnabled) {
676701
GET_LIBRARY_ERROR(loadLibraryErrorValue);
677-
std::string errorMessage = "Load Library of " + create_library_path( MAKE_LIBRARY_NAME( "ze_null", L0_LOADER_VERSION ), loaderLibraryPath.c_str()) + " failed with ";
702+
std::string errorMessage = "Load Library of " + nullDriverPath + " failed with ";
678703
debug_trace_message(errorMessage, loadLibraryErrorValue);
679704
loadLibraryErrorValue.clear();
680705
}
@@ -731,9 +756,24 @@ namespace loader
731756
{
732757
zel_logger->log_info("Validation Layer Enabled");
733758
std::string validationLayerLibraryPath = create_library_path(MAKE_LAYER_NAME( "ze_validation_layer" ), loaderLibraryPath.c_str());
759+
if (debugTraceEnabled)
760+
debug_trace_message("Validation Layer Library Path (requested): ", validationLayerLibraryPath);
734761
validationLayer = LOAD_DRIVER_LIBRARY( validationLayerLibraryPath.c_str() );
735762
if(validationLayer)
736763
{
764+
if (debugTraceEnabled) {
765+
#if !defined(_WIN32) && !defined(ANDROID)
766+
struct link_map *dlinfo_map;
767+
if (dlinfo(validationLayer, RTLD_DI_LINKMAP, &dlinfo_map) == 0) {
768+
debug_trace_message("Validation Layer Library Path (resolved): ", std::string(dlinfo_map->l_name));
769+
}
770+
#elif defined(_WIN32)
771+
char resolved[MAX_PATH];
772+
if (GetModuleFileNameA(static_cast<HMODULE>(validationLayer), resolved, MAX_PATH)) {
773+
debug_trace_message("Validation Layer Library Path (resolved): ", std::string(resolved));
774+
}
775+
#endif
776+
}
737777
auto getVersion = reinterpret_cast<getVersion_t>(
738778
GET_FUNCTION_PTR(validationLayer, "zelLoaderGetVersion"));
739779
zel_component_version_t compVersion;
@@ -755,10 +795,23 @@ namespace loader
755795
}
756796
std::string tracingLayerLibraryPath = create_library_path(MAKE_LAYER_NAME( "ze_tracing_layer" ), loaderLibraryPath.c_str());
757797
if (debugTraceEnabled)
758-
debug_trace_message("Tracing Layer Library Path: ", tracingLayerLibraryPath);
798+
debug_trace_message("Tracing Layer Library Path (requested): ", tracingLayerLibraryPath);
759799
tracingLayer = LOAD_DRIVER_LIBRARY( tracingLayerLibraryPath.c_str() );
760800
if(tracingLayer)
761801
{
802+
if (debugTraceEnabled) {
803+
#if !defined(_WIN32) && !defined(ANDROID)
804+
struct link_map *dlinfo_map;
805+
if (dlinfo(tracingLayer, RTLD_DI_LINKMAP, &dlinfo_map) == 0) {
806+
debug_trace_message("Tracing Layer Library Path (resolved): ", std::string(dlinfo_map->l_name));
807+
}
808+
#elif defined(_WIN32)
809+
char resolved[MAX_PATH];
810+
if (GetModuleFileNameA(static_cast<HMODULE>(tracingLayer), resolved, MAX_PATH)) {
811+
debug_trace_message("Tracing Layer Library Path (resolved): ", std::string(resolved));
812+
}
813+
#endif
814+
}
762815
auto getVersion = reinterpret_cast<getVersion_t>(
763816
GET_FUNCTION_PTR(tracingLayer, "zelLoaderGetVersion"));
764817
zel_component_version_t compVersion;

0 commit comments

Comments
 (0)