1 2004-12-03 H.J. Lu <hongjiu.lu@intel.com>
4 * configure.ac: Check if assembler supports COMDAT group.
5 * configure: Regenerated.
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.
12 * output.h (elf_comdat_group): New.
13 (readonly_data_section_in_function_group): Likewise.
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.
21 * config/sparc/sysv4.h (TARGET_ASM_NAMED_SECTION): Define only
22 if HAVE_GAS_COMDAT_GROUP is not defined.
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
27 /* Define if your assembler supports .balign and .p2align. */
28 #undef HAVE_GAS_BALIGN_AND_P2ALIGN
30 +/* Define 0/1 if your assembler supports COMDAT group. */
31 +#undef HAVE_GAS_COMDAT_GROUP
33 /* Define if your assembler uses the new HImode fild and fist notation. */
34 #undef HAVE_GAS_FILDS_FISTS
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)
41 char flagchars[10], *f = flagchars;
42 + const char *section_name = NULL, *group_name = NULL;
44 +#ifndef HAVE_GAS_COMDAT_GROUP
45 if (! named_section_first_declaration (name))
47 fprintf (asm_out_file, "\t.section\t%s\n", name);
52 if (!(flags & SECTION_DEBUG))
54 @@ -13177,9 +13180,17 @@ arm_elf_asm_named_section (const char *n
56 if (flags & SECTION_TLS)
58 +#ifdef HAVE_GAS_COMDAT_GROUP
59 + if (elf_comdat_group (name, §ion_name, &group_name))
64 - fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
66 + fprintf (asm_out_file, "\t.section\t%s,\"%s\"", section_name,
69 + fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
71 if (!(flags & SECTION_NOTYPE))
73 @@ -13196,6 +13207,9 @@ arm_elf_asm_named_section (const char *n
74 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
78 + fprintf (asm_out_file, ",%s,comdat", group_name);
80 putc ('\n', asm_out_file);
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"
89 +/* COMDAT group cannot be expressed in SPARC's section attributes
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
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
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
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.])
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
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])
139 +if test $in_tree_ld != yes && test x"$ld_vers" != x; then
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
145 + elif test "$ld_vers_major" -lt 2; then
147 + elif test "$ld_vers_major" -eq 2 -a "$ld_vers_minor" -lt 15; then
149 + elif test "$ld_vers_major" -eq 2 -a "$ld_vers_minor" -eq 15 -a "$ld_vers_patch" -lt 92; then
153 + if test $comdat_group = no; then
154 + gcc_cv_as_comdat_group=no
155 + gcc_cv_as_comdat_group_percent=no
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.])
162 # Thread-local storage - the check is heavily parametrized.
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
171 +#ifdef HAVE_GAS_COMDAT_GROUP
172 + readonly_data_section_in_function_group
173 + (current_function_decl);
175 readonly_data_section ();
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 */
186 +extern const char *elf_comdat_group (const char *, 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)
198 +#ifdef HAVE_GAS_COMDAT_GROUP
200 +/* Tell assembler to switch to read-only data section in the same
201 + comdat group as DECL. */
204 +readonly_data_section_in_function_group (tree decl)
206 + if (decl == NULL_TREE || !DECL_P (decl))
209 + if (DECL_SECTION_NAME (decl) == NULL_TREE || ! DECL_ONE_ONLY (decl))
210 + readonly_data_section ();
214 + const char *name = TREE_STRING_POINTER (DECL_SECTION_NAME (decl));
216 + if (strncmp (name, ".gnu.linkonce.t.", 16) != 0)
219 + rodata = xstrdup (name);
221 + named_section_flags (rodata, 0);
227 /* Tell assembler to switch to read-only data section. This is normally
230 @@ -4651,16 +4680,97 @@ default_no_named_section (const char *na
234 +/* Extract section name and group name from the linkonce section
238 +elf_comdat_group (const char *name, const char **section,
239 + const char **group)
242 + const char *sec = NULL;
243 + static const char *one [] =
261 + ".rodata", /* 'r' */
262 + ".sdata", /* 's' */
266 + if (strncmp (name, ".gnu.linkonce.", 14) != 0)
272 + if (p [0] > 'a' && p [0] < 'u')
273 + sec = one [p [0] - 'b'];
278 + else if (p [2] == '.')
284 + else if (p [1] == 'b')
287 + else if (p [0] == 't')
291 + else if (p [1] == 'd')
294 + else if (p [0] == 'w' && p [1] == 'i')
295 + sec = ".debug_info";
300 + else if (strncmp (p, "sb2.", 4) == 0)
313 default_elf_asm_named_section (const char *name, unsigned int flags)
315 char flagchars[10], *f = flagchars;
316 + const char *section_name = NULL, *group_name = NULL;
318 +#ifndef HAVE_GAS_COMDAT_GROUP
319 if (! named_section_first_declaration (name))
321 fprintf (asm_out_file, "\t.section\t%s\n", name);
326 if (!(flags & SECTION_DEBUG))
328 @@ -4676,9 +4786,17 @@ default_elf_asm_named_section (const cha
330 if (flags & SECTION_TLS)
332 +#ifdef HAVE_GAS_COMDAT_GROUP
333 + if (elf_comdat_group (name, §ion_name, &group_name))
338 - fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
340 + fprintf (asm_out_file, "\t.section\t%s,\"%s\"", section_name,
343 + fprintf (asm_out_file, "\t.section\t%s,\"%s\"", name, flagchars);
345 if (!(flags & SECTION_NOTYPE))
347 @@ -4695,6 +4813,9 @@ default_elf_asm_named_section (const cha
348 fprintf (asm_out_file, ",%d", flags & SECTION_ENTSIZE);
352 + fprintf (asm_out_file, ",%s,comdat", group_name);
354 putc ('\n', asm_out_file);