diff mbox series

[1/1] package/libtalloc: fix build wihout SSP

Message ID 20220613201758.293344-1-fontaine.fabrice@gmail.com
State Accepted
Headers show
Series [1/1] package/libtalloc: fix build wihout SSP | expand

Commit Message

Fabrice Fontaine June 13, 2022, 8:17 p.m. UTC
Fix the following build failure without SSP raised since the addition of
the package in commit f0d37e275a915539a581c4ac7fd066eddc41fc8c:

/home/autobuild/autobuild/instance-5/output-1/host/lib/gcc/i686-buildroot-linux-musl/9.4.0/../../../../i686-buildroot-linux-musl/bin/ld: talloc.c.5.o: in function `_vasprintf_tc':
talloc.c:(.text+0x427d): undefined reference to `__stack_chk_fail_local'

Fixes:
 - http://autobuild.buildroot.org/results/e221bde25c7622db99761d0adcd56663296beb15

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
---
 ...mba-add-disable-stack-protector-opti.patch | 116 ++++++++++++++++++
 package/libtalloc/libtalloc.mk                |   1 +
 2 files changed, 117 insertions(+)
 create mode 100644 package/libtalloc/0001-buildtools-wafsamba-add-disable-stack-protector-opti.patch

Comments

Arnout Vandecappelle June 19, 2022, 3:55 p.m. UTC | #1
On 13/06/2022 22:17, Fabrice Fontaine wrote:
> Fix the following build failure without SSP raised since the addition of
> the package in commit f0d37e275a915539a581c4ac7fd066eddc41fc8c:
> 
> /home/autobuild/autobuild/instance-5/output-1/host/lib/gcc/i686-buildroot-linux-musl/9.4.0/../../../../i686-buildroot-linux-musl/bin/ld: talloc.c.5.o: in function `_vasprintf_tc':
> talloc.c:(.text+0x427d): undefined reference to `__stack_chk_fail_local'
> 
> Fixes:
>   - http://autobuild.buildroot.org/results/e221bde25c7622db99761d0adcd56663296beb15
> 
> Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>


  Applied to master, thanks.

  Since upstream seemed to risk not accepting the package, I added a comment 
that hopefully will tickle them (for real this time).

  Regards,
  Arnout

