[Spice-devel] m4/spice-compile-warnings: Squelch _FORTIFY_SOURCE when needed to avoid glibc #warnings.

Submitted by Alon Levy on June 6, 2012, 1:07 p.m.

Details

Message ID 1338988020-14957-1-git-send-email-alevy@redhat.com
State Accepted
Commit d905a1f24c93e99812388f6def42f8285c2acc6c
Headers show

Not browsing as part of any series.

Commit Message

Alon Levy June 6, 2012, 1:07 p.m.
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]

cc1: all warnings being treated as errors

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/spice-compile-warnings.m4 |    8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Patch hide | download patch | download mbox

diff --git a/m4/spice-compile-warnings.m4 b/m4/spice-compile-warnings.m4
index 601ecf8..959971a 100644
--- a/m4/spice-compile-warnings.m4
+++ b/m4/spice-compile-warnings.m4
@@ -111,8 +111,12 @@  AC_DEFUN([SPICE_COMPILE_WARNINGS],[
     gl_WARN_ADD([-Wframe-larger-than=20460])
 
     # 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 __OPTIMIZE__
+# define _FORTIFY_SOURCE 2
+#endif
+])
 
     # Extra special flags
     dnl -fstack-protector stuff passes gl_WARN_ADD with gcc

Comments

Ack.

On 06/06/2012 03:07 PM, Alon Levy 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]
>
> cc1: all warnings being treated as errors
>
> 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/spice-compile-warnings.m4 |    8 ++++++--
>   1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/m4/spice-compile-warnings.m4 b/m4/spice-compile-warnings.m4
> index 601ecf8..959971a 100644
> --- a/m4/spice-compile-warnings.m4
> +++ b/m4/spice-compile-warnings.m4
> @@ -111,8 +111,12 @@ AC_DEFUN([SPICE_COMPILE_WARNINGS],[
>       gl_WARN_ADD([-Wframe-larger-than=20460])
>
>       # 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 __OPTIMIZE__
> +# define _FORTIFY_SOURCE 2
> +#endif
> +])
>
>       # Extra special flags
>       dnl -fstack-protector stuff passes gl_WARN_ADD with gcc