From nobody Wed Dec 17 03:58:13 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1517844549808729.8832588548509; Mon, 5 Feb 2018 07:29:09 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CA92978553; Mon, 5 Feb 2018 15:29:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 884F35D6A2; Mon, 5 Feb 2018 15:29:08 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3B9C318033E8; Mon, 5 Feb 2018 15:29:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w15FT6ka003018 for ; Mon, 5 Feb 2018 10:29:06 -0500 Received: by smtp.corp.redhat.com (Postfix) id BDC535D6A2; Mon, 5 Feb 2018 15:29:06 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 15B0062678; Mon, 5 Feb 2018 15:29:00 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Mon, 5 Feb 2018 15:28:28 +0000 Message-Id: <20180205152829.12577-15-berrange@redhat.com> In-Reply-To: <20180205152829.12577-1-berrange@redhat.com> References: <20180205152829.12577-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: Peter Krempa Subject: [libvirt] [PATCH v3 14/15] build: passing the "-z defs" linker flag to prevent undefined symbols X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 05 Feb 2018 15:29:09 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Undefined symbols are a bad thing in general because they can get resolved in unexpected ways at runtime if multiple sources provide the same symbol name. For example both glibc and libtirpc may provide XDR symbols and we want to ensure that we resolve to libtirpc if that's what we originally built against. The toolchain maintainers thus strongly recommend that all applications use the '-z defs' linker flag to prevent undefined symbols. This is shortly becoming part of the default linker flags for RPMs. As an added benefit this aligns Linux builds with Windows builds, where the linker has never permitted undefined symbols. Signed-off-by: Daniel P. Berrange --- configure.ac | 1 + daemon/Makefile.am | 2 ++ m4/virt-linker-no-undefined.m4 | 32 ++++++++++++++++++++++++++++++++ src/Makefile.am | 40 ++++++++++++++++++++++++--------------= -- tools/Makefile.am | 1 + 5 files changed, 60 insertions(+), 16 deletions(-) create mode 100644 m4/virt-linker-no-undefined.m4 diff --git a/configure.ac b/configure.ac index 4cccf7f4de..7997ec5a14 100644 --- a/configure.ac +++ b/configure.ac @@ -237,6 +237,7 @@ LIBVIRT_COMPILE_WARNINGS LIBVIRT_COMPILE_PIE LIBVIRT_LINKER_RELRO LIBVIRT_LINKER_NO_INDIRECT +LIBVIRT_LINKER_NO_UNDEFINED =20 LIBVIRT_ARG_APPARMOR LIBVIRT_ARG_ATTR diff --git a/daemon/Makefile.am b/daemon/Makefile.am index 9c1dfcfac6..77dfd8943a 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -125,6 +125,7 @@ libvirtd_conf_la_LDFLAGS =3D \ $(PIE_LDFLAGS) \ $(COVERAGE_LDFLAGS) \ $(NO_INDIRECT_LDFLAGS) \ + $(NO_UNDEFINED_LDFLAGS) \ $(NULL) libvirtd_conf_la_LIBADD =3D $(LIBXML_LIBS) =20 @@ -158,6 +159,7 @@ libvirtd_LDFLAGS =3D \ $(PIE_LDFLAGS) \ $(COVERAGE_LDFLAGS) \ $(NO_INDIRECT_LDFLAGS) \ + $(NO_UNDEFINED_LDFLAGS) \ $(NULL) =20 libvirtd_LDADD =3D \ diff --git a/m4/virt-linker-no-undefined.m4 b/m4/virt-linker-no-undefined.m4 new file mode 100644 index 0000000000..532b0de212 --- /dev/null +++ b/m4/virt-linker-no-undefined.m4 @@ -0,0 +1,32 @@ +dnl +dnl Check for -z defs linker flag +dnl +dnl Copyright (C) 2013-2018 Red Hat, Inc. +dnl +dnl This library is free software; you can redistribute it and/or +dnl modify it under the terms of the GNU Lesser General Public +dnl License as published by the Free Software Foundation; either +dnl version 2.1 of the License, or (at your option) any later version. +dnl +dnl This library is distributed in the hope that it will be useful, +dnl but WITHOUT ANY WARRANTY; without even the implied warranty of +dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +dnl Lesser General Public License for more details. +dnl +dnl You should have received a copy of the GNU Lesser General Public +dnl License along with this library. If not, see +dnl . +dnl + +AC_DEFUN([LIBVIRT_LINKER_NO_UNDEFINED],[ + AC_MSG_CHECKING([for how to stop undefined symbols at link time]) + + NO_UNDEFINED_LDFLAGS=3D + ld_help=3D`$LD --help 2>&1` + case $ld_help in + *"-z defs"*) NO_UNDEFINED_LDFLAGS=3D"-Wl,-z -Wl,defs" ;; + esac + AC_SUBST([NO_UNDEFINED_LDFLAGS]) + + AC_MSG_RESULT([$NO_UNDEFINED_LDFLAGS]) +]) diff --git a/src/Makefile.am b/src/Makefile.am index 38efde012e..2cfa36a142 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -52,6 +52,7 @@ AM_LDFLAGS =3D $(DRIVER_MODULES_LDFLAGS) \ $(MINGW_EXTRA_LDFLAGS) \ $(NULL) AM_LDFLAGS_MOD =3D -module -avoid-version $(AM_LDFLAGS) +AM_LDFLAGS_MOD_NOUNDEF =3D $(AM_LDFLAGS_MOD) $(NO_UNDEFINED_LDFLAGS) =20 POD2MAN =3D pod2man -c "Virtualization Support" -r "$(PACKAGE)-$(VERSION)" =20 @@ -1342,7 +1343,7 @@ libvirt_driver_xen_la_SOURCES =3D libvirt_driver_xen_la_LIBADD =3D libvirt_driver_xen_impl.la mod_LTLIBRARIES +=3D libvirt_driver_xen.la libvirt_driver_xen_la_LIBADD +=3D libvirt.la ../gnulib/lib/libgnu.la -libvirt_driver_xen_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) +libvirt_driver_xen_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) =20 libvirt_driver_xen_impl_la_CFLAGS =3D \ $(XEN_CFLAGS) \ @@ -1388,7 +1389,7 @@ libvirt_driver_vbox_la_LIBADD =3D libvirt_driver_vbox= _impl.la mod_LTLIBRARIES +=3D \ libvirt_driver_vbox.la libvirt_driver_vbox_la_LIBADD +=3D libvirt.la ../gnulib/lib/libgnu.la -libvirt_driver_vbox_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) +libvirt_driver_vbox_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) =20 libvirt_driver_vbox_impl_la_CFLAGS =3D \ -I$(srcdir)/conf \ @@ -1417,10 +1418,11 @@ libvirt_driver_libxl_la_SOURCES =3D libvirt_driver_libxl_la_LIBADD =3D libvirt_driver_libxl_impl.la mod_LTLIBRARIES +=3D libvirt_driver_libxl.la libvirt_driver_libxl_la_LIBADD +=3D libvirt.la ../gnulib/lib/libgnu.la -libvirt_driver_libxl_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) +libvirt_driver_libxl_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) =20 libvirt_driver_libxl_impl_la_CFLAGS =3D \ $(LIBXL_CFLAGS) \ + $(LIBXML_CFLAGS) \ -I$(srcdir)/access \ -I$(srcdir)/conf \ -I$(srcdir)/secret \ @@ -1428,6 +1430,7 @@ libvirt_driver_libxl_impl_la_CFLAGS =3D \ $(AM_CFLAGS) libvirt_driver_libxl_impl_la_LDFLAGS =3D $(AM_LDFLAGS) libvirt_driver_libxl_impl_la_LIBADD =3D $(LIBXL_LIBS) \ + $(LIBXML_LIBS) \ libvirt_xenconfig_libxl.la libvirt_driver_libxl_impl_la_SOURCES =3D $(LIBXL_DRIVER_SOURCES) =20 @@ -1446,11 +1449,12 @@ libvirt_driver_qemu_la_SOURCES =3D libvirt_driver_qemu_la_LIBADD =3D libvirt_driver_qemu_impl.la mod_LTLIBRARIES +=3D libvirt_driver_qemu.la libvirt_driver_qemu_la_LIBADD +=3D libvirt.la ../gnulib/lib/libgnu.la -libvirt_driver_qemu_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) +libvirt_driver_qemu_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) =20 libvirt_driver_qemu_impl_la_CFLAGS =3D \ $(GNUTLS_CFLAGS) \ $(LIBNL_CFLAGS) \ + $(SELINUX_CFLAGS) \ $(XDR_CFLAGS) \ -I$(srcdir)/access \ -I$(srcdir)/conf \ @@ -1460,6 +1464,7 @@ libvirt_driver_qemu_impl_la_LDFLAGS =3D $(AM_LDFLAGS) libvirt_driver_qemu_impl_la_LIBADD =3D $(CAPNG_LIBS) \ $(GNUTLS_LIBS) \ $(LIBNL_LIBS) \ + $(SELINUX_LIBS) \ $(LIBXML_LIBS) \ $(NULL) libvirt_driver_qemu_impl_la_SOURCES =3D $(QEMU_DRIVER_SOURCES) @@ -1481,7 +1486,7 @@ libvirt_driver_lxc_la_SOURCES =3D libvirt_driver_lxc_la_LIBADD =3D libvirt_driver_lxc_impl.la mod_LTLIBRARIES +=3D libvirt_driver_lxc.la libvirt_driver_lxc_la_LIBADD +=3D libvirt.la ../gnulib/lib/libgnu.la -libvirt_driver_lxc_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) +libvirt_driver_lxc_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) =20 libvirt_driver_lxc_impl_la_CFLAGS =3D \ $(LIBNL_CFLAGS) \ @@ -1518,7 +1523,7 @@ libvirt_driver_uml_la_SOURCES =3D libvirt_driver_uml_la_LIBADD =3D libvirt_driver_uml_impl.la mod_LTLIBRARIES +=3D libvirt_driver_uml.la libvirt_driver_uml_la_LIBADD +=3D libvirt.la ../gnulib/lib/libgnu.la -libvirt_driver_uml_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) +libvirt_driver_uml_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) =20 libvirt_driver_uml_impl_la_CFLAGS =3D \ -I$(srcdir)/access \ @@ -1590,7 +1595,7 @@ libvirt_driver_vz_la_SOURCES =3D libvirt_driver_vz_la_LIBADD =3D libvirt_driver_vz_impl.la mod_LTLIBRARIES +=3D libvirt_driver_vz.la libvirt_driver_vz_la_LIBADD +=3D libvirt.la ../gnulib/lib/libgnu.la -libvirt_driver_vz_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) +libvirt_driver_vz_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) libvirt_driver_vz_impl_la_CFLAGS =3D \ -I$(srcdir)/conf \ -I$(srcdir)/access \ @@ -1606,7 +1611,7 @@ libvirt_driver_bhyve_la_SOURCES =3D libvirt_driver_bhyve_la_LIBADD =3D libvirt_driver_bhyve_impl.la mod_LTLIBRARIES +=3D libvirt_driver_bhyve.la libvirt_driver_bhyve_la_LIBADD +=3D libvirt.la ../gnulib/lib/libgnu.la -libvirt_driver_bhyve_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) +libvirt_driver_bhyve_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) =20 libvirt_driver_bhyve_impl_la_CFLAGS =3D \ -I$(srcdir)/access \ @@ -1632,7 +1637,7 @@ libvirt_driver_network_la_LIBADD +=3D libvirt.la ../g= nulib/lib/libgnu.la \ $(LIBNL_LIBS) \ $(DBUS_LIBS) \ $(NULL) -libvirt_driver_network_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) +libvirt_driver_network_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) =20 libvirt_driver_network_impl_la_CFLAGS =3D \ $(LIBNL_CFLAGS) \ @@ -1652,7 +1657,7 @@ libvirt_driver_interface_la_CFLAGS =3D \ -I$(srcdir)/access \ -I$(srcdir)/conf \ $(AM_CFLAGS) $(LIBNL_CFLAGS) -libvirt_driver_interface_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) +libvirt_driver_interface_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) libvirt_driver_interface_la_LIBADD =3D if WITH_NETCF libvirt_driver_interface_la_CFLAGS +=3D $(NETCF_CFLAGS) @@ -1673,7 +1678,7 @@ libvirt_driver_secret_la_CFLAGS =3D \ -I$(srcdir)/conf \ $(AM_CFLAGS) libvirt_driver_secret_la_LIBADD =3D libvirt.la ../gnulib/lib/libgnu.la -libvirt_driver_secret_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) +libvirt_driver_secret_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) libvirt_driver_secret_la_SOURCES =3D $(SECRET_DRIVER_SOURCES) endif WITH_SECRETS =20 @@ -1701,7 +1706,7 @@ libvirt_driver_storage_la_SOURCES =3D libvirt_driver_storage_la_LIBADD =3D libvirt_driver_storage_impl.la mod_LTLIBRARIES +=3D libvirt_driver_storage.la libvirt_driver_storage_la_LIBADD +=3D libvirt.la ../gnulib/lib/libgnu.la -libvirt_driver_storage_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) +libvirt_driver_storage_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) libvirt_driver_storage_impl_la_SOURCES +=3D $(STORAGE_DRIVER_SOURCES) =20 =20 @@ -1855,7 +1860,7 @@ libvirt_driver_nodedev_la_CFLAGS =3D \ -I$(srcdir)/access \ -I$(srcdir)/conf \ $(AM_CFLAGS) $(LIBNL_CFLAGS) -libvirt_driver_nodedev_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) +libvirt_driver_nodedev_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) libvirt_driver_nodedev_la_LIBADD =3D =20 if WITH_LIBVIRTD @@ -1880,7 +1885,7 @@ noinst_LTLIBRARIES +=3D libvirt_driver_nwfilter_impl.= la libvirt_driver_nwfilter_la_SOURCES =3D libvirt_driver_nwfilter_la_LIBADD =3D libvirt_driver_nwfilter_impl.la mod_LTLIBRARIES +=3D libvirt_driver_nwfilter.la -libvirt_driver_nwfilter_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) +libvirt_driver_nwfilter_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) libvirt_driver_nwfilter_impl_la_CFLAGS =3D \ $(LIBPCAP_CFLAGS) \ $(LIBNL_CFLAGS) \ @@ -2389,6 +2394,7 @@ libvirt_la_LDFLAGS =3D \ $(VERSION_SCRIPT_FLAGS)$(LIBVIRT_SYMBOL_FILE) \ -version-info $(LIBVIRT_VERSION_INFO) \ $(LIBVIRT_NODELETE) \ + $(NO_UNDEFINED_LDFLAGS) \ $(AM_LDFLAGS) \ $(NULL) libvirt_la_BUILT_LIBADD +=3D ../gnulib/lib/libgnu.la @@ -2591,7 +2597,7 @@ lockd_la_SOURCES =3D \ lockd_la_CFLAGS =3D -I$(srcdir)/conf \ $(XDR_CFLAGS) \ $(AM_CFLAGS) -lockd_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) +lockd_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) lockd_la_LIBADD =3D libvirt.la ../gnulib/lib/libgnu.la augeas_DATA +=3D locking/libvirt_lockd.aug if WITH_DTRACE_PROBES @@ -2631,6 +2637,7 @@ virtlockd_CFLAGS =3D \ virtlockd_LDFLAGS =3D \ $(AM_LDFLAGS) \ $(PIE_LDFLAGS) \ + $(NO_UNDEFINED_LDFLAGS) \ $(NULL) virtlockd_LDADD =3D \ libvirt_driver_admin.la \ @@ -2658,6 +2665,7 @@ virtlogd_CFLAGS =3D \ virtlogd_LDFLAGS =3D \ $(AM_LDFLAGS) \ $(PIE_LDFLAGS) \ + $(NO_UNDEFINED_LDFLAGS) \ $(NULL) virtlogd_LDADD =3D \ libvirt_driver_admin.la \ @@ -2872,7 +2880,7 @@ if WITH_SANLOCK lockdriver_LTLIBRARIES +=3D sanlock.la sanlock_la_SOURCES =3D $(LOCK_DRIVER_SANLOCK_SOURCES) sanlock_la_CFLAGS =3D -I$(srcdir)/conf $(AM_CFLAGS) -sanlock_la_LDFLAGS =3D $(AM_LDFLAGS_MOD) +sanlock_la_LDFLAGS =3D $(AM_LDFLAGS_MOD_NOUNDEF) sanlock_la_LIBADD =3D -lsanlock_client libvirt.la ../gnulib/lib/libgnu.la =20 augeas_DATA +=3D locking/libvirt_sanlock.aug diff --git a/tools/Makefile.am b/tools/Makefile.am index 4c33e78a1d..85e640b9e7 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -35,6 +35,7 @@ AM_CFLAGS =3D \ AM_LDFLAGS =3D \ $(RELRO_LDFLAGS) \ $(NO_INDIRECT_LDFLAGS) \ + $(NO_UNDEFINED_LDFLAGS) \ $(NULL) =20 ICON_FILES =3D \ --=20 2.14.3 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list