910-mbsd_multi.patch 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. commit 99368862e44740ff4fd33760893f04e14f9dbdf1
  2. Author: Felix Fietkau <nbd@openwrt.org>
  3. Date: Tue Jul 31 00:52:27 2007 +0000
  4. Port the mbsd_multi patch from freewrt, which adds -fhonour-copts. This will emit warnings in packages that don't use our target cflags properly
  5. SVN-Revision: 8256
  6. This patch brings over a feature from MirBSD:
  7. * -fhonour-copts
  8. If this option is not given, it's warned (depending
  9. on environment variables). This is to catch errors
  10. of misbuilt packages which override CFLAGS themselves.
  11. This patch was authored by Thorsten Glaser <tg at mirbsd.de>
  12. with copyright assignment to the FSF in effect.
  13. --- a/gcc/c-family/c-opts.cc
  14. +++ b/gcc/c-family/c-opts.cc
  15. @@ -104,6 +104,9 @@ static size_t include_cursor;
  16. /* Whether any standard preincluded header has been preincluded. */
  17. static bool done_preinclude;
  18. +/* Check if a port honours COPTS. */
  19. +static int honour_copts = 0;
  20. +
  21. static void handle_OPT_d (const char *);
  22. static void set_std_cxx98 (int);
  23. static void set_std_cxx11 (int);
  24. @@ -475,6 +478,12 @@ c_common_handle_option (size_t scode, co
  25. flag_no_builtin = !value;
  26. break;
  27. + case OPT_fhonour_copts:
  28. + if (c_language == clk_c) {
  29. + honour_copts++;
  30. + }
  31. + break;
  32. +
  33. case OPT_fconstant_string_class_:
  34. constant_string_class_name = arg;
  35. break;
  36. @@ -1228,6 +1237,47 @@ c_common_init (void)
  37. return false;
  38. }
  39. + if (c_language == clk_c) {
  40. + char *ev = getenv ("GCC_HONOUR_COPTS");
  41. + int evv;
  42. + if (ev == NULL)
  43. + evv = -1;
  44. + else if ((*ev == '0') || (*ev == '\0'))
  45. + evv = 0;
  46. + else if (*ev == '1')
  47. + evv = 1;
  48. + else if (*ev == '2')
  49. + evv = 2;
  50. + else if (*ev == 's')
  51. + evv = -1;
  52. + else {
  53. + warning (0, "unknown GCC_HONOUR_COPTS value, assuming 1");
  54. + evv = 1; /* maybe depend this on something like MIRBSD_NATIVE? */
  55. + }
  56. + if (evv == 1) {
  57. + if (honour_copts == 0) {
  58. + error ("someone does not honour COPTS at all in lenient mode");
  59. + return false;
  60. + } else if (honour_copts != 1) {
  61. + warning (0, "someone does not honour COPTS correctly, passed %d times",
  62. + honour_copts);
  63. + }
  64. + } else if (evv == 2) {
  65. + if (honour_copts == 0) {
  66. + error ("someone does not honour COPTS at all in strict mode");
  67. + return false;
  68. + } else if (honour_copts != 1) {
  69. + error ("someone does not honour COPTS correctly, passed %d times",
  70. + honour_copts);
  71. + return false;
  72. + }
  73. + } else if (evv == 0) {
  74. + if (honour_copts != 1)
  75. + inform (UNKNOWN_LOCATION, "someone does not honour COPTS correctly, passed %d times",
  76. + honour_copts);
  77. + }
  78. + }
  79. +
  80. return true;
  81. }
  82. --- a/gcc/c-family/c.opt
  83. +++ b/gcc/c-family/c.opt
  84. @@ -1837,6 +1837,9 @@ C++ ObjC++ Optimization Alias(fexception
  85. fhonor-std
  86. C++ ObjC++ WarnRemoved
  87. +fhonour-copts
  88. +C ObjC C++ ObjC++ RejectNegative
  89. +
  90. fhosted
  91. C ObjC
  92. Assume normal C execution environment.
  93. --- a/gcc/common.opt
  94. +++ b/gcc/common.opt
  95. @@ -1801,6 +1801,9 @@ fharden-conditional-branches
  96. Common Var(flag_harden_conditional_branches) Optimization
  97. Harden conditional branches by checking reversed conditions.
  98. +fhonour-copts
  99. +Common RejectNegative
  100. +
  101. ; Nonzero means ignore `#ident' directives. 0 means handle them.
  102. ; Generate position-independent code for executables if possible
  103. ; On SVR4 targets, it also controls whether or not to emit a
  104. --- a/gcc/doc/invoke.texi
  105. +++ b/gcc/doc/invoke.texi
  106. @@ -10062,6 +10062,17 @@ This option is only supported for C and
  107. @option{-Wall} and by @option{-Wpedantic}, which can be disabled with
  108. @option{-Wno-pointer-sign}.
  109. +@item -fhonour-copts
  110. +@opindex fhonour-copts
  111. +If @env{GCC_HONOUR_COPTS} is set to 1, abort if this option is not
  112. +given at least once, and warn if it is given more than once.
  113. +If @env{GCC_HONOUR_COPTS} is set to 2, abort if this option is not
  114. +given exactly once.
  115. +If @env{GCC_HONOUR_COPTS} is set to 0 or unset, warn if this option
  116. +is not given exactly once.
  117. +The warning is quelled if @env{GCC_HONOUR_COPTS} is set to @samp{s}.
  118. +This flag and environment variable only affect the C language.
  119. +
  120. @opindex Wstack-protector
  121. @opindex Wno-stack-protector
  122. @item -Wstack-protector
  123. --- a/gcc/opts.cc
  124. +++ b/gcc/opts.cc
  125. @@ -2767,6 +2767,9 @@ common_handle_option (struct gcc_options
  126. add_comma_separated_to_vector (&opts->x_flag_ignored_attributes, arg);
  127. break;
  128. + case OPT_fhonour_copts:
  129. + break;
  130. +
  131. case OPT_Werror:
  132. dc->warning_as_error_requested = value;
  133. break;