From: Michael Jeanson Date: Wed, 10 Mar 2021 15:57:30 +0000 (-0500) Subject: Expose liblttng-libc-wrapper malloc ctor in public header X-Git-Tag: v2.13.0-rc1~316 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d1f1110f9563855ede8d1511a4db3b89630ebc1e;p=lttng-ust.git Expose liblttng-libc-wrapper malloc ctor in public header Document the reason why the liblttng-libc-wrapper malloc constructor is ABI in a public header. Also namespace it under 'lttng_ust_libc_wrapper_' in case we add other public symbols to this library. Change-Id: I2db6f685ba5368a1ce1929e6baa64cd6322c83e7 Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- diff --git a/include/Makefile.am b/include/Makefile.am index d29ef192..0dd7cf39 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -33,6 +33,7 @@ nobase_include_HEADERS = \ lttng/ust-getcpu.h \ lttng/ust-elf.h \ lttng/counter-config.h \ + lttng/ust-libc-wrapper.h \ lttng/urcu/pointer.h \ lttng/urcu/urcu-ust.h \ lttng/urcu/static/pointer.h \ diff --git a/include/lttng/ust-libc-wrapper.h b/include/lttng/ust-libc-wrapper.h new file mode 100644 index 00000000..685ebfbd --- /dev/null +++ b/include/lttng/ust-libc-wrapper.h @@ -0,0 +1,25 @@ +/* + * SPDX-License-Identifier: MIT + * + * Copyright (C) 2020 Michael Jeanson + * + * Public symbols of liblttng-ust-libc-wrapper.so + */ + +#ifndef _LTTNG_UST_LIBC_WRAPPER_H +#define _LTTNG_UST_LIBC_WRAPPER_H + +/* + * This is the constructor for the malloc part of the libc wrapper. It is + * publicly exposed because the malloc override needs to be initialized before + * the process becomes multithreaded and thus must happen before the main + * constructor of liblttng-ust starts threads. Since there is no reliable way + * to guarantee the execution order of constructors across shared library, the + * liblttng-ust constructor has to call the malloc constructor before starting + * any thread. This is achieved by having a weak public version of this + * function in liblttng-ust that is overridden by the one in + * liblttng-ust-wrapper-libc when it's preloaded. + */ +void lttng_ust_libc_wrapper_malloc_init(void); + +#endif diff --git a/liblttng-ust-libc-wrapper/lttng-ust-malloc.c b/liblttng-ust-libc-wrapper/lttng-ust-malloc.c index be13f214..54b40e6a 100644 --- a/liblttng-ust-libc-wrapper/lttng-ust-malloc.c +++ b/liblttng-ust-libc-wrapper/lttng-ust-malloc.c @@ -415,7 +415,7 @@ void lttng_ust_fixup_malloc_nesting_tls(void) } __attribute__((constructor)) -void lttng_ust_malloc_wrapper_init(void) +void lttng_ust_libc_wrapper_malloc_init(void) { /* Initialization already done */ if (cur_alloc.calloc) { diff --git a/liblttng-ust/lttng-tracer-core.h b/liblttng-ust/lttng-tracer-core.h index 7b503081..6a918f9b 100644 --- a/liblttng-ust/lttng-tracer-core.h +++ b/liblttng-ust/lttng-tracer-core.h @@ -72,8 +72,6 @@ char* lttng_ust_sockinfo_get_procname(void *owner); void lttng_ust_sockinfo_session_enabled(void *owner); -void lttng_ust_malloc_wrapper_init(void); - ssize_t lttng_ust_read(int fd, void *buf, size_t len); size_t lttng_ust_dummy_get_size(struct lttng_ctx_field *field, size_t offset); diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index 25de5dd5..a5902681 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -2052,7 +2053,7 @@ quit: * Weak symbol to call when the ust malloc wrapper is not loaded. */ __attribute__((weak)) -void lttng_ust_malloc_wrapper_init(void) +void lttng_ust_libc_wrapper_malloc_init(void) { } @@ -2125,7 +2126,7 @@ void __attribute__((constructor)) lttng_ust_init(void) /* * Invoke ust malloc wrapper init before starting other threads. */ - lttng_ust_malloc_wrapper_init(); + lttng_ust_libc_wrapper_malloc_init(); timeout_mode = get_constructor_timeout(&constructor_timeout);