OSDN Git Service

libitm: Remove unused code.
[pf3gnuchains/gcc-fork.git] / gcc / config / sol2.c
index 3531e79..b1f0196 100644 (file)
@@ -1,5 +1,5 @@
 /* General Solaris system support.
-   Copyright (C) 2004, 2005 , 2007, 2010 Free Software Foundation, Inc.
+   Copyright (C) 2004, 2005 , 2007, 2010, 2011 Free Software Foundation, Inc.
    Contributed by CodeSourcery, LLC.
 
 This file is part of GCC.
@@ -25,9 +25,11 @@ along with GCC; see the file COPYING3.  If not see
 #include "output.h"
 #include "tm.h"
 #include "rtl.h"
+#include "target.h"
 #include "tm_p.h"
-#include "toplev.h"
+#include "diagnostic-core.h"
 #include "ggc.h"
+#include "hashtab.h"
 
 tree solaris_pending_aligns, solaris_pending_inits, solaris_pending_finis;
 
@@ -105,14 +107,14 @@ solaris_output_init_fini (FILE *file, tree decl)
 {
   if (lookup_attribute ("init", DECL_ATTRIBUTES (decl)))
     {
-      fprintf (file, "\t.pushsection\t\".init\"\n");
+      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, "\t.pushsection\t\".fini\"\n");
+      fprintf (file, "\t.pushsection\t" SECTION_NAME_FORMAT "\n", ".fini");
       ASM_OUTPUT_CALL (file, decl);
       fprintf (file, "\t.popsection\n");
     }
@@ -122,8 +124,10 @@ solaris_output_init_fini (FILE *file, tree decl)
    the visibility type VIS, which must not be VISIBILITY_DEFAULT.  */
 
 void
-solaris_assemble_visibility (tree decl, int vis)
+solaris_assemble_visibility (tree decl ATTRIBUTE_UNUSED,
+                            int vis ATTRIBUTE_UNUSED)
 {
+#ifdef HAVE_GAS_HIDDEN
   /* Sun as uses .symbolic for STV_PROTECTED.  STV_INTERNAL is marked as
      `currently reserved', but the linker treats it like STV_HIDDEN.  Sun
      Studio 12.1 cc emits .hidden instead.
@@ -132,10 +136,8 @@ solaris_assemble_visibility (tree decl, int vis)
      STV_SINGLETON, and STV_ELIMINATE.
 
      See Linker and Libraries Guide, Ch. 2, Link-Editor, Defining
-     Additional Symbols with a mapfile,
-     http://docs.sun.com/app/docs/doc/819-0690/gdzmc?a=view
-     and Ch. 7, Object-File Format, Symbol Table Section,
-     http://docs.sun.com/app/docs/doc/819-0690/chapter6-79797?a=view  */
+     Additional Symbols, and Ch. 7, Object-File Format, Symbol Table
+     Section.  */
 
   static const char * const visibility_types[] = {
     NULL, "symbolic", "hidden", "hidden"
@@ -146,9 +148,6 @@ solaris_assemble_visibility (tree decl, int vis)
   name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
   type = visibility_types[vis];
 
-  /* .hidden dates back before Solaris 2.5, but .symbolic was only added in
-     Solaris 9 12/02.  */
-#ifdef HAVE_GAS_HIDDEN
   fprintf (asm_out_file, "\t.%s\t", type);
   assemble_name (asm_out_file, name);
   fprintf (asm_out_file, "\n");
@@ -157,3 +156,129 @@ solaris_assemble_visibility (tree decl, int vis)
           "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_file_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_file_end (void)
+{
+  if (solaris_comdat_htab == NULL)
+    return;
+
+  htab_traverse (solaris_comdat_htab, solaris_define_comdat_signature, NULL);
+}