Expose liblttng-libc-wrapper malloc ctor in public header
authorMichael Jeanson <mjeanson@efficios.com>
Wed, 10 Mar 2021 15:57:30 +0000 (10:57 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 10 Mar 2021 21:27:50 +0000 (16:27 -0500)
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 <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/Makefile.am
include/lttng/ust-libc-wrapper.h [new file with mode: 0644]
liblttng-ust-libc-wrapper/lttng-ust-malloc.c
liblttng-ust/lttng-tracer-core.h
liblttng-ust/lttng-ust-comm.c

index d29ef192cdf9ba97cbf0e47e1a5fc8a4e947e906..0dd7cf397a5938afedaa5b0ec61f34e5cdf28526 100644 (file)
@@ -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 (file)
index 0000000..685ebfb
--- /dev/null
@@ -0,0 +1,25 @@
+/*
+ * SPDX-License-Identifier: MIT
+ *
+ * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * 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
index be13f214480bfb09402b25d3328fd36c69d3e2b6..54b40e6a0a9546cbada853974994ddaf8fdac82e 100644 (file)
@@ -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) {
index 7b5030817aac85e099a17694e0544f46ab651368..6a918f9b379c3141bd2adf22b63bbba96d88cffb 100644 (file)
@@ -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);
index 25de5dd5535a3f25ee4b15e8d9ac709152bf4cf1..a590268179c485cc11e71bbd95e27dae852573a1 100644 (file)
@@ -34,6 +34,7 @@
 #include <lttng/ust.h>
 #include <lttng/ust-error.h>
 #include <lttng/ust-ctl.h>
+#include <lttng/ust-libc-wrapper.h>
 #include <urcu/tls-compat.h>
 #include <ust-comm.h>
 #include <ust-fd.h>
@@ -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);
 
This page took 0.029702 seconds and 4 git commands to generate.