From nobody Wed May 14 22:06:21 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1516873160710691.9449493910412; Thu, 25 Jan 2018 01:39:20 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A6F471279B; Thu, 25 Jan 2018 09:39:19 +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 6BC8F6064E; Thu, 25 Jan 2018 09:39:19 +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 33AE818033E0; Thu, 25 Jan 2018 09:39:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w0P9dIpY003355 for ; Thu, 25 Jan 2018 04:39:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7372D50F4E; Thu, 25 Jan 2018 09:39:18 +0000 (UTC) Received: from t460.redhat.com (unknown [10.33.36.85]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42ED46031B; Thu, 25 Jan 2018 09:39:16 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Date: Thu, 25 Jan 2018 09:38:24 +0000 Message-Id: <20180125093825.5834-14-berrange@redhat.com> In-Reply-To: <20180125093825.5834-1-berrange@redhat.com> References: <20180125093825.5834-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 13/14] 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 25 Jan 2018 09:39:20 +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 | 3 +++ m4/virt-linker-no-undefined.m4 | 32 ++++++++++++++++++++++++++++++++ src/Makefile.am | 36 ++++++++++++++++++++---------------- tools/Makefile.am | 1 + 5 files changed, 57 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 f7519efe2f..e20b551be9 100644 --- a/daemon/Makefile.am +++ b/daemon/Makefile.am @@ -133,6 +133,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 @@ -153,6 +154,7 @@ libvirtd_admin_la_LDFLAGS =3D \ $(RELRO_LDFLAGS) \ $(COVERAGE_LDFLAGS) \ $(NO_INDIRECT_LDFLAGS) \ + $(NO_UNDEFINED_LDFLAGS) \ $(NULL) libvirtd_admin_la_LIBADD =3D \ ../src/libvirt-admin.la @@ -187,6 +189,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 335b3a0c81..8fddafee51 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 @@ -1336,7 +1337,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) \ @@ -1382,7 +1383,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 \ @@ -1411,7 +1412,7 @@ 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) \ @@ -1440,7 +1441,7 @@ 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) \ @@ -1475,7 +1476,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) \ @@ -1512,7 +1513,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 \ @@ -1584,7 +1585,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 \ @@ -1600,7 +1601,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 \ @@ -1626,7 +1627,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) \ @@ -1646,7 +1647,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) @@ -1667,7 +1668,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 @@ -1695,7 +1696,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 @@ -1849,7 +1850,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 @@ -1874,7 +1875,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) \ @@ -2361,6 +2362,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 @@ -2563,7 +2565,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 @@ -2603,6 +2605,7 @@ virtlockd_CFLAGS =3D \ virtlockd_LDFLAGS =3D \ $(AM_LDFLAGS) \ $(PIE_LDFLAGS) \ + $(NO_UNDEFINED_LDFLAGS) \ $(NULL) virtlockd_LDADD =3D \ libvirt-net-rpc-server.la \ @@ -2629,6 +2632,7 @@ virtlogd_CFLAGS =3D \ virtlogd_LDFLAGS =3D \ $(AM_LDFLAGS) \ $(PIE_LDFLAGS) \ + $(NO_UNDEFINED_LDFLAGS) \ $(NULL) virtlogd_LDADD =3D \ libvirt-net-rpc-server.la \ @@ -2842,7 +2846,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 e9597cdb47..627e06addc 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