cflags.patch 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. This patch brings over a few features from MirBSD:
  2. * -fhonour-copts
  3. If this option is not given, it's warned (depending
  4. on environment variables). This is to catch errors
  5. of misbuilt packages which override CFLAGS themselves.
  6. * -Werror-maybe-reset
  7. Has the effect of -Wno-error if GCC_NO_WERROR is
  8. set and not '0', a no-operation otherwise. This is
  9. to be able to use -Werror in "make" but prevent
  10. GNU autoconf generated configure scripts from
  11. freaking out.
  12. * Make -fno-strict-aliasing and -fno-delete-null-pointer-checks
  13. the default for -O2/-Os, because they trigger gcc bugs
  14. and can delete code with security implications.
  15. This patch was authored by Thorsten Glaser <tg at mirbsd.de>
  16. with copyright assignment to the FSF in effect.
  17. --- a/gcc/c-opts.c
  18. +++ b/gcc/c-opts.c
  19. @@ -105,6 +105,9 @@ static size_t deferred_count;
  20. /* Number of deferred options scanned for -include. */
  21. static size_t include_cursor;
  22. +/* Check if a port honours COPTS. */
  23. +static int honour_copts = 0;
  24. +
  25. static void set_Wimplicit (int);
  26. static void handle_OPT_d (const char *);
  27. static void set_std_cxx98 (int);
  28. @@ -454,6 +457,14 @@ c_common_handle_option (size_t scode, co
  29. enable_warning_as_error ("implicit-function-declaration", value, CL_C | CL_ObjC);
  30. break;
  31. + case OPT_Werror_maybe_reset:
  32. + {
  33. + char *ev = getenv ("GCC_NO_WERROR");
  34. + if ((ev != NULL) && (*ev != '0'))
  35. + cpp_opts->warnings_are_errors = 0;
  36. + }
  37. + break;
  38. +
  39. case OPT_Wformat:
  40. set_Wformat (value);
  41. break;
  42. @@ -690,6 +701,12 @@ c_common_handle_option (size_t scode, co
  43. flag_exceptions = value;
  44. break;
  45. + case OPT_fhonour_copts:
  46. + if (c_language == clk_c) {
  47. + honour_copts++;
  48. + }
  49. + break;
  50. +
  51. case OPT_fimplement_inlines:
  52. flag_implement_inlines = value;
  53. break;
  54. @@ -1209,6 +1226,47 @@ c_common_init (void)
  55. return false;
  56. }
  57. + if (c_language == clk_c) {
  58. + char *ev = getenv ("GCC_HONOUR_COPTS");
  59. + int evv;
  60. + if (ev == NULL)
  61. + evv = -1;
  62. + else if ((*ev == '0') || (*ev == '\0'))
  63. + evv = 0;
  64. + else if (*ev == '1')
  65. + evv = 1;
  66. + else if (*ev == '2')
  67. + evv = 2;
  68. + else if (*ev == 's')
  69. + evv = -1;
  70. + else {
  71. + warning (0, "unknown GCC_HONOUR_COPTS value, assuming 1");
  72. + evv = 1; /* maybe depend this on something like MIRBSD_NATIVE? */
  73. + }
  74. + if (evv == 1) {
  75. + if (honour_copts == 0) {
  76. + error ("someone does not honour COPTS at all in lenient mode");
  77. + return false;
  78. + } else if (honour_copts != 1) {
  79. + warning (0, "someone does not honour COPTS correctly, passed %d times",
  80. + honour_copts);
  81. + }
  82. + } else if (evv == 2) {
  83. + if (honour_copts == 0) {
  84. + error ("someone does not honour COPTS at all in strict mode");
  85. + return false;
  86. + } else if (honour_copts != 1) {
  87. + error ("someone does not honour COPTS correctly, passed %d times",
  88. + honour_copts);
  89. + return false;
  90. + }
  91. + } else if (evv == 0) {
  92. + if (honour_copts != 1)
  93. + inform (0, "someone does not honour COPTS correctly, passed %d times",
  94. + honour_copts);
  95. + }
  96. + }
  97. +
  98. return true;
  99. }
  100. --- a/gcc/c.opt
  101. +++ b/gcc/c.opt
  102. @@ -215,6 +215,10 @@ Werror-implicit-function-declaration
  103. C ObjC RejectNegative Warning
  104. This switch is deprecated; use -Werror=implicit-function-declaration instead
  105. +Werror-maybe-reset
  106. +C ObjC C++ ObjC++
  107. +; Documented in common.opt
  108. +
  109. Wfloat-equal
  110. C ObjC C++ ObjC++ Var(warn_float_equal) Warning
  111. Warn if testing floating point numbers for equality
  112. @@ -613,6 +617,9 @@ C++ ObjC++ Optimization
  113. fhonor-std
  114. C++ ObjC++
  115. +fhonour-copts
  116. +C ObjC C++ ObjC++ RejectNegative
  117. +
  118. fhosted
  119. C ObjC
  120. Assume normal C execution environment
  121. --- a/gcc/common.opt
  122. +++ b/gcc/common.opt
  123. @@ -102,6 +102,10 @@ Werror=
  124. Common Joined
  125. Treat specified warning as error
  126. +Werror-maybe-reset
  127. +Common
  128. +If environment variable GCC_NO_WERROR is set, act as -Wno-error
  129. +
  130. Wextra
  131. Common Warning
  132. Print extra (possibly unwanted) warnings
  133. @@ -573,6 +577,9 @@ fguess-branch-probability
  134. Common Report Var(flag_guess_branch_prob) Optimization
  135. Enable guessing of branch probabilities
  136. +fhonour-copts
  137. +Common RejectNegative
  138. +
  139. ; Nonzero means ignore `#ident' directives. 0 means handle them.
  140. ; Generate position-independent code for executables if possible
  141. ; On SVR4 targets, it also controls whether or not to emit a
  142. --- a/gcc/opts.c
  143. +++ b/gcc/opts.c
  144. @@ -898,9 +898,6 @@ decode_options (unsigned int argc, const
  145. flag_schedule_insns_after_reload = opt2;
  146. #endif
  147. flag_regmove = opt2;
  148. - flag_strict_aliasing = opt2;
  149. - flag_strict_overflow = opt2;
  150. - flag_delete_null_pointer_checks = opt2;
  151. flag_reorder_blocks = opt2;
  152. flag_reorder_functions = opt2;
  153. flag_tree_vrp = opt2;
  154. @@ -924,6 +921,9 @@ decode_options (unsigned int argc, const
  155. /* -O3 optimizations. */
  156. opt3 = (optimize >= 3);
  157. + flag_strict_aliasing = opt3;
  158. + flag_strict_overflow = opt3;
  159. + flag_delete_null_pointer_checks = opt3;
  160. flag_predictive_commoning = opt3;
  161. flag_inline_functions = opt3;
  162. flag_unswitch_loops = opt3;
  163. @@ -1603,6 +1603,17 @@ common_handle_option (size_t scode, cons
  164. enable_warning_as_error (arg, value, lang_mask);
  165. break;
  166. + case OPT_Werror_maybe_reset:
  167. + {
  168. + char *ev = getenv ("GCC_NO_WERROR");
  169. + if ((ev != NULL) && (*ev != '0'))
  170. + warnings_are_errors = 0;
  171. + }
  172. + break;
  173. +
  174. + case OPT_fhonour_copts:
  175. + break;
  176. +
  177. case OPT_Wextra:
  178. set_Wextra (value);
  179. break;
  180. --- a/gcc/doc/cppopts.texi
  181. +++ b/gcc/doc/cppopts.texi
  182. @@ -164,6 +164,11 @@ in older programs. This warning is on b
  183. Make all warnings into hard errors. Source code which triggers warnings
  184. will be rejected.
  185. + at item -Werror-maybe-reset
  186. + at opindex Werror-maybe-reset
  187. +Act like @samp{-Wno-error} if the @env{GCC_NO_WERROR} environment
  188. +variable is set to anything other than 0 or empty.
  189. +
  190. @item -Wsystem-headers
  191. @opindex Wsystem-headers
  192. Issue warnings for code in system headers. These are normally unhelpful
  193. --- a/gcc/doc/invoke.texi
  194. +++ b/gcc/doc/invoke.texi
  195. @@ -234,7 +234,7 @@ Objective-C and Objective-C++ Dialects}.
  196. -Wconversion -Wcoverage-mismatch -Wno-deprecated @gol
  197. -Wno-deprecated-declarations -Wdisabled-optimization @gol
  198. -Wno-div-by-zero -Wempty-body -Wenum-compare -Wno-endif-labels @gol
  199. --Werror -Werror=* @gol
  200. +-Werror -Werror=* -Werror-maybe-reset @gol
  201. -Wfatal-errors -Wfloat-equal -Wformat -Wformat=2 @gol
  202. -Wno-format-contains-nul -Wno-format-extra-args -Wformat-nonliteral @gol
  203. -Wformat-security -Wformat-y2k @gol
  204. @@ -4182,6 +4182,22 @@ This option is only supported for C and
  205. @option{-Wall} and by @option{-pedantic}, which can be disabled with
  206. @option{-Wno-pointer-sign}.
  207. + at item -Werror-maybe-reset
  208. + at opindex Werror-maybe-reset
  209. +Act like @samp{-Wno-error} if the @env{GCC_NO_WERROR} environment
  210. +variable is set to anything other than 0 or empty.
  211. +
  212. + at item -fhonour-copts
  213. + at opindex fhonour-copts
  214. +If @env{GCC_HONOUR_COPTS} is set to 1, abort if this option is not
  215. +given at least once, and warn if it is given more than once.
  216. +If @env{GCC_HONOUR_COPTS} is set to 2, abort if this option is not
  217. +given exactly once.
  218. +If @env{GCC_HONOUR_COPTS} is set to 0 or unset, warn if this option
  219. +is not given exactly once.
  220. +The warning is quelled if @env{GCC_HONOUR_COPTS} is set to @samp{s}.
  221. +This flag and environment variable only affect the C language.
  222. +
  223. @item -Wstack-protector
  224. @opindex Wstack-protector
  225. @opindex Wno-stack-protector
  226. @@ -5721,7 +5737,7 @@ so, the first branch is redirected to ei
  227. second branch or a point immediately following it, depending on whether
  228. the condition is known to be true or false.
  229. -Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}.
  230. +Enabled at levels @option{-O3}.
  231. @item -fsplit-wide-types
  232. @opindex fsplit-wide-types
  233. @@ -5866,7 +5882,7 @@ safely dereference null pointers. Use
  234. @option{-fno-delete-null-pointer-checks} to disable this optimization
  235. for programs which depend on that behavior.
  236. -Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}.
  237. +Enabled at levels @option{-O3}.
  238. @item -fexpensive-optimizations
  239. @opindex fexpensive-optimizations
  240. --- a/gcc/java/jvspec.c
  241. +++ b/gcc/java/jvspec.c
  242. @@ -670,6 +670,7 @@ lang_specific_pre_link (void)
  243. class name. Append dummy `.c' that can be stripped by set_input so %b
  244. is correct. */
  245. set_input (concat (main_class_name, "main.c", NULL));
  246. + putenv ("GCC_HONOUR_COPTS=s"); /* XXX hack! */
  247. err = do_spec (jvgenmain_spec);
  248. if (err == 0)
  249. {