0002-Better-configure-test-for-fstack-protector.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. Better configure test for -fstack-protector. Some gcc installations may
  2. be missing the ssp library even though the compiler supports it.
  3. Backported from upstream:
  4. http://www.sudo.ws/repos/sudo/rev/4ade5d1249f4
  5. Signed-off-by: Vicente Olivert Riera <Vincent.Riera@imgtec.com>
  6. # HG changeset patch
  7. # User Todd C. Miller <Todd.Miller@courtesan.com>
  8. # Date 1446137469 21600
  9. # Node ID 4ade5d1249f483c4dd6c579c70b327791094afe8
  10. # Parent 97ee37d905ceefa433e93a0f552c2a3e5926e2fb
  11. Better configure test for -fstack-protector. Some gcc installations
  12. may be missing the ssp library even though the compiler supports it.
  13. diff -r 97ee37d905ce -r 4ade5d1249f4 configure
  14. --- a/configure Sun Oct 25 14:28:38 2015 -0600
  15. +++ b/configure Thu Oct 29 10:51:09 2015 -0600
  16. @@ -23916,236 +23916,94 @@
  17. fi
  18. if test "$enable_hardening" != "no"; then
  19. - if test -n "$GCC"; then
  20. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -fstack-protector-strong" >&5
  21. -$as_echo_n "checking whether C compiler accepts -fstack-protector-strong... " >&6; }
  22. -if ${ax_cv_check_cflags___fstack_protector_strong+:} false; then :
  23. - $as_echo_n "(cached) " >&6
  24. -else
  25. -
  26. - ax_check_save_flags=$CFLAGS
  27. - CFLAGS="$CFLAGS -fstack-protector-strong"
  28. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  29. -/* end confdefs.h. */
  30. -
  31. -int
  32. -main ()
  33. -{
  34. -
  35. - ;
  36. - return 0;
  37. -}
  38. -_ACEOF
  39. -if ac_fn_c_try_compile "$LINENO"; then :
  40. - ax_cv_check_cflags___fstack_protector_strong=yes
  41. -else
  42. - ax_cv_check_cflags___fstack_protector_strong=no
  43. -fi
  44. -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  45. - CFLAGS=$ax_check_save_flags
  46. -fi
  47. -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___fstack_protector_strong" >&5
  48. -$as_echo "$ax_cv_check_cflags___fstack_protector_strong" >&6; }
  49. -if test x"$ax_cv_check_cflags___fstack_protector_strong" = xyes; then :
  50. -
  51. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the linker accepts -fstack-protector-strong" >&5
  52. -$as_echo_n "checking whether the linker accepts -fstack-protector-strong... " >&6; }
  53. -if ${ax_cv_check_ldflags___fstack_protector_strong+:} false; then :
  54. - $as_echo_n "(cached) " >&6
  55. -else
  56. -
  57. - ax_check_save_flags=$LDFLAGS
  58. - LDFLAGS="$LDFLAGS -fstack-protector-strong"
  59. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  60. -/* end confdefs.h. */
  61. -
  62. -int
  63. -main ()
  64. -{
  65. -
  66. - ;
  67. - return 0;
  68. -}
  69. -_ACEOF
  70. -if ac_fn_c_try_link "$LINENO"; then :
  71. - ax_cv_check_ldflags___fstack_protector_strong=yes
  72. -else
  73. - ax_cv_check_ldflags___fstack_protector_strong=no
  74. -fi
  75. -rm -f core conftest.err conftest.$ac_objext \
  76. - conftest$ac_exeext conftest.$ac_ext
  77. - LDFLAGS=$ax_check_save_flags
  78. -fi
  79. -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_ldflags___fstack_protector_strong" >&5
  80. -$as_echo "$ax_cv_check_ldflags___fstack_protector_strong" >&6; }
  81. -if test x"$ax_cv_check_ldflags___fstack_protector_strong" = xyes; then :
  82. -
  83. - SSP_CFLAGS="-fstack-protector-strong"
  84. - SSP_LDFLAGS="-Wc,-fstack-protector-strong"
  85. -
  86. -else
  87. - :
  88. -fi
  89. -
  90. -
  91. -else
  92. - :
  93. -fi
  94. -
  95. - if test -z "$SSP_CFLAGS"; then
  96. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -fstack-protector-all" >&5
  97. -$as_echo_n "checking whether C compiler accepts -fstack-protector-all... " >&6; }
  98. -if ${ax_cv_check_cflags___fstack_protector_all+:} false; then :
  99. - $as_echo_n "(cached) " >&6
  100. -else
  101. -
  102. - ax_check_save_flags=$CFLAGS
  103. - CFLAGS="$CFLAGS -fstack-protector-all"
  104. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  105. -/* end confdefs.h. */
  106. -
  107. -int
  108. -main ()
  109. -{
  110. -
  111. - ;
  112. - return 0;
  113. -}
  114. -_ACEOF
  115. -if ac_fn_c_try_compile "$LINENO"; then :
  116. - ax_cv_check_cflags___fstack_protector_all=yes
  117. -else
  118. - ax_cv_check_cflags___fstack_protector_all=no
  119. -fi
  120. -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  121. - CFLAGS=$ax_check_save_flags
  122. -fi
  123. -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___fstack_protector_all" >&5
  124. -$as_echo "$ax_cv_check_cflags___fstack_protector_all" >&6; }
  125. -if test x"$ax_cv_check_cflags___fstack_protector_all" = xyes; then :
  126. -
  127. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the linker accepts -fstack-protector-all" >&5
  128. -$as_echo_n "checking whether the linker accepts -fstack-protector-all... " >&6; }
  129. -if ${ax_cv_check_ldflags___fstack_protector_all+:} false; then :
  130. - $as_echo_n "(cached) " >&6
  131. -else
  132. -
  133. - ax_check_save_flags=$LDFLAGS
  134. - LDFLAGS="$LDFLAGS -fstack-protector-all"
  135. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  136. -/* end confdefs.h. */
  137. -
  138. -int
  139. -main ()
  140. -{
  141. -
  142. - ;
  143. - return 0;
  144. -}
  145. -_ACEOF
  146. -if ac_fn_c_try_link "$LINENO"; then :
  147. - ax_cv_check_ldflags___fstack_protector_all=yes
  148. -else
  149. - ax_cv_check_ldflags___fstack_protector_all=no
  150. -fi
  151. -rm -f core conftest.err conftest.$ac_objext \
  152. - conftest$ac_exeext conftest.$ac_ext
  153. - LDFLAGS=$ax_check_save_flags
  154. -fi
  155. -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_ldflags___fstack_protector_all" >&5
  156. -$as_echo "$ax_cv_check_ldflags___fstack_protector_all" >&6; }
  157. -if test x"$ax_cv_check_ldflags___fstack_protector_all" = xyes; then :
  158. -
  159. - SSP_CFLAGS="-fstack-protector-all"
  160. - SSP_LDFLAGS="-Wc,-fstack-protector-all"
  161. -
  162. -else
  163. - :
  164. -fi
  165. -
  166. -
  167. -else
  168. - :
  169. -fi
  170. -
  171. - if test -z "$SSP_CFLAGS"; then
  172. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether C compiler accepts -fstack-protector" >&5
  173. -$as_echo_n "checking whether C compiler accepts -fstack-protector... " >&6; }
  174. -if ${ax_cv_check_cflags___fstack_protector+:} false; then :
  175. - $as_echo_n "(cached) " >&6
  176. -else
  177. -
  178. - ax_check_save_flags=$CFLAGS
  179. - CFLAGS="$CFLAGS -fstack-protector"
  180. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  181. -/* end confdefs.h. */
  182. -
  183. -int
  184. -main ()
  185. -{
  186. -
  187. - ;
  188. - return 0;
  189. -}
  190. -_ACEOF
  191. -if ac_fn_c_try_compile "$LINENO"; then :
  192. - ax_cv_check_cflags___fstack_protector=yes
  193. -else
  194. - ax_cv_check_cflags___fstack_protector=no
  195. -fi
  196. -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  197. - CFLAGS=$ax_check_save_flags
  198. -fi
  199. -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_cflags___fstack_protector" >&5
  200. -$as_echo "$ax_cv_check_cflags___fstack_protector" >&6; }
  201. -if test x"$ax_cv_check_cflags___fstack_protector" = xyes; then :
  202. -
  203. - { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the linker accepts -fstack-protector" >&5
  204. -$as_echo_n "checking whether the linker accepts -fstack-protector... " >&6; }
  205. -if ${ax_cv_check_ldflags___fstack_protector+:} false; then :
  206. - $as_echo_n "(cached) " >&6
  207. -else
  208. -
  209. - ax_check_save_flags=$LDFLAGS
  210. - LDFLAGS="$LDFLAGS -fstack-protector"
  211. - cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  212. -/* end confdefs.h. */
  213. -
  214. -int
  215. -main ()
  216. -{
  217. -
  218. - ;
  219. - return 0;
  220. -}
  221. -_ACEOF
  222. -if ac_fn_c_try_link "$LINENO"; then :
  223. - ax_cv_check_ldflags___fstack_protector=yes
  224. -else
  225. - ax_cv_check_ldflags___fstack_protector=no
  226. -fi
  227. -rm -f core conftest.err conftest.$ac_objext \
  228. - conftest$ac_exeext conftest.$ac_ext
  229. - LDFLAGS=$ax_check_save_flags
  230. -fi
  231. -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ax_cv_check_ldflags___fstack_protector" >&5
  232. -$as_echo "$ax_cv_check_ldflags___fstack_protector" >&6; }
  233. -if test x"$ax_cv_check_ldflags___fstack_protector" = xyes; then :
  234. -
  235. - SSP_CFLAGS="-fstack-protector"
  236. - SSP_LDFLAGS="-Wc,-fstack-protector"
  237. -
  238. -else
  239. - :
  240. -fi
  241. -
  242. -
  243. -else
  244. - :
  245. -fi
  246. -
  247. - fi
  248. - fi
  249. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking for compiler stack protector support" >&5
  250. +$as_echo_n "checking for compiler stack protector support... " >&6; }
  251. +if ${sudo_cv_var_stack_protector+:} false; then :
  252. + $as_echo_n "(cached) " >&6
  253. +else
  254. +
  255. + sudo_cv_var_stack_protector=no
  256. + _CFLAGS="$CFLAGS"
  257. + _LDFLAGS="$LDFLAGS"
  258. + CFLAGS="-fstack-protector-strong"
  259. + LDFLAGS="-fstack-protector-strong"
  260. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  261. +/* end confdefs.h. */
  262. +
  263. + $ac_includes_default
  264. +int
  265. +main ()
  266. +{
  267. +char buf[1024]; buf[1023] = '\0';
  268. + ;
  269. + return 0;
  270. +}
  271. +
  272. +_ACEOF
  273. +if ac_fn_c_try_compile "$LINENO"; then :
  274. +
  275. + sudo_cv_var_stack_protector="-fstack-protector-strong"
  276. +
  277. +else
  278. +
  279. + CFLAGS="-fstack-protector-all"
  280. + LDFLAGS="-fstack-protector-all"
  281. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  282. +/* end confdefs.h. */
  283. +
  284. + $ac_includes_default
  285. +int
  286. +main ()
  287. +{
  288. +char buf[1024]; buf[1023] = '\0';
  289. + ;
  290. + return 0;
  291. +}
  292. +
  293. +_ACEOF
  294. +if ac_fn_c_try_compile "$LINENO"; then :
  295. +
  296. + sudo_cv_var_stack_protector="-fstack-protector-all"
  297. +
  298. +else
  299. +
  300. + CFLAGS="-fstack-protector"
  301. + LDFLAGS="-fstack-protector"
  302. + cat confdefs.h - <<_ACEOF >conftest.$ac_ext
  303. +/* end confdefs.h. */
  304. +
  305. + $ac_includes_default
  306. +int
  307. +main ()
  308. +{
  309. +char buf[1024]; buf[1023] = '\0';
  310. + ;
  311. + return 0;
  312. +}
  313. +
  314. +_ACEOF
  315. +if ac_fn_c_try_compile "$LINENO"; then :
  316. +
  317. + sudo_cv_var_stack_protector="-fstack-protector"
  318. +
  319. +fi
  320. +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  321. +
  322. +fi
  323. +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  324. +
  325. +fi
  326. +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
  327. + CFLAGS="$_CFLAGS"
  328. + LDFLAGS="$_LDFLAGS"
  329. +
  330. +
  331. +fi
  332. +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $sudo_cv_var_stack_protector" >&5
  333. +$as_echo "$sudo_cv_var_stack_protector" >&6; }
  334. + if test X"$sudo_cv_var_stack_protector" != X"no"; then
  335. + SSP_CFLAGS="$sudo_cv_var_stack_protector"
  336. + SSP_LDFLAGS="-Wc,$sudo_cv_var_stack_protector"
  337. fi
  338. { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the linker accepts -Wl,-z,relro" >&5
  339. $as_echo_n "checking whether the linker accepts -Wl,-z,relro... " >&6; }
  340. diff -r 97ee37d905ce -r 4ade5d1249f4 configure.ac
  341. --- a/configure.ac Sun Oct 25 14:28:38 2015 -0600
  342. +++ b/configure.ac Thu Oct 29 10:51:09 2015 -0600
  343. @@ -3978,29 +3978,45 @@
  344. dnl This test relies on AC_LANG_WERROR
  345. dnl
  346. if test "$enable_hardening" != "no"; then
  347. - if test -n "$GCC"; then
  348. - AX_CHECK_COMPILE_FLAG([-fstack-protector-strong], [
  349. - AX_CHECK_LINK_FLAG([-fstack-protector-strong], [
  350. - SSP_CFLAGS="-fstack-protector-strong"
  351. - SSP_LDFLAGS="-Wc,-fstack-protector-strong"
  352. - ])
  353. - ])
  354. - if test -z "$SSP_CFLAGS"; then
  355. - AX_CHECK_COMPILE_FLAG([-fstack-protector-all], [
  356. - AX_CHECK_LINK_FLAG([-fstack-protector-all], [
  357. - SSP_CFLAGS="-fstack-protector-all"
  358. - SSP_LDFLAGS="-Wc,-fstack-protector-all"
  359. + AC_CACHE_CHECK([for compiler stack protector support],
  360. + [sudo_cv_var_stack_protector],
  361. + [
  362. + sudo_cv_var_stack_protector=no
  363. + _CFLAGS="$CFLAGS"
  364. + _LDFLAGS="$LDFLAGS"
  365. + CFLAGS="-fstack-protector-strong"
  366. + LDFLAGS="-fstack-protector-strong"
  367. + AC_COMPILE_IFELSE([
  368. + AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
  369. + [[char buf[1024]; buf[1023] = '\0';]])
  370. + ], [
  371. + sudo_cv_var_stack_protector="-fstack-protector-strong"
  372. + ], [
  373. + CFLAGS="-fstack-protector-all"
  374. + LDFLAGS="-fstack-protector-all"
  375. + AC_COMPILE_IFELSE([
  376. + AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
  377. + [[char buf[1024]; buf[1023] = '\0';]])
  378. + ], [
  379. + sudo_cv_var_stack_protector="-fstack-protector-all"
  380. + ], [
  381. + CFLAGS="-fstack-protector"
  382. + LDFLAGS="-fstack-protector"
  383. + AC_COMPILE_IFELSE([
  384. + AC_LANG_PROGRAM([AC_INCLUDES_DEFAULT],
  385. + [[char buf[1024]; buf[1023] = '\0';]])
  386. + ], [
  387. + sudo_cv_var_stack_protector="-fstack-protector"
  388. + ], [])
  389. ])
  390. ])
  391. - if test -z "$SSP_CFLAGS"; then
  392. - AX_CHECK_COMPILE_FLAG([-fstack-protector], [
  393. - AX_CHECK_LINK_FLAG([-fstack-protector], [
  394. - SSP_CFLAGS="-fstack-protector"
  395. - SSP_LDFLAGS="-Wc,-fstack-protector"
  396. - ])
  397. - ])
  398. - fi
  399. - fi
  400. + CFLAGS="$_CFLAGS"
  401. + LDFLAGS="$_LDFLAGS"
  402. + ]
  403. + )
  404. + if test X"$sudo_cv_var_stack_protector" != X"no"; then
  405. + SSP_CFLAGS="$sudo_cv_var_stack_protector"
  406. + SSP_LDFLAGS="-Wc,$sudo_cv_var_stack_protector"
  407. fi
  408. AX_CHECK_LINK_FLAG([-Wl,-z,relro], [LDFLAGS="${LDFLAGS} -Wl,-z,relro"])
  409. fi