> ---
>   ...mba-add-disable-stack-protector-opti.patch | 116 ++++++++++++++++++
>   package/libtalloc/libtalloc.mk                |   1 +
>   2 files changed, 117 insertions(+)
>   create mode 100644 package/libtalloc/0001-buildtools-wafsamba-add-disable-stack-protector-opti.patch
> 
> diff --git a/package/libtalloc/0001-buildtools-wafsamba-add-disable-stack-protector-opti.patch b/package/libtalloc/0001-buildtools-wafsamba-add-disable-stack-protector-opti.patch
> new file mode 100644
> index 0000000000..839479a3fa
> --- /dev/null
> +++ b/package/libtalloc/0001-buildtools-wafsamba-add-disable-stack-protector-opti.patch
> @@ -0,0 +1,116 @@
> +From 5885ed8e6db7648e6842d9811aace7edc4e8aba7 Mon Sep 17 00:00:00 2001
> +From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
> +Date: Wed, 20 Apr 2022 11:16:52 +0200
> +Subject: [PATCH] buildtools/wafsamba: add --disable-stack-protector option
> +
> +Allow the user to disable stack-protector through
> +--disable-stack-protector to avoid the following build failure with
> +libtalloc on embedded toolchains which don't support stack-protector:
> +
> +/home/autobuild/autobuild/instance-5/output-1/host/lib/gcc/i686-buildroot-linux-musl/9.4.0/../../../../i686-buildroot-linux-musl/bin/ld: talloc.c.5.o: in function `_vasprintf_tc':
> +talloc.c:(.text+0x427d): undefined reference to `__stack_chk_fail_local'
> +
> +This build failure is raised since
> +https://gitlab.com/ffontaine/samba/-/commit/38e97f8b52e85bdfcf2d74a4fb3c848fa46ba371
> +because stack-protector is enabled on libtalloc despite the fact that
> +libssp is not available:
> +
> +Checking if compiler accepts -fstack-protector-strong                                           : yes
> +
> +Fixes:
> + - http://autobuild.buildroot.org/results/e221bde25c7622db99761d0adcd56663296beb15
> +
> +Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
> +[Upstream status:
> +https://gitlab.com/samba-team/samba/-/merge_requests/2493]
> +---
> + buildtools/wafsamba/samba_autoconf.py | 49 ++++++++++++++-------------
> + buildtools/wafsamba/wscript           |  3 ++
> + 2 files changed, 28 insertions(+), 24 deletions(-)
> +
> +diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py
> +index 78927d85193..23a995e1c34 100644
> +--- a/buildtools/wafsamba/samba_autoconf.py
> ++++ b/buildtools/wafsamba/samba_autoconf.py
> +@@ -703,9 +703,28 @@ def SAMBA_CONFIG_H(conf, path=None):
> +     if not IN_LAUNCH_DIR(conf):
> +         return
> +
> +-    # we need to build real code that can't be optimized away to test
> +-    stack_protect_list = ['-fstack-protector-strong', '-fstack-protector']
> +-    for stack_protect_flag in stack_protect_list:
> ++    if not Options.options.disable_stack_protector:
> ++        # we need to build real code that can't be optimized away to test
> ++        stack_protect_list = ['-fstack-protector-strong', '-fstack-protector']
> ++        for stack_protect_flag in stack_protect_list:
> ++            flag_supported = conf.check(fragment='''
> ++                                        #include <stdio.h>
> ++
> ++                                        int main(void)
> ++                                        {
> ++                                            char t[100000];
> ++                                            while (fgets(t, sizeof(t), stdin));
> ++                                            return 0;
> ++                                        }
> ++                                        ''',
> ++                                        execute=0,
> ++                                        cflags=[ '-Werror', '-Wp,-D_FORTIFY_SOURCE=2', stack_protect_flag],
> ++                                        mandatory=False,
> ++                                        msg='Checking if compiler accepts %s' % (stack_protect_flag))
> ++            if flag_supported:
> ++                conf.ADD_CFLAGS('%s' % (stack_protect_flag))
> ++                break
> ++
> +         flag_supported = conf.check(fragment='''
> +                                     #include <stdio.h>
> +
> +@@ -717,29 +736,11 @@ def SAMBA_CONFIG_H(conf, path=None):
> +                                     }
> +                                     ''',
> +                                     execute=0,
> +-                                    cflags=[ '-Werror', '-Wp,-D_FORTIFY_SOURCE=2', stack_protect_flag],
> ++                                    cflags=[ '-Werror', '-fstack-clash-protection'],
> +                                     mandatory=False,
> +-                                    msg='Checking if compiler accepts %s' % (stack_protect_flag))
> ++                                    msg='Checking if compiler accepts -fstack-clash-protection')
> +         if flag_supported:
> +-            conf.ADD_CFLAGS('%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,
> +-                                cflags=[ '-Werror', '-fstack-clash-protection'],
> +-                                mandatory=False,
> +-                                msg='Checking if compiler accepts -fstack-clash-protection')
> +-    if flag_supported:
> +-        conf.ADD_CFLAGS('-fstack-clash-protection')
> ++            conf.ADD_CFLAGS('-fstack-clash-protection')
> +
> +     if Options.options.debug:
> +         conf.ADD_CFLAGS('-g', testflags=True)
> +diff --git a/buildtools/wafsamba/wscript b/buildtools/wafsamba/wscript
> +index 8729b0829da..d75bb3b1c0c 100644
> +--- a/buildtools/wafsamba/wscript
> ++++ b/buildtools/wafsamba/wscript
> +@@ -165,6 +165,9 @@ Currently the only tested value is 'smbtorture,smbd/smbd' for Samba'''),
> +     gr.add_option('--disable-warnings-as-errors',
> +                    help=("Do not treat all warnings as errors (disable -Werror)"),
> +                    action="store_true", dest='disable_warnings_as_errors', default=False)
> ++    gr.add_option('--disable-stack-protector',
> ++                   help=("Disable stack-protector"),
> ++                   action="store_true", dest='disable_stack_protector', default=False)
> +     opt.add_option('--enable-coverage',
> +                    help=("enable options necessary for code coverage "
> +                          "reporting on selftest (default=no)"),
> +--
> +2.35.1
> +
> diff --git a/package/libtalloc/libtalloc.mk b/package/libtalloc/libtalloc.mk
> index 79bcf94947..8cba699ea1 100644
> --- a/package/libtalloc/libtalloc.mk
> +++ b/package/libtalloc/libtalloc.mk
> @@ -20,6 +20,7 @@ LIBTALLOC_INSTALL_STAGING = YES
>   # libtalloc since it's optional.
>   LIBTALLOC_CONF_OPTS += --cross-compile \
>   		--cross-answers=$(@D)/cache.txt \
> +		--disable-stack-protector \
>   		--hostcc=gcc \
>   		--with-libiconv=$(STAGING_DIR)/usr
>
Peter Korsgaard July 19, 2022, 5:02 p.m. UTC | #2
>>>>> "Arnout" == Arnout Vandecappelle <arnout@mind.be> writes:

 > On 13/06/2022 22:17, Fabrice Fontaine wrote:
 >> Fix the following build failure without SSP raised since the addition of
 >> the package in commit f0d37e275a915539a581c4ac7fd066eddc41fc8c:
 >> /home/autobuild/autobuild/instance-5/output-1/host/lib/gcc/i686-buildroot-linux-musl/9.4.0/../../../../i686-buildroot-linux-musl/bin/ld:
 >> talloc.c.5.o: in function `_vasprintf_tc':
 >> talloc.c:(.text+0x427d): undefined reference to `__stack_chk_fail_local'
 >> Fixes:
 >> - http://autobuild.buildroot.org/results/e221bde25c7622db99761d0adcd56663296beb15
 >> Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>


 >  Applied to master, thanks.

 >  Since upstream seemed to risk not accepting the package, I added a
 >  comment that hopefully will tickle them (for real this time).

Committed to 2022.05.x and 2022.02.x, thanks.
diff mbox series

Patch

diff --git a/package/libtalloc/0001-buildtools-wafsamba-add-disable-stack-protector-opti.patch b/package/libtalloc/0001-buildtools-wafsamba-add-disable-stack-protector-opti.patch
new file mode 100644
index 0000000000..839479a3fa
--- /dev/null
+++ b/package/libtalloc/0001-buildtools-wafsamba-add-disable-stack-protector-opti.patch
@@ -0,0 +1,116 @@ 
+From 5885ed8e6db7648e6842d9811aace7edc4e8aba7 Mon Sep 17 00:00:00 2001
+From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
+Date: Wed, 20 Apr 2022 11:16:52 +0200
+Subject: [PATCH] buildtools/wafsamba: add --disable-stack-protector option
+
+Allow the user to disable stack-protector through
+--disable-stack-protector to avoid the following build failure with
+libtalloc on embedded toolchains which don't support stack-protector:
+
+/home/autobuild/autobuild/instance-5/output-1/host/lib/gcc/i686-buildroot-linux-musl/9.4.0/../../../../i686-buildroot-linux-musl/bin/ld: talloc.c.5.o: in function `_vasprintf_tc':
+talloc.c:(.text+0x427d): undefined reference to `__stack_chk_fail_local'
+
+This build failure is raised since
+https://gitlab.com/ffontaine/samba/-/commit/38e97f8b52e85bdfcf2d74a4fb3c848fa46ba371
+because stack-protector is enabled on libtalloc despite the fact that
+libssp is not available:
+
+Checking if compiler accepts -fstack-protector-strong                                           : yes
+
+Fixes:
+ - http://autobuild.buildroot.org/results/e221bde25c7622db99761d0adcd56663296beb15
+
+Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
+[Upstream status:
+https://gitlab.com/samba-team/samba/-/merge_requests/2493]
+---
+ buildtools/wafsamba/samba_autoconf.py | 49 ++++++++++++++-------------
+ buildtools/wafsamba/wscript           |  3 ++
+ 2 files changed, 28 insertions(+), 24 deletions(-)
+
+diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py
+index 78927d85193..23a995e1c34 100644
+--- a/buildtools/wafsamba/samba_autoconf.py
++++ b/buildtools/wafsamba/samba_autoconf.py
+@@ -703,9 +703,28 @@ def SAMBA_CONFIG_H(conf, path=None):
+     if not IN_LAUNCH_DIR(conf):
+         return
+ 
+-    # we need to build real code that can't be optimized away to test
+-    stack_protect_list = ['-fstack-protector-strong', '-fstack-protector']
+-    for stack_protect_flag in stack_protect_list:
++    if not Options.options.disable_stack_protector:
++        # we need to build real code that can't be optimized away to test
++        stack_protect_list = ['-fstack-protector-strong', '-fstack-protector']
++        for stack_protect_flag in stack_protect_list:
++            flag_supported = conf.check(fragment='''
++                                        #include <stdio.h>
++
++                                        int main(void)
++                                        {
++                                            char t[100000];
++                                            while (fgets(t, sizeof(t), stdin));
++                                            return 0;
++                                        }
++                                        ''',
++                                        execute=0,
++                                        cflags=[ '-Werror', '-Wp,-D_FORTIFY_SOURCE=2', stack_protect_flag],
++                                        mandatory=False,
++                                        msg='Checking if compiler accepts %s' % (stack_protect_flag))
++            if flag_supported:
++                conf.ADD_CFLAGS('%s' % (stack_protect_flag))
++                break
++
+         flag_supported = conf.check(fragment='''
+                                     #include <stdio.h>
+ 
+@@ -717,29 +736,11 @@ def SAMBA_CONFIG_H(conf, path=None):
+                                     }
+                                     ''',
+                                     execute=0,
+-                                    cflags=[ '-Werror', '-Wp,-D_FORTIFY_SOURCE=2', stack_protect_flag],
++                                    cflags=[ '-Werror', '-fstack-clash-protection'],
+                                     mandatory=False,
+-                                    msg='Checking if compiler accepts %s' % (stack_protect_flag))
++                                    msg='Checking if compiler accepts -fstack-clash-protection')
+         if flag_supported:
+-            conf.ADD_CFLAGS('%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,
+-                                cflags=[ '-Werror', '-fstack-clash-protection'],
+-                                mandatory=False,
+-                                msg='Checking if compiler accepts -fstack-clash-protection')
+-    if flag_supported:
+-        conf.ADD_CFLAGS('-fstack-clash-protection')
++            conf.ADD_CFLAGS('-fstack-clash-protection')
+ 
+     if Options.options.debug:
+         conf.ADD_CFLAGS('-g', testflags=True)
+diff --git a/buildtools/wafsamba/wscript b/buildtools/wafsamba/wscript
+index 8729b0829da..d75bb3b1c0c 100644
+--- a/buildtools/wafsamba/wscript
++++ b/buildtools/wafsamba/wscript
+@@ -165,6 +165,9 @@ Currently the only tested value is 'smbtorture,smbd/smbd' for Samba'''),
+     gr.add_option('--disable-warnings-as-errors',
+                    help=("Do not treat all warnings as errors (disable -Werror)"),
+                    action="store_true", dest='disable_warnings_as_errors', default=False)
++    gr.add_option('--disable-stack-protector',
++                   help=("Disable stack-protector"),
++                   action="store_true", dest='disable_stack_protector', default=False)
+     opt.add_option('--enable-coverage',
+                    help=("enable options necessary for code coverage "
+                          "reporting on selftest (default=no)"),
+-- 
+2.35.1
+
diff --git a/package/libtalloc/libtalloc.mk b/package/libtalloc/libtalloc.mk
index 79bcf94947..8cba699ea1 100644
--- a/package/libtalloc/libtalloc.mk
+++ b/package/libtalloc/libtalloc.mk
@@ -20,6 +20,7 @@  LIBTALLOC_INSTALL_STAGING = YES
 # libtalloc since it's optional.
 LIBTALLOC_CONF_OPTS += --cross-compile \
 		--cross-answers=$(@D)/cache.txt \
+		--disable-stack-protector \
 		--hostcc=gcc \
 		--with-libiconv=$(STAGING_DIR)/usr