waf: Add -fstack-clash-protection
authorAndreas Schneider <asn@samba.org>
Mon, 3 Sep 2018 08:49:52 +0000 (10:49 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 4 Sep 2018 00:31:27 +0000 (02:31 +0200)
https://developers.redhat.com/blog/2018/03/21/compiler-and-linker-flags-gcc/

BUG: https://bugzilla.samba.org/show_bug.cgi?id=13601

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
buildtools/wafsamba/samba_autoconf.py

index bfd6f9710db20010964d8b162870dc35e71ac7d4..f2b3ec8db8de38f9bb52a419c37ea068db2ea821 100644 (file)
@@ -694,6 +694,23 @@ def SAMBA_CONFIG_H(conf, path=None):
             conf.ADD_CFLAGS('-Wp,-D_FORTIFY_SOURCE=2 %s' % (stack_protect_flag))
             break
 
+    flag_supported = conf.check(fragment='''
+                                #include <stdio.h>
+
+                                int main(void)
+                                {
+                                    char t[100000];
+                                    while (fgets(t, sizeof(t), stdin));
+                                    return 0;
+                                }
+                                ''',
+                                execute=0,
+                                ccflags=[ '-Werror', '-fstack-clash-protection'],
+                                mandatory=False,
+                                msg='Checking if compiler accepts -fstack-clash-protection')
+    if flag_supported:
+        conf.ADD_CFLAGS('-fstack-clash-protection')
+
     if Options.options.debug:
         conf.ADD_CFLAGS('-g', testflags=True)