This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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]

Re: [RFC] Default ld -r should not combine .init_array sections


On 02/26/2010 09:24 PM, H.J. Lu wrote:
On Fri, Feb 26, 2010 at 12:30 AM, Jie Zhang<jie@codesourcery.com> wrote:
On 02/26/2010 12:30 AM, H.J. Lu wrote:

On Thu, Feb 25, 2010 at 8:05 AM, Jie Zhang<jie@codesourcery.com> wrote:

We found this issue on arm-none-eabi target. The default ld -r combines .init_array.* sections. Such that priority information recorded in section name will be lost. When the object file from the output of "ld -r" is linked into the final executable, the static constructors will do initialization in wrong order.

I think you can use assembly input and .d file for testcase. There
is no need for a complete new cdtest2.exp.

Good idea. How about this new version? I also rebased it on Alan's change.

Another question is: If this change is good, should I also change other .sc files which have .init_array and .fini_array?


Regards, Jie
	* scripttempl/elf.sc: Don't combine .init_array.* or
	.fini_array.* when do relocatable linking.

	testsuite/
	* ld-elf/init-fini-arrays.s: New test.
	* ld-elf/init-fini-arrays.d: New test.

Index: scripttempl/elf.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/elf.sc,v
retrieving revision 1.99
diff -u -r1.99 elf.sc
--- scripttempl/elf.sc	26 Feb 2010 11:36:32 -0000	1.99
+++ scripttempl/elf.sc	26 Feb 2010 16:55:11 -0000
@@ -216,6 +216,20 @@
     *(.ldata${RELOCATING+ .ldata.* .gnu.linkonce.l.*})
     ${RELOCATING+. = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
   }"
+INIT_ARRAY=".init_array   ${RELOCATING-0} :
+  {
+     ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_start = .);}}
+     KEEP (*(SORT(.init_array.*)))
+     KEEP (*(.init_array))
+     ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_end = .);}}
+  }"
+FINI_ARRAY=".fini_array   ${RELOCATING-0} :
+  {
+    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_start = .);}}
+    KEEP (*(SORT(.fini_array.*)))
+    KEEP (*(.fini_array))
+    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_end = .);}}
+  }"
 CTOR=".ctors        ${CONSTRUCTING-0} : 
   {
     ${CONSTRUCTING+${CTOR_START}}
@@ -455,20 +469,8 @@
     KEEP (*(.preinit_array))
     ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_end = .);}}
   }
-  .init_array   ${RELOCATING-0} :
-  {
-     ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_start = .);}}
-     KEEP (*(SORT(.init_array.*)))
-     KEEP (*(.init_array))
-     ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_end = .);}}
-  }
-  .fini_array   ${RELOCATING-0} :
-  {
-    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_start = .);}}
-    KEEP (*(SORT(.fini_array.*)))
-    KEEP (*(.fini_array))
-    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_end = .);}}
-  }
+  ${RELOCATING+${INIT_ARRAY}}
+  ${RELOCATING+${FINI_ARRAY}}
   ${SMALL_DATA_CTOR-${RELOCATING+${CTOR}}}
   ${SMALL_DATA_DTOR-${RELOCATING+${DTOR}}}
   .jcr          ${RELOCATING-0} : { KEEP (*(.jcr)) }
Index: testsuite/ld-elf/init-fini-arrays.d
===================================================================
RCS file: testsuite/ld-elf/init-fini-arrays.d
diff -N testsuite/ld-elf/init-fini-arrays.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/ld-elf/init-fini-arrays.d	26 Feb 2010 16:55:11 -0000
@@ -0,0 +1,9 @@
+#source: init-fini-arrays.s
+#ld: -r
+#readelf: -S
+
+#...
+  \[[ 0-9]+\] \.init_array\.01000[ \t]+PROGBITS[ \t0-9a-f]+WA?.*
+#...
+  \[[ 0-9]+\] \.fini_array\.01000[ \t]+PROGBITS[ \t0-9a-f]+WA?.*
+#pass
Index: testsuite/ld-elf/init-fini-arrays.s
===================================================================
RCS file: testsuite/ld-elf/init-fini-arrays.s
diff -N testsuite/ld-elf/init-fini-arrays.s
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/ld-elf/init-fini-arrays.s	26 Feb 2010 16:55:11 -0000
@@ -0,0 +1,6 @@
+        .section        .init_array.01000,"aw",%progbits
+        .align  4
+        .word 0
+        .section        .fini_array.01000,"aw",%progbits
+        .align  4
+        .word 0

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