[PATCH] ARC: Fix ld/pr24511 test

Shahab Vahedi shahab.vahedi@gmail.com
Thu Jul 30 16:40:41 GMT 2020


From: Shahab Vahedi <shahab@synopsys.com>

With this patch, ld/pr24511 test passes for ARC.

At first glance, the test was failing because the order of
"__init_array_start" and "__fini_array_start" weak symbols were
reversed:

$ nm -n dump.out

      expected output          |          real output
00002104 D __init_array_start  |  00002104 D __fini_array_start
0000210c D __fini_array_start  |  00002104 D __init_array_start

The order of the symbols are different as a side effect of both
symbols being mapped to the _same_ address (0x2104).  Looking
further into the mapping logs [1] revealed that the linker
script must consider all instances of ".init_array" (in other
words ".init_array.*") inside its relevant section. Same logic
holds for ".fini_array".

Therefore, adding "KEEP (*(SORT(.init_array.*)))" to the linker
script, along with the one for ".finit_array.*", resolved the
problem.  While at it, I took the liberty of refactoring the
script a little bit and made those pieces of script macros.

[1] Linker's mapping for the relevant part of the test
---------------------------------------------------------------
.init_array     0x2104        0x0
                0x2104        PROVIDE (__init_array_start = .)
 *(.init_array)
                [!provide]    PROVIDE (__init_array_end = .)

.fini_array     0x2104        0x0
                0x2104        PROVIDE (__fini_array_start = .)
 *(.fini_array)
                [!provide]    PROVIDE (__fini_array_end = .)

.data           0x2104        0x0
 *(.data .data.* .gnu.linkonce.d.*)
 .data          0x2104        0x0 pr24511.o

.init_array.01000
                0x2104        0x8
 .init_array.01000
                0x2104        0x8 pr24511.o

.fini_array.01000
                0x210c        0x8
 .fini_array.01000
                0x210c        0x8 pr24511.o
---------------------------------------------------------------

ld:
	* scripttempl/elfarc.sc (.init_array): Keep ".init_array.*".
	  (.fini_array): Keep ".fini_array.*".
---
 ld/scripttempl/elfarc.sc | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/ld/scripttempl/elfarc.sc b/ld/scripttempl/elfarc.sc
index 8851c771f22..ebf40b84528 100644
--- a/ld/scripttempl/elfarc.sc
+++ b/ld/scripttempl/elfarc.sc
@@ -118,6 +118,20 @@ if test -z "${NO_SMALL_DATA}"; then
   REL_SBSS2=".rel.sbss2    ${RELOCATING-0} : { *(.rel.sbss2${RELOCATING+ .rel.sbss2.* .rel.gnu.linkonce.sb2.*}) }
   .rela.sbss2   ${RELOCATING-0} : { *(.rela.sbss2${RELOCATING+ .rela.sbss2.* .rela.gnu.linkonce.sb2.*}) }"
 fi
+INIT_ARRAY=".init_array   ${RELOCATING-0} :
+  {
+    ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .);}}
+    KEEP (*(SORT(.init_array.*)))
+    KEEP (*(.init_array))
+    ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
+  }"
+FINI_ARRAY=".fini_array   ${RELOCATING-0} :
+  {
+    ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
+    KEEP (*(SORT(.fini_array.*)))
+    KEEP (*(.fini_array))
+    ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
+  }"
 CTOR=".ctors        ${CONSTRUCTING-0} :
   {
     ${CONSTRUCTING+${CTOR_START}}
@@ -314,14 +328,8 @@ cat <<EOF
   ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
   .preinit_array   ${RELOCATING-0} : { *(.preinit_array) }
   ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .);}}
-  .init_array   ${RELOCATING-0} : { *(.init_array) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
-
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
-  .fini_array   ${RELOCATING-0} : { *(.fini_array) }
-  ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}
+  ${RELOCATING+${INIT_ARRAY}}
+  ${RELOCATING+${FINI_ARRAY}}
 
   .data         ${RELOCATING-0} :
   {
-- 
2.28.0



More information about the Binutils mailing list