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