This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Use .init_array for static constructors for ARM EABI


Hi,

This is a patch from the csl-arm branch. Original thread is here:

http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02475.html

The patch makes ARM EABI targets use the .init_array section for static constructor lists. Non-EABI targets are unaffected. The pointers in this section are relocated by R_ARM_TARGET1 relocations.

The EABI doesn't provide a mechanism for supporting the init_priority
attribute, so support for this is disabled on EABI based targets. This causes some tests to be omitted:


g++.dg/special/conpr-1.C execution test
g++.dg/special/conpr-1.C (test for excess errors)
g++.dg/special/conpr-2.C execution test
g++.dg/special/conpr-2.C (test for excess errors)
g++.dg/special/conpr-3.C execution test
g++.dg/special/conpr-3.C (test for excess errors)
g++.dg/special/conpr-4.C execution test
g++.dg/special/conpr-4.C (test for excess errors)
g++.dg/special/initp1.C execution test
g++.dg/special/initp1.C (test for excess errors)

Though this is to be expected.

Tested on arm-none-eabi and arm-none-elf.

OK to apply?

Julian

ChangeLog (Paul Brook):

 * config/arm/arm.c (arm_elf_asm_constructor): New function.
 * config/arm/arm.h (CTORS_SECTION_ASM_OP): Define.
 (CTORS_SECTION_FOR_TARGET, CTOR_LIST_END, CTOR_LIST_BEGIN): Define.
 * config/arm/elf.h (TARGET_ASM_CONSTRUCTOR): Define.
 (SUPPORTS_INIT_PRIORITY): Evaluate to false for EABI based targets.
Index: gcc/config/arm/arm.c
===================================================================
RCS file: /home/gcc/repos/gcc/gcc/gcc/config/arm/arm.c,v
retrieving revision 1.444
diff -c -p -r1.444 arm.c
*** gcc/config/arm/arm.c	19 Apr 2005 22:12:59 -0000	1.444
--- gcc/config/arm/arm.c	20 Apr 2005 18:38:09 -0000
*************** static void emit_constant_insn (rtx cond
*** 144,149 ****
--- 144,152 ----
  static int arm_arg_partial_bytes (CUMULATIVE_ARGS *, enum machine_mode,
  				  tree, bool);
  
+ #ifdef OBJECT_FORMAT_ELF
+ static void arm_elf_asm_constructor (rtx, int);
+ #endif
  #ifndef ARM_PE
  static void arm_encode_section_info (tree, rtx, int);
  #endif
*************** arm_assemble_integer (rtx x, unsigned in
*** 10717,10722 ****
--- 10720,10745 ----
      }
  
    return default_assemble_integer (x, size, aligned_p);
+ }
+ 
+ 
+ /* Add a function to the list of static constructors.  */
+ 
+ static void
+ arm_elf_asm_constructor (rtx symbol, int priority ATTRIBUTE_UNUSED)
+ {
+   if (!TARGET_AAPCS_BASED)
+     {
+       default_named_section_asm_out_constructor (symbol, priority);
+       return;
+     }
+ 
+   /* Put these in the .init_array section, using a special relocation.  */
+   ctors_section ();
+   assemble_align (POINTER_SIZE);
+   fputs ("\t.word\t", asm_out_file);
+   output_addr_const (asm_out_file, symbol);
+   fputs ("(target1)\n", asm_out_file);
  }
  #endif
  
Index: gcc/config/arm/arm.h
===================================================================
RCS file: /home/gcc/repos/gcc/gcc/gcc/config/arm/arm.h,v
retrieving revision 1.273
diff -c -p -r1.273 arm.h
*** gcc/config/arm/arm.h	12 Apr 2005 06:33:27 -0000	1.273
--- gcc/config/arm/arm.h	19 Apr 2005 22:43:07 -0000
*************** typedef struct
*** 2108,2113 ****
--- 2108,2144 ----
  #define ASM_OUTPUT_LABELREF(FILE, NAME)		\
     arm_asm_output_labelref (FILE, NAME)
  
+ /* The EABI specifies that constructors should go in .init_array.
+    Other targets use .ctors for compatibility.  */
+ #undef CTORS_SECTION_ASM_OP
+ #define CTORS_SECTION_ASM_OP (TARGET_AAPCS_BASED	\
+   ? "\t.section\t.init_array,\"aw\",%init_array"	\
+   : "\t.section\t.ctors,\"aw\",%progbits")
+ 
+ /* There macros are used in target files.  We need to define them here
+    because CTORS_SECTION_ASM_OP is not a constant.  The code is identical
+    to the code in crtstuff.c, but duplicated here to avoid depending on
+    TARGET_AAPCS_BASED.  */
+ 
+ #ifdef __ARM_EABI__
+ #define CTORS_SECTION_FOR_TARGET "\t.section\t.init_array,\"aw\",%init_array"
+ #else
+ #define CTORS_SECTION_FOR_TARGET "\t.section\t.ctors,\"aw\",%progbits"
+ #endif
+ 
+ #define CTOR_LIST_END							\
+   static func_ptr force_to_data[1] __attribute__ ((__unused__)) = { };	\
+   asm (CTORS_SECTION_FOR_TARGET);					\
+   STATIC func_ptr __CTOR_END__[1]					\
+     __attribute__((aligned(sizeof(func_ptr))))				\
+     = { (func_ptr) 0 };
+ #define CTOR_LIST_BEGIN							\
+   static func_ptr force_to_data[1] __attribute__ ((__unused__)) = { };	\
+   asm (CTORS_SECTION_FOR_TARGET);					\
+   STATIC func_ptr __CTOR_LIST__[1]					\
+     __attribute__ ((__unused__, aligned(sizeof(func_ptr))))		\
+     = { (func_ptr) (-1) };
+ 
  /* True if the operating system can merge entities with vague linkage
     (e.g., symbols in COMDAT group) during dynamic linking.  */
  #ifndef TARGET_ARM_DYNAMIC_VAGUE_LINKAGE_P
Index: gcc/config/arm/elf.h
===================================================================
RCS file: /home/gcc/repos/gcc/gcc/gcc/config/arm/elf.h,v
retrieving revision 1.49
diff -c -p -r1.49 elf.h
*** gcc/config/arm/elf.h	18 Nov 2004 15:59:47 -0000	1.49
--- gcc/config/arm/elf.h	19 Apr 2005 22:24:55 -0000
***************
*** 120,125 ****
--- 120,129 ----
  #define TARGET_ASM_FILE_START_FILE_DIRECTIVE true
  
  
+ /* Output an element in the static constructor array.  */
+ #undef TARGET_ASM_CONSTRUCTOR
+ #define TARGET_ASM_CONSTRUCTOR arm_elf_asm_constructor
+ 
  /* For PIC code we need to explicitly specify (PLT) and (GOT) relocs.  */
  #define NEED_PLT_RELOC	flag_pic
  #define NEED_GOT_RELOC	flag_pic
***************
*** 143,146 ****
      }							\
    while (0)
  
! #define SUPPORTS_INIT_PRIORITY 1
--- 147,151 ----
      }							\
    while (0)
  
! /* The EABI doesn't provide a way of implementing init_priority.  */
! #define SUPPORTS_INIT_PRIORITY (!TARGET_AAPCS_BASED)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]