Patchwork [2/4] build-sys: must link with -fstack-protector

login
register
mail settings
Submitter Marc-André Lureau
Date Feb. 25, 2013, 5:56 p.m.
Message ID <1361815009-24145-2-git-send-email-marcandre.lureau@redhat.com>
Download mbox | patch
Permalink /patch/222988/
State New
Headers show

Comments

Marc-André Lureau - Feb. 25, 2013, 5:56 p.m.
From: Marc-André Lureau <marcandre.lureau@gmail.com>

It is needed to give that flag to the linker as well, but latest
libtool 2.4.2 still swallows that argument, so let's pass it with
libtool -Wc argument.

qemu-1.4.0/stubs/arch-query-cpu-def.c:6: undefined reference to `__stack_chk_guard'

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 configure | 8 +++++++-
 rules.mak | 2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)
Paolo Bonzini - Feb. 25, 2013, 6:13 p.m.
Il 25/02/2013 18:56, Marc-André Lureau ha scritto:
> From: Marc-André Lureau <marcandre.lureau@gmail.com>
> 
> It is needed to give that flag to the linker as well, but latest
> libtool 2.4.2 still swallows that argument, so let's pass it with
> libtool -Wc argument.
> 
> qemu-1.4.0/stubs/arch-query-cpu-def.c:6: undefined reference to `__stack_chk_guard'
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  configure | 8 +++++++-
>  rules.mak | 2 +-
>  2 files changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/configure b/configure
> index dcaa67c..c591314 100755
> --- a/configure
> +++ b/configure
> @@ -1196,7 +1196,7 @@ fi
>  gcc_flags="-Wold-style-declaration -Wold-style-definition -Wtype-limits"
>  gcc_flags="-Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers $gcc_flags"
>  gcc_flags="-Wmissing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
> -gcc_flags="-fstack-protector-all -Wendif-labels $gcc_flags"
> +gcc_flags="-Wendif-labels $gcc_flags"
>  gcc_flags="-Wno-initializer-overrides $gcc_flags"
>  # Note that we do not add -Werror to gcc_flags here, because that would
>  # enable it for all configure tests. If a configure test failed due
> @@ -1215,6 +1215,11 @@ for flag in $gcc_flags; do
>      fi
>  done
>  
> +if compile_prog "-Werror -fstack-protector-all" "" ; then
> +    QEMU_CFLAGS="$QEMU_CFLAGS -fstack-protector-all"
> +    LIBTOOLFLAGS="$LIBTOOLFLAGS -Wc,-fstack-protector-all"
> +fi
> +
>  # Workaround for http://gcc.gnu.org/PR55489.  Happens with -fPIE/-fPIC and
>  # large functions that use global variables.  The bug is in all releases of
>  # GCC, but it became particularly acute in 4.6.x and 4.7.x.  It is fixed in
> @@ -3842,6 +3847,7 @@ else
>    echo "AUTOCONF_HOST := "                             >> $config_host_mak
>  fi
>  echo "LDFLAGS=$LDFLAGS" >> $config_host_mak
> +echo "LIBTOOLFLAGS=$LIBTOOLFLAGS" >> $config_host_mak
>  echo "ARLIBS_BEGIN=$arlibs_begin" >> $config_host_mak
>  echo "ARLIBS_END=$arlibs_end" >> $config_host_mak
>  echo "LIBS+=$LIBS" >> $config_host_mak
> diff --git a/rules.mak b/rules.mak
> index edc2552..0be8e60 100644
> --- a/rules.mak
> +++ b/rules.mak
> @@ -34,7 +34,7 @@ LIBTOOL += $(if $(V),,--quiet)
>  
>  LINK = $(call quiet-command,\
>         $(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \
> -       )$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
> +       )$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) $(LIBTOOLFLAGS) -o $@ \
>         $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
>         $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", "  LINK  ")"$(TARGET_DIR)$@")
>  endif
> 

Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Marc-André Lureau - Feb. 25, 2013, 6:16 p.m.
self nack, it fails to link without libtool

Patch

diff --git a/configure b/configure
index dcaa67c..c591314 100755
--- a/configure
+++ b/configure
@@ -1196,7 +1196,7 @@  fi
 gcc_flags="-Wold-style-declaration -Wold-style-definition -Wtype-limits"
 gcc_flags="-Wformat-security -Wformat-y2k -Winit-self -Wignored-qualifiers $gcc_flags"
 gcc_flags="-Wmissing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
-gcc_flags="-fstack-protector-all -Wendif-labels $gcc_flags"
+gcc_flags="-Wendif-labels $gcc_flags"
 gcc_flags="-Wno-initializer-overrides $gcc_flags"
 # Note that we do not add -Werror to gcc_flags here, because that would
 # enable it for all configure tests. If a configure test failed due
@@ -1215,6 +1215,11 @@  for flag in $gcc_flags; do
     fi
 done
 
+if compile_prog "-Werror -fstack-protector-all" "" ; then
+    QEMU_CFLAGS="$QEMU_CFLAGS -fstack-protector-all"
+    LIBTOOLFLAGS="$LIBTOOLFLAGS -Wc,-fstack-protector-all"
+fi
+
 # Workaround for http://gcc.gnu.org/PR55489.  Happens with -fPIE/-fPIC and
 # large functions that use global variables.  The bug is in all releases of
 # GCC, but it became particularly acute in 4.6.x and 4.7.x.  It is fixed in
@@ -3842,6 +3847,7 @@  else
   echo "AUTOCONF_HOST := "                             >> $config_host_mak
 fi
 echo "LDFLAGS=$LDFLAGS" >> $config_host_mak
+echo "LIBTOOLFLAGS=$LIBTOOLFLAGS" >> $config_host_mak
 echo "ARLIBS_BEGIN=$arlibs_begin" >> $config_host_mak
 echo "ARLIBS_END=$arlibs_end" >> $config_host_mak
 echo "LIBS+=$LIBS" >> $config_host_mak
diff --git a/rules.mak b/rules.mak
index edc2552..0be8e60 100644
--- a/rules.mak
+++ b/rules.mak
@@ -34,7 +34,7 @@  LIBTOOL += $(if $(V),,--quiet)
 
 LINK = $(call quiet-command,\
        $(if $(filter %.lo %.la,$^),$(LIBTOOL) --mode=link --tag=CC \
-       )$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ \
+       )$(CC) $(QEMU_CFLAGS) $(CFLAGS) $(LDFLAGS) $(LIBTOOLFLAGS) -o $@ \
        $(sort $(filter %.o, $1)) $(filter-out %.o, $1) $(version-obj-y) \
        $(LIBS),$(if $(filter %.lo %.la,$^),"lt LINK ", "  LINK  ")"$(TARGET_DIR)$@")
 endif