diff mbox

[ovs-dev] Add configuration option to link ovs binaries statically

Message ID d7c4f5f2cdb91795b8b4e0462f30da14ed6491f7.1497973255.git.tredaelli@redhat.com
State Deferred
Delegated to: Ben Pfaff
Headers show

Commit Message

Timothy Redaelli June 20, 2017, 3:43 p.m. UTC
Add --enable-static-binaries configuration option for enabling or disabling
static linking with libopenvswitch, libsflow, libovsdb, libvtep, libovn and
libofproto also when --enable-shared is specified.

This is needed to avoid link binaries with position-independent code (PIC)
that generates slower code, but to permit building the ovs shared librares,
since it's needed, for example, by the C extension wrapper for Python JSON
parsing.

--enable-static-binaries option can only be used when both --enable-static
(default) and --enable-shared options are specified since if only
--enable-static is specified the binaries are already statically linked and if
only --enable-shared is specified the binaries cannot link with nonbuilt static
libraries.

Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
---
 configure.ac                    |  1 +
 m4/openvswitch.m4               | 21 +++++++++++++++++++++
 ovn/controller-vtep/automake.mk |  1 +
 ovn/controller/automake.mk      |  1 +
 ovn/northd/automake.mk          |  1 +
 ovn/utilities/automake.mk       |  3 +++
 ovsdb/automake.mk               |  3 +++
 tests/automake.mk               |  3 +++
 utilities/automake.mk           |  7 +++++++
 vswitchd/automake.mk            |  2 +-
 vtep/automake.mk                |  1 +
 11 files changed, 43 insertions(+), 1 deletion(-)

Comments

Ben Pfaff July 11, 2017, 6:22 p.m. UTC | #1
On Tue, Jun 20, 2017 at 05:43:56PM +0200, Timothy Redaelli wrote:
> Add --enable-static-binaries configuration option for enabling or disabling
> static linking with libopenvswitch, libsflow, libovsdb, libvtep, libovn and
> libofproto also when --enable-shared is specified.
> 
> This is needed to avoid link binaries with position-independent code (PIC)
> that generates slower code, but to permit building the ovs shared librares,
> since it's needed, for example, by the C extension wrapper for Python JSON
> parsing.
> 
> --enable-static-binaries option can only be used when both --enable-static
> (default) and --enable-shared options are specified since if only
> --enable-static is specified the binaries are already statically linked and if
> only --enable-shared is specified the binaries cannot link with nonbuilt static
> libraries.
> 
> Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>

This strikes me as an unusual configuration option.  Is there precedent
for this in other projects?  I've always taken the cost of dynamic
linking as a given when a project generates shared libraries.
Ben Pfaff Oct. 30, 2017, 9:08 p.m. UTC | #2
On Tue, Jul 11, 2017 at 11:22:26AM -0700, Ben Pfaff wrote:
> On Tue, Jun 20, 2017 at 05:43:56PM +0200, Timothy Redaelli wrote:
> > Add --enable-static-binaries configuration option for enabling or disabling
> > static linking with libopenvswitch, libsflow, libovsdb, libvtep, libovn and
> > libofproto also when --enable-shared is specified.
> > 
> > This is needed to avoid link binaries with position-independent code (PIC)
> > that generates slower code, but to permit building the ovs shared librares,
> > since it's needed, for example, by the C extension wrapper for Python JSON
> > parsing.
> > 
> > --enable-static-binaries option can only be used when both --enable-static
> > (default) and --enable-shared options are specified since if only
> > --enable-static is specified the binaries are already statically linked and if
> > only --enable-shared is specified the binaries cannot link with nonbuilt static
> > libraries.
> > 
> > Signed-off-by: Timothy Redaelli <tredaelli@redhat.com>
> 
> This strikes me as an unusual configuration option.  Is there precedent
> for this in other projects?  I've always taken the cost of dynamic
> linking as a given when a project generates shared libraries.

I don't know whether this patch is still important to you.  If it is,
then you should follow up with more information.
diff mbox

Patch

diff --git a/configure.ac b/configure.ac
index 6404b5fc1..78200e48c 100644
--- a/configure.ac
+++ b/configure.ac
@@ -99,6 +99,7 @@  OVS_CHECK_PYTHON3
 OVS_CHECK_FLAKE8
 OVS_CHECK_SPHINX
 OVS_CHECK_DOT
