re PR target/14457 (ICE with simple c++ source)
[gcc.git] / gcc / config / darwin.c
index dec2eb72a358aa12c93c515509c361c646acb6c7..63c75df7c8e3af8c4a9f260d62940a1a97126133 100644 (file)
@@ -221,12 +221,9 @@ static GTY(()) char * function_base;
 const char *
 machopic_function_base_name (void)
 {
-  const char *current_name;
   /* if dynamic-no-pic is on, we should not get here */
   if (MACHO_DYNAMIC_NO_PIC_P)
     abort ();
-  current_name =
-    IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
 
   if (function_base == NULL)
     function_base =
@@ -502,6 +499,8 @@ machopic_indirect_data_reference (rtx orig, rtx reg)
       ptr_ref = gen_rtx_SYMBOL_REF (Pmode,
                                    machopic_non_lazy_ptr_name (name));
 
+     SYMBOL_REF_DECL (ptr_ref) = SYMBOL_REF_DECL (orig);
+
       ptr_ref = gen_rtx_MEM (Pmode, ptr_ref);
       RTX_UNCHANGING_P (ptr_ref) = 1;
 
@@ -586,8 +585,10 @@ machopic_indirect_call_target (rtx target)
       if (!machopic_name_defined_p (name))
        {
          const char *stub_name = machopic_stub_name (name);
+         tree decl = SYMBOL_REF_DECL (XEXP (target, 0));
 
          XEXP (target, 0) = gen_rtx_SYMBOL_REF (mode, stub_name);
+         SYMBOL_REF_DECL (XEXP (target, 0)) = decl;
          RTX_UNCHANGING_P (target) = 1;
        }
     }
@@ -1007,7 +1008,7 @@ darwin_encode_section_info (tree decl, rtx rtl, int first ATTRIBUTE_UNUSED)
       && (!TREE_PUBLIC (decl) || (!DECL_ONE_ONLY (decl) && !DECL_WEAK (decl)))
       && ((TREE_STATIC (decl)
           && (!DECL_COMMON (decl) || !TREE_PUBLIC (decl)))
-         || (DECL_INITIAL (decl)
+         || (!DECL_COMMON (decl) && DECL_INITIAL (decl)
              && DECL_INITIAL (decl) != error_mark_node)))
     defined = 1;
 
@@ -1307,7 +1308,10 @@ darwin_globalize_label (FILE *stream, const char *name)
 void
 darwin_asm_named_section (const char *name, unsigned int flags ATTRIBUTE_UNUSED)
 {
-  fprintf (asm_out_file, ".section %s\n", name);
+  if (flag_reorder_blocks_and_partition)
+    fprintf (asm_out_file, SECTION_FORMAT_STRING, name);
+  else
+    fprintf (asm_out_file, ".section %s\n", name);
 }
 
 unsigned int
@@ -1334,10 +1338,12 @@ darwin_unique_section (tree decl, int reloc ATTRIBUTE_UNUSED)
 }
 
 /* Emit a label for an FDE, making it global and/or weak if appropriate. 
-   The third parameter is nonzero if this is just a placeholder for an
+   The third parameter is nonzero if this is for exception handling.
+   The fourth parameter is nonzero if this is just a placeholder for an
    FDE that we are omitting. */
+
 void 
-darwin_emit_unwind_label(FILE *file, tree decl, int empty)
+darwin_emit_unwind_label (FILE *file, tree decl, int for_eh, int empty)
 {
   tree id = DECL_ASSEMBLER_NAME (decl)
     ? DECL_ASSEMBLER_NAME (decl)
@@ -1350,12 +1356,15 @@ darwin_emit_unwind_label(FILE *file, tree decl, int empty)
   unsigned int base_len = IDENTIFIER_LENGTH (id);
 
   const char *suffix = ".eh";
-  unsigned int suffix_len = 3;
 
   int need_quotes = name_needs_quotes (base);
   int quotes_len = need_quotes ? 2 : 0;
+  char *lab;
 
-  char *lab = xmalloc (prefix_len + base_len + suffix_len + quotes_len + 1);
+  if (! for_eh)
+    suffix = ".eh1";
+
+  lab = xmalloc (prefix_len + base_len + strlen (suffix) + quotes_len + 1);
   lab[0] = '\0';
 
   if (need_quotes)
@@ -1385,6 +1394,7 @@ darwin_emit_unwind_label(FILE *file, tree decl, int empty)
 }
 
 /* Generate a PC-relative reference to a Mach-O non-lazy-symbol.  */ 
+
 void
 darwin_non_lazy_pcrel (FILE *file, rtx addr)
 {