]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Make linker include library ctor/dtor in statically linked libisc
authorOndřej Surý <ondrej@isc.org>
Fri, 26 Feb 2021 20:09:48 +0000 (21:09 +0100)
committerOndřej Surý <ondrej@isc.org>
Fri, 26 Feb 2021 20:19:33 +0000 (21:19 +0100)
Under normal situation, the linker throws out all symbols from
compilation unit when no symbols are used in the final binary, which is
the case for lib/isc/lib.c.  This commit adds empty function to lib.c
that's being called from different CU (mem.c in this case) and that
makes the linker to include all the symbols including the normally
unreferenced isc__initialize() and isc__shutdown() in the final binary.

lib/isc/include/isc/lib.h
lib/isc/lib.c
lib/isc/mem.c
lib/isc/win32/libisc.def.in

index 4a77293c32f1ca3db33b9da1d7e41a28aaf99e8f..05e6dfe608ccc972b565f40fff76ef1179f5755c 100644 (file)
@@ -9,8 +9,7 @@
  * information regarding copyright ownership.
  */
 
-#ifndef ISC_LIB_H
-#define ISC_LIB_H 1
+#pragma once
 
 /*! \file isc/lib.h */
 
@@ -28,6 +27,10 @@ isc_lib_register(void);
  * function very early in main().
  */
 
-ISC_LANG_ENDDECLS
+extern void
+isc_enable_constructors(void);
+/*!<
+ * \bried Enable constructor linkage in non-libtool static builds
+ */
 
-#endif /* ISC_LIB_H */
+ISC_LANG_ENDDECLS
index b1afa2b35542a663d27ffbdd5a6651a084718f76..27d7be10ea7e50610a04fbfb77e37c17aa9bfe19 100644 (file)
@@ -48,3 +48,14 @@ isc__shutdown(void) {
        isc__tls_shutdown();
        isc__mem_shutdown();
 }
+
+/*
+ * This is a workaround for situation when libisc is statically linked.  Under
+ * normal situation, the linker throws out all symbols from compilation unit
+ * when no symbols are used in the final binary.  This empty function must be
+ * called at least once from different compilation unit (mem.c in this case).
+ */
+void
+isc_enable_constructors() {
+       /* do nothing */
+}
index fc4640a24752b415bbd975529ec68f29f9171df3..df5142f99735127e6fec779f89371d0731f983e1 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <isc/bind9.h>
 #include <isc/hash.h>
+#include <isc/lib.h>
 #include <isc/magic.h>
 #include <isc/mem.h>
 #include <isc/mutex.h>
@@ -776,6 +777,8 @@ mem_create(isc_mem_t **ctxp, unsigned int flags) {
 
        isc__mem_t *ctx;
 
+       isc_enable_constructors();
+
        STATIC_ASSERT((ALIGNMENT_SIZE & (ALIGNMENT_SIZE - 1)) == 0,
                      "wrong alignment size");
 
index 79fee67763afcd1057761ddeace538d85d5e55b8..1455933f5dd30103b59156e33d51566a6ea9ff4f 100644 (file)
@@ -190,6 +190,7 @@ isc_dir_init
 isc_dir_open
 isc_dir_read
 isc_dir_reset
+isc_enable_constructors
 isc_entropy_get
 isc_errno_toresult
 isc_error_fatal