Blame SOURCES/fstack_flags.patch

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