1
0

cflags.patch 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 @@
  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,9 @@
  29. enable_warning_as_error ("implicit-function-declaration", value, CL_C | CL_ObjC);
  30. break;
  31. + case OPT_Werror_maybe_reset:
  32. + break;
  33. +
  34. case OPT_Wformat:
  35. set_Wformat (value);
  36. break;
  37. @@ -690,6 +701,12 @@
  38. flag_exceptions = value;
  39. break;
  40. + case OPT_fhonour_copts:
  41. + if (c_language == clk_c) {
  42. + honour_copts++;
  43. + }
  44. + break;
  45. +
  46. case OPT_fimplement_inlines:
  47. flag_implement_inlines = value;
  48. break;
  49. @@ -1209,6 +1226,47 @@
  50. return false;
  51. }
  52. + if (c_language == clk_c) {
  53. + char *ev = getenv ("GCC_HONOUR_COPTS");
  54. + int evv;
  55. + if (ev == NULL)
  56. + evv = -1;
  57. + else if ((*ev == '0') || (*ev == '\0'))
  58. + evv = 0;
  59. + else if (*ev == '1')
  60. + evv = 1;
  61. + else if (*ev == '2')
  62. + evv = 2;
  63. + else if (*ev == 's')
  64. + evv = -1;
  65. + else {
  66. + warning (0, "unknown GCC_HONOUR_COPTS value, assuming 1");
  67. + evv = 1; /* maybe depend this on something like MIRBSD_NATIVE? */
  68. + }
  69. + if (evv == 1) {
  70. + if (honour_copts == 0) {
  71. + error ("someone does not honour COPTS at all in lenient mode");
  72. + return false;
  73. + } else if (honour_copts != 1) {
  74. + warning (0, "someone does not honour COPTS correctly, passed %d times",
  75. + honour_copts);
  76. + }
  77. + } else if (evv == 2) {
  78. + if (honour_copts == 0) {
  79. + error ("someone does not honour COPTS at all in strict mode");
  80. + return false;
  81. + } else if (honour_copts != 1) {
  82. + error ("someone does not honour COPTS correctly, passed %d times",
  83. + honour_copts);
  84. + return false;
  85. + }
  86. + } else if (evv == 0) {
  87. + if (honour_copts != 1)
  88. + inform (0, "someone does not honour COPTS correctly, passed %d times",
  89. + honour_copts);
  90. + }
  91. + }
  92. +
  93. return true;
  94. }
  95. --- a/gcc/c.opt
  96. +++ b/gcc/c.opt
  97. @@ -215,6 +215,10 @@
  98. C ObjC RejectNegative Warning
  99. This switch is deprecated; use -Werror=implicit-function-declaration instead
  100. +Werror-maybe-reset
  101. +C ObjC C++ ObjC++
  102. +; Documented in common.opt
  103. +
  104. Wfloat-equal
  105. C ObjC C++ ObjC++ Var(warn_float_equal) Warning
  106. Warn if testing floating point numbers for equality
  107. @@ -609,6 +613,9 @@
  108. fhonor-std
  109. C++ ObjC++
  110. +fhonour-copts
  111. +C ObjC C++ ObjC++ RejectNegative
  112. +
  113. fhosted
  114. C ObjC
  115. Assume normal C execution environment
  116. --- a/gcc/common.opt
  117. +++ b/gcc/common.opt
  118. @@ -102,6 +102,10 @@
  119. Common Joined
  120. Treat specified warning as error
  121. +Werror-maybe-reset
  122. +Common
  123. +If environment variable GCC_NO_WERROR is set, act as -Wno-error
  124. +
  125. Wextra
  126. Common Warning
  127. Print extra (possibly unwanted) warnings
  128. @@ -573,6 +577,9 @@
  129. Common Report Var(flag_guess_branch_prob) Optimization
  130. Enable guessing of branch probabilities
  131. +fhonour-copts
  132. +Common RejectNegative
  133. +
  134. ; Nonzero means ignore `#ident' directives. 0 means handle them.
  135. ; Generate position-independent code for executables if possible
  136. ; On SVR4 targets, it also controls whether or not to emit a
  137. --- a/gcc/opts.c
  138. +++ b/gcc/opts.c
  139. @@ -896,8 +896,6 @@
  140. flag_schedule_insns_after_reload = opt2;
  141. #endif
  142. flag_regmove = opt2;
  143. - flag_strict_aliasing = opt2;
  144. - flag_strict_overflow = opt2;
  145. flag_reorder_blocks = opt2;
  146. flag_reorder_functions = opt2;
  147. flag_tree_vrp = opt2;
  148. @@ -922,6 +919,8 @@
  149. /* -O3 optimizations. */
  150. opt3 = (optimize >= 3);
  151. + flag_strict_aliasing = opt3;
  152. + flag_strict_overflow = opt3;
  153. flag_predictive_commoning = opt3;
  154. flag_inline_functions = opt3;
  155. flag_unswitch_loops = opt3;
  156. @@ -1601,6 +1601,17 @@
  157. enable_warning_as_error (arg, value, lang_mask);
  158. break;
  159. + case OPT_Werror_maybe_reset:
  160. + {
  161. + char *ev = getenv ("GCC_NO_WERROR");
  162. + if ((ev != NULL) && (*ev != '0'))
  163. + warnings_are_errors = 0;
  164. + }
  165. + break;
  166. +
  167. + case OPT_fhonour_copts:
  168. + break;
  169. +
  170. case OPT_Wlarger_than_:
  171. /* This form corresponds to -Wlarger-than-.
  172. Kept for backward compatibility.
  173. --- a/gcc/doc/cppopts.texi
  174. +++ b/gcc/doc/cppopts.texi
  175. @@ -164,6 +164,11 @@
  176. Make all warnings into hard errors. Source code which triggers warnings
  177. will be rejected.
  178. + at item -Werror-maybe-reset
  179. + at opindex Werror-maybe-reset
  180. +Act like @samp{-Wno-error} if the @env{GCC_NO_WERROR} environment
  181. +variable is set to anything other than 0 or empty.
  182. +
  183. @item -Wsystem-headers
  184. @opindex Wsystem-headers
  185. Issue warnings for code in system headers. These are normally unhelpful
  186. --- a/gcc/doc/invoke.texi
  187. +++ b/gcc/doc/invoke.texi
  188. @@ -234,7 +234,7 @@
  189. -Wconversion -Wcoverage-mismatch -Wno-deprecated @gol
  190. -Wno-deprecated-declarations -Wdisabled-optimization @gol
  191. -Wno-div-by-zero -Wempty-body -Wenum-compare -Wno-endif-labels @gol
  192. --Werror -Werror=* @gol
  193. +-Werror -Werror=* -Werror-maybe-reset @gol
  194. -Wfatal-errors -Wfloat-equal -Wformat -Wformat=2 @gol
  195. -Wno-format-contains-nul -Wno-format-extra-args -Wformat-nonliteral @gol
  196. -Wformat-security -Wformat-y2k @gol
  197. @@ -4161,6 +4161,22 @@
  198. @option{-Wall} and by @option{-pedantic}, which can be disabled with
  199. @option{-Wno-pointer-sign}.
  200. + at item -Werror-maybe-reset
  201. + at opindex Werror-maybe-reset
  202. +Act like @samp{-Wno-error} if the @env{GCC_NO_WERROR} environment
  203. +variable is set to anything other than 0 or empty.
  204. +
  205. + at item -fhonour-copts
  206. + at opindex fhonour-copts
  207. +If @env{GCC_HONOUR_COPTS} is set to 1, abort if this option is not
  208. +given at least once, and warn if it is given more than once.
  209. +If @env{GCC_HONOUR_COPTS} is set to 2, abort if this option is not
  210. +given exactly once.
  211. +If @env{GCC_HONOUR_COPTS} is set to 0 or unset, warn if this option
  212. +is not given exactly once.
  213. +The warning is quelled if @env{GCC_HONOUR_COPTS} is set to @samp{s}.
  214. +This flag and environment variable only affect the C language.
  215. +
  216. @item -Wstack-protector
  217. @opindex Wstack-protector
  218. @opindex Wno-stack-protector
  219. @@ -5699,7 +5715,7 @@
  220. second branch or a point immediately following it, depending on whether
  221. the condition is known to be true or false.
  222. -Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}.
  223. +Enabled at levels @option{-O3}.
  224. @item -fsplit-wide-types
  225. @opindex fsplit-wide-types
  226. --- a/gcc/java/jvspec.c
  227. +++ b/gcc/java/jvspec.c
  228. @@ -670,6 +670,7 @@
  229. class name. Append dummy `.c' that can be stripped by set_input so %b
  230. is correct. */
  231. set_input (concat (main_class_name, "main.c", NULL));
  232. + putenv ("GCC_HONOUR_COPTS=s"); /* XXX hack! */
  233. err = do_spec (jvgenmain_spec);
  234. if (err == 0)
  235. {