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