PATCH: Properly align __*_array_start

H. J. Lu hjl@lucon.org
Mon Dec 16 10:09:00 GMT 2002


Hi Jakub,

I don't believe

http://sources.redhat.com/ml/libc-hacker/2002-12/msg00017.html

is correct. The problem is we can have the .init_array section in a.o,
b.o, c.o, .... You only want to align the first .init_array section
the linker sees to the proper alignment according to the ABI since the
linker will concatenate all .init_array sections into one. We don't
want any gaps between them. The glibc problem is a linker bug. Please
try the patch enclosed here.


H.J.
-------------- next part --------------
2002-12-15  H.J. Lu <hjl@gnu.org>

	* emulparams/elf_x86_64.sh (ARRAY_ALIGNMENT): New.

	* scripttempl/elf.sc: Properly align __preinit_array_start,
	__init_array_start and __fini_array_start with ARRAY_ALIGNMENT.

--- ld/emulparams/elf_x86_64.sh.array	Wed Oct 23 23:37:54 2002
+++ ld/emulparams/elf_x86_64.sh	Mon Dec 16 09:48:19 2002
@@ -11,6 +11,7 @@ NOP=0x90909090
 TEMPLATE_NAME=elf32
 GENERATE_SHLIB_SCRIPT=yes
 NO_SMALL_DATA=yes
+ARRAY_ALIGNMENT=16
 
 if [ "x${host}" = "x${target}" ]; then
   case " $EMULATION_LIBPATH " in
--- ld/scripttempl/elf.sc.array	Wed Sep 25 09:23:49 2002
+++ ld/scripttempl/elf.sc	Mon Dec 16 09:47:42 2002
@@ -71,6 +71,7 @@ test -z "${LITTLE_OUTPUT_FORMAT}" && LIT
 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
 test -z "${ELFSIZE}" && ELFSIZE=32
 test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
+test -z "${ARRAY_ALIGNMENT}" && ARRAY_ALIGNMENT="${ALIGNMENT}"
 test "$LD_FLAG" = "N" && DATA_ADDR=.
 test -n "$CREATE_SHLIB" && test -n "$SHLIB_DATA_ADDR" && COMMONPAGESIZE=""
 test -z "$CREATE_SHLIB" && test -n "$DATA_ADDR" && COMMONPAGESIZE=""
@@ -290,15 +291,17 @@ cat <<EOF
      could instead move the label definition inside the section, but
      the linker would then create the section even if it turns out to
      be empty, which isn't pretty.  */
-  ${RELOCATING+. = ALIGN(${ALIGNMENT});}
+  ${RELOCATING+. = ALIGN(${ARRAY_ALIGNMENT});}
   ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_start = .);}}
   .preinit_array   ${RELOCATING-0} : { *(.preinit_array) }
   ${RELOCATING+${CREATE_SHLIB-PROVIDE (__preinit_array_end = .);}}
 
+  ${RELOCATING+. = ALIGN(${ARRAY_ALIGNMENT});}
   ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_start = .);}}
   .init_array   ${RELOCATING-0} : { *(.init_array) }
   ${RELOCATING+${CREATE_SHLIB-PROVIDE (__init_array_end = .);}}
 
+  ${RELOCATING+. = ALIGN(${ARRAY_ALIGNMENT});}
   ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_start = .);}}
   .fini_array   ${RELOCATING-0} : { *(.fini_array) }
   ${RELOCATING+${CREATE_SHLIB-PROVIDE (__fini_array_end = .);}}


More information about the Binutils mailing list