kernel: update 4.4 to 4.4.88
[oweals/openwrt.git] / toolchain / gcc / patches / 7.1.0 / 910-mbsd_multi.patch
1
2         This patch brings over a feature from MirBSD:
3         * -fhonour-copts
4           If this option is not given, it's warned (depending
5           on environment variables). This is to catch errors
6           of misbuilt packages which override CFLAGS themselves.
7
8         This patch was authored by Thorsten Glaser <tg at mirbsd.de>
9         with copyright assignment to the FSF in effect.
10
11 --- a/gcc/c-family/c-opts.c
12 +++ b/gcc/c-family/c-opts.c
13 @@ -108,6 +108,9 @@ static int class_dump_flags;
14  /* Whether any standard preincluded header has been preincluded.  */
15  static bool done_preinclude;
16  
17 +/* Check if a port honours COPTS.  */
18 +static int honour_copts = 0;
19 +
20  static void handle_OPT_d (const char *);
21  static void set_std_cxx98 (int);
22  static void set_std_cxx11 (int);
23 @@ -456,6 +459,12 @@ c_common_handle_option (size_t scode, co
24        flag_no_builtin = !value;
25        break;
26  
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 @@ -1084,6 +1093,47 @@ c_common_init (void)
37        return false;
38      }
39  
40 +  if (c_language == clk_c) {
41 +    char *ev = getenv ("GCC_HONOUR_COPTS");
42 +    int evv;
43 +    if (ev == NULL)
44 +      evv = -1;
45 +    else if ((*ev == '0') || (*ev == '\0'))
46 +      evv = 0;
47 +    else if (*ev == '1')
48 +      evv = 1;
49 +    else if (*ev == '2')
50 +      evv = 2;
51 +    else if (*ev == 's')
52 +      evv = -1;
53 +    else {
54 +      warning (0, "unknown GCC_HONOUR_COPTS value, assuming 1");
55 +      evv = 1; /* maybe depend this on something like MIRBSD_NATIVE?  */
56 +    }
57 +    if (evv == 1) {
58 +      if (honour_copts == 0) {
59 +        error ("someone does not honour COPTS at all in lenient mode");
60 +        return false;
61 +      } else if (honour_copts != 1) {
62 +        warning (0, "someone does not honour COPTS correctly, passed %d times",
63 +         honour_copts);
64 +      }
65 +    } else if (evv == 2) {
66 +      if (honour_copts == 0) {
67 +        error ("someone does not honour COPTS at all in strict mode");
68 +        return false;
69 +      } else if (honour_copts != 1) {
70 +        error ("someone does not honour COPTS correctly, passed %d times",
71 +         honour_copts);
72 +        return false;
73 +      }
74 +    } else if (evv == 0) {
75 +      if (honour_copts != 1)
76 +        inform (0, "someone does not honour COPTS correctly, passed %d times",
77 +         honour_copts);
78 +    }
79 +  }
80 +
81    return true;
82  }
83  
84 --- a/gcc/c-family/c.opt
85 +++ b/gcc/c-family/c.opt
86 @@ -1412,6 +1412,9 @@ C++ ObjC++ Optimization Alias(fexception
87  fhonor-std
88  C++ ObjC++ Ignore Warn(switch %qs is no longer supported)
89  
90 +fhonour-copts
91 +C ObjC C++ ObjC++ RejectNegative
92 +
93  fhosted
94  C ObjC
95  Assume normal C execution environment.
96 --- a/gcc/common.opt
97 +++ b/gcc/common.opt
98 @@ -1510,6 +1510,9 @@ fguess-branch-probability
99  Common Report Var(flag_guess_branch_prob) Optimization
100  Enable guessing of branch probabilities.
101  
102 +fhonour-copts
103 +Common RejectNegative
104 +
105  ; Nonzero means ignore `#ident' directives.  0 means handle them.
106  ; Generate position-independent code for executables if possible
107  ; On SVR4 targets, it also controls whether or not to emit a
108 --- a/gcc/opts.c
109 +++ b/gcc/opts.c
110 @@ -1921,6 +1921,9 @@ common_handle_option (struct gcc_options
111                                opts, opts_set, loc, dc);
112        break;
113  
114 +    case OPT_fhonour_copts:
115 +      break;
116 +
117      case OPT_Wlarger_than_:
118        opts->x_larger_than_size = value;
119        opts->x_warn_larger_than = value != -1;
120 --- a/gcc/doc/invoke.texi
121 +++ b/gcc/doc/invoke.texi
122 @@ -6565,6 +6565,17 @@ This option is only supported for C and
123  @option{-Wall} and by @option{-Wpedantic}, which can be disabled with
124  @option{-Wno-pointer-sign}.
125  
126 +@item -fhonour-copts
127 +@opindex fhonour-copts
128 +If @env{GCC_HONOUR_COPTS} is set to 1, abort if this option is not
129 +given at least once, and warn if it is given more than once.
130 +If @env{GCC_HONOUR_COPTS} is set to 2, abort if this option is not
131 +given exactly once.
132 +If @env{GCC_HONOUR_COPTS} is set to 0 or unset, warn if this option
133 +is not given exactly once.
134 +The warning is quelled if @env{GCC_HONOUR_COPTS} is set to @samp{s}.
135 +This flag and environment variable only affect the C language.
136 +
137  @item -Wstack-protector
138  @opindex Wstack-protector
139  @opindex Wno-stack-protector
140