This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
fix for section redeclarations
- To: gcc-patches at gcc dot gnu dot org
- Subject: fix for section redeclarations
- From: Robert Lipe <robertlipe at usa dot net>
- Date: Mon, 8 Oct 2001 16:39:27 -0500
Richard Henderson and I talked this through. While he's not amused by
the problem on the trunk, he doesn't hate the solution we came to. :-)
The current trunk will, for even an empty source file, emit duplicate
section headers:
$ ./cc1 -o - -g /tmp/j.i | grep section
.section .debug_abbrev,"",@progbits
.section .debug_info,"",@progbits
.section .debug_line,"",@progbits
.section .debug_frame,"",@progbits
.section .debug_abbrev,"",@progbits
.section .debug_info,"",@progbits
.section .debug_line,"",@progbits
.section .debug_frame,"",@progbits
Some assemblers will warn about the multiple occurrences of the section
type information on the grounds that you might be redefining the
attributes of the section. (I know, that's pretty circumstantial...)
This patch makes suppresses the redefinition for ELF and makes the
output of the above into:
.section .debug_abbrev,"",@progbits
.section .debug_info,"",@progbits
.section .debug_line,"",@progbits
.section .debug_frame,"",@progbits
.section .debug_line
.section .debug_info
.section .debug_abbrev
This removes about a zillion warnings when building C for
i686-pc-sco3.2v5.0.5.
RJL
* varasm.c (struct in_named_entry): Add declared.
(named_section_first_declaration): New.
(default_elf_asm_named_section): Use it.
Index: varasm.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/varasm.c,v
retrieving revision 1.212
diff -u -p -r1.212 varasm.c
--- varasm.c 2001/10/08 16:46:23 1.212
+++ varasm.c 2001/10/08 21:28:54
@@ -216,6 +216,7 @@ struct in_named_entry
{
const char *name;
unsigned int flags;
+ bool declared;
};
static htab_t in_named_htab;
@@ -340,6 +341,31 @@ get_named_section_flags (section)
return slot ? (*slot)->flags : 0;
}
+/* Returns true if the section has been declared before. Sets internal
+ flag on this section in in_named_hash so subsequent calls on this
+ section will return false. */
+
+bool
+named_section_first_declaration (name)
+ const char *name;
+{
+ struct in_named_entry **slot;
+
+ slot = (struct in_named_entry**)
+ htab_find_slot_with_hash (in_named_htab, name,
+ htab_hash_string (name), NO_INSERT);
+ if (! (*slot)->declared)
+ {
+ (*slot)->declared = true;
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+}
+
+
/* Record FLAGS for SECTION. If SECTION was previously recorded with a
different set of flags, return false. */
@@ -5205,6 +5231,12 @@ default_elf_asm_named_section (name, fla
char flagchars[10], *f = flagchars;
const char *type;
+ if (! named_section_first_declaration (name))
+ {
+ fprintf (asm_out_file, "\t.section\t%s\n", name);
+ return;
+ }
+
if (!(flags & SECTION_DEBUG))
*f++ = 'a';
if (flags & SECTION_WRITE)
@@ -5224,12 +5256,10 @@ default_elf_asm_named_section (name, fla
else
type = "progbits";
- if (flags & SECTION_ENTSIZE)
- fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s,%d\n",
- name, flagchars, type, flags & SECTION_ENTSIZE);
- else
- fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s\n",
- name, flagchars, type);
+ fprintf (asm_out_file, "\t.section\t%s,\"%s\",@%s", name, flagchars, type);
+ if (flags & SECTION_ENTSIZE)
+ fprintf(asm_out_file, ",%d", flags & SECTION_ENTSIZE);
+ fprintf(asm_out_file, "\n");
}
void