0004-Turn-on-D_FORTIFY_SOURCE-2-by-default-for-C-C-ObjC-O.patch 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. From 4eb1b3849325b77c4cb66b675119299de35125bb Mon Sep 17 00:00:00 2001
  2. From: Ariadne Conill <ariadne@dereferenced.org>
  3. Date: Fri, 21 Aug 2020 06:46:22 +0000
  4. Subject: [PATCH] Turn on -D_FORTIFY_SOURCE=2 by default for C, C++, ObjC,
  5. ObjC++, if the optimization level is > 0
  6. ---
  7. gcc/c-family/c-cppbuiltin.c | 4 ++++
  8. gcc/doc/invoke.texi | 6 ++++++
  9. 2 files changed, 10 insertions(+)
  10. diff --git a/gcc/c-family/c-cppbuiltin.c b/gcc/c-family/c-cppbuiltin.c
  11. index 11e015bdb87..de8b7bf246f 100644
  12. --- a/gcc/c-family/c-cppbuiltin.c
  13. +++ b/gcc/c-family/c-cppbuiltin.c
  14. @@ -1427,6 +1427,10 @@ c_cpp_builtins (cpp_reader *pfile)
  15. builtin_define_with_value ("__REGISTER_PREFIX__", REGISTER_PREFIX, 0);
  16. builtin_define_with_value ("__USER_LABEL_PREFIX__", user_label_prefix, 0);
  17. + /* Fortify Source enabled by default for optimization levels > 0 */
  18. + if (optimize)
  19. + builtin_define_with_int_value ("_FORTIFY_SOURCE", 2);
  20. +
  21. /* Misc. */
  22. if (flag_gnu89_inline)
  23. cpp_define (pfile, "__GNUC_GNU_INLINE__");
  24. diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
  25. index 485d2d6b742..164929f7583 100644
  26. --- a/gcc/doc/invoke.texi
  27. +++ b/gcc/doc/invoke.texi
  28. @@ -10225,6 +10225,12 @@ also turns on the following optimization flags:
  29. Please note the warning under @option{-fgcse} about
  30. invoking @option{-O2} on programs that use computed gotos.
  31. +NOTE: In Alpine Linux, @option{-D_FORTIFY_SOURCE=2} is
  32. +set by default, and is activated when @option{-O} is set to 2 or higher.
  33. +This enables additional compile-time and run-time checks for several libc
  34. +functions. To disable, specify either @option{-U_FORTIFY_SOURCE} or
  35. +@option{-D_FORTIFY_SOURCE=0}.
  36. +
  37. @item -O3
  38. @opindex O3
  39. Optimize yet more. @option{-O3} turns on all optimizations specified
  40. --
  41. 2.35.1