about summary refs log tree commit diff
path: root/include/libc-symbols.h
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2016-08-26 22:40:27 +0200
committerFlorian Weimer <fweimer@redhat.com>2016-08-26 23:20:41 +0200
commitef4f97648dc95849e417dd3e6328165de4c22185 (patch)
tree8d250b1f15efcb2d718939c8d75d732efa8e70c2 /include/libc-symbols.h
parent21e79af4cf72429f98480fa34912a4ce236b09a0 (diff)
downloadglibc-ef4f97648dc95849e417dd3e6328165de4c22185.tar.gz
glibc-ef4f97648dc95849e417dd3e6328165de4c22185.tar.xz
glibc-ef4f97648dc95849e417dd3e6328165de4c22185.zip
malloc: Simplify static malloc interposition [BZ #20432]
Existing interposed mallocs do not define the glibc-internal
fork callbacks (and they should not), so statically interposed
mallocs lead to link failures because the strong reference from
fork pulls in glibc's malloc, resulting in multiple definitions
of malloc-related symbols.
Diffstat (limited to 'include/libc-symbols.h')
-rw-r--r--include/libc-symbols.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/include/libc-symbols.h b/include/libc-symbols.h
index c2b499ae36..e362d42095 100644
--- a/include/libc-symbols.h
+++ b/include/libc-symbols.h
@@ -121,6 +121,21 @@
 # define weak_extern(symbol) _weak_extern (weak symbol)
 # define _weak_extern(expr) _Pragma (#expr)
 
+/* In shared builds, the expression call_function_static_weak
+   (FUNCTION-SYMBOL, ARGUMENTS) invokes FUNCTION-SYMBOL (an
+   identifier) unconditionally, with the (potentially empty) argument
+   list ARGUMENTS.  In static builds, if FUNCTION-SYMBOL has a
+   definition, the function is invoked as before; if FUNCTION-SYMBOL
+   is NULL, no call is performed.  */
+# ifdef SHARED
+#  define call_function_static_weak(func, ...) func (__VA_ARGS__)
+# else	/* !SHARED */
+#  define call_function_static_weak(func, ...)		\
+  ({							\
+    extern __typeof__ (func) func weak_function;	\
+    (func != NULL ? func (__VA_ARGS__) : (void)0);	\
+  })
+# endif
 
 #else /* __ASSEMBLER__ */