1 Description: Fixes linkone/comdat issue
2 Origin: Original patch from LFS against 3.4.3.
3 This patch is re-diffed against gcc 3.4.4.
4 Upstream status: Unknown
5
6 diff -Nru gcc-3.4.4/gcc/config/alpha/alpha.c gcc-3.4.4-new/gcc/config/alpha/alpha.c
7 --- gcc-3.4.4/gcc/config/alpha/alpha.c 2004-11-12 10:11:33.000000000 +0100
8 +++ gcc-3.4.4-new/gcc/config/alpha/alpha.c 2005-07-21 21:22:56.000000000 +0200
9 @@ -10175,6 +10175,8 @@
10 # define TARGET_SECTION_TYPE_FLAGS unicosmk_section_type_flags
11 # undef TARGET_ASM_UNIQUE_SECTION
12 # define TARGET_ASM_UNIQUE_SECTION unicosmk_unique_section
13 +#undef TARGET_ASM_FUNCTION_RODATA_SECTION
14 +#define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
15 # undef TARGET_ASM_GLOBALIZE_LABEL
16 # define TARGET_ASM_GLOBALIZE_LABEL hook_void_FILEptr_constcharptr
17 #endif
18 diff -Nru gcc-3.4.4/gcc/config/arm/pe.h gcc-3.4.4-new/gcc/config/arm/pe.h
19 --- gcc-3.4.4/gcc/config/arm/pe.h 2004-02-24 15:25:22.000000000 +0100
20 +++ gcc-3.4.4-new/gcc/config/arm/pe.h 2005-07-21 21:22:56.000000000 +0200
21 @@ -97,6 +97,7 @@
22 #define MULTIPLE_SYMBOL_SPACES
23
24 #define TARGET_ASM_UNIQUE_SECTION arm_pe_unique_section
25 +#define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
26
27 #define SUPPORTS_ONE_ONLY 1
28
29 diff -Nru gcc-3.4.4/gcc/config/avr/avr.c gcc-3.4.4-new/gcc/config/avr/avr.c
30 --- gcc-3.4.4/gcc/config/avr/avr.c 2005-03-20 22:14:28.000000000 +0100
31 +++ gcc-3.4.4-new/gcc/config/avr/avr.c 2005-07-21 21:22:56.000000000 +0200
32 @@ -229,6 +229,8 @@
33 #define TARGET_ASM_FUNCTION_EPILOGUE avr_output_function_epilogue
34 #undef TARGET_ATTRIBUTE_TABLE
35 #define TARGET_ATTRIBUTE_TABLE avr_attribute_table
36 +#undef TARGET_ASM_FUNCTION_RODATA_SECTION
37 +#define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
38 #undef TARGET_INSERT_ATTRIBUTES
39 #define TARGET_INSERT_ATTRIBUTES avr_insert_attributes
40 #undef TARGET_SECTION_TYPE_FLAGS
41 diff -Nru gcc-3.4.4/gcc/config/darwin.h gcc-3.4.4-new/gcc/config/darwin.h
42 --- gcc-3.4.4/gcc/config/darwin.h 2004-09-11 22:32:17.000000000 +0200
43 +++ gcc-3.4.4-new/gcc/config/darwin.h 2005-07-21 21:22:56.000000000 +0200
44 @@ -686,6 +686,9 @@
45 #undef TARGET_ASM_SELECT_RTX_SECTION
46 #define TARGET_ASM_SELECT_RTX_SECTION machopic_select_rtx_section
47
48 +#undef TARGET_ASM_FUNCTION_RODATA_SECTION
49 +#define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
50 +
51 #define ASM_DECLARE_UNRESOLVED_REFERENCE(FILE,NAME) \
52 do { \
53 if (FILE) { \
54 diff -Nru gcc-3.4.4/gcc/config/i386/cygming.h gcc-3.4.4-new/gcc/config/i386/cygming.h
55 --- gcc-3.4.4/gcc/config/i386/cygming.h 2004-06-08 08:30:13.000000000 +0200
56 +++ gcc-3.4.4-new/gcc/config/i386/cygming.h 2005-07-21 21:22:56.000000000 +0200
57 @@ -255,6 +255,7 @@
58
59 extern void i386_pe_unique_section (TREE, int);
60 #define TARGET_ASM_UNIQUE_SECTION i386_pe_unique_section
61 +#define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
62
63 #define SUPPORTS_ONE_ONLY 1
64
65 diff -Nru gcc-3.4.4/gcc/config/i386/i386-interix.h gcc-3.4.4-new/gcc/config/i386/i386-interix.h
66 --- gcc-3.4.4/gcc/config/i386/i386-interix.h 2004-01-31 07:18:20.000000000 +0100
67 +++ gcc-3.4.4-new/gcc/config/i386/i386-interix.h 2005-07-21 21:22:56.000000000 +0200
68 @@ -344,6 +344,7 @@
69
70 extern void i386_pe_unique_section (tree, int);
71 #define TARGET_ASM_UNIQUE_SECTION i386_pe_unique_section
72 +#define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
73
74 #define SUPPORTS_ONE_ONLY 1
75 #endif /* 0 */
76 diff -Nru gcc-3.4.4/gcc/config/ip2k/ip2k.c gcc-3.4.4-new/gcc/config/ip2k/ip2k.c
77 --- gcc-3.4.4/gcc/config/ip2k/ip2k.c 2004-01-31 07:18:25.000000000 +0100
78 +++ gcc-3.4.4-new/gcc/config/ip2k/ip2k.c 2005-07-21 21:22:56.000000000 +0200
79 @@ -98,6 +98,9 @@
80 #undef TARGET_ASM_UNIQUE_SECTION
81 #define TARGET_ASM_UNIQUE_SECTION unique_section
82
83 +#undef TARGET_ASM_FUNCTION_RODATA_SECTION
84 +#define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
85 +
86 #undef TARGET_ATTRIBUTE_TABLE
87 #define TARGET_ATTRIBUTE_TABLE ip2k_attribute_table
88
89 diff -Nru gcc-3.4.4/gcc/config/mcore/mcore.c gcc-3.4.4-new/gcc/config/mcore/mcore.c
90 --- gcc-3.4.4/gcc/config/mcore/mcore.c 2004-01-31 07:18:29.000000000 +0100
91 +++ gcc-3.4.4-new/gcc/config/mcore/mcore.c 2005-07-21 21:22:56.000000000 +0200
92 @@ -165,6 +165,8 @@
93 #define TARGET_ATTRIBUTE_TABLE mcore_attribute_table
94 #undef TARGET_ASM_UNIQUE_SECTION
95 #define TARGET_ASM_UNIQUE_SECTION mcore_unique_section
96 +#undef TARGET_ASM_FUNCTION_RODATA_SECTION
97 +#define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
98 #undef TARGET_ENCODE_SECTION_INFO
99 #define TARGET_ENCODE_SECTION_INFO mcore_encode_section_info
100 #undef TARGET_STRIP_NAME_ENCODING
101 diff -Nru gcc-3.4.4/gcc/config/rs6000/xcoff.h gcc-3.4.4-new/gcc/config/rs6000/xcoff.h
102 --- gcc-3.4.4/gcc/config/rs6000/xcoff.h 2004-01-31 07:18:34.000000000 +0100
103 +++ gcc-3.4.4-new/gcc/config/rs6000/xcoff.h 2005-07-21 21:22:56.000000000 +0200
104 @@ -172,6 +172,7 @@
105 #define TARGET_ASM_SELECT_SECTION rs6000_xcoff_select_section
106 #define TARGET_ASM_SELECT_RTX_SECTION rs6000_xcoff_select_rtx_section
107 #define TARGET_ASM_UNIQUE_SECTION rs6000_xcoff_unique_section
108 +#define TARGET_ASM_FUNCTION_RODATA_SECTION default_no_function_rodata_section
109 #define TARGET_STRIP_NAME_ENCODING rs6000_xcoff_strip_name_encoding
110 #define TARGET_SECTION_TYPE_FLAGS rs6000_xcoff_section_type_flags
111
112 diff -Nru gcc-3.4.4/gcc/doc/tm.texi gcc-3.4.4-new/gcc/doc/tm.texi
113 --- gcc-3.4.4/gcc/doc/tm.texi 2005-01-16 17:01:28.000000000 +0100
114 +++ gcc-3.4.4-new/gcc/doc/tm.texi 2005-07-21 21:22:56.000000000 +0200
115 @@ -6003,6 +6003,15 @@
116 Whatever the actual target object format, this is often good enough.
117 @end deftypefn
118
119 +@deftypefn {Target Hook} void TARGET_ASM_FUNCTION_RODATA_SECTION (tree @var{decl})
120 +Switches to a readonly data section associated with
121 +@samp{DECL_SECTION_NAME (@var{decl})}.
122 +The default version of this function switches to @code{.gnu.linkonce.r.name}
123 +section if function's section is @code{.gnu.linkonce.t.name}, to
124 +@code{.rodata.name} if function is in @code{.text.name} section
125 +and otherwise switches to the normal readonly data section.
126 +@end deftypefn
127 +
128 @deftypefn {Target Hook} void TARGET_ASM_SELECT_RTX_SECTION (enum machine_mode @var{mode}, rtx @var{x}, unsigned HOST_WIDE_INT @var{align})
129 Switches to the appropriate section for output of constant pool entry
130 @var{x} in @var{mode}. You can assume that @var{x} is some kind of
131 diff -Nru gcc-3.4.4/gcc/final.c gcc-3.4.4-new/gcc/final.c
132 --- gcc-3.4.4/gcc/final.c 2004-01-18 23:39:57.000000000 +0100
133 +++ gcc-3.4.4-new/gcc/final.c 2005-07-21 21:22:56.000000000 +0200
134 @@ -1881,7 +1881,7 @@
135 {
136 int log_align;
137
138 - readonly_data_section ();
139 + targetm.asm_out.function_rodata_section (current_function_decl);
140
141 #ifdef ADDR_VEC_ALIGN
142 log_align = ADDR_VEC_ALIGN (NEXT_INSN (insn));
143 diff -Nru gcc-3.4.4/gcc/output.h gcc-3.4.4-new/gcc/output.h
144 --- gcc-3.4.4/gcc/output.h 2004-01-18 23:39:57.000000000 +0100
145 +++ gcc-3.4.4-new/gcc/output.h 2005-07-21 21:22:56.000000000 +0200
146 @@ -500,6 +500,8 @@
147 unsigned HOST_WIDE_INT, int);
148 extern void default_unique_section (tree, int);
149 extern void default_unique_section_1 (tree, int, int);
150 +extern void default_function_rodata_section (tree);
151 +extern void default_no_function_rodata_section (tree);
152 extern void default_select_rtx_section (enum machine_mode, rtx,
153 unsigned HOST_WIDE_INT);
154 extern void default_elf_select_rtx_section (enum machine_mode, rtx,
155 diff -Nru gcc-3.4.4/gcc/target-def.h gcc-3.4.4-new/gcc/target-def.h
156 --- gcc-3.4.4/gcc/target-def.h 2004-08-23 20:02:40.000000000 +0200
157 +++ gcc-3.4.4-new/gcc/target-def.h 2005-07-21 21:22:56.000000000 +0200
158 @@ -78,6 +78,10 @@
159 #define TARGET_ASM_UNIQUE_SECTION default_unique_section
160 #endif
161
162 +#ifndef TARGET_ASM_FUNCTION_RODATA_SECTION
163 +#define TARGET_ASM_FUNCTION_RODATA_SECTION default_function_rodata_section
164 +#endif
165 +
166 #ifndef TARGET_ASM_SELECT_RTX_SECTION
167 #define TARGET_ASM_SELECT_RTX_SECTION default_select_rtx_section
168 #endif
169 @@ -201,6 +205,7 @@
170 TARGET_ASM_SELECT_SECTION, \
171 TARGET_ASM_SELECT_RTX_SECTION, \
172 TARGET_ASM_UNIQUE_SECTION, \
173 + TARGET_ASM_FUNCTION_RODATA_SECTION, \
174 TARGET_ASM_CONSTRUCTOR, \
175 TARGET_ASM_DESTRUCTOR, \
176 TARGET_ASM_OUTPUT_MI_THUNK, \
177 diff -Nru gcc-3.4.4/gcc/target.h gcc-3.4.4-new/gcc/target.h
178 --- gcc-3.4.4/gcc/target.h 2004-08-23 20:02:41.000000000 +0200
179 +++ gcc-3.4.4-new/gcc/target.h 2005-07-21 21:22:56.000000000 +0200
180 @@ -118,6 +118,10 @@
181 for SELECT_SECTION. */
182 void (* unique_section) (tree, int);
183
184 + /* Tell assembler to switch to the readonly data section associated
185 + with function DECL. */
186 + void (* function_rodata_section) (tree);
187 +
188 /* Output a constructor for a symbol with a given priority. */
189 void (* constructor) (rtx, int);
190
191 diff -Nru gcc-3.4.4/gcc/testsuite/g++.old-deja/g++.other/comdat4-aux.cc gcc-3.4.4-new/gcc/testsuite/g++.old-deja/g++.other/comdat4-aux.cc
192 --- gcc-3.4.4/gcc/testsuite/g++.old-deja/g++.other/comdat4-aux.cc 1970-01-01 01:00:00.000000000 +0100
193 +++ gcc-3.4.4-new/gcc/testsuite/g++.old-deja/g++.other/comdat4-aux.cc 2005-07-21 21:22:56.000000000 +0200
194 @@ -0,0 +1,40 @@
195 +extern void
196 +bar (int x);
197 +
198 +inline void
199 +foo (int i)
200 +{
201 + switch (i)
202 + {
203 + case 3:
204 + case 5:
205 + case 6:
206 + case 9:
207 + case 15:
208 + bar (1);
209 + break;
210 + case 2:
211 + case 4:
212 + case 7:
213 + case 10:
214 + case 11:
215 + case 12:
216 + bar (2);
217 + break;
218 + case 0:
219 + case 1:
220 + case 8:
221 + case 13:
222 + case 16:
223 + bar (3);
224 + break;
225 + case 14:
226 + bar (4);
227 + break;
228 + default:
229 + bar (5);
230 + break;
231 + }
232 +}
233 +
234 +void *fooaddr2 = (void *) foo;
235 diff -Nru gcc-3.4.4/gcc/testsuite/g++.old-deja/g++.other/comdat4.C gcc-3.4.4-new/gcc/testsuite/g++.old-deja/g++.other/comdat4.C
236 --- gcc-3.4.4/gcc/testsuite/g++.old-deja/g++.other/comdat4.C 1970-01-01 01:00:00.000000000 +0100
237 +++ gcc-3.4.4-new/gcc/testsuite/g++.old-deja/g++.other/comdat4.C 2005-07-21 21:22:56.000000000 +0200
238 @@ -0,0 +1,57 @@
239 +// PR c++/16276
240 +// { dg-do link }
241 +// { dg-additional-sources " comdat4-aux.cc" }
242 +// { dg-options "-O2" }
243 +
244 +extern void
245 +bar (int x);
246 +
247 +inline void
248 +foo (int i)
249 +{
250 + switch (i)
251 + {
252 + case 3:
253 + case 5:
254 + case 6:
255 + case 9:
256 + case 15:
257 + bar (1);
258 + break;
259 + case 2:
260 + case 4:
261 + case 7:
262 + case 10:
263 + case 11:
264 + case 12:
265 + bar (2);
266 + break;
267 + case 0:
268 + case 1:
269 + case 8:
270 + case 13:
271 + case 16:
272 + bar (3);
273 + break;
274 + case 14:
275 + bar (4);
276 + break;
277 + default:
278 + bar (5);
279 + break;
280 + }
281 +}
282 +
283 +void *fooaddr = (void *) foo;
284 +
285 +void
286 +bar (int x)
287 +{
288 + __asm __volatile ("" : : "r" (x));
289 +}
290 +
291 +int
292 +main (void)
293 +{
294 + return 0;
295 +}
296 diff -Nru gcc-3.4.4/gcc/varasm.c gcc-3.4.4-new/gcc/varasm.c
297 --- gcc-3.4.4/gcc/varasm.c 2005-03-02 21:57:48.000000000 +0100
298 +++ gcc-3.4.4-new/gcc/varasm.c 2005-07-21 21:22:56.000000000 +0200
299 @@ -535,6 +535,53 @@
300 text_section ();
301 }
302
303 +/* Switch to read-only data section associated with function DECL. */
304 +
305 +void
306 +default_function_rodata_section (tree decl)
307 +{
308 + if (decl != NULL_TREE && DECL_SECTION_NAME (decl))
309 + {
310 + const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
311 +
312 + /* For .gnu.linkonce.t.foo we want to use .gnu.linkonce.r.foo. */
313 + if (DECL_ONE_ONLY (decl) && strncmp (name, ".gnu.linkonce.t.", 16) == 0)
314 + {
315 + size_t len = strlen (name) + 1;
316 + char *rname = alloca (len);
317 +
318 + memcpy (rname, name, len);
319 + rname[14] = 'r';
320 + named_section_flags (rname, SECTION_LINKONCE);
321 + return;
322 + }
323 + /* For .text.foo we want to use .rodata.foo. */
324 + else if (flag_function_sections && flag_data_sections
325 + && strncmp (name, ".text.", 6) == 0)
326 + {
327 + size_t len = strlen (name) + 1;
328 + char *rname = alloca (len + 2);
329 +
330 + memcpy (rname, ".rodata", 7);
331 + memcpy (rname + 7, name + 5, len - 5);
332 + named_section_flags (rname, 0);
333 + return;
334 + }
335 + }
336 +
337 + readonly_data_section ();
338 +}
339 +
340 +/* Switch to read-only data section associated with function DECL
341 + for targets where that section should be always the single
342 + readonly data section. */
343 +
344 +void
345 +default_no_function_rodata_section (tree decl ATTRIBUTE_UNUSED)
346 +{
347 + readonly_data_section ();
348 +}
349 +
350 /* Switch to section for variable DECL. RELOC is the same as the
351 argument to SELECT_SECTION. */
352
|