910-mbsd_multi.patch 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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. * Make -fno-strict-aliasing and -fno-delete-null-pointer-checks
  7. the default for -O2/-Os, because they trigger gcc bugs
  8. and can delete code with security implications.
  9. This patch was authored by Thorsten Glaser <tg at mirbsd.de>
  10. with copyright assignment to the FSF in effect.
  11. --- a/gcc/c-opts.c
  12. +++ b/gcc/c-opts.c
  13. @@ -105,6 +105,9 @@
  14. /* Number of deferred options scanned for -include. */
  15. static size_t include_cursor;
  16. +/* Check if a port honours COPTS. */
  17. +static int honour_copts = 0;
  18. +
  19. static void set_Wimplicit (int);
  20. static void handle_OPT_d (const char *);
  21. static void set_std_cxx98 (int);
  22. @@ -690,6 +701,12 @@
  23. flag_exceptions = value;
  24. break;
  25. + case OPT_fhonour_copts:
  26. + if (c_language == clk_c) {
  27. + honour_copts++;
  28. + }
  29. + break;
  30. +
  31. case OPT_fimplement_inlines:
  32. flag_implement_inlines = value;
  33. break;
  34. @@ -1209,6 +1226,47 @@
  35. return false;
  36. }
  37. + if (c_language == clk_c) {
  38. + char *ev = getenv ("GCC_HONOUR_COPTS");
  39. + int evv;
  40. + if (ev == NULL)
  41. + evv = -1;
  42. + else if ((*ev == '0') || (*ev == '\0'))
  43. + evv = 0;
  44. + else if (*ev == '1')
  45. + evv = 1;
  46. + else if (*ev == '2')
  47. + evv = 2;
  48. + else if (*ev == 's')
  49. + evv = -1;
  50. + else {
  51. + warning (0, "unknown GCC_HONOUR_COPTS value, assuming 1");
  52. + evv = 1; /* maybe depend this on something like MIRBSD_NATIVE? */
  53. + }
  54. + if (evv == 1) {
  55. + if (honour_copts == 0) {
  56. + error ("someone does not honour COPTS at all in lenient mode");
  57. + return false;
  58. + } else if (honour_copts != 1) {
  59. + warning (0, "someone does not honour COPTS correctly, passed %d times",
  60. + honour_copts);
  61. + }
  62. + } else if (evv == 2) {
  63. + if (honour_copts == 0) {
  64. + error ("someone does not honour COPTS at all in strict mode");
  65. + return false;
  66. + } else if (honour_copts != 1) {
  67. + error ("someone does not honour COPTS correctly, passed %d times",
  68. + honour_copts);
  69. + return false;
  70. + }
  71. + } else if (evv == 0) {
  72. + if (honour_copts != 1)
  73. + inform (0, "someone does not honour COPTS correctly, passed %d times",
  74. + honour_copts);
  75. + }
  76. + }
  77. +
  78. return true;
  79. }
  80. --- a/gcc/c.opt
  81. +++ b/gcc/c.opt
  82. @@ -609,6 +613,9 @@
  83. fhonor-std
  84. C++ ObjC++
  85. +fhonour-copts
  86. +C ObjC C++ ObjC++ RejectNegative
  87. +
  88. fhosted
  89. C ObjC
  90. Assume normal C execution environment
  91. --- a/gcc/common.opt
  92. +++ b/gcc/common.opt
  93. @@ -573,6 +577,9 @@
  94. Common Report Var(flag_guess_branch_prob) Optimization
  95. Enable guessing of branch probabilities
  96. +fhonour-copts
  97. +Common RejectNegative
  98. +
  99. ; Nonzero means ignore `#ident' directives. 0 means handle them.
  100. ; Generate position-independent code for executables if possible
  101. ; On SVR4 targets, it also controls whether or not to emit a
  102. --- a/gcc/opts.c
  103. +++ b/gcc/opts.c
  104. @@ -896,9 +896,6 @@
  105. flag_schedule_insns_after_reload = opt2;
  106. #endif
  107. flag_regmove = opt2;
  108. - flag_strict_aliasing = opt2;
  109. - flag_strict_overflow = opt2;
  110. - flag_delete_null_pointer_checks = opt2;
  111. flag_reorder_blocks = opt2;
  112. flag_reorder_functions = opt2;
  113. flag_tree_vrp = opt2;
  114. @@ -922,6 +919,9 @@
  115. /* -O3 optimizations. */
  116. opt3 = (optimize >= 3);
  117. + flag_strict_aliasing = opt3;
  118. + flag_strict_overflow = opt3;
  119. + flag_delete_null_pointer_checks = opt3;
  120. flag_predictive_commoning = opt3;
  121. flag_inline_functions = opt3;
  122. flag_unswitch_loops = opt3;
  123. @@ -1605,6 +1605,9 @@
  124. enable_warning_as_error (arg, value, lang_mask);
  125. break;
  126. + case OPT_fhonour_copts:
  127. + break;
  128. +
  129. case OPT_Wextra:
  130. set_Wextra (value);
  131. break;
  132. --- a/gcc/doc/invoke.texi
  133. +++ b/gcc/doc/invoke.texi
  134. @@ -5699,7 +5715,7 @@
  135. second branch or a point immediately following it, depending on whether
  136. the condition is known to be true or false.
  137. -Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}.
  138. +Enabled at levels @option{-O3}.
  139. @item -fsplit-wide-types
  140. @opindex fsplit-wide-types
  141. @@ -5844,7 +5860,7 @@
  142. @option{-fno-delete-null-pointer-checks} to disable this optimization
  143. for programs which depend on that behavior.
  144. -Enabled at levels @option{-O2}, @option{-O3}, @option{-Os}.
  145. +Enabled at levels @option{-O3}.
  146. @item -fexpensive-optimizations
  147. @opindex fexpensive-optimizations
  148. --- a/gcc/java/jvspec.c
  149. +++ b/gcc/java/jvspec.c
  150. @@ -670,6 +670,7 @@
  151. class name. Append dummy `.c' that can be stripped by set_input so %b
  152. is correct. */
  153. set_input (concat (main_class_name, "main.c", NULL));
  154. + putenv ("GCC_HONOUR_COPTS=s"); /* XXX hack! */
  155. err = do_spec (jvgenmain_spec);
  156. if (err == 0)
  157. {