Blame SOURCES/fstack_flags.patch

1a7d6d
From 9673dcd70489c1c9df22aa0eb7a98afbccc0ced3 Mon Sep 17 00:00:00 2001
1a7d6d
From: Andreas Schneider <asn@samba.org>
1a7d6d
Date: Mon, 3 Sep 2018 10:35:08 +0200
1a7d6d
Subject: [PATCH 1/2] waf: Check for -fstack-protect-strong support
1a7d6d
1a7d6d
The -fstack-protector* flags are compiler only flags, don't pass them to
1a7d6d
the linker.
1a7d6d
1a7d6d
https://developers.redhat.com/blog/2018/03/21/compiler-and-linker-flags-gcc/
1a7d6d
1a7d6d
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13601
1a7d6d
1a7d6d
Signed-off-by: Andreas Schneider <asn@samba.org>
1a7d6d
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
1a7d6d
(cherry picked from commit 38e97f8b52e85bdfcf2d74a4fb3c848fa46ba371)
1a7d6d
---
1a7d6d
 buildtools/wafsamba/samba_autoconf.py | 36 ++++++++++++++-------------
1a7d6d
 1 file changed, 19 insertions(+), 17 deletions(-)
1a7d6d
1a7d6d
diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py
1a7d6d
index c4391d0c4dc..bfd6f9710db 100644
1a7d6d
--- a/buildtools/wafsamba/samba_autoconf.py
1a7d6d
+++ b/buildtools/wafsamba/samba_autoconf.py
1a7d6d
@@ -674,23 +674,25 @@ def SAMBA_CONFIG_H(conf, path=None):
1a7d6d
         return
1a7d6d
 
1a7d6d
     # we need to build real code that can't be optimized away to test
1a7d6d
-    if conf.check(fragment='''
1a7d6d
-        #include <stdio.h>
1a7d6d
-
1a7d6d
-        int main(void)
1a7d6d
-        {
1a7d6d
-            char t[100000];
1a7d6d
-            while (fgets(t, sizeof(t), stdin));
1a7d6d
-            return 0;
1a7d6d
-        }
1a7d6d
-        ''',
1a7d6d
-        execute=0,
1a7d6d
-        ccflags='-fstack-protector',
1a7d6d
-        ldflags='-fstack-protector',
1a7d6d
-        mandatory=False,
1a7d6d
-        msg='Checking if toolchain accepts -fstack-protector'):
1a7d6d
-            conf.ADD_CFLAGS('-fstack-protector')
1a7d6d
-            conf.ADD_LDFLAGS('-fstack-protector')
1a7d6d
+    stack_protect_list = ['-fstack-protector-strong', '-fstack-protector']
1a7d6d
+    for stack_protect_flag in stack_protect_list:
1a7d6d
+        flag_supported = conf.check(fragment='''
1a7d6d
+                                    #include <stdio.h>
1a7d6d
+
1a7d6d
+                                    int main(void)
1a7d6d
+                                    {
1a7d6d
+                                        char t[100000];
1a7d6d
+                                        while (fgets(t, sizeof(t), stdin));
1a7d6d
+                                        return 0;
1a7d6d
+                                    }
1a7d6d
+                                    ''',
1a7d6d
+                                    execute=0,
1a7d6d
+                                    ccflags=[ '-Werror', '-Wp,-D_FORTIFY_SOURCE=2', stack_protect_flag],
1a7d6d
+                                    mandatory=False,
1a7d6d
+                                    msg='Checking if compiler accepts %s' % (stack_protect_flag))
1a7d6d
+        if flag_supported:
1a7d6d
+            conf.ADD_CFLAGS('-Wp,-D_FORTIFY_SOURCE=2 %s' % (stack_protect_flag))
1a7d6d
+            break
1a7d6d
 
1a7d6d
     if Options.options.debug:
1a7d6d
         conf.ADD_CFLAGS('-g', testflags=True)
1a7d6d
-- 
1a7d6d
2.18.0
1a7d6d
1a7d6d
1a7d6d
From 5cfefc8d4c7fc4aba5b1dc2b7ea6f02c126d4070 Mon Sep 17 00:00:00 2001
1a7d6d
From: Andreas Schneider <asn@samba.org>
1a7d6d
Date: Mon, 3 Sep 2018 10:49:52 +0200
1a7d6d
Subject: [PATCH 2/2] waf: Add -fstack-clash-protection
1a7d6d
1a7d6d
https://developers.redhat.com/blog/2018/03/21/compiler-and-linker-flags-gcc/
1a7d6d
1a7d6d
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13601
1a7d6d
1a7d6d
Signed-off-by: Andreas Schneider <asn@samba.org>
1a7d6d
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
1a7d6d
(cherry picked from commit fc4df251c88365142515a81bea1120b2b84cc4a0)
1a7d6d
---
1a7d6d
 buildtools/wafsamba/samba_autoconf.py | 17 +++++++++++++++++
1a7d6d
 1 file changed, 17 insertions(+)
1a7d6d
1a7d6d
diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py
1a7d6d
index bfd6f9710db..f2b3ec8db8d 100644
1a7d6d
--- a/buildtools/wafsamba/samba_autoconf.py
1a7d6d
+++ b/buildtools/wafsamba/samba_autoconf.py
1a7d6d
@@ -694,6 +694,23 @@ def SAMBA_CONFIG_H(conf, path=None):
1a7d6d
             conf.ADD_CFLAGS('-Wp,-D_FORTIFY_SOURCE=2 %s' % (stack_protect_flag))
1a7d6d
             break
1a7d6d
 
1a7d6d
+    flag_supported = conf.check(fragment='''
1a7d6d
+                                #include <stdio.h>
1a7d6d
+
1a7d6d
+                                int main(void)
1a7d6d
+                                {
1a7d6d
+                                    char t[100000];
1a7d6d
+                                    while (fgets(t, sizeof(t), stdin));
1a7d6d
+                                    return 0;
1a7d6d
+                                }
1a7d6d
+                                ''',
1a7d6d
+                                execute=0,
1a7d6d
+                                ccflags=[ '-Werror', '-fstack-clash-protection'],
1a7d6d
+                                mandatory=False,
1a7d6d
+                                msg='Checking if compiler accepts -fstack-clash-protection')
1a7d6d
+    if flag_supported:
1a7d6d
+        conf.ADD_CFLAGS('-fstack-clash-protection')
1a7d6d
+
1a7d6d
     if Options.options.debug:
1a7d6d
         conf.ADD_CFLAGS('-g', testflags=True)
1a7d6d
 
1a7d6d
-- 
1a7d6d
2.18.0
1a7d6d