Add Init_priority support.
authorAjit Agarwal <ajitkum@xilinx.com>
Mon, 18 Aug 2014 17:04:41 +0000 (17:04 +0000)
committerMichael Eager <eager@gcc.gnu.org>
Mon, 18 Aug 2014 17:04:41 +0000 (17:04 +0000)
Added TARGET_ASM_CONSTRUCTOR and TARGET_ASM_DESTRUCTOR macros. These
macros allows users to control the order of initialization of objects
defined at namespace scope with the init_priority attribute by
specifying a relative priority.

ChangeLog:
2014-07-28  Ajit Agarwal  <ajitkum@xilinx.com>

* config/microblaze/microblaze.c (microblaze_elf_asm_cdtor): New.
(microblaze_elf_asm_constructor,microblaze_elf_asm_destructor): New.
* config/microblaze/microblaze.h
(TARGET_ASM_CONSTRUCTOR,TARGET_ASM_DESTRUCTOR): New Macros.

From-SVN: r214110

gcc/ChangeLog
gcc/config/microblaze/microblaze.c
gcc/config/microblaze/microblaze.h

index 408974b..629ae5f 100644 (file)
@@ -1,3 +1,10 @@
+2014-08-18  Ajit Agarwal  <ajitkum@xilinx.com>
+
+       * config/microblaze/microblaze.c (microblaze_elf_asm_cdtor): New.
+       (microblaze_elf_asm_constructor,microblaze_elf_asm_destructor): New.
+       * config/microblaze/microblaze.h
+       (TARGET_ASM_CONSTRUCTOR,TARGET_ASM_DESTRUCTOR): New Macros.
+
 2014-08-18  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR other/62168
index 0c2aec8..3ae61db 100644 (file)
@@ -231,6 +231,9 @@ const struct attribute_spec microblaze_attribute_table[] = {
 
 static int microblaze_interrupt_function_p (tree);
 
+static void microblaze_elf_asm_constructor (rtx, int) ATTRIBUTE_UNUSED;
+static void microblaze_elf_asm_destructor (rtx, int) ATTRIBUTE_UNUSED;
+
 section *sdata2_section;
 
 #ifdef HAVE_AS_TLS
@@ -2714,6 +2717,47 @@ microblaze_function_end_prologue (FILE * file)
     }
 }
 
+static void
+microblaze_elf_asm_cdtor (rtx symbol, int priority, bool is_ctor)
+{
+  section *s;
+
+  if (priority != DEFAULT_INIT_PRIORITY)
+    {
+      char buf[18];
+      sprintf (buf, "%s.%.5u",
+               is_ctor ? ".ctors" : ".dtors",
+               MAX_INIT_PRIORITY - priority);
+      s = get_section (buf, SECTION_WRITE, NULL_TREE);
+    }
+  else if (is_ctor)
+    s = ctors_section;
+  else
+    s = dtors_section;
+
+  switch_to_section (s);
+  assemble_align (POINTER_SIZE);
+  fputs ("\t.word\t", asm_out_file);
+  output_addr_const (asm_out_file, symbol);
+  fputs ("\n", asm_out_file);
+}
+
+/* Add a function to the list of static constructors.  */
+
+static void
+microblaze_elf_asm_constructor (rtx symbol, int priority)
+{
+  microblaze_elf_asm_cdtor (symbol, priority, /*is_ctor=*/true);
+}
+
+/* Add a function to the list of static destructors.  */
+
+static void
+microblaze_elf_asm_destructor (rtx symbol, int priority)
+{
+  microblaze_elf_asm_cdtor (symbol, priority, /*is_ctor=*/false);
+}
+
 /* Expand the prologue into a bunch of separate insns.  */
 
 void
index edb7d8a..17be22c 100644 (file)
@@ -691,6 +691,12 @@ do {                                                                       \
 {                                                                       \
 }
 
+#undef TARGET_ASM_CONSTRUCTOR
+#define TARGET_ASM_CONSTRUCTOR microblaze_elf_asm_constructor
+
+#undef TARGET_ASM_DESTRUCTOR
+#define TARGET_ASM_DESTRUCTOR microblaze_elf_asm_destructor
+
 #define ASM_GENERATE_INTERNAL_LABEL(LABEL,PREFIX,NUM)                  \
   sprintf ((LABEL), "*%s%s%ld", (LOCAL_LABEL_PREFIX), (PREFIX), (long)(NUM))