1
0

cflags.patch 8.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-family/c-opts.c
  18. +++ b/gcc/c-family/c-opts.c
  19. @@ -103,6 +103,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 handle_OPT_d (const char *);
  26. static void set_std_cxx98 (int);
  27. static void set_std_cxx0x (int);
  28. @@ -441,6 +444,9 @@ c_common_handle_option (size_t scode, co
  29. global_dc->warning_as_error_requested = value;
  30. break;
  31. + case OPT_Werror_maybe_reset:
  32. + break;
  33. +
  34. case OPT_Wformat:
  35. set_Wformat (value);
  36. break;
  37. @@ -584,6 +590,12 @@ c_common_handle_option (size_t scode, co
  38. flag_no_builtin = !value;
  39. break;
  40. + case OPT_fhonour_copts:
  41. + if (c_language == clk_c) {
  42. + honour_copts++;
  43. + }
  44. + break;
  45. +
  46. case OPT_fconstant_string_class_:
  47. constant_string_class_name = arg;
  48. break;
  49. @@ -1058,6 +1070,47 @@ c_common_init (void)
  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-family/c.opt
  96. +++ b/gcc/c-family/c.opt
  97. @@ -363,6 +363,10 @@ Werror-implicit-function-declaration
  98. C ObjC RejectNegative Warning Alias(Werror=, implicit-function-declaration)
  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. @@ -794,6 +798,9 @@ C++ ObjC++ Optimization Alias(fexception
  108. fhonor-std
  109. C++ ObjC++ Ignore Warn(switch %qs is no longer supported)
  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. @@ -520,6 +520,10 @@ Werror=
  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 Var(extra_warnings) Warning
  127. Print extra (possibly unwanted) warnings
  128. @@ -1156,6 +1160,9 @@ fguess-branch-probability
  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. @@ -477,8 +477,6 @@ static const struct default_options defa
  140. { OPT_LEVELS_2_PLUS, OPT_fschedule_insns2, NULL, 1 },
  141. #endif
  142. { OPT_LEVELS_2_PLUS, OPT_fregmove, NULL, 1 },
  143. - { OPT_LEVELS_2_PLUS, OPT_fstrict_aliasing, NULL, 1 },
  144. - { OPT_LEVELS_2_PLUS, OPT_fstrict_overflow, NULL, 1 },
  145. { OPT_LEVELS_2_PLUS, OPT_freorder_blocks, NULL, 1 },
  146. { OPT_LEVELS_2_PLUS, OPT_freorder_functions, NULL, 1 },
  147. { OPT_LEVELS_2_PLUS, OPT_ftree_vrp, NULL, 1 },
  148. @@ -494,6 +492,8 @@ static const struct default_options defa
  149. { OPT_LEVELS_2_PLUS, OPT_falign_functions, NULL, 1 },
  150. /* -O3 optimizations. */
  151. + { OPT_LEVELS_3_PLUS, OPT_fstrict_aliasing, NULL, 1 },
  152. + { OPT_LEVELS_3_PLUS, OPT_fstrict_overflow, NULL, 1 },
  153. { OPT_LEVELS_3_PLUS, OPT_ftree_loop_distribute_patterns, NULL, 1 },
  154. { OPT_LEVELS_3_PLUS, OPT_fpredictive_commoning, NULL, 1 },
  155. /* Inlining of functions reducing size is a good idea with -Os
  156. @@ -1399,6 +1399,17 @@ common_handle_option (struct gcc_options
  157. opts, opts_set, loc, dc);
  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. opts->x_larger_than_size = value;
  172. opts->x_warn_larger_than = value != -1;
  173. --- a/gcc/doc/cppopts.texi
  174. +++ b/gcc/doc/cppopts.texi
  175. @@ -164,6 +164,11 @@ in older programs. This warning is on b
  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. @@ -240,7 +240,7 @@ Objective-C and Objective-C++ Dialects}.
  189. -Wconversion -Wcoverage-mismatch -Wno-cpp -Wno-deprecated @gol
  190. -Wno-deprecated-declarations -Wdisabled-optimization @gol
  191. -Wno-div-by-zero -Wdouble-promotion -Wempty-body -Wenum-compare @gol
  192. --Wno-endif-labels -Werror -Werror=* @gol
  193. +-Wno-endif-labels -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. @@ -4497,6 +4497,22 @@ This option is only supported for C and
  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. @@ -6319,7 +6335,7 @@ so, the first branch is redirected to ei
  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. @@ -627,6 +627,7 @@ lang_specific_pre_link (void)
  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. {