summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Lamparter <equinox@opensourcerouting.org>2018-09-10 20:10:19 +0200
committerDavid Lamparter <equinox@opensourcerouting.org>2018-10-01 14:56:18 +0200
commitd6e762570619f84318ade5b44fdeb2f920637f1f (patch)
tree753c129e6a267da47b70931a1fe6467797942519
parentMerge pull request #3111 from pacovn/Coverity_1302499_Logically_dead_code (diff)
downloadfrr-d6e762570619f84318ade5b44fdeb2f920637f1f.tar.xz
frr-d6e762570619f84318ade5b44fdeb2f920637f1f.zip
build: add --enable-static-bin option
This option can be used to get statically linked binaries. Note: libfrr.la is removed from modules' library dependency list. This is intentional and explained in a comment in lib/subdir.am. Signed-off-by: David Lamparter <equinox@diac24.net>
-rw-r--r--Makefile.am2
-rwxr-xr-xconfigure.ac11
-rw-r--r--lib/subdir.am15
-rw-r--r--m4/.gitignore1
-rw-r--r--m4/libtool-whole-archive.patch18
-rw-r--r--ospfclient/subdir.am14
6 files changed, 58 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am
index fb052a8de..65aed7915 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -12,6 +12,7 @@ AM_CPPFLAGS = \
-I$(top_builddir) -I$(top_builddir)/include -I$(top_builddir)/lib
AM_LDFLAGS = \
-export-dynamic \
+ $(AC_LDFLAGS) \
$(SAN_FLAGS) \
# end
DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" -DCONFDATE=$(CONFDATE)
@@ -154,6 +155,7 @@ EXTRA_DIST += \
aclocal.m4 \
README.md \
m4/README.txt \
+ m4/libtool-whole-archive.patch \
\
python/clidef.py \
python/clippy/__init__.py \
diff --git a/configure.ac b/configure.ac
index 4d18c7997..cf6ba2bf1 100755
--- a/configure.ac
+++ b/configure.ac
@@ -310,7 +310,18 @@ AC_CHECK_TOOL(AR, ar)
dnl -------
dnl libtool
dnl -------
+AC_ARG_ENABLE(static-bin,
+ AS_HELP_STRING([--enable-static-bin], [link binaries statically]))
LT_INIT
+_LT_CONFIG_LIBTOOL([
+ patch -N -i "${srcdir}/m4/libtool-whole-archive.patch" libtool >&AS_MESSAGE_LOG_FD || \
+ AC_MSG_WARN([Could not patch libtool for static linking support. Loading modules into a statically linked daemon will fail.])
+])
+if test "$enable_static_bin" = "yes"; then
+ AC_LDFLAGS="-static"
+fi
+AC_SUBST(AC_LDFLAGS)
+AM_CONDITIONAL([STATIC_BIN], [test "x$enable_static_bin" = "xyes"])
dnl ----------------------
dnl Packages configuration
diff --git a/lib/subdir.am b/lib/subdir.am
index 6dc2fc529..eb032c058 100644
--- a/lib/subdir.am
+++ b/lib/subdir.am
@@ -207,6 +207,17 @@ noinst_HEADERS += \
lib/plist_int.h \
#end
+# General note about module and module helper library (libfrrsnmp, libfrrzmq)
+# linking: If we're linking libfrr statically into daemons, we *must* remove
+# libfrr from modules because modules will always link it in dynamically and
+# thus 2 copies of libfrr will be loaded... hilarity ensues.
+#
+# Not linking libfrr into modules should generally work fine because the
+# executable refers to libfrr either way and the dynamic linker should make
+# libfrr available to modules. If some OS platform has a dynamic linker that
+# doesn't do that, libfrr needs to be readded to modules, but _only_ _if_
+# it's not linked into daemons statically.
+
#
# SNMP support
#
@@ -216,7 +227,7 @@ endif
lib_libfrrsnmp_la_CFLAGS = $(WERROR) $(SNMP_CFLAGS) -std=gnu99
lib_libfrrsnmp_la_LDFLAGS = -version-info 0:0:0
-lib_libfrrsnmp_la_LIBADD = lib/libfrr.la $(SNMP_LIBS)
+lib_libfrrsnmp_la_LIBADD = $(SNMP_LIBS)
lib_libfrrsnmp_la_SOURCES = \
lib/agentx.c \
lib/snmp.c \
@@ -232,7 +243,7 @@ endif
lib_libfrrzmq_la_CFLAGS = $(WERROR) $(ZEROMQ_CFLAGS)
lib_libfrrzmq_la_LDFLAGS = -version-info 0:0:0
-lib_libfrrzmq_la_LIBADD = lib/libfrr.la $(ZEROMQ_LIBS)
+lib_libfrrzmq_la_LIBADD = $(ZEROMQ_LIBS)
lib_libfrrzmq_la_SOURCES = \
lib/frr_zmq.c \
#end
diff --git a/m4/.gitignore b/m4/.gitignore
index 357e65588..2c0416365 100644
--- a/m4/.gitignore
+++ b/m4/.gitignore
@@ -1,4 +1,5 @@
*.m4
+!*.patch
!ax_compare_version.m4
!ax_prog_perl_modules.m4
diff --git a/m4/libtool-whole-archive.patch b/m4/libtool-whole-archive.patch
new file mode 100644
index 000000000..7e2749c90
--- /dev/null
+++ b/m4/libtool-whole-archive.patch
@@ -0,0 +1,18 @@
+--- /usr/share/libtool/build-aux/ltmain.sh 2017-08-01 07:13:09.611041402 +0200
++++ ltmain.sh 2018-08-31 17:32:15.381903718 +0200
+@@ -8439,8 +8439,13 @@
+ # shared platforms.
+ if test unsupported != "$hardcode_direct"; then
+ test -n "$old_library" && linklib=$old_library
+- compile_deplibs="$dir/$linklib $compile_deplibs"
+- finalize_deplibs="$dir/$linklib $finalize_deplibs"
++ if test yes,yes = "$export_dynamic,$with_gnu_ld"; then
++ compile_deplibs="-Wl,--no-whole-archive $dir/$linklib -Wl,--whole-archive $compile_deplibs"
++ finalize_deplibs="-Wl,--no-whole-archive $dir/$linklib -Wl,--whole-archive $finalize_deplibs"
++ else
++ compile_deplibs="$dir/$linklib $compile_deplibs"
++ finalize_deplibs="$dir/$linklib $finalize_deplibs"
++ fi
+ else
+ compile_deplibs="-l$name -L$dir $compile_deplibs"
+ finalize_deplibs="-l$name -L$dir $finalize_deplibs"
diff --git a/ospfclient/subdir.am b/ospfclient/subdir.am
index df7d85a1f..d42c5b450 100644
--- a/ospfclient/subdir.am
+++ b/ospfclient/subdir.am
@@ -23,9 +23,21 @@ endif
ospfclient_ospfclient_LDADD = \
ospfclient/libfrrospfapiclient.la \
- lib/libfrr.la \
@LIBCAP@ \
# end
+
+if STATIC_BIN
+# libfrr is linked in through libfrrospfapiclient. If we list it here too,
+# it gets linked twice and we get a ton of symbol collisions.
+
+else # !STATIC_BIN
+# For most systems we don't need this, except Debian, who patch their linker
+# to disallow transitive references *while* *als* not patching their libtool
+# to work appropriately. RedHat has the same linker behaviour, but things
+# work as expected since they also patch libtool.
+ospfclient_ospfclient_LDADD += lib/libfrr.la
+endif
+
ospfclient_ospfclient_SOURCES = \
ospfclient/ospfclient.c \
# end