[PATCH] meson: Adjust -fstack-protector use

Andrea Bolognani posted 1 patch 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20240120222932.307887-1-abologna@redhat.com
There is a newer version of this series
meson.build | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
[PATCH] meson: Adjust -fstack-protector use
Posted by Andrea Bolognani 1 month ago
Back in 2014, -fstack-protector was reported not to work on
aarch64, so fe881ae086ec disabled it on that target. OS-wise,
its use is currently limited to just Linux, FreeBSD and Windows.

Looking at the situation today, it seems that whatever issue was
affecting aarch64 a decade ago has been resolved; moreover,
macOS can also use the feature these days.

I haven't checked any of the other BSDs, but since the feature
works on FreeBSD it's pretty safe to the assume that they can
use it too. If we get reports that it's not the case, we can
always further restrict its usage accordingly.

The only platform where -fstack-protector is known to still have
issues is alpha, so single that one out.

Best viewed with 'git show -w'.

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
---
Test pipeline: https://gitlab.com/abologna/libvirt/-/pipelines/1145401848

Notice how all aarch64 jobs are fine - even the macOS ones.

 meson.build | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/meson.build b/meson.build
index 611cc582c0..01cb49b306 100644
--- a/meson.build
+++ b/meson.build
@@ -442,22 +442,23 @@ supported_cc_flags = []
 if get_option('warning_level') == '2'
   supported_cc_flags = cc.get_supported_arguments(cc_flags)
 
-  # on aarch64 error: -fstack-protector not supported for this target
-  if host_machine.cpu_family() != 'aarch64'
-    if host_machine.system() in [ 'linux', 'freebsd', 'windows' ]
-      # we prefer -fstack-protector-strong but fallback to -fstack-protector-all
-      fstack_cflags = cc.first_supported_argument([
-        '-fstack-protector-strong',
-        '-fstack-protector-all',
-      ])
-      supported_cc_flags += fstack_cflags
-
-      # When building with mingw using -fstack-protector requires libssp library
-      # which is included by using -fstack-protector with linker.
-      if fstack_cflags.length() == 1 and host_machine.system() == 'windows'
-        add_project_link_arguments(fstack_cflags, language: 'c')
-      endif
-    endif
+  if host_machine.system() == 'linux' and host_machine.cpu_family() == 'alpha'
+    # On alpha, gcc advertises support for -fstack-protector but then
+    # raises a warning when you actually try to use it
+    fstack_cflags = []
+  else
+    # we prefer -fstack-protector-strong but fallback to -fstack-protector-all
+    fstack_cflags = cc.first_supported_argument([
+      '-fstack-protector-strong',
+      '-fstack-protector-all',
+    ])
+    supported_cc_flags += fstack_cflags
+  endif
+
+  # When building with mingw using -fstack-protector requires libssp library
+  # which is included by using -fstack-protector with linker.
+  if fstack_cflags.length() == 1 and host_machine.system() == 'windows'
+    add_project_link_arguments(fstack_cflags, language: 'c')
   endif
 
   if supported_cc_flags.contains('-Wlogical-op')
-- 
2.43.0
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org
Re: [PATCH] meson: Adjust -fstack-protector use
Posted by Daniel P. Berrangé 1 month ago
On Sat, Jan 20, 2024 at 11:29:32PM +0100, Andrea Bolognani wrote:
> Back in 2014, -fstack-protector was reported not to work on
> aarch64, so fe881ae086ec disabled it on that target. OS-wise,
> its use is currently limited to just Linux, FreeBSD and Windows.
> 
> Looking at the situation today, it seems that whatever issue was
> affecting aarch64 a decade ago has been resolved; moreover,
> macOS can also use the feature these days.
> 
> I haven't checked any of the other BSDs, but since the feature
> works on FreeBSD it's pretty safe to the assume that they can
> use it too. If we get reports that it's not the case, we can
> always further restrict its usage accordingly.
> 
> The only platform where -fstack-protector is known to still have
> issues is alpha, so single that one out.

Alpha is not a supported arch in any distro we target & the
hardware hasn't been made since before libvirt even existed.
So I think that special case should just be removed. 

> 
> Best viewed with 'git show -w'.
> 
> Signed-off-by: Andrea Bolognani <abologna@redhat.com>
> ---
> Test pipeline: https://gitlab.com/abologna/libvirt/-/pipelines/1145401848
> 
> Notice how all aarch64 jobs are fine - even the macOS ones.
> 
>  meson.build | 33 +++++++++++++++++----------------
>  1 file changed, 17 insertions(+), 16 deletions(-)
> 
> diff --git a/meson.build b/meson.build
> index 611cc582c0..01cb49b306 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -442,22 +442,23 @@ supported_cc_flags = []
>  if get_option('warning_level') == '2'
>    supported_cc_flags = cc.get_supported_arguments(cc_flags)
>  
> -  # on aarch64 error: -fstack-protector not supported for this target
> -  if host_machine.cpu_family() != 'aarch64'
> -    if host_machine.system() in [ 'linux', 'freebsd', 'windows' ]
> -      # we prefer -fstack-protector-strong but fallback to -fstack-protector-all
> -      fstack_cflags = cc.first_supported_argument([
> -        '-fstack-protector-strong',
> -        '-fstack-protector-all',
> -      ])
> -      supported_cc_flags += fstack_cflags
> -
> -      # When building with mingw using -fstack-protector requires libssp library
> -      # which is included by using -fstack-protector with linker.
> -      if fstack_cflags.length() == 1 and host_machine.system() == 'windows'
> -        add_project_link_arguments(fstack_cflags, language: 'c')
> -      endif
> -    endif
> +  if host_machine.system() == 'linux' and host_machine.cpu_family() == 'alpha'
> +    # On alpha, gcc advertises support for -fstack-protector but then
> +    # raises a warning when you actually try to use it
> +    fstack_cflags = []
> +  else
> +    # we prefer -fstack-protector-strong but fallback to -fstack-protector-all
> +    fstack_cflags = cc.first_supported_argument([
> +      '-fstack-protector-strong',
> +      '-fstack-protector-all',
> +    ])
> +    supported_cc_flags += fstack_cflags
> +  endif
> +
> +  # When building with mingw using -fstack-protector requires libssp library
> +  # which is included by using -fstack-protector with linker.
> +  if fstack_cflags.length() == 1 and host_machine.system() == 'windows'
> +    add_project_link_arguments(fstack_cflags, language: 'c')
>    endif
>  
>    if supported_cc_flags.contains('-Wlogical-op')
> -- 
> 2.43.0
> _______________________________________________
> Devel mailing list -- devel@lists.libvirt.org
> To unsubscribe send an email to devel-leave@lists.libvirt.org

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
_______________________________________________
Devel mailing list -- devel@lists.libvirt.org
To unsubscribe send an email to devel-leave@lists.libvirt.org