+OVS_CHECK_STATIC_BINARIES
 OVS_CHECK_IF_PACKET
 OVS_CHECK_IF_DL
 OVS_CHECK_STRTOK_R
diff --git a/m4/openvswitch.m4 b/m4/openvswitch.m4
index 648750ab5..ebeda8450 100644
--- a/m4/openvswitch.m4
+++ b/m4/openvswitch.m4
@@ -620,3 +620,24 @@  AC_DEFUN([OVS_LIBTOOL_VERSIONS],
   AC_MSG_RESULT([libX-$OVS_MAJOR.$OVS_MINOR.so.$LT_CURRENT.0.$OVS_MICRO)])
   AC_SUBST(OVS_LTINFO)
     ])
+
+dnl Checks for --enable-static-binaries.
+AC_DEFUN([OVS_CHECK_STATIC_BINARIES],
+    [AC_ARG_ENABLE(
+     [static-binaries],
+     [AC_HELP_STRING([--enable-static-binaries],
+                     [Build binaries statically linked with openvswitch libraries.])],
+     [case "${enableval}" in
+        (yes) static_binaries=true ;;
+        (no)  static_binaries=false ;;
+        (*) AC_MSG_ERROR([bad value ${enableval} for --enable-static-binaries]) ;;
+      esac],
+     [static_binaries=false])
+    if test x$static_binaries = xtrue && test x$enable_static = xyes &&
+    test x$enable_shared = xyes; then
+      STATIC_BINARIES_LDFLAGS=-static
+    else
+      STATIC_BINARIES_LDFLAGS=
+    fi
+    AC_SUBST([STATIC_BINARIES_LDFLAGS])
+    ])
diff --git a/ovn/controller-vtep/automake.mk b/ovn/controller-vtep/automake.mk
index 0c83dc70a..89a266f88 100644
--- a/ovn/controller-vtep/automake.mk
+++ b/ovn/controller-vtep/automake.mk
@@ -9,6 +9,7 @@  ovn_controller_vtep_ovn_controller_vtep_SOURCES = \
 	ovn/controller-vtep/vtep.c \
 	ovn/controller-vtep/vtep.h
 ovn_controller_vtep_ovn_controller_vtep_LDADD = ovn/lib/libovn.la lib/libopenvswitch.la vtep/libvtep.la
+ovn_controller_vtep_ovn_controller_vtep_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 man_MANS += ovn/controller-vtep/ovn-controller-vtep.8
 EXTRA_DIST += ovn/controller-vtep/ovn-controller-vtep.8.xml
 CLEANFILES += ovn/controller-vtep/ovn-controller-vtep.8
diff --git a/ovn/controller/automake.mk b/ovn/controller/automake.mk
index 8c6a78757..ff01c0304 100644
--- a/ovn/controller/automake.mk
+++ b/ovn/controller/automake.mk
@@ -21,6 +21,7 @@  ovn_controller_ovn_controller_SOURCES = \
 	ovn/controller/physical.c \
 	ovn/controller/physical.h
 ovn_controller_ovn_controller_LDADD = ovn/lib/libovn.la lib/libopenvswitch.la
+ovn_controller_ovn_controller_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 man_MANS += ovn/controller/ovn-controller.8
 EXTRA_DIST += ovn/controller/ovn-controller.8.xml
 CLEANFILES += ovn/controller/ovn-controller.8
diff --git a/ovn/northd/automake.mk b/ovn/northd/automake.mk
index 93aebe8b1..1b3cbd833 100644
--- a/ovn/northd/automake.mk
+++ b/ovn/northd/automake.mk
@@ -5,6 +5,7 @@  ovn_northd_ovn_northd_LDADD = \
 	ovn/lib/libovn.la \
 	ovsdb/libovsdb.la \
 	lib/libopenvswitch.la
+ovn_northd_ovn_northd_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 man_MANS += ovn/northd/ovn-northd.8
 EXTRA_DIST += ovn/northd/ovn-northd.8.xml
 CLEANFILES += ovn/northd/ovn-northd.8
