910-mbsd_multi.patch 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  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 <[email protected]>
  16. with copyright assignment to the FSF in effect.
  17. --- a/gcc/c-opts.c
  18. +++ b/gcc/c-opts.c
  19. @@ -109,6 +109,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. @@ -502,6 +505,14 @@ c_common_handle_option (size_t scode, co
  29. mesg_implicit_function_declaration = 2;
  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. @@ -778,6 +789,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. @@ -1295,6 +1312,47 @@ c_common_init (void)
  55. /* Has to wait until now so that cpplib has its hash table. */
  56. init_pragma ();
  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 ("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. @@ -220,6 +220,10 @@ C ObjC C++ ObjC++
  103. Warn about extra tokens at the end of prepreprocessor directives
  104. ; APPLE LOCAL end -Wextra-tokens
  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)
  111. Warn if testing floating point numbers for equality
  112. @@ -675,6 +679,9 @@ C++ ObjC++
  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. @@ -81,6 +81,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
  132. Print extra (possibly unwanted) warnings
  133. @@ -607,6 +611,9 @@ Common Report Var(flag_guess_branch_prob
  134. Enable guessing of branch probabilities
  135. ; APPLE LOCAL end optimization pragmas 3124235/3420242
  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. @@ -507,9 +507,6 @@ void set_flags_from_O (unsigned int cmdl
  145. #endif
  146. flag_regmove = 1;
  147. /* APPLE LOCAL optimization pragmas 3124235/3420242 */
  148. - if (cmdline) flag_strict_aliasing = 1;
  149. - flag_strict_overflow = 1;
  150. - flag_delete_null_pointer_checks = 1;
  151. flag_reorder_blocks = 1;
  152. /* APPLE LOCAL optimization pragmas 3124235/3420242 */
  153. if (cmdline) flag_reorder_functions = 1;
  154. @@ -536,6 +533,9 @@ void set_flags_from_O (unsigned int cmdl
  155. if (optimize >= 3)
  156. {
  157. + if (cmdline) flag_strict_aliasing = 1;
  158. + flag_strict_overflow = 1;
  159. + flag_delete_null_pointer_checks = 1;
  160. if (cmdline)
  161. flag_inline_functions = 1;
  162. flag_unswitch_loops = 1;
  163. @@ -873,6 +873,17 @@ common_handle_option (size_t scode, cons
  164. }
  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. @@ -166,6 +166,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. +@item -Werror-maybe-reset
  186. +@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. @@ -282,7 +282,7 @@ Objective-C and Objective-C++ Dialects}.
  196. -Wc++-compat -Wcast-align -Wcast-qual -Wchar-subscripts -Wcomment @gol
  197. -Wconversion -Wno-deprecated-declarations @gol
  198. -Wdisabled-optimization -Wno-div-by-zero -Wno-endif-labels @gol
  199. --Werror -Werror=* -Werror-implicit-function-declaration @gol
  200. +-Werror -Werror-maybe-reset -Werror=* -Werror-implicit-function-declaration @gol
  201. @c APPLE LOCAL default to Wformat-security 5764921
  202. -Wfatal-errors -Wfloat-equal -Wno-format -Wformat=2 @gol
  203. -Wno-format-extra-args -Wformat-nonliteral @gol
  204. @@ -4031,6 +4031,22 @@ Note that specifying @option{-Werror=}@v
  205. @option{-W}@var{foo}. However, @option{-Wno-error=}@var{foo} does not
  206. imply anything.
  207. +@item -Werror-maybe-reset
  208. +@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. +@item -fhonour-copts
  213. +@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. This option is only active when @option{-fstack-protector} is active. It
  226. @@ -5533,7 +5549,7 @@ second branch or a point immediately fol
  227. the condition is known to be true or false.
  228. @c APPLE LOCAL 4231761 -Oz
  229. -Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}, @option{-Oz} (APPLE ONLY).
  230. +Enabled at levels @option{-O3}, @option{-Oz} (APPLE ONLY).
  231. @item -fcse-follow-jumps
  232. @opindex fcse-follow-jumps
  233. @@ -5659,7 +5675,7 @@ safely dereference null pointers. Use
  234. for programs which depend on that behavior.
  235. @c APPLE LOCAL 4231761 -Oz
  236. -Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}, @option{-Oz} (APPLE ONLY).
  237. +Enabled at levels @option{-O3}, @option{-Oz} (APPLE ONLY).
  238. @item -fexpensive-optimizations
  239. @opindex fexpensive-optimizations
  240. @@ -6103,7 +6119,7 @@ allowed to alias. For an example, see t
  241. @code{c_get_alias_set}.
  242. @c APPLE LOCAL 4231761 -Oz
  243. -Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}, @option{-Oz} (APPLE ONLY).
  244. +Enabled at levels @option{-O3}, @option{-Oz} (APPLE ONLY).
  245. @item -fstrict-overflow
  246. @opindex fstrict-overflow
  247. --- a/gcc/java/jvspec.c
  248. +++ b/gcc/java/jvspec.c
  249. @@ -632,6 +632,7 @@ lang_specific_pre_link (void)
  250. class name. Append dummy `.c' that can be stripped by set_input so %b
  251. is correct. */
  252. set_input (concat (main_class_name, "main.c", NULL));
  253. + putenv ("GCC_HONOUR_COPTS=s"); /* XXX hack! */
  254. err = do_spec (jvgenmain_spec);
  255. if (err == 0)
  256. {