rs6000.c (rs6000_elf_asm_out_constructor): New.
authorRichard Henderson <rth@redhat.com>
Sun, 12 Aug 2001 21:17:43 +0000 (14:17 -0700)
committerRichard Henderson <rth@gcc.gnu.org>
Sun, 12 Aug 2001 21:17:43 +0000 (14:17 -0700)
        * config/rs6000/rs6000.c (rs6000_elf_asm_out_constructor): New.
        (rs6000_elf_asm_out_destructor): New.                                           * config/rs6000/sysv4.h (CTORS_SECTION_ASM_OP): Remove.
        (DTORS_SECTION_ASM_OP): Remove.                                                 (TARGET_ASM_CONSTRUCTOR, TARGET_ASM_DESTRUCTOR): New.
        (ASM_OUTPUT_INT): Don't hack TARGET_RELOCATABLE for constructors.

From-SVN: r44835

gcc/ChangeLog
gcc/config/rs6000/rs6000.c
gcc/config/rs6000/sysv4.h

index 6d6b192817f4c78e08751262d0948c960a8b2456..45cf6169e6dca574cca649985da8eade77cb18d1 100644 (file)
@@ -1,3 +1,12 @@
+2001-08-12  Richard Henderson  <rth@redhat.com>
+
+       * config/rs6000/rs6000.c (rs6000_elf_asm_out_constructor): New.
+       (rs6000_elf_asm_out_destructor): New.
+       * config/rs6000/sysv4.h (CTORS_SECTION_ASM_OP): Remove.
+       (DTORS_SECTION_ASM_OP): Remove.
+       (TARGET_ASM_CONSTRUCTOR, TARGET_ASM_DESTRUCTOR): New.
+       (ASM_OUTPUT_INT): Don't hack TARGET_RELOCATABLE for constructors.
+
 2001-08-12  David Edelsohn  <edelsohn@gnu.org>
 
        Revert:
index 924c2445ef097a5b62bf2dffef23c456d816a983..a7221c2ceee738ffa580fe53f9d7605562eb2235 100644 (file)
@@ -134,6 +134,8 @@ static rtx rs6000_emit_set_long_const PARAMS ((rtx,
 #if TARGET_ELF
 static unsigned int rs6000_elf_section_type_flags PARAMS ((tree, const char *,
                                                           int));
+static void rs6000_elf_asm_out_constructor PARAMS ((rtx, int));
+static void rs6000_elf_asm_out_destructor PARAMS ((rtx, int));
 #endif
 #ifdef OBJECT_FORMAT_COFF
 static void xcoff_asm_named_section PARAMS ((const char *, unsigned int,
@@ -8707,6 +8709,73 @@ rs6000_elf_section_type_flags (decl, name, reloc)
 
   return flags;
 }
+
+/* Record an element in the table of global constructors.  SYMBOL is
+   a SYMBOL_REF of the function to be called; PRIORITY is a number
+   between 0 and MAX_INIT_PRIORITY.
+
+   This differs from default_named_section_asm_out_constructor in
+   that we have special handling for -mrelocatable.  */
+
+static void
+rs6000_elf_asm_out_constructor (symbol, priority)
+     rtx symbol;
+     int priority;
+{
+  const char *section = ".ctors";
+  char buf[16];
+
+  if (priority != DEFAULT_INIT_PRIORITY)
+    {
+      sprintf (buf, ".ctors.%.5u",
+               /* Invert the numbering so the linker puts us in the proper
+                  order; constructors are run from right to left, and the
+                  linker sorts in increasing order.  */
+               MAX_INIT_PRIORITY - priority);
+      section = buf;
+    }
+
+  named_section_flags (section, SECTION_WRITE, POINTER_SIZE / BITS_PER_UNIT);
+
+  if (TARGET_RELOCATABLE)
+    {
+      fputs ("\t.long (", asm_out_file);
+      output_addr_const (asm_out_file, symbol);
+      fputs (")@fixup\n", asm_out_file);
+    }
+  else
+    assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, 1);
+}
+
+static void
+rs6000_elf_asm_out_destructor (symbol, priority)
+     rtx symbol;
+     int priority;
+{
+  const char *section = ".dtors";
+  char buf[16];
+
+  if (priority != DEFAULT_INIT_PRIORITY)
+    {
+      sprintf (buf, ".dtors.%.5u",
+               /* Invert the numbering so the linker puts us in the proper
+                  order; constructors are run from right to left, and the
+                  linker sorts in increasing order.  */
+               MAX_INIT_PRIORITY - priority);
+      section = buf;
+    }
+
+  named_section_flags (section, SECTION_WRITE, POINTER_SIZE / BITS_PER_UNIT);
+
+  if (TARGET_RELOCATABLE)
+    {
+      fputs ("\t.long (", asm_out_file);
+      output_addr_const (asm_out_file, symbol);
+      fputs (")@fixup\n", asm_out_file);
+    }
+  else
+    assemble_integer (symbol, POINTER_SIZE / BITS_PER_UNIT, 1);
+}
 #endif
 
 #ifdef OBJECT_FORMAT_COFF
index f52efa6e69be96a8e493699d286ba3c7a4f410da..39813b6409bb6d5d5a5015af7caad44d389b0d2c 100644 (file)
@@ -555,13 +555,6 @@ fini_section ()                                                            \
     }                                                                  \
 }
 
-/* Ordinarily, we wouldn't need to define these, since generic code would
-   do the right thing based on knowing that we have named sections.
-   However, -mrelocatable needs to know when we're in [cd]tors sections,
-   and the easiest way to do that is rely on varasm.c defining in_[cd]tors.  */
-#define CTORS_SECTION_ASM_OP   "\t.section\t.ctors,\"aw\""
-#define DTORS_SECTION_ASM_OP   "\t.section\t.dtors,\"aw\""
-
 /* A C statement or statements to switch to the appropriate section
    for output of RTX in mode MODE.  You can assume that RTX is some
    kind of constant in RTL.  The argument MODE is redundant except in
@@ -816,6 +809,10 @@ do {                                                                       \
 
 extern int fixuplabelno;
 
+/* Handle constructors specially for -mrelocatable.  */
+#define TARGET_ASM_CONSTRUCTOR  rs6000_elf_asm_out_constructor
+#define TARGET_ASM_DESTRUCTOR   rs6000_elf_asm_out_destructor
+
 /* This is how to output an assembler line defining an `int' constant.
    For -mrelocatable, we mark all addresses that need to be fixed up
    in the .fixup section.  */
@@ -827,8 +824,6 @@ do {                                                                        \
   if (TARGET_RELOCATABLE                                               \
       && in_section != in_toc                                          \
       && in_section != in_text                                         \
-      && in_section != in_ctors                                                \
-      && in_section != in_dtors                                                \
       && !recurse                                                      \
       && GET_CODE (VALUE) != CONST_INT                                 \
       && GET_CODE (VALUE) != CONST_DOUBLE                              \