diff --git a/ovn/utilities/automake.mk b/ovn/utilities/automake.mk
index b96f9bf6a..9921c8793 100644
--- a/ovn/utilities/automake.mk
+++ b/ovn/utilities/automake.mk
@@ -41,15 +41,18 @@  CLEANFILES += \
 bin_PROGRAMS += ovn/utilities/ovn-nbctl
 ovn_utilities_ovn_nbctl_SOURCES = ovn/utilities/ovn-nbctl.c
 ovn_utilities_ovn_nbctl_LDADD = ovn/lib/libovn.la ovsdb/libovsdb.la lib/libopenvswitch.la
+ovn_utilities_ovn_nbctl_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 
 # ovn-sbctl
 bin_PROGRAMS += ovn/utilities/ovn-sbctl
 ovn_utilities_ovn_sbctl_SOURCES = ovn/utilities/ovn-sbctl.c
 ovn_utilities_ovn_sbctl_LDADD = ovn/lib/libovn.la ovsdb/libovsdb.la lib/libopenvswitch.la
+ovn_utilities_ovn_sbctl_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 
 # ovn-trace
 bin_PROGRAMS += ovn/utilities/ovn-trace
 ovn_utilities_ovn_trace_SOURCES = ovn/utilities/ovn-trace.c
 ovn_utilities_ovn_trace_LDADD = ovn/lib/libovn.la ovsdb/libovsdb.la lib/libopenvswitch.la
+ovn_utilities_ovn_trace_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 
 include ovn/utilities/bugtool/automake.mk
diff --git a/ovsdb/automake.mk b/ovsdb/automake.mk
index 50e5ab367..87799c5dd 100644
--- a/ovsdb/automake.mk
+++ b/ovsdb/automake.mk
@@ -60,6 +60,7 @@  EXTRA_DIST += \
 bin_PROGRAMS += ovsdb/ovsdb-tool
 ovsdb_ovsdb_tool_SOURCES = ovsdb/ovsdb-tool.c
 ovsdb_ovsdb_tool_LDADD = ovsdb/libovsdb.la lib/libopenvswitch.la
+ovsdb_ovsdb_tool_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 # ovsdb-tool.1
 man_MANS += ovsdb/ovsdb-tool.1
 CLEANFILES += ovsdb/ovsdb-tool.1
@@ -69,6 +70,7 @@  MAN_ROOTS += ovsdb/ovsdb-tool.1.in
 bin_PROGRAMS += ovsdb/ovsdb-client
 ovsdb_ovsdb_client_SOURCES = ovsdb/ovsdb-client.c
 ovsdb_ovsdb_client_LDADD = ovsdb/libovsdb.la lib/libopenvswitch.la
+ovsdb_ovsdb_client_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 # ovsdb-client.1
 man_MANS += ovsdb/ovsdb-client.1
 CLEANFILES += ovsdb/ovsdb-client.1
@@ -78,6 +80,7 @@  MAN_ROOTS += ovsdb/ovsdb-client.1.in
 sbin_PROGRAMS += ovsdb/ovsdb-server
 ovsdb_ovsdb_server_SOURCES = ovsdb/ovsdb-server.c
 ovsdb_ovsdb_server_LDADD = ovsdb/libovsdb.la lib/libopenvswitch.la
+ovsdb_ovsdb_server_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 # ovsdb-server.1
 man_MANS += ovsdb/ovsdb-server.1
 CLEANFILES += ovsdb/ovsdb-server.1
diff --git a/tests/automake.mk b/tests/automake.mk
index a13b55e47..a7f9d6ebf 100644
--- a/tests/automake.mk
+++ b/tests/automake.mk
@@ -286,11 +286,13 @@  tests_test_ovsdb_SOURCES = tests/test-ovsdb.c
 nodist_tests_test_ovsdb_SOURCES = tests/idltest.c tests/idltest.h
 EXTRA_DIST += tests/uuidfilt.pl tests/ovsdb-monitor-sort.pl
 tests_test_ovsdb_LDADD = ovsdb/libovsdb.la lib/libopenvswitch.la
