]>
Commit | Line | Data |
---|---|---|
36829a82 AM |
1 | 2004-12-03 H.J. Lu <hongjiu.lu@intel.com> |
2 | ||
3 | PR c++/16276 | |
4 | * configure.ac: Check if assembler supports COMDAT group. | |
5 | * configure: Regenerated. | |
6 | * config.in: Likewise. | |
7 | ||
8 | * final.c (final_scan_insn): When generating jump table, call | |
9 | readonly_data_section_in_function_group instead of | |
10 | readonly_data_section if HAVE_GAS_COMDAT_GROUP is defined. | |
11 | ||
12 | * output.h (elf_comdat_group): New. | |
13 | (readonly_data_section_in_function_group): Likewise. | |
14 | ||
15 | * varasm.c (readonly_data_section_in_function_group): New. | |
16 | (elf_comdat_group): Likewise. | |
17 | (default_elf_asm_named_section): Use COMDAT group if | |
18 | HAVE_GAS_COMDAT_GROUP is defined. | |
19 | * config/arm/arm.c (arm_elf_asm_named_section): Likewise. | |
20 | ||
21 | * config/sparc/sysv4.h (TARGET_ASM_NAMED_SECTION): Define only | |
22 | if HAVE_GAS_COMDAT_GROUP is not defined. | |
23 | ||
24 | --- gcc/config.in.comdat 2004-12-03 09:15:49.000000000 -0800 | |
25 | +++ gcc/config.in 2004-12-03 09:15:50.000000000 -0800 | |
26 | @@ -252,6 +252,9 @@ | |
27 | /* Define if your assembler supports .balign and .p2align. */ | |
28 | #undef HAVE_GAS_BALIGN_AND_P2ALIGN | |
29 | ||
30 | +/* Define 0/1 if your assembler supports COMDAT group. */ | |
31 | +#undef HAVE_GAS_COMDAT_GROUP | |
32 | + | |
33 | /* Define if your assembler uses the new HImode fild and fist notation. */ | |
34 | #undef HAVE_GAS_FILDS_FISTS | |
35 | ||
36 | --- gcc/config/arm/arm.c.comdat 2004-04-30 10:36:39.000000000 -0700 | |
37 | +++ gcc/config/arm/arm.c 2004-12-03 09:15:50.000000000 -0800 | |
38 | @@ -13156,12 +13156,15 @@ static void | |
39 | arm_elf_asm_named_section (const char *name, unsigned int flags) | |
40 | { | |
41 | char flagchars[10], *f = flagchars; | |
42 | + const char *section_name = NULL, *group_name = NULL; | |
43 | ||
44 | +#ifndef HAVE_GAS_COMDAT_GROUP | |
45 | if (! named_section_first_declaration (name)) | |
46 | { | |
47 | fprintf (asm_out_file, "\t.section\t%s\n", name); | |
48 | return; | |
49 | } | |
50 | +#endif | |
51 | ||
52 | if (!(flags & SECTION_DEBUG)) | |
53 | *f++ = 'a'; | |
54 | @@ -13177,9 +13180,17 @@ arm_elf_asm_named_section (const char *n | |
55 | *f++ = 'S'; | |
56 | if (flags & SECTION_TLS) | |
57 | *f++ = 'T'; | |
58 | +#ifdef HAVE_GAS_COMDAT_GROUP | |
59 | + if (elf_comdat_group (name, §ion_name, &group_name)) | |
60 | + *f++ = 'G'; | |
61 | +#endif | |
62 | *f = '\0'; | |
63 | ||
64 | - fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars); | |
65 | + if (section_name) | |
66 | + fprintf (asm_out_file, "\t.section\t%s,\"%s\"", section_name, | |
67 | + flagchars); | |
68 | + else | |
69 | + fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars); | |
70 | ||
71 | if (!(flags & SECTION_NOTYPE)) | |
72 | { | |
73 | @@ -13196,6 +13207,9 @@ arm_elf_asm_named_section (const char *n | |
74 | fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE); | |
75 | } | |
76 | ||
77 | + if (group_name) | |
78 | + fprintf (asm_out_file, ",%s,comdat", group_name); | |
79 | + | |
80 | putc ('\n', asm_out_file); | |
81 | } | |
82 | #endif | |
83 | --- gcc/config/sparc/sysv4.h.comdat 2003-06-17 17:03:32.000000000 -0700 | |
84 | +++ gcc/config/sparc/sysv4.h 2004-12-03 09:15:50.000000000 -0800 | |
85 | @@ -150,9 +150,13 @@ do { ASM_OUTPUT_ALIGN ((FILE), Pmode == | |
86 | #undef DTORS_SECTION_ASM_OP | |
87 | #define DTORS_SECTION_ASM_OP "\t.section\t\".dtors\",#alloc,#write" | |
88 | ||
89 | +/* COMDAT group cannot be expressed in SPARC's section attributes | |
90 | + encoding style. */ | |
91 | +#ifndef HAVE_GAS_COMDAT_GROUP | |
92 | /* Switch into a generic section. */ | |
93 | #undef TARGET_ASM_NAMED_SECTION | |
94 | #define TARGET_ASM_NAMED_SECTION sparc_elf_asm_named_section | |
95 | +#endif | |
96 | ||
97 | #undef ASM_OUTPUT_ALIGNED_BSS | |
98 | #define ASM_OUTPUT_ALIGNED_BSS(FILE, DECL, NAME, SIZE, ALIGN) \ | |
99 | --- gcc/configure.ac.comdat 2004-12-03 09:15:49.000000000 -0800 | |
100 | +++ gcc/configure.ac 2004-12-03 09:22:29.000000000 -0800 | |
101 | @@ -1913,8 +1913,12 @@ changequote(,)dnl | |
102 | -e 's,^.*[ ]\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)$,\1,p' \ | |
103 | -e 's,^.*[ ]\([0-9][0-9]*\.[0-9][0-9]*\)[ ].*$,\1,p' \ | |
104 | -e 's,^.*[ ]\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)[ ].*$,\1,p' \ | |
105 | - -e 's,^.*[ ]\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)[ ].*$,\1,p'` | |
106 | + -e 's,^.*[ ]\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)[ ].*$,\1,p' \ | |
107 | + -e 's,^.*[ ]\([0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*\)[ ].*$,\1,p'` | |
108 | ld_date=`echo $ld_ver | sed -n 's,^.*\([2-9][0-9][0-9][0-9]\)[-]*\([01][0-9]\)[-]*\([0-3][0-9]\).*$,\1\2\3,p'` | |
109 | + ld_vers_major=`expr "$ld_vers" : '\([0-9]*\)'` | |
110 | + ld_vers_minor=`expr "$ld_vers" : '[0-9]*\.\([0-9]*\)'` | |
111 | + ld_vers_patch=`expr "$ld_vers" : '[0-9]*\.[0-9]*\.\([0-9]*\)'` | |
112 | if test 0"$ld_date" -lt 20020404; then | |
113 | if test -n "$ld_date"; then | |
114 | # If there was date string, but was earlier than 2002-04-04, fail | |
115 | @@ -1923,9 +1927,6 @@ changequote(,)dnl | |
116 | # If there was no date string nor ld version number, something is wrong | |
117 | gcc_cv_ld_hidden=no | |
118 | else | |
119 | - ld_vers_major=`expr "$ld_vers" : '\([0-9]*\)'` | |
120 | - ld_vers_minor=`expr "$ld_vers" : '[0-9]*\.\([0-9]*\)'` | |
121 | - ld_vers_patch=`expr "$ld_vers" : '[0-9]*\.[0-9]*\.\([0-9]*\)'` | |
122 | test -z "$ld_vers_patch" && ld_vers_patch=0 | |
123 | if test "$ld_vers_major" -lt 2; then | |
124 | gcc_cv_ld_hidden=no | |
125 | @@ -2060,6 +2061,39 @@ AC_DEFINE_UNQUOTED(HAVE_GAS_SHF_MERGE, | |
126 | [`if test $gcc_cv_as_shf_merge = yes; then echo 1; else echo 0; fi`], | |
127 | [Define 0/1 if your assembler supports marking sections with SHF_MERGE flag.]) | |
128 | ||
129 | +gcc_GAS_CHECK_FEATURE(COMDAT group support, gcc_cv_as_comdat_group, | |
130 | + [elf,2,15,92], [--fatal-warnings], | |
131 | + [.section .text,"axG",@progbits,.foo,comdat]) | |
132 | +if test $gcc_cv_as_comdat_group = yes; then | |
133 | + gcc_cv_as_comdat_group_percent=no | |
134 | +else | |
135 | + gcc_GAS_CHECK_FEATURE(COMDAT group support, gcc_cv_as_comdat_group_percent, | |
136 | + [elf,2,15,92], [--fatal-warnings], | |
137 | + [.section .text,"axG",%progbits,.foo,comdat]) | |
138 | +fi | |
139 | +if test $in_tree_ld != yes && test x"$ld_vers" != x; then | |
140 | + comdat_group=yes | |
141 | + if test 0"$ld_date" -lt 20040727; then | |
142 | + if test -n "$ld_date"; then | |
143 | + # If there was date string, but was earlier than 2002-07-27, fail | |
144 | + comdat_group=no | |
145 | + elif test "$ld_vers_major" -lt 2; then | |
146 | + comdat_group=no | |
147 | + elif test "$ld_vers_major" -eq 2 -a "$ld_vers_minor" -lt 15; then | |
148 | + comdat_group=no | |
149 | + elif test "$ld_vers_major" -eq 2 -a "$ld_vers_minor" -eq 15 -a "$ld_vers_patch" -lt 92; then | |
150 | + comdat_group=no | |
151 | + fi | |
152 | + fi | |
153 | + if test $comdat_group = no; then | |
154 | + gcc_cv_as_comdat_group=no | |
155 | + gcc_cv_as_comdat_group_percent=no | |
156 | + fi | |
157 | +fi | |
158 | +AC_DEFINE_UNQUOTED(HAVE_GAS_COMDAT_GROUP, | |
159 | + [`if test $gcc_cv_as_comdat_group = yes || test $gcc_cv_as_comdat_group_percent = yes; then echo 1; else echo 0; fi`], | |
160 | +[Define 0/1 if your assembler supports COMDAT group.]) | |
161 | + | |
162 | # Thread-local storage - the check is heavily parametrized. | |
163 | conftest_s= | |
164 | tls_first_major= | |
165 | --- gcc/final.c.comdat 2004-02-23 13:24:09.000000000 -0800 | |
166 | +++ gcc/final.c 2004-12-03 09:15:50.000000000 -0800 | |
167 | @@ -1881,7 +1881,12 @@ final_scan_insn (rtx insn, FILE *file, i | |
168 | { | |
169 | int log_align; | |
170 | ||
171 | +#ifdef HAVE_GAS_COMDAT_GROUP | |
172 | + readonly_data_section_in_function_group | |
173 | + (current_function_decl); | |
174 | +#else | |
175 | readonly_data_section (); | |
176 | +#endif | |
177 | ||
178 | #ifdef ADDR_VEC_ALIGN | |
179 | log_align = ADDR_VEC_ALIGN (NEXT_INSN (insn)); | |
180 | --- gcc/output.h.comdat 2004-03-26 09:25:41.000000000 -0800 | |
181 | +++ gcc/output.h 2004-12-03 09:15:50.000000000 -0800 | |
182 | @@ -475,6 +475,9 @@ extern void no_asm_to_stream (FILE *); | |
183 | #define SECTION_NOTYPE 0x80000 /* don't output @progbits */ | |
184 | #define SECTION_MACH_DEP 0x100000 /* subsequent bits reserved for target */ | |
185 | ||
186 | +extern const char *elf_comdat_group (const char *, const char **, | |
187 | + const char **); | |
188 | +extern void readonly_data_section_in_function_group (tree); | |
189 | extern unsigned int get_named_section_flags (const char *); | |
190 | extern bool set_named_section_flags (const char *, unsigned int); | |
191 | extern void named_section_flags (const char *, unsigned int); | |
192 | --- gcc/varasm.c.comdat 2004-11-01 14:04:58.000000000 -0800 | |
193 | +++ gcc/varasm.c 2004-12-03 09:30:54.005496029 -0800 | |
194 | @@ -259,6 +259,35 @@ data_section (void) | |
195 | } | |
196 | } | |
197 | ||
198 | +#ifdef HAVE_GAS_COMDAT_GROUP | |
199 | + | |
200 | +/* Tell assembler to switch to read-only data section in the same | |
201 | + comdat group as DECL. */ | |
202 | + | |
203 | +void | |
204 | +readonly_data_section_in_function_group (tree decl) | |
205 | +{ | |
206 | + if (decl == NULL_TREE || !DECL_P (decl)) | |
207 | + abort (); | |
208 | + | |
209 | + if (DECL_SECTION_NAME (decl) == NULL_TREE || ! DECL_ONE_ONLY (decl)) | |
210 | + readonly_data_section (); | |
211 | + else | |
212 | + { | |
213 | + char *rodata; | |
214 | + const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl)); | |
215 | + | |
216 | + if (strncmp (name, ".gnu.linkonce.t.", 16) != 0) | |
217 | + abort (); | |
218 | + | |
219 | + rodata = xstrdup (name); | |
220 | + rodata [14] = 'r'; | |
221 | + named_section_flags (rodata, 0); | |
222 | + free (rodata); | |
223 | + } | |
224 | +} | |
225 | +#endif | |
226 | + | |
227 | /* Tell assembler to switch to read-only data section. This is normally | |
228 | the text section. */ | |
229 | ||
230 | @@ -4651,16 +4680,97 @@ default_no_named_section (const char *na | |
231 | abort (); | |
232 | } | |
233 | ||
234 | +/* Extract section name and group name from the linkonce section | |
235 | + name. */ | |
236 | + | |
237 | +const char * | |
238 | +elf_comdat_group (const char *name, const char **section, | |
239 | + const char **group) | |
240 | +{ | |
241 | + const char *p; | |
242 | + const char *sec = NULL; | |
243 | + static const char *one [] = | |
244 | + { | |
245 | + ".bss", /* 'b' */ | |
246 | + NULL, /* 'c' */ | |
247 | + ".data", /* 'd' */ | |
248 | + NULL, /* 'e' */ | |
249 | + NULL, /* 'f' */ | |
250 | + NULL, /* 'q' */ | |
251 | + NULL, /* 'h' */ | |
252 | + NULL, /* 'i' */ | |
253 | + NULL, /* 'j' */ | |
254 | + NULL, /* 'k' */ | |
255 | + NULL, /* 'l' */ | |
256 | + NULL, /* 'm' */ | |
257 | + NULL, /* 'n' */ | |
258 | + NULL, /* 'o' */ | |
259 | + NULL, /* 'p' */ | |
260 | + NULL, /* 'q' */ | |
261 | + ".rodata", /* 'r' */ | |
262 | + ".sdata", /* 's' */ | |
263 | + ".text" /* 't' */ | |
264 | + }; | |
265 | + | |
266 | + if (strncmp (name, ".gnu.linkonce.", 14) != 0) | |
267 | + return sec; | |
268 | + | |
269 | + p = name + 14; | |
270 | + if (p [1] == '.') | |
271 | + { | |
272 | + if (p [0] > 'a' && p [0] < 'u') | |
273 | + sec = one [p [0] - 'b']; | |
274 | + | |
275 | + if (sec) | |
276 | + *group = p + 2; | |
277 | + } | |
278 | + else if (p [2] == '.') | |
279 | + { | |
280 | + if (p [0] == 's') | |
281 | + { | |
282 | + if (p [1] == '2') | |
283 | + sec = ".sdata2"; | |
284 | + else if (p [1] == 'b') | |
285 | + sec = ".sbss"; | |
286 | + } | |
287 | + else if (p [0] == 't') | |
288 | + { | |
289 | + if (p [1] == 'b') | |
290 | + sec = ".tbss"; | |
291 | + else if (p [1] == 'd') | |
292 | + sec = ".tdata"; | |
293 | + } | |
294 | + else if (p [0] == 'w' && p [1] == 'i') | |
295 | + sec = ".debug_info"; | |
296 | + | |
297 | + if (sec) | |
298 | + *group = p + 3; | |
299 | + } | |
300 | + else if (strncmp (p, "sb2.", 4) == 0) | |
301 | + { | |
302 | + sec = ".sbss2"; | |
303 | + *group = p + 4; | |
304 | + } | |
305 | + | |
306 | + if (sec) | |
307 | + *section = sec; | |
308 | + | |
309 | + return sec; | |
310 | +} | |
311 | + | |
312 | void | |
313 | default_elf_asm_named_section (const char *name, unsigned int flags) | |
314 | { | |
315 | char flagchars[10], *f = flagchars; | |
316 | + const char *section_name = NULL, *group_name = NULL; | |
317 | ||
318 | +#ifndef HAVE_GAS_COMDAT_GROUP | |
319 | if (! named_section_first_declaration (name)) | |
320 | { | |
321 | fprintf (asm_out_file, "\t.section\t%s\n", name); | |
322 | return; | |
323 | } | |
324 | +#endif | |
325 | ||
326 | if (!(flags & SECTION_DEBUG)) | |
327 | *f++ = 'a'; | |
328 | @@ -4676,9 +4786,17 @@ default_elf_asm_named_section (const cha | |
329 | *f++ = 'S'; | |
330 | if (flags & SECTION_TLS) | |
331 | *f++ = 'T'; | |
332 | +#ifdef HAVE_GAS_COMDAT_GROUP | |
333 | + if (elf_comdat_group (name, §ion_name, &group_name)) | |
334 | + *f++ = 'G'; | |
335 | +#endif | |
336 | *f = '\0'; | |
337 | ||
338 | - fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars); | |
339 | + if (section_name) | |
340 | + fprintf (asm_out_file, "\t.section\t%s,\"%s\"", section_name, | |
341 | + flagchars); | |
342 | + else | |
343 | + fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars); | |
344 | ||
345 | if (!(flags & SECTION_NOTYPE)) | |
346 | { | |
347 | @@ -4695,6 +4813,9 @@ default_elf_asm_named_section (const cha | |
348 | fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE); | |
349 | } | |
350 | ||
351 | + if (group_name) | |
352 | + fprintf (asm_out_file, ",%s,comdat", group_name); | |
353 | + | |
354 | putc ('\n', asm_out_file); | |
355 | } | |
356 |