0001-buildtools-wafsamba-add-disable-stack-protector-opti.patch 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. From 5885ed8e6db7648e6842d9811aace7edc4e8aba7 Mon Sep 17 00:00:00 2001
  2. From: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  3. Date: Wed, 20 Apr 2022 11:16:52 +0200
  4. Subject: [PATCH] buildtools/wafsamba: add --disable-stack-protector option
  5. Allow the user to disable stack-protector through
  6. --disable-stack-protector to avoid the following build failure with
  7. libtalloc on embedded toolchains which don't support stack-protector:
  8. /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':
  9. talloc.c:(.text+0x427d): undefined reference to `__stack_chk_fail_local'
  10. This build failure is raised since
  11. https://gitlab.com/ffontaine/samba/-/commit/38e97f8b52e85bdfcf2d74a4fb3c848fa46ba371
  12. because stack-protector is enabled on libtalloc despite the fact that
  13. libssp is not available:
  14. Checking if compiler accepts -fstack-protector-strong : yes
  15. Fixes:
  16. - http://autobuild.buildroot.org/results/e221bde25c7622db99761d0adcd56663296beb15
  17. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
  18. [Upstream status:
  19. https://gitlab.com/samba-team/samba/-/merge_requests/2493]
  20. ---
  21. buildtools/wafsamba/samba_autoconf.py | 49 ++++++++++++++-------------
  22. buildtools/wafsamba/wscript | 3 ++
  23. 2 files changed, 28 insertions(+), 24 deletions(-)
  24. diff --git a/buildtools/wafsamba/samba_autoconf.py b/buildtools/wafsamba/samba_autoconf.py
  25. index 78927d85193..23a995e1c34 100644
  26. --- a/buildtools/wafsamba/samba_autoconf.py
  27. +++ b/buildtools/wafsamba/samba_autoconf.py
  28. @@ -703,9 +703,28 @@ def SAMBA_CONFIG_H(conf, path=None):
  29. if not IN_LAUNCH_DIR(conf):
  30. return
  31. - # we need to build real code that can't be optimized away to test
  32. - stack_protect_list = ['-fstack-protector-strong', '-fstack-protector']
  33. - for stack_protect_flag in stack_protect_list:
  34. + if not Options.options.disable_stack_protector:
  35. + # we need to build real code that can't be optimized away to test
  36. + stack_protect_list = ['-fstack-protector-strong', '-fstack-protector']
  37. + for stack_protect_flag in stack_protect_list:
  38. + flag_supported = conf.check(fragment='''
  39. + #include <stdio.h>
  40. +
  41. + int main(void)
  42. + {
  43. + char t[100000];
  44. + while (fgets(t, sizeof(t), stdin));
  45. + return 0;
  46. + }
  47. + ''',
  48. + execute=0,
  49. + cflags=[ '-Werror', '-Wp,-D_FORTIFY_SOURCE=2', stack_protect_flag],
  50. + mandatory=False,
  51. + msg='Checking if compiler accepts %s' % (stack_protect_flag))
  52. + if flag_supported:
  53. + conf.ADD_CFLAGS('%s' % (stack_protect_flag))
  54. + break
  55. +
  56. flag_supported = conf.check(fragment='''
  57. #include <stdio.h>
  58. @@ -717,29 +736,11 @@ def SAMBA_CONFIG_H(conf, path=None):
  59. }
  60. ''',
  61. execute=0,
  62. - cflags=[ '-Werror', '-Wp,-D_FORTIFY_SOURCE=2', stack_protect_flag],
  63. + cflags=[ '-Werror', '-fstack-clash-protection'],
  64. mandatory=False,
  65. - msg='Checking if compiler accepts %s' % (stack_protect_flag))
  66. + msg='Checking if compiler accepts -fstack-clash-protection')
  67. if flag_supported:
  68. - conf.ADD_CFLAGS('%s' % (stack_protect_flag))
  69. - break
  70. -
  71. - flag_supported = conf.check(fragment='''
  72. - #include <stdio.h>
  73. -
  74. - int main(void)
  75. - {
  76. - char t[100000];
  77. - while (fgets(t, sizeof(t), stdin));
  78. - return 0;
  79. - }
  80. - ''',
  81. - execute=0,
  82. - cflags=[ '-Werror', '-fstack-clash-protection'],
  83. - mandatory=False,
  84. - msg='Checking if compiler accepts -fstack-clash-protection')
  85. - if flag_supported:
  86. - conf.ADD_CFLAGS('-fstack-clash-protection')
  87. + conf.ADD_CFLAGS('-fstack-clash-protection')
  88. if Options.options.debug:
  89. conf.ADD_CFLAGS('-g', testflags=True)
  90. diff --git a/buildtools/wafsamba/wscript b/buildtools/wafsamba/wscript
  91. index 8729b0829da..d75bb3b1c0c 100644
  92. --- a/buildtools/wafsamba/wscript
  93. +++ b/buildtools/wafsamba/wscript
  94. @@ -165,6 +165,9 @@ Currently the only tested value is 'smbtorture,smbd/smbd' for Samba'''),
  95. gr.add_option('--disable-warnings-as-errors',
  96. help=("Do not treat all warnings as errors (disable -Werror)"),
  97. action="store_true", dest='disable_warnings_as_errors', default=False)
  98. + gr.add_option('--disable-stack-protector',
  99. + help=("Disable stack-protector"),
  100. + action="store_true", dest='disable_stack_protector', default=False)
  101. opt.add_option('--enable-coverage',
  102. help=("enable options necessary for code coverage "
  103. "reporting on selftest (default=no)"),
  104. --
  105. 2.35.1