From 63116a7008706988136785ffa011cefee0355193 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Wed, 21 Jul 2021 11:04:23 +0200 Subject: [PATCH 1/2] build: fix `AM_LDFLAGS` usage (and gcov) like the other automake variables, setting `xyz_LDFLAGS` causes `AM_LDFLAGS` to be ignored for `xyz`. For some reason I had in my mind that automake doesn't do this for LDFLAGS, but... it does. (Which is consistent with `_CFLAGS` and co.) So, all the libraries and modules have been ignoring `AM_LDFLAGS` (which includes `SAN_FLAGS` too). Set up new `LIB_LDFLAGS` and `MODULE_LDFLAGS` to handle all of this correctly (and move these bits to a central location.) Fixes: #9034 Fixes: 0c4285d77eb ("build: properly split CFLAGS from AC_CFLAGS") Signed-off-by: David Lamparter --- Makefile.am | 22 ++++++++++++++++++++++ bgpd/subdir.am | 6 +++--- configure.ac | 3 ++- fpm/subdir.am | 2 +- grpc/subdir.am | 2 +- isisd/subdir.am | 2 +- ldpd/subdir.am | 2 +- lib/subdir.am | 17 +++++++++-------- mlag/subdir.am | 2 +- ospf6d/subdir.am | 2 +- ospfclient/subdir.am | 2 +- ospfd/subdir.am | 2 +- pathd/subdir.am | 2 +- qpb/subdir.am | 2 +- ripd/subdir.am | 2 +- zebra/subdir.am | 12 ++++++------ 16 files changed, 53 insertions(+), 29 deletions(-) diff --git a/Makefile.am b/Makefile.am index 9bc5dd7d22..ce0f70a1a2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -29,11 +29,33 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/lib/assert \ $(CPPFLAGS_BASE) \ # end + +# AM_LDFLAGS is used for executables (daemons). LDFLAGS can be left alone, +# but if it is changed it should include $(AM_LDFLAGS) AM_LDFLAGS = \ + -export-dynamic \ + $(AC_LDFLAGS) \ + $(AC_LDFLAGS_EXEC) \ + $(SAN_FLAGS) \ + # end + +# libraries need to use libxxx_LDFLAGS = $(LIB_LDFLAGS) -version-info X:Y:Z +LIB_LDFLAGS = \ -export-dynamic \ $(AC_LDFLAGS) \ $(SAN_FLAGS) \ # end + +# modules need to use xxx_LDFLAGS = $(MODULE_LDFLAGS) +MODULE_LDFLAGS = \ + -export-dynamic \ + -avoid-version \ + -module \ + -shared \ + $(AC_LDFLAGS) \ + $(SAN_FLAGS) \ + # end + DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" -DCONFDATE=$(CONFDATE) AR_FLAGS = @AR_FLAGS@ diff --git a/bgpd/subdir.am b/bgpd/subdir.am index 53225192f2..cb9af08c95 100644 --- a/bgpd/subdir.am +++ b/bgpd/subdir.am @@ -219,17 +219,17 @@ bgpd_bgp_btoa_LDADD = bgpd/libbgp.a $(RFPLDADD) lib/libfrr.la $(LIBYANG_LIBS) $( bgpd_bgpd_snmp_la_SOURCES = bgpd/bgp_snmp.c bgpd/bgp_mplsvpn_snmp.c bgpd_bgpd_snmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11 -bgpd_bgpd_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +bgpd_bgpd_snmp_la_LDFLAGS = $(MODULE_LDFLAGS) bgpd_bgpd_snmp_la_LIBADD = lib/libfrrsnmp.la bgpd_bgpd_rpki_la_SOURCES = bgpd/bgp_rpki.c bgpd_bgpd_rpki_la_CFLAGS = $(AM_CFLAGS) $(RTRLIB_CFLAGS) -bgpd_bgpd_rpki_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +bgpd_bgpd_rpki_la_LDFLAGS = $(MODULE_LDFLAGS) bgpd_bgpd_rpki_la_LIBADD = $(RTRLIB_LIBS) bgpd_bgpd_bmp_la_SOURCES = bgpd/bgp_bmp.c bgpd_bgpd_bmp_la_LIBADD = lib/libfrrcares.la -bgpd_bgpd_bmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +bgpd_bgpd_bmp_la_LDFLAGS = $(MODULE_LDFLAGS) clippy_scan += \ bgpd/bgp_bmp.c \ diff --git a/configure.ac b/configure.ac index 1ad87d9435..ecab39a30f 100644 --- a/configure.ac +++ b/configure.ac @@ -492,7 +492,7 @@ _LT_CONFIG_LIBTOOL([ sed -e 's%func_warning ".*has not been installed in%true #\0%' -i libtool || true ]) if test "$enable_static_bin" = "yes"; then - AC_LDFLAGS="-static" + AC_LDFLAGS_EXEC="-static" if test "$enable_static" != "yes"; then AC_MSG_ERROR([The --enable-static-bin option must be combined with --enable-static.]) fi @@ -501,6 +501,7 @@ if test "$enable_shared" != "yes"; then AC_MSG_ERROR([FRR cannot be built with --disable-shared. If you want statically linked daemons, use --enable-shared --enable-static --enable-static-bin]) fi AC_SUBST([AC_LDFLAGS]) +AC_SUBST([AC_LDFLAGS_EXEC]) AM_CONDITIONAL([STATIC_BIN], [test "$enable_static_bin" = "yes"]) AC_ARG_ENABLE([rpath], diff --git a/fpm/subdir.am b/fpm/subdir.am index a645ca2b03..b5988137e0 100644 --- a/fpm/subdir.am +++ b/fpm/subdir.am @@ -4,7 +4,7 @@ lib_LTLIBRARIES += fpm/libfrrfpm_pb.la endif endif -fpm_libfrrfpm_pb_la_LDFLAGS = -version-info 0:0:0 +fpm_libfrrfpm_pb_la_LDFLAGS = $(LIB_LDFLAGS) -version-info 0:0:0 fpm_libfrrfpm_pb_la_CPPFLAGS = $(AM_CPPFLAGS) $(PROTOBUF_C_CFLAGS) fpm_libfrrfpm_pb_la_SOURCES = \ fpm/fpm.h \ diff --git a/grpc/subdir.am b/grpc/subdir.am index d9ec365ba8..cbebd72323 100644 --- a/grpc/subdir.am +++ b/grpc/subdir.am @@ -2,7 +2,7 @@ if GRPC lib_LTLIBRARIES += grpc/libfrrgrpc_pb.la endif -grpc_libfrrgrpc_pb_la_LDFLAGS = -version-info 0:0:0 +grpc_libfrrgrpc_pb_la_LDFLAGS = $(LIB_LDFLAGS) -version-info 0:0:0 grpc_libfrrgrpc_pb_la_CPPFLAGS = $(AM_CPPFLAGS) $(GRPC_CXXFLAGS) if GRPC diff --git a/isisd/subdir.am b/isisd/subdir.am index 4243bd60cf..3e5816c16b 100644 --- a/isisd/subdir.am +++ b/isisd/subdir.am @@ -139,7 +139,7 @@ nodist_isisd_isisd_SOURCES = \ isisd_isisd_snmp_la_SOURCES = isisd/isis_snmp.c isisd_isisd_snmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11 -isisd_isisd_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +isisd_isisd_snmp_la_LDFLAGS = $(MODULE_LDFLAGS) isisd_isisd_snmp_la_LIBADD = lib/libfrrsnmp.la # Building fabricd diff --git a/ldpd/subdir.am b/ldpd/subdir.am index b7e2ab72d6..083effb703 100644 --- a/ldpd/subdir.am +++ b/ldpd/subdir.am @@ -65,5 +65,5 @@ ldpd_ldpd_LDADD = ldpd/libldp.a lib/libfrr.la $(LIBCAP) ldpd_ldpd_snmp_la_SOURCES = ldpd/ldp_snmp.c ldpd_ldpd_snmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11 -ldpd_ldpd_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +ldpd_ldpd_snmp_la_LDFLAGS = $(MODULE_LDFLAGS) ldpd_ldpd_snmp_la_LIBADD = lib/libfrrsnmp.la diff --git a/lib/subdir.am b/lib/subdir.am index 90301d800a..714af43238 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -2,7 +2,7 @@ # libfrr # lib_LTLIBRARIES += lib/libfrr.la -lib_libfrr_la_LDFLAGS = -version-info 0:0:0 -Xlinker -e_libfrr_version +lib_libfrr_la_LDFLAGS = $(LIB_LDFLAGS) -version-info 0:0:0 -Xlinker -e_libfrr_version lib_libfrr_la_LIBADD = $(LIBCAP) $(UNWIND_LIBS) $(LIBYANG_LIBS) $(LUA_LIB) $(UST_LIBS) $(LIBM) lib_libfrr_la_SOURCES = \ @@ -322,7 +322,7 @@ lib_LTLIBRARIES += lib/libfrrsnmp.la endif lib_libfrrsnmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11 -lib_libfrrsnmp_la_LDFLAGS = -version-info 0:0:0 +lib_libfrrsnmp_la_LDFLAGS = $(LIB_LDFLAGS) -version-info 0:0:0 lib_libfrrsnmp_la_LIBADD = $(SNMP_LIBS) lib_libfrrsnmp_la_SOURCES = \ lib/agentx.c \ @@ -338,7 +338,7 @@ pkginclude_HEADERS += lib/resolver.h endif lib_libfrrcares_la_CFLAGS = $(AM_CFLAGS) $(CARES_CFLAGS) -lib_libfrrcares_la_LDFLAGS = -version-info 0:0:0 +lib_libfrrcares_la_LDFLAGS = $(LIB_LDFLAGS) -version-info 0:0:0 lib_libfrrcares_la_LIBADD = $(CARES_LIBS) lib_libfrrcares_la_SOURCES = \ lib/resolver.c \ @@ -353,7 +353,7 @@ pkginclude_HEADERS += lib/frr_zmq.h endif lib_libfrrzmq_la_CFLAGS = $(AM_CFLAGS) $(ZEROMQ_CFLAGS) -lib_libfrrzmq_la_LDFLAGS = -version-info 0:0:0 +lib_libfrrzmq_la_LDFLAGS = $(LIB_LDFLAGS) -version-info 0:0:0 lib_libfrrzmq_la_LIBADD = $(ZEROMQ_LIBS) lib_libfrrzmq_la_SOURCES = \ lib/frr_zmq.c \ @@ -367,7 +367,7 @@ module_LTLIBRARIES += lib/confd.la endif lib_confd_la_CFLAGS = $(AM_CFLAGS) $(CONFD_CFLAGS) -lib_confd_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +lib_confd_la_LDFLAGS = $(MODULE_LDFLAGS) lib_confd_la_LIBADD = lib/libfrr.la $(CONFD_LIBS) lib_confd_la_SOURCES = lib/northbound_confd.c @@ -379,7 +379,7 @@ module_LTLIBRARIES += lib/sysrepo.la endif lib_sysrepo_la_CFLAGS = $(AM_CFLAGS) $(SYSREPO_CFLAGS) -lib_sysrepo_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +lib_sysrepo_la_LDFLAGS = $(MODULE_LDFLAGS) lib_sysrepo_la_LIBADD = lib/libfrr.la $(SYSREPO_LIBS) lib_sysrepo_la_SOURCES = lib/northbound_sysrepo.c @@ -391,7 +391,7 @@ module_LTLIBRARIES += lib/grpc.la endif lib_grpc_la_CXXFLAGS = $(WERROR) $(GRPC_CFLAGS) -lib_grpc_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +lib_grpc_la_LDFLAGS = $(MODULE_LDFLAGS) lib_grpc_la_LIBADD = lib/libfrr.la grpc/libfrrgrpc_pb.la $(GRPC_LIBS) lib_grpc_la_SOURCES = lib/northbound_grpc.cpp @@ -419,7 +419,8 @@ lib_grammar_sandbox_LDADD = \ lib_clippy_CPPFLAGS = $(CPPFLAGS_BASE) -D_GNU_SOURCE -DBUILDING_CLIPPY lib_clippy_CFLAGS = $(AC_CFLAGS) $(PYTHON_CFLAGS) lib_clippy_LDADD = $(PYTHON_LIBS) $(UST_LIBS) -lelf -lib_clippy_LDFLAGS = -export-dynamic +# no $(SAN_FLAGS) here +lib_clippy_LDFLAGS = -export-dynamic $(AC_LDFLAGS) $(AC_LDFLAGS_EXEC) lib_clippy_SOURCES = \ lib/jhash.c \ lib/clippy.c \ diff --git a/mlag/subdir.am b/mlag/subdir.am index 49d1761505..376eea8bc9 100644 --- a/mlag/subdir.am +++ b/mlag/subdir.am @@ -2,7 +2,7 @@ if HAVE_PROTOBUF3 lib_LTLIBRARIES += mlag/libmlag_pb.la endif -mlag_libmlag_pb_la_LDFLAGS = -version-info 0:0:0 +mlag_libmlag_pb_la_LDFLAGS = $(LIB_LDFLAGS) -version-info 0:0:0 mlag_libmlag_pb_la_CPPFLAGS = $(AM_CPPFLAGS) $(PROTOBUF_C_CFLAGS) mlag_libmlag_pb_la_SOURCES = \ # end diff --git a/ospf6d/subdir.am b/ospf6d/subdir.am index 2b7bce5392..3f9ff76f3b 100644 --- a/ospf6d/subdir.am +++ b/ospf6d/subdir.am @@ -84,7 +84,7 @@ ospf6d_ospf6d_SOURCES = \ ospf6d_ospf6d_snmp_la_SOURCES = ospf6d/ospf6_snmp.c ospf6d_ospf6d_snmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11 -ospf6d_ospf6d_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +ospf6d_ospf6d_snmp_la_LDFLAGS = $(MODULE_LDFLAGS) ospf6d_ospf6d_snmp_la_LIBADD = lib/libfrrsnmp.la clippy_scan += \ diff --git a/ospfclient/subdir.am b/ospfclient/subdir.am index 756ad88f15..1f9547ab87 100644 --- a/ospfclient/subdir.am +++ b/ospfclient/subdir.am @@ -8,7 +8,7 @@ noinst_PROGRAMS += ospfclient/ospfclient #man8 += $(MANBUILD)/frr-ospfclient.8 endif -ospfclient_libfrrospfapiclient_la_LDFLAGS = -version-info 0:0:0 +ospfclient_libfrrospfapiclient_la_LDFLAGS = $(LIB_LDFLAGS) -version-info 0:0:0 ospfclient_libfrrospfapiclient_la_LIBADD = lib/libfrr.la ospfclient_libfrrospfapiclient_la_SOURCES = \ ospfclient/ospf_apiclient.c \ diff --git a/ospfd/subdir.am b/ospfd/subdir.am index 2c4cc262c1..4f9cbc7b1e 100644 --- a/ospfd/subdir.am +++ b/ospfd/subdir.am @@ -119,7 +119,7 @@ ospfd_ospfd_SOURCES = ospfd/ospf_main.c ospfd_ospfd_snmp_la_SOURCES = ospfd/ospf_snmp.c ospfd_ospfd_snmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11 -ospfd_ospfd_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +ospfd_ospfd_snmp_la_LDFLAGS = $(MODULE_LDFLAGS) ospfd_ospfd_snmp_la_LIBADD = lib/libfrrsnmp.la EXTRA_DIST += \ diff --git a/pathd/subdir.am b/pathd/subdir.am index 693afabb39..f339c79225 100644 --- a/pathd/subdir.am +++ b/pathd/subdir.am @@ -82,4 +82,4 @@ endif #pathd_pathd_pcep_la_CFLAGS = $(AM_CFLAGS) -pathd_pathd_pcep_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +pathd_pathd_pcep_la_LDFLAGS = $(MODULE_LDFLAGS) diff --git a/qpb/subdir.am b/qpb/subdir.am index 704efc5930..e897822ecc 100644 --- a/qpb/subdir.am +++ b/qpb/subdir.am @@ -4,7 +4,7 @@ endif qpb_libfrr_pb_la_CPPFLAGS = $(AM_CPPFLAGS) $(PROTOBUF_C_CFLAGS) qpb_libfrr_pb_la_LIBADD = $(PROTOBUF_C_LIBS) -qpb_libfrr_pb_la_LDFLAGS = -version-info 0:0:0 +qpb_libfrr_pb_la_LDFLAGS = $(LIB_LDFLAGS) -version-info 0:0:0 qpb_libfrr_pb_la_SOURCES = \ qpb/qpb.c \ diff --git a/ripd/subdir.am b/ripd/subdir.am index 8de0fc4b5a..b43e369ab2 100644 --- a/ripd/subdir.am +++ b/ripd/subdir.am @@ -57,5 +57,5 @@ nodist_ripd_ripd_SOURCES = \ ripd_ripd_snmp_la_SOURCES = ripd/rip_snmp.c ripd_ripd_snmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11 -ripd_ripd_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +ripd_ripd_snmp_la_LDFLAGS = $(MODULE_LDFLAGS) ripd_ripd_snmp_la_LIBADD = lib/libfrrsnmp.la diff --git a/zebra/subdir.am b/zebra/subdir.am index 70d8c4005d..731f0c9ad1 100644 --- a/zebra/subdir.am +++ b/zebra/subdir.am @@ -196,14 +196,14 @@ zebra_zebra_irdp_la_SOURCES = \ zebra/irdp_main.c \ zebra/irdp_packet.c \ # end -zebra_zebra_irdp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +zebra_zebra_irdp_la_LDFLAGS = $(MODULE_LDFLAGS) zebra_zebra_snmp_la_SOURCES = zebra/zebra_snmp.c zebra_zebra_snmp_la_CFLAGS = $(AM_CFLAGS) $(SNMP_CFLAGS) -std=gnu11 -zebra_zebra_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +zebra_zebra_snmp_la_LDFLAGS = $(MODULE_LDFLAGS) zebra_zebra_snmp_la_LIBADD = lib/libfrrsnmp.la -zebra_zebra_fpm_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +zebra_zebra_fpm_la_LDFLAGS = $(MODULE_LDFLAGS) zebra_zebra_fpm_la_LIBADD = zebra_zebra_fpm_la_SOURCES = zebra/zebra_fpm.c zebra_zebra_fpm_la_SOURCES += zebra/zebra_fpm_netlink.c @@ -220,7 +220,7 @@ endif # Sample dataplane plugin if DEV_BUILD zebra_dplane_sample_plugin_la_SOURCES = zebra/sample_plugin.c -zebra_dplane_sample_plugin_la_LDFLAGS = -module -shared -avoid-version -export-dynamic +zebra_dplane_sample_plugin_la_LDFLAGS = $(MODULE_LDFLAGS) endif nodist_zebra_zebra_SOURCES = \ @@ -229,13 +229,13 @@ nodist_zebra_zebra_SOURCES = \ # end zebra_zebra_cumulus_mlag_la_SOURCES = zebra/zebra_mlag_private.c -zebra_zebra_cumulus_mlag_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +zebra_zebra_cumulus_mlag_la_LDFLAGS = $(MODULE_LDFLAGS) if LINUX module_LTLIBRARIES += zebra/dplane_fpm_nl.la zebra_dplane_fpm_nl_la_SOURCES = zebra/dplane_fpm_nl.c -zebra_dplane_fpm_nl_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +zebra_dplane_fpm_nl_la_LDFLAGS = $(MODULE_LDFLAGS) zebra_dplane_fpm_nl_la_LIBADD = vtysh_scan += zebra/dplane_fpm_nl.c From 81aff2127f35da2ec667bc60989cac7df7a8ef48 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Wed, 21 Jul 2021 11:23:23 +0200 Subject: [PATCH 2/2] build: use `--coverage` for gcov libtool does not understand `-coverage` with a single dash. Official gcc docs also say `--coverage` rather than `-coverage`. (clang lists both.) Also, for correct linking, libtool needs `--coverage` in LDFLAGS as opposed to `-lgcov` (with the latter you get library ordering/deps issues) Signed-off-by: David Lamparter --- configure.ac | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index ecab39a30f..c86f47d073 100644 --- a/configure.ac +++ b/configure.ac @@ -264,11 +264,11 @@ AC_C_FLAG([-std=gnu11], [CC="$ac_cc"], [CC="$CC -std=gnu11"]) dnl if the user has specified any CFLAGS, override our settings if test "$enable_gcov" = "yes"; then if test "$orig_cflags" = ""; then - AC_C_FLAG([-coverage]) + AC_C_FLAG([--coverage]) AC_C_FLAG([-O0]) fi - AC_LDFLAGS="${AC_LDFLAGS} -lgcov" + AC_LDFLAGS="${AC_LDFLAGS} --coverage" fi if test "$enable_clang_coverage" = "yes"; then