[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 12/24] build: move SafeStack tests to meson
From: |
Paolo Bonzini |
Subject: |
[PATCH 12/24] build: move SafeStack tests to meson |
Date: |
Thu, 11 May 2023 11:50:09 +0200 |
This disables the old behavior of detecting SafeStack from environment
CFLAGS. SafeStack is now enabled purely based on the configure arguments.
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
configure | 73 -----------------------------------
meson.build | 26 +++++++++++++
meson_options.txt | 2 +
scripts/meson-buildoptions.sh | 4 ++
4 files changed, 32 insertions(+), 73 deletions(-)
diff --git a/configure b/configure
index a99fbaf3e7af..3989d2660e47 100755
--- a/configure
+++ b/configure
@@ -227,7 +227,6 @@ cross_compile="no"
cross_prefix=""
host_cc="cc"
stack_protector=""
-safe_stack=""
use_containers="yes"
gdb_bin=$(command -v "gdb-multiarch" || command -v "gdb")
gdb_arches=""
@@ -830,10 +829,6 @@ for opt do
;;
--disable-stack-protector) stack_protector="no"
;;
- --enable-safe-stack) safe_stack="yes"
- ;;
- --disable-safe-stack) safe_stack="no"
- ;;
--enable-cfi)
cfi="true";
meson_option_add -Db_lto=true
@@ -1024,8 +1019,6 @@ cat << EOF
pie Position Independent Executables
debug-tcg TCG debugging (default is disabled)
debug-info debugging information
- safe-stack SafeStack Stack Smash Protection. Depends on
- clang/llvm and requires coroutine backend ucontext.
NOTE: The object files are built at the place where configure is launched
EOF
@@ -1521,68 +1514,6 @@ else
esac
fi
-##################################################
-# SafeStack
-
-
-if test "$safe_stack" = "yes"; then
-cat > $TMPC << EOF
-int main(void)
-{
-#if ! __has_feature(safe_stack)
-#error SafeStack Disabled
-#endif
- return 0;
-}
-EOF
- flag="-fsanitize=safe-stack"
- # Check that safe-stack is supported and enabled.
- if compile_prog "-Werror $flag" "$flag"; then
- # Flag needed both at compilation and at linking
- QEMU_CFLAGS="$QEMU_CFLAGS $flag"
- QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
- else
- error_exit "SafeStack not supported by your compiler"
- fi
- if test "$coroutine" != "ucontext"; then
- error_exit "SafeStack is only supported by the coroutine backend ucontext"
- fi
-else
-cat > $TMPC << EOF
-int main(void)
-{
-#if defined(__has_feature)
-#if __has_feature(safe_stack)
-#error SafeStack Enabled
-#endif
-#endif
- return 0;
-}
-EOF
-if test "$safe_stack" = "no"; then
- # Make sure that safe-stack is disabled
- if ! compile_prog "-Werror" ""; then
- # SafeStack was already enabled, try to explicitly remove the feature
- flag="-fno-sanitize=safe-stack"
- if ! compile_prog "-Werror $flag" "$flag"; then
- error_exit "Configure cannot disable SafeStack"
- fi
- QEMU_CFLAGS="$QEMU_CFLAGS $flag"
- QEMU_LDFLAGS="$QEMU_LDFLAGS $flag"
- fi
-else # "$safe_stack" = ""
- # Set safe_stack to yes or no based on pre-existing flags
- if compile_prog "-Werror" ""; then
- safe_stack="no"
- else
- safe_stack="yes"
- if test "$coroutine" != "ucontext"; then
- error_exit "SafeStack is only supported by the coroutine backend
ucontext"
- fi
- fi
-fi
-fi
-
########################################
# check if ccache is interfering with
# semantic analysis of macros
@@ -2242,10 +2173,6 @@ if test "$ccache_cpp2" = "yes"; then
echo "export CCACHE_CPP2=y" >> $config_host_mak
fi
-if test "$safe_stack" = "yes"; then
- echo "CONFIG_SAFESTACK=y" >> $config_host_mak
-fi
-
# tests/tcg configuration
(config_host_mak=tests/tcg/config-host.mak
mkdir -p tests/tcg
diff --git a/meson.build b/meson.build
index 4a52c870813b..31151f240ad8 100644
--- a/meson.build
+++ b/meson.build
@@ -211,6 +211,31 @@ if get_option('prefer_static')
qemu_ldflags += get_option('b_pie') ? '-static-pie' : '-static'
endif
+# Compiles if SafeStack *not* enabled
+safe_stack_probe = '''
+ int main(void)
+ {
+ #if defined(__has_feature)
+ #if __has_feature(safe_stack)
+ #error SafeStack Enabled
+ #endif
+ #endif
+ return 0;
+ }'''
+if get_option('safe_stack') != not cc.compiles(safe_stack_probe)
+ safe_stack_arg = get_option('safe_stack') ? '-fsanitize=safe-stack' :
'-fno-sanitize=safe-stack'
+ if get_option('safe_stack') != not cc.compiles(safe_stack_probe, args:
safe_stack_arg)
+ error(get_option('safe_stack') \
+ ? 'SafeStack not supported by your compiler' \
+ : 'Cannot disable SafeStack')
+ endif
+ qemu_cflags += safe_stack_arg
+ qemu_ldflags += safe_stack_arg
+endif
+if get_option('safe_stack') and config_host['CONFIG_COROUTINE_BACKEND'] !=
'ucontext'
+ error('SafeStack is only supported with the ucontext coroutine backend')
+endif
+
if get_option('sanitizers')
if cc.has_argument('-fsanitize=address')
qemu_cflags = ['-fsanitize=address'] + qemu_cflags
@@ -1946,6 +1971,7 @@ config_host_data.set('CONFIG_OPENGL', opengl.found())
config_host_data.set('CONFIG_PROFILER', get_option('profiler'))
config_host_data.set('CONFIG_RBD', rbd.found())
config_host_data.set('CONFIG_RDMA', rdma.found())
+config_host_data.set('CONFIG_SAFESTACK', get_option('safe_stack'))
config_host_data.set('CONFIG_SDL', sdl.found())
config_host_data.set('CONFIG_SDL_IMAGE', sdl_image.found())
config_host_data.set('CONFIG_SECCOMP', seccomp.found())
diff --git a/meson_options.txt b/meson_options.txt
index 71cc9c85703f..f04b12ca0783 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -82,6 +82,8 @@ option('tcg', type: 'feature', value: 'enabled',
description: 'TCG support')
option('tcg_interpreter', type: 'boolean', value: false,
description: 'TCG with bytecode interpreter (slow)')
+option('safe_stack', type: 'boolean', value: false,
+ description: 'SafeStack Stack Smash Protection (requires clang/llvm and
coroutine backend ucontext)')
option('sanitizers', type: 'boolean', value: false,
description: 'enable default sanitizers')
option('tsan', type: 'boolean', value: false,
diff --git a/scripts/meson-buildoptions.sh b/scripts/meson-buildoptions.sh
index 7485012d4634..5ea787deb89e 100644
--- a/scripts/meson-buildoptions.sh
+++ b/scripts/meson-buildoptions.sh
@@ -39,6 +39,8 @@ meson_options_help() {
printf "%s\n" ' --enable-profiler profiler support'
printf "%s\n" ' --enable-rng-none dummy RNG, avoid using
/dev/(u)random and'
printf "%s\n" ' getrandom()'
+ printf "%s\n" ' --enable-safe-stack SafeStack Stack Smash Protection
(requires'
+ printf "%s\n" ' clang/llvm and coroutine backend
ucontext)'
printf "%s\n" ' --enable-sanitizers enable default sanitizers'
printf "%s\n" ' --enable-strip Strip targets on install'
printf "%s\n" ' --enable-tcg-interpreter TCG with bytecode interpreter
(slow)'
@@ -401,6 +403,8 @@ _meson_option_parse() {
--disable-replication) printf "%s" -Dreplication=disabled ;;
--enable-rng-none) printf "%s" -Drng_none=true ;;
--disable-rng-none) printf "%s" -Drng_none=false ;;
+ --enable-safe-stack) printf "%s" -Dsafe_stack=true ;;
+ --disable-safe-stack) printf "%s" -Dsafe_stack=false ;;
--enable-sanitizers) printf "%s" -Dsanitizers=true ;;
--disable-sanitizers) printf "%s" -Dsanitizers=false ;;
--enable-sdl) printf "%s" -Dsdl=enabled ;;
--
2.40.1
- [PATCH 01/24] meson: regenerate meson-buildoptions.sh, (continued)
- [PATCH 01/24] meson: regenerate meson-buildoptions.sh, Paolo Bonzini, 2023/05/11
- [PATCH 03/24] meson: use prefer_static option, Paolo Bonzini, 2023/05/11
- [PATCH 04/24] meson: remove static_kwargs, Paolo Bonzini, 2023/05/11
- [PATCH 05/24] meson: add more version numbers to the summary, Paolo Bonzini, 2023/05/11
- [PATCH 08/24] configure: remove pkg-config functions, Paolo Bonzini, 2023/05/11
- [PATCH 09/24] configure, meson: move --enable-modules to Meson, Paolo Bonzini, 2023/05/11
- [PATCH 06/24] meson: drop unnecessary declare_dependency(), Paolo Bonzini, 2023/05/11
- [PATCH 07/24] build: move glib detection and workarounds to meson, Paolo Bonzini, 2023/05/11
- [PATCH 10/24] meson: prepare move of QEMU_CFLAGS to meson, Paolo Bonzini, 2023/05/11
- [PATCH 11/24] build: move sanitizer tests to meson, Paolo Bonzini, 2023/05/11
- [PATCH 12/24] build: move SafeStack tests to meson,
Paolo Bonzini <=
- [PATCH 13/24] build: move coroutine backend selection to meson, Paolo Bonzini, 2023/05/11
- [PATCH 14/24] build: move stack protector flag selection to meson, Paolo Bonzini, 2023/05/11
- [PATCH 15/24] build: move warning flag selection to meson, Paolo Bonzini, 2023/05/11
- [PATCH 17/24] build: move compiler version check to meson, Paolo Bonzini, 2023/05/11
- [PATCH 02/24] meson: require 0.63.0, Paolo Bonzini, 2023/05/11
- [PATCH 16/24] build: move remaining compiler flag tests to meson, Paolo Bonzini, 2023/05/11
- [PATCH 19/24] configure: remove compiler sanity check, Paolo Bonzini, 2023/05/11
- [PATCH 22/24] configure: reorder option parsing code, Paolo Bonzini, 2023/05/11
- [PATCH 18/24] build: move --disable-debug-info to meson, Paolo Bonzini, 2023/05/11
- [PATCH 20/24] configure: do not rerun the tests with -Werror, Paolo Bonzini, 2023/05/11