diff --git a/libdwfl/debuginfod-client.c b/libdwfl/debuginfod-client.c index 37a4c71f..ee604ad9 100644 --- a/libdwfl/debuginfod-client.c +++ b/libdwfl/debuginfod-client.c @@ -46,32 +46,7 @@ get_client (Dwfl *dwfl) if (dwfl->debuginfod != NULL) return dwfl->debuginfod; - if (fp_debuginfod_begin == NULL) - { - void *debuginfod_so = dlopen("libdebuginfod-" VERSION ".so", RTLD_LAZY); - - if (debuginfod_so == NULL) - debuginfod_so = dlopen("libdebuginfod.so", RTLD_LAZY); - - if (debuginfod_so != NULL) - { - fp_debuginfod_begin = dlsym (debuginfod_so, "debuginfod_begin"); - fp_debuginfod_find_executable = dlsym (debuginfod_so, - "debuginfod_find_executable"); - fp_debuginfod_find_debuginfo = dlsym (debuginfod_so, - "debuginfod_find_debuginfo"); - fp_debuginfod_end = dlsym (debuginfod_so, "debuginfod_end"); - } - - if (fp_debuginfod_begin == NULL - || fp_debuginfod_find_executable == NULL - || fp_debuginfod_find_debuginfo == NULL - || fp_debuginfod_end == NULL) - fp_debuginfod_begin = (void *) -1; /* never try again */ - } - - if (fp_debuginfod_begin != NULL - && fp_debuginfod_begin != (void *) -1) + if (fp_debuginfod_begin != NULL) { dwfl->debuginfod = (*fp_debuginfod_begin) (); return dwfl->debuginfod; @@ -120,3 +95,37 @@ __libdwfl_debuginfod_end (debuginfod_client *c) if (c != NULL) (*fp_debuginfod_end) (c); } + +/* Try to get the libdebuginfod library functions to make sure + everything is initialized early. */ +void __attribute__ ((constructor)) +__libdwfl_debuginfod_init (void) +{ + void *debuginfod_so = dlopen("libdebuginfod-" VERSION ".so", RTLD_LAZY); + + if (debuginfod_so == NULL) + debuginfod_so = dlopen("libdebuginfod.so", RTLD_LAZY); + + if (debuginfod_so != NULL) + { + fp_debuginfod_begin = dlsym (debuginfod_so, "debuginfod_begin"); + fp_debuginfod_find_executable = dlsym (debuginfod_so, + "debuginfod_find_executable"); + fp_debuginfod_find_debuginfo = dlsym (debuginfod_so, + "debuginfod_find_debuginfo"); + fp_debuginfod_end = dlsym (debuginfod_so, "debuginfod_end"); + + /* We either get them all, or we get none. */ + if (fp_debuginfod_begin == NULL + || fp_debuginfod_find_executable == NULL + || fp_debuginfod_find_debuginfo == NULL + || fp_debuginfod_end == NULL) + { + fp_debuginfod_begin = NULL; + fp_debuginfod_find_executable = NULL; + fp_debuginfod_find_debuginfo = NULL; + fp_debuginfod_end = NULL; + dlclose (debuginfod_so); + } + } +}