@@ -307,6 +307,7 @@ audio_win_int=""
307
307
libs_qga=" "
308
308
debug_info=" yes"
309
309
stack_protector=" "
310
+ safe_stack=" "
310
311
use_containers=" yes"
311
312
gdb_bin=$( command -v " gdb-multiarch" || command -v " gdb" )
312
313
@@ -1287,6 +1288,10 @@ for opt do
1287
1288
;;
1288
1289
--disable-stack-protector) stack_protector=" no"
1289
1290
;;
1291
+ --enable-safe-stack) safe_stack=" yes"
1292
+ ;;
1293
+ --disable-safe-stack) safe_stack=" no"
1294
+ ;;
1290
1295
--disable-curses) curses=" no"
1291
1296
;;
1292
1297
--enable-curses) curses=" yes"
@@ -1829,6 +1834,8 @@ disabled with --disable-FEATURE, default is enabled if available:
1829
1834
debug-tcg TCG debugging (default is disabled)
1830
1835
debug-info debugging information
1831
1836
sparse sparse checker
1837
+ safe-stack SafeStack Stack Smash Protection. Depends on
1838
+ clang/llvm >= 3.7 and requires coroutine backend ucontext.
1832
1839
1833
1840
gnutls GNUTLS cryptography support
1834
1841
nettle nettle cryptography support
@@ -5573,6 +5580,67 @@ if test "$debug_stack_usage" = "yes"; then
5573
5580
fi
5574
5581
fi
5575
5582
5583
+ # #################################################
5584
+ # SafeStack
5585
+
5586
+
5587
+ if test " $safe_stack " = " yes" ; then
5588
+ cat > $TMPC << EOF
5589
+ int main(int argc, char *argv[])
5590
+ {
5591
+ #if ! __has_feature(safe_stack)
5592
+ #error SafeStack Disabled
5593
+ #endif
5594
+ return 0;
5595
+ }
5596
+ EOF
5597
+ flag=" -fsanitize=safe-stack"
5598
+ # Check that safe-stack is supported and enabled.
5599
+ if compile_prog " -Werror $flag " " $flag " ; then
5600
+ # Flag needed both at compilation and at linking
5601
+ QEMU_CFLAGS=" $QEMU_CFLAGS $flag "
5602
+ QEMU_LDFLAGS=" $QEMU_LDFLAGS $flag "
5603
+ else
5604
+ error_exit " SafeStack not supported by your compiler"
5605
+ fi
5606
+ if test " $coroutine " ! = " ucontext" ; then
5607
+ error_exit " SafeStack is only supported by the coroutine backend ucontext"
5608
+ fi
5609
+ else
5610
+ cat > $TMPC << EOF
5611
+ int main(int argc, char *argv[])
5612
+ {
5613
+ #if defined(__has_feature)
5614
+ #if __has_feature(safe_stack)
5615
+ #error SafeStack Enabled
5616
+ #endif
5617
+ #endif
5618
+ return 0;
5619
+ }
5620
+ EOF
5621
+ if test " $safe_stack " = " no" ; then
5622
+ # Make sure that safe-stack is disabled
5623
+ if ! compile_prog " -Werror" " " ; then
5624
+ # SafeStack was already enabled, try to explicitly remove the feature
5625
+ flag=" -fno-sanitize=safe-stack"
5626
+ if ! compile_prog " -Werror $flag " " $flag " ; then
5627
+ error_exit " Configure cannot disable SafeStack"
5628
+ fi
5629
+ QEMU_CFLAGS=" $QEMU_CFLAGS $flag "
5630
+ QEMU_LDFLAGS=" $QEMU_LDFLAGS $flag "
5631
+ fi
5632
+ else # "$safe_stack" = ""
5633
+ # Set safe_stack to yes or no based on pre-existing flags
5634
+ if compile_prog " -Werror" " " ; then
5635
+ safe_stack=" no"
5636
+ else
5637
+ safe_stack=" yes"
5638
+ if test " $coroutine " ! = " ucontext" ; then
5639
+ error_exit " SafeStack is only supported by the coroutine backend ucontext"
5640
+ fi
5641
+ fi
5642
+ fi
5643
+ fi
5576
5644
5577
5645
# #########################################
5578
5646
# check if we have open_by_handle_at
@@ -6765,6 +6833,7 @@ echo "sparse enabled $sparse"
6765
6833
echo " strip binaries $strip_opt "
6766
6834
echo " profiler $profiler "
6767
6835
echo " static build $static "
6836
+ echo " safe stack $safe_stack "
6768
6837
if test " $darwin " = " yes" ; then
6769
6838
echo " Cocoa support $cocoa "
6770
6839
fi
@@ -8370,6 +8439,10 @@ if test "$ccache_cpp2" = "yes"; then
8370
8439
echo " export CCACHE_CPP2=y" >> $config_host_mak
8371
8440
fi
8372
8441
8442
+ if test " $safe_stack " = " yes" ; then
8443
+ echo " CONFIG_SAFESTACK=y" >> $config_host_mak
8444
+ fi
8445
+
8373
8446
# If we're using a separate build tree, set it up now.
8374
8447
# DIRS are directories which we simply mkdir in the build tree;
8375
8448
# LINKS are things to symlink back into the source tree
0 commit comments