diff options
author | Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE> | 2011-05-19 14:29:05 +0000 |
---|---|---|
committer | Rainer Orth <ro@gcc.gnu.org> | 2011-05-19 14:29:05 +0000 |
commit | 2ca48caa2c83ba7ba516a227788b2e86f8ca74ec (patch) | |
tree | 126d3363c833de58bd88e73fd92d6cd7e70bb915 /gcc/config/sol2.c | |
parent | ea93a47bc825a409079665551203aa194e71fc18 (diff) | |
download | gcc-2ca48caa2c83ba7ba516a227788b2e86f8ca74ec.zip gcc-2ca48caa2c83ba7ba516a227788b2e86f8ca74ec.tar.gz gcc-2ca48caa2c83ba7ba516a227788b2e86f8ca74ec.tar.bz2 |
re PR target/40483 (gcc 4.x needs to utilize better COMDAT mechanism under Solaris)
PR target/40483
* configure.ac (gcc_cv_as_comdat_group_group): Check for Sun as
COMDAT group syntax, both SPARC and x86 variants.
(HAVE_COMDAT_GROUP): Also define if gcc_cv_as_comdat_group_group.
* configure: Regenerate.
* config/sol2.h (TARGET_SOLARIS): Define.
(PUSHSECTION_FORMAT): Remove.
(SECTION_NAME_FORMAT): Define.
* config/sol2.c: Include hashtab.h.
(solaris_output_init_fini): Replace PUSHSECTION_FORMAT by its
expansion, using SECTION_NAME_FORMAT.
(solaris_comdat_htab): New variable.
(struct comdat_entry): Define.
(comdat_hash): New function.
(comdat_eq): New function.
(solaris_elf_asm_comdat_section): New function.
(solaris_define_comdat_signature): New function.
(solaris_code_end): New function.
* config/sol2-protos.h (solaris_elf_asm_comdat_section): Declare.
(solaris_code_end): Declare.
* config/t-sol2 (sol2.o): Add $HASHTAB_H dependency.
* config/i386/i386.c (ix86_code_end) [TARGET_SOLARIS]: Call
solaris_code_end.
(i386_solaris_elf_named_section): Wrap in TARGET_SOLARIS.
Remove ATTRIBUTE_UNUSED.
[!USE_GAS]: Call solaris_elf_asm_comdat_section for
SECTION_LINKONCE sections if HAVE_COMDAT_GROUP.
* config/sparc/sparc.c (sparc_solaris_elf_asm_named_section):
Likewise.
* config/i386/sol2-10.h (TARGET_ASM_NAMED_SECTION): Moved ...
* config/i386/sol2.h (TARGET_ASM_NAMED_SECTION): ... here.
* config/sparc/sol2.h (TARGET_ASM_CODE_END): Redefine.
(PUSHSECTION_FORMAT): Remove.
(SECTION_NAME_FORMAT): Redefine.
From-SVN: r173913
Diffstat (limited to 'gcc/config/sol2.c')
-rw-r--r-- | gcc/config/sol2.c | 131 |
1 files changed, 129 insertions, 2 deletions
diff --git a/gcc/config/sol2.c b/gcc/config/sol2.c index decde2f..7fed184 100644 --- a/gcc/config/sol2.c +++ b/gcc/config/sol2.c @@ -29,6 +29,7 @@ along with GCC; see the file COPYING3. If not see #include "tm_p.h" #include "diagnostic-core.h" #include "ggc.h" +#include "hashtab.h" tree solaris_pending_aligns, solaris_pending_inits, solaris_pending_finis; @@ -106,14 +107,14 @@ solaris_output_init_fini (FILE *file, tree decl) { if (lookup_attribute ("init", DECL_ATTRIBUTES (decl))) { - fprintf (file, PUSHSECTION_FORMAT, ".init"); + fprintf (file, "\t.pushsection\t" SECTION_NAME_FORMAT "\n", ".init"); ASM_OUTPUT_CALL (file, decl); fprintf (file, "\t.popsection\n"); } if (lookup_attribute ("fini", DECL_ATTRIBUTES (decl))) { - fprintf (file, PUSHSECTION_FORMAT, ".fini"); + fprintf (file, "\t.pushsection\t" SECTION_NAME_FORMAT "\n", ".fini"); ASM_OUTPUT_CALL (file, decl); fprintf (file, "\t.popsection\n"); } @@ -155,3 +156,129 @@ solaris_assemble_visibility (tree decl ATTRIBUTE_UNUSED, "in this configuration; ignored"); #endif } + +/* Hash table of group signature symbols. */ + +static htab_t solaris_comdat_htab; + +/* Group section information entry stored in solaris_comdat_htab. */ + +typedef struct comdat_entry +{ + const char *name; + unsigned int flags; + tree decl; + const char *sig; +} comdat_entry; + +/* Helper routines for maintaining solaris_comdat_htab. */ + +static hashval_t +comdat_hash (const void *p) +{ + const comdat_entry *entry = (const comdat_entry *) p; + + return htab_hash_string (entry->sig); +} + +static int +comdat_eq (const void *p1, const void *p2) +{ + const comdat_entry *entry1 = (const comdat_entry *) p1; + const comdat_entry *entry2 = (const comdat_entry *) p2; + + return strcmp (entry1->sig, entry2->sig) == 0; +} + +/* Output assembly to switch to COMDAT group section NAME with attributes + FLAGS and group signature symbol DECL, using Sun as syntax. */ + +void +solaris_elf_asm_comdat_section (const char *name, unsigned int flags, tree decl) +{ + const char *signature; + char *section; + comdat_entry entry, **slot; + + if (TREE_CODE (decl) == IDENTIFIER_NODE) + signature = IDENTIFIER_POINTER (decl); + else + signature = IDENTIFIER_POINTER (DECL_COMDAT_GROUP (decl)); + + /* Sun as requires group sections to be fragmented, i.e. to have names of + the form <section>%<fragment>. Strictly speaking this is only + necessary to support cc -xF, but is enforced globally in violation of + the ELF gABI. We keep the section names generated by GCC (generally + of the form .text.<signature>) and append %<signature> to pacify as, + despite the redundancy. */ + section = concat (name, "%", signature, NULL); + + /* Clear SECTION_LINKONCE flag so targetm.asm_out.named_section only + emits this as a regular section. Emit section before .group + directive since Sun as treats undeclared sections as @progbits, + which conflicts with .bss* sections which are @nobits. */ + targetm.asm_out.named_section (section, flags & ~SECTION_LINKONCE, decl); + + /* Sun as separates declaration of a group section and of the group + itself, using the .group directive and the #comdat flag. */ + fprintf (asm_out_file, "\t.group\t%s," SECTION_NAME_FORMAT ",#comdat\n", + signature, section); + + /* Unlike GNU as, group signature symbols need to be defined explicitly + for Sun as. With a few exceptions, this is already the case. To + identify the missing ones without changing the affected frontents, + remember the signature symbols and emit those not marked + TREE_SYMBOL_REFERENCED in solaris_code_end. */ + if (solaris_comdat_htab == NULL) + solaris_comdat_htab = htab_create_alloc (37, comdat_hash, comdat_eq, NULL, + xcalloc, free); + + entry.sig = signature; + slot = (comdat_entry **) htab_find_slot (solaris_comdat_htab, &entry, INSERT); + + if (*slot == NULL) + { + *slot = XCNEW (comdat_entry); + /* Remember fragmented section name. */ + (*slot)->name = section; + /* Emit as regular section, .group declaration has already been done. */ + (*slot)->flags = flags & ~SECTION_LINKONCE; + (*slot)->decl = decl; + (*slot)->sig = signature; + } +} + +/* Define unreferenced COMDAT group signature symbol corresponding to SLOT. */ + +static int +solaris_define_comdat_signature (void **slot, void *aux ATTRIBUTE_UNUSED) +{ + comdat_entry *entry = *(comdat_entry **) slot; + tree decl = entry->decl; + + if (TREE_CODE (decl) != IDENTIFIER_NODE) + decl = DECL_COMDAT_GROUP (decl); + + if (!TREE_SYMBOL_REFERENCED (decl)) + { + /* Switch to group section, otherwise Sun as complains + `Group Id symbol defined outside of group'. */ + switch_to_section (get_section (entry->name, entry->flags, entry->decl)); + + ASM_OUTPUT_LABEL (asm_out_file, entry->sig); + } + + /* Continue with scan. */ + return 1; +} + +/* Emit unreferenced COMDAT group signature symbols for Sun as. */ + +void +solaris_code_end (void) +{ + if (solaris_comdat_htab == NULL) + return; + + htab_traverse (solaris_comdat_htab, solaris_define_comdat_signature, NULL); +} |