+2022-04-22 Mark Wielaard <mark@klomp.org>
+
+ * Makefile.am (libdebuginfod): Add -lpthread.
+ (libdebuginfod_so_LDLIBS): Likewise.
+ * debuginfod-client.c (init_control): New static pthread_once_t.
+ (libcurl_init): New static function.
+ (debuginfod_begin): Use ptrace_once to call libcurl_init.
+ (libdebuginfod_ctor): Removed.
+ (libdebuginfod_dtor): Likewise.
+
2022-04-24 Mark Wielaard <mark@klomp.org>
* debuginfod.cxx (main): Add MHD_USE_ITC to MHD_start_daemon flags.
if DUMMY_LIBDEBUGINFOD
libdebuginfod = ./libdebuginfod.a
else
-libdebuginfod = ./libdebuginfod.a $(libcurl_LIBS)
+libdebuginfod = ./libdebuginfod.a -lpthread $(libcurl_LIBS)
endif
else
libasm = ../libasm/libasm.so
if DUMMY_LIBDEBUGINFOD
libdebuginfod_so_LDLIBS =
else
-libdebuginfod_so_LDLIBS = $(libcurl_LIBS) $(fts_LIBS)
+libdebuginfod_so_LDLIBS = -lpthread $(libcurl_LIBS) $(fts_LIBS)
endif
$(LIBDEBUGINFOD_SONAME): $(srcdir)/libdebuginfod.map $(libdebuginfod_so_LIBS)
$(AM_V_CCLD)$(LINK) $(dso_LDFLAGS) -o $@ \
/* Retrieve ELF / DWARF / source files from the debuginfod.
Copyright (C) 2019-2021 Red Hat, Inc.
- Copyright (C) 2021 Mark J. Wielaard <mark@klomp.org>
+ Copyright (C) 2021, 2022 Mark J. Wielaard <mark@klomp.org>
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
#include <fts.h>
#endif
+#include <pthread.h>
+
+static pthread_once_t init_control = PTHREAD_ONCE_INIT;
+
+static void
+libcurl_init(void)
+{
+ curl_global_init(CURL_GLOBAL_DEFAULT);
+}
+
struct debuginfod_client
{
/* Progress/interrupt callback function. */
debuginfod_client *
debuginfod_begin (void)
{
+ /* Initialize libcurl lazily, but only once. */
+ pthread_once (&init_control, libcurl_init);
+
debuginfod_client *client;
size_t size = sizeof (struct debuginfod_client);
client = calloc (1, size);
client->verbose_fd = fd;
}
-
-/* NB: these are thread-unsafe. */
-__attribute__((constructor)) attribute_hidden void libdebuginfod_ctor(void)
-{
- curl_global_init(CURL_GLOBAL_DEFAULT);
-}
-
-/* NB: this is very thread-unsafe: it breaks other threads that are still in libcurl */
-__attribute__((destructor)) attribute_hidden void libdebuginfod_dtor(void)
-{
- /* ... so don't do this: */
- /* curl_global_cleanup(); */
-}
-
#endif /* DUMMY_LIBDEBUGINFOD */
+2022-04-22 Mark Wielaard <mark@klomp.org>
+
+ * debuginfod-client.c (init_control): New static pthread_once_t.
+ (get_client): Use pthread_once to call __libdwfl_debuginfod_init.
+ (__libdwfl_debuginfod_init): Make static, remove attribute
+ constructor.
+
2022-02-18 Mark Wielaard <mark@klomp.org>
* image-header.c (__libdw_image_header): Assign header values for
/* Try to get an ELF or debug file through the debuginfod.
Copyright (C) 2019 Red Hat, Inc.
+ Copyright (C) 2022 Mark J. Wielaard <mark@klomp.org>
This file is part of elfutils.
This file is free software; you can redistribute it and/or modify
#endif
#include "libdwflP.h"
+#include <pthread.h>
#include <dlfcn.h>
static __typeof__ (debuginfod_begin) *fp_debuginfod_begin;
static __typeof__ (debuginfod_find_debuginfo) *fp_debuginfod_find_debuginfo;
static __typeof__ (debuginfod_end) *fp_debuginfod_end;
+static void __libdwfl_debuginfod_init (void);
+
+static pthread_once_t init_control = PTHREAD_ONCE_INIT;
+
/* NB: this is slightly thread-unsafe */
static debuginfod_client *
if (dwfl->debuginfod != NULL)
return dwfl->debuginfod;
+ pthread_once (&init_control, __libdwfl_debuginfod_init);
+
if (fp_debuginfod_begin != NULL)
{
dwfl->debuginfod = (*fp_debuginfod_begin) ();
(*fp_debuginfod_end) (c);
}
-/* Try to get the libdebuginfod library functions to make sure
- everything is initialized early. */
-void __attribute__ ((constructor))
+/* Try to get the libdebuginfod library functions.
+ Only needs to be called once from get_client. */
+static void
__libdwfl_debuginfod_init (void)
{
void *debuginfod_so = dlopen(DEBUGINFOD_SONAME, RTLD_LAZY);