[libvirt] [PATCH 1/2] build: allow building with newer glibc-headers and -O0

Fix copied from libvirt, commit by Eric Blake. glibc 2.15 (on Fedora 17) coupled with explicit disabling of optimization during development dies a painful death: /usr/include/features.h:314:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp] Work around this by only conditionally defining _FORTIFY_SOURCE, in the case where glibc can actually use it. The trick is using AH_VERBATIM instead of AC_DEFINE. --- m4/virt-compile-warnings.m4 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4 index d403587..913abca 100644 --- a/m4/virt-compile-warnings.m4 +++ b/m4/virt-compile-warnings.m4 @@ -84,8 +84,12 @@ AC_DEFUN([LIBVIRT_DESIGNER_COMPILE_WARNINGS],[ gl_WARN_ADD([-Wframe-larger-than=4096]) # Use improved glibc headers - AC_DEFINE([_FORTIFY_SOURCE], [2], - [enable compile-time and run-time bounds-checking, and some warnings]) + AH_VERBATIM([FORTIFY_SOURCE], + [/* Enable compile-time and run-time bounds-checking, and some warnings. */ + #if defined __OPTIMIZE__ && __OPTIMIZE__ + # define _FORTIFY_SOURCE 2 + #endif + ]) # Extra special flags dnl -fstack-protector stuff passes gl_WARN_ADD with gcc -- 1.7.11.4

'list' is freed in error cases, and in the 2 functions modified by this commit, we may jump to the error: label before 'list' is initialized when 'db' is NULL. --- examples/virtxml.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/virtxml.c b/examples/virtxml.c index 9783ba6..b0c3a77 100644 --- a/examples/virtxml.c +++ b/examples/virtxml.c @@ -97,7 +97,7 @@ print_oses(const gchar *option_name, GError **error) { OsinfoDb *db = get_default_osinfo_db(); - OsinfoOsList *list; + OsinfoOsList *list = NULL; GList *oses = NULL; GList *os_iter; int ret = EXIT_FAILURE; @@ -140,7 +140,7 @@ print_platforms(const gchar *option_name, GError **error) { OsinfoDb *db = get_default_osinfo_db(); - OsinfoPlatformList *list; + OsinfoPlatformList *list = NULL; GList *platforms = NULL; GList *platform_iter; int ret = EXIT_FAILURE; -- 1.7.11.4

On 12.09.2012 17:42, Christophe Fergeau wrote:
Fix copied from libvirt, commit by Eric Blake.
glibc 2.15 (on Fedora 17) coupled with explicit disabling of optimization during development dies a painful death:
/usr/include/features.h:314:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
Work around this by only conditionally defining _FORTIFY_SOURCE, in the case where glibc can actually use it. The trick is using AH_VERBATIM instead of AC_DEFINE. --- m4/virt-compile-warnings.m4 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/m4/virt-compile-warnings.m4 b/m4/virt-compile-warnings.m4 index d403587..913abca 100644 --- a/m4/virt-compile-warnings.m4 +++ b/m4/virt-compile-warnings.m4 @@ -84,8 +84,12 @@ AC_DEFUN([LIBVIRT_DESIGNER_COMPILE_WARNINGS],[ gl_WARN_ADD([-Wframe-larger-than=4096])
# Use improved glibc headers - AC_DEFINE([_FORTIFY_SOURCE], [2], - [enable compile-time and run-time bounds-checking, and some warnings]) + AH_VERBATIM([FORTIFY_SOURCE], + [/* Enable compile-time and run-time bounds-checking, and some warnings. */ + #if defined __OPTIMIZE__ && __OPTIMIZE__ + # define _FORTIFY_SOURCE 2 + #endif + ])
# Extra special flags dnl -fstack-protector stuff passes gl_WARN_ADD with gcc
ACK Michal

On 09/12/2012 09:42 AM, Christophe Fergeau wrote:
Fix copied from libvirt, commit by Eric Blake.
glibc 2.15 (on Fedora 17) coupled with explicit disabling of optimization during development dies a painful death:
/usr/include/features.h:314:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
Work around this by only conditionally defining _FORTIFY_SOURCE, in the case where glibc can actually use it. The trick is using AH_VERBATIM instead of AC_DEFINE. --- m4/virt-compile-warnings.m4 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
Which project? Your git config settings didn't identify which repo this was for, which was particularly confusing since the same filename exists in the libvirt.git repo. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Fri, Sep 14, 2012 at 11:05:05AM -0600, Eric Blake wrote:
On 09/12/2012 09:42 AM, Christophe Fergeau wrote:
Fix copied from libvirt, commit by Eric Blake.
glibc 2.15 (on Fedora 17) coupled with explicit disabling of optimization during development dies a painful death:
/usr/include/features.h:314:4: error: #warning _FORTIFY_SOURCE requires compiling with optimization (-O) [-Werror=cpp]
Work around this by only conditionally defining _FORTIFY_SOURCE, in the case where glibc can actually use it. The trick is using AH_VERBATIM instead of AC_DEFINE. --- m4/virt-compile-warnings.m4 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
Which project? Your git config settings didn't identify which repo this was for, which was particularly confusing since the same filename exists in the libvirt.git repo.
Yes, sorry about that, I missed --subject-prefix when sending this patch. I've now set it in .git/config. This was a libvirt-designer patch. Christophe
participants (3)
-
Christophe Fergeau
-
Eric Blake
-
Michal Privoznik