+tests_test_ovsdb_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 
 noinst_PROGRAMS += tests/test-lib
 tests_test_lib_SOURCES = \
 	tests/test-lib.c
 tests_test_lib_LDADD = lib/libopenvswitch.la
+tests_test_lib_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 
 # idltest schema and IDL
 OVSIDL_BUILT += tests/idltest.c tests/idltest.h tests/idltest.ovsidl
@@ -362,6 +364,7 @@  tests_ovstest_SOURCES += \
 endif
 
 tests_ovstest_LDADD = lib/libopenvswitch.la ovn/lib/libovn.la
+tests_ovstest_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 dist_check_SCRIPTS = tests/flowgen.pl
 
 noinst_PROGRAMS += tests/test-strtok_r
diff --git a/utilities/automake.mk b/utilities/automake.mk
index 1636cb93e..9a6a8812d 100644
--- a/utilities/automake.mk
+++ b/utilities/automake.mk
@@ -119,29 +119,36 @@  man_MANS += \
 
 utilities_ovs_appctl_SOURCES = utilities/ovs-appctl.c
 utilities_ovs_appctl_LDADD = lib/libopenvswitch.la
+utilities_ovs_appctl_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 
 utilities_ovs_testcontroller_SOURCES = utilities/ovs-testcontroller.c
 utilities_ovs_testcontroller_LDADD = lib/libopenvswitch.la $(SSL_LIBS)
+utilities_ovs_testcontroller_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 
 utilities_ovs_dpctl_SOURCES = utilities/ovs-dpctl.c
 utilities_ovs_dpctl_LDADD = lib/libopenvswitch.la
+utilities_ovs_dpctl_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 
 utilities_ovs_ofctl_SOURCES = utilities/ovs-ofctl.c
 utilities_ovs_ofctl_LDADD = \
 	ofproto/libofproto.la \
 	lib/libopenvswitch.la
+utilities_ovs_ofctl_LDLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 
 utilities_ovs_vsctl_SOURCES = utilities/ovs-vsctl.c
 utilities_ovs_vsctl_LDADD = lib/libopenvswitch.la
+utilities_ovs_vsctl_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 
 if LINUX
 sbin_PROGRAMS += utilities/ovs-vlan-bug-workaround
 utilities_ovs_vlan_bug_workaround_SOURCES = utilities/ovs-vlan-bug-workaround.c
 utilities_ovs_vlan_bug_workaround_LDADD = lib/libopenvswitch.la
+utilities_ovs_vlan_bug_workaround_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 
 noinst_PROGRAMS += utilities/nlmon
 utilities_nlmon_SOURCES = utilities/nlmon.c
 utilities_nlmon_LDADD = lib/libopenvswitch.la
+utilities_nlmon_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 endif
 
 FLAKE8_PYFILES += utilities/ovs-pcap.in \
diff --git a/vswitchd/automake.mk b/vswitchd/automake.mk
index aa4224561..ffd66ce89 100644
--- a/vswitchd/automake.mk
+++ b/vswitchd/automake.mk
@@ -15,7 +15,7 @@  vswitchd_ovs_vswitchd_LDADD = \
 	ofproto/libofproto.la \
 	lib/libsflow.la \
 	lib/libopenvswitch.la
-vswitchd_ovs_vswitchd_LDFLAGS = $(AM_LDFLAGS) $(DPDK_vswitchd_LDFLAGS)
+vswitchd_ovs_vswitchd_LDFLAGS = $(AM_LDFLAGS) $(DPDK_vswitchd_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 MAN_ROOTS += vswitchd/ovs-vswitchd.8.in
 
 # vswitch schema and IDL
diff --git a/vtep/automake.mk b/vtep/automake.mk
index 6bcb03188..a31463e20 100644
--- a/vtep/automake.mk
+++ b/vtep/automake.mk
@@ -35,6 +35,7 @@  man_MANS += \
 
 vtep_vtep_ctl_SOURCES = vtep/vtep-ctl.c
 vtep_vtep_ctl_LDADD = vtep/libvtep.la lib/libopenvswitch.la
+vtep_vtep_ctl_LDFLAGS = $(AM_LDFLAGS) $(STATIC_BINARIES_LDFLAGS)
 
 # ovs-vtep
 scripts_SCRIPTS += \