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: ELF ld script optimisation


Alan Modra wrote:
I've been playing with ideas for SPU dynamic libraries.  One oddity is
that we don't want the dynamic sections loaded, since relocation
processing and symbol resolution will likely be done by the PPU, or at
least will happen on an image in PPU memory.  NON_ALLOC_DYN puts all
the dynamic sections in a different place.

NO_REL*_RELOCS cuts down on unnecessary linker script statements.
Since that is a generally useful little optimisation, I'm committing
it now, before the SPU dynamic support is ready.  I haven't enabled
this for all ELF targets, only those that use elf.sc and have no hint
that they might support both REL and RELA relocs.

* scripttempl/elf.sc (NO_REL_RELOCS, NO_RELA_RELOCS, NON_ALLOC_DYN): Handle these defines.
* emulparams/criself.sh, * emulparams/crislinux.sh,
* emulparams/elf32am33lin.sh, * emulparams/elf32fr30.sh,
* emulparams/elf32_i860.sh, * emulparams/elf32ip2k.sh,
* emulparams/elf32mcore.sh, * emulparams/elf32ppccommon.sh,
* emulparams/elf32ppcwindiss.sh, * emulparams/elf32_sparc.sh,
* emulparams/elf32_spu.sh, * emulparams/elf32vax.sh,
* emulparams/elf64alpha.sh, * emulparams/elf64mmix.sh,
* emulparams/elf64ppc.sh, * emulparams/elf64_s390.sh,
* emulparams/elf64_sparc.sh, * emulparams/elf_s390.sh,
* emulparams/elf_x86_64.sh, * emulparams/h8300elf.sh,
* emulparams/hppa64linux.sh, * emulparams/hppalinux.sh,
* emulparams/m68kelf.sh, * emulparams/mn10200.sh,
* emulparams/pjelf.sh, * emulparams/ppclynx.sh,
* emulparams/shelf32.sh, * emulparams/shelf_nto.sh,
* emulparams/shelf.sh, * emulparams/shelf_vxworks.sh,
* emulparams/shlelf32_linux.sh, * emulparams/shlelf_linux.sh,
* emulparams/shlelf_nto.sh (NO_REL_RELOCS): Set.
* emulparams/arcelf.sh, * emulparams/elf32_i960.sh,
* emulparams/elf32openrisc.sh, * emulparams/elf_i386_be.sh,
* emulparams/elf_i386_ldso.sh, * emulparams/elf_i386.sh,
* emulparams/elf_i386_vxworks.sh, * emulparams/i386lynx.sh,
* emulparams/i386moss.sh, * emulparams/i386nto.sh,
* emulparams/or32elf.sh, * emulparams/scoreelf.sh (NO_RELA_RELOCS): Set.

I've committed the following patch to put this into the elfxtensa.sc scripts.


2008-11-03 Bob Wilson <bob.wilson@acm.org>

	* emulparams/elf32xtensa.sh (NO_REL_RELOCS): Set.
	* scripttempl/elfxtensa.sc (NO_REL_RELOCS, NO_RELA_RELOCS)
	(NON_ALLOC_DYN): Import changes from elf.sc.

Index: emulparams/elf32xtensa.sh
===================================================================
RCS file: /cvs/src/src/ld/emulparams/elf32xtensa.sh,v
retrieving revision 1.12
diff -u -r1.12 elf32xtensa.sh
--- emulparams/elf32xtensa.sh	9 Aug 2007 11:02:24 -0000	1.12
+++ emulparams/elf32xtensa.sh	3 Nov 2008 18:28:51 -0000
@@ -4,6 +4,7 @@
 OUTPUT_FORMAT=undefined
 BIG_OUTPUT_FORMAT="elf32-xtensa-be"
 LITTLE_OUTPUT_FORMAT="elf32-xtensa-le"
+NO_REL_RELOCS=yes
 TEXT_START_ADDR=0x400000
 MAXPAGESIZE="CONSTANT (MAXPAGESIZE)"
 ARCH=xtensa
Index: scripttempl/elfxtensa.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/elfxtensa.sc,v
retrieving revision 1.16
diff -u -r1.16 elfxtensa.sc
--- scripttempl/elfxtensa.sc	18 Jan 2008 22:49:38 -0000	1.16
+++ scripttempl/elfxtensa.sc	3 Nov 2008 18:28:51 -0000
@@ -36,6 +36,9 @@
 #	DATA_PLT - .plt should be in data segment, not text segment.
 #	PLT_BEFORE_GOT - .plt just before .got when .plt is in data segement.
 #	BSS_PLT - .plt should be in bss segment
+#	NO_REL_RELOCS - Don't include .rel.* sections in script
+#	NO_RELA_RELOCS - Don't include .rela.* sections in script
+#	NON_ALLOC_DYN - Place dynamic sections after data segment.
 #	TEXT_DYNAMIC - .dynamic in text segment, not data segment.
 #	EMBEDDED - whether this is for an embedded system. 
 #	SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
@@ -282,6 +285,11 @@
   ${CREATE_PIE+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
   ${INITIAL_READONLY_SECTIONS}
   .note.gnu.build-id : { *(.note.gnu.build-id) }
+EOF
+
+test -n "${RELOCATING+0}" || unset NON_ALLOC_DYN
+test -z "${NON_ALLOC_DYN}" || TEXT_DYNAMIC=
+cat > ldscripts/dyntmp.$$ <<EOF
   ${TEXT_DYNAMIC+${DYNAMIC}}
   .hash         ${RELOCATING-0} : { *(.hash) }
   .gnu.hash     ${RELOCATING-0} : { *(.gnu.hash) }
@@ -290,10 +298,10 @@
   .gnu.version  ${RELOCATING-0} : { *(.gnu.version) }
   .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
   .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
-
 EOF
+
 if [ "x$COMBRELOC" = x ]; then
-  COMBRELOCCAT=cat
+  COMBRELOCCAT="cat >> ldscripts/dyntmp.$$"
 else
   COMBRELOCCAT="cat > $COMBRELOC"
 fi
@@ -330,27 +338,45 @@
   .rela.bss     ${RELOCATING-0} : { *(.rela.bss${RELOCATING+ .rela.bss.* .rela.gnu.linkonce.b.*}) }
   ${REL_LARGE}
 EOF
+
 if [ -n "$COMBRELOC" ]; then
-cat <<EOF
+cat >> ldscripts/dyntmp.$$ <<EOF
   .rel.dyn      ${RELOCATING-0} :
     {
 EOF
-sed -e '/^[ 	]*[{}][ 	]*$/d;/:[ 	]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/      \1/' $COMBRELOC
-cat <<EOF
+sed -e '/^[ 	]*[{}][ 	]*$/d;/:[ 	]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/      \1/' $COMBRELOC >> ldscripts/dyntmp.$$
+cat >> ldscripts/dyntmp.$$ <<EOF
     }
   .rela.dyn     ${RELOCATING-0} :
     {
 EOF
-sed -e '/^[ 	]*[{}][ 	]*$/d;/:[ 	]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/      \1/' $COMBRELOC
-cat <<EOF
+sed -e '/^[ 	]*[{}][ 	]*$/d;/:[ 	]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/      \1/' $COMBRELOC >> ldscripts/dyntmp.$$
+cat >> ldscripts/dyntmp.$$ <<EOF
     }
 EOF
 fi
-cat <<EOF
+
+cat >> ldscripts/dyntmp.$$ <<EOF
   .rel.plt      ${RELOCATING-0} : { *(.rel.plt) }
   .rela.plt     ${RELOCATING-0} : { *(.rela.plt) }
   ${OTHER_PLT_RELOC_SECTIONS}
+EOF
 
+if test -z "${NON_ALLOC_DYN}"; then
+  if test -z "${NO_REL_RELOCS}${NO_RELA_RELOCS}"; then
+    cat ldscripts/dyntmp.$$
+  else
+    if test -z "${NO_REL_RELOCS}"; then
+      sed -e '/^[ 	]*\.rela\.[^}]*$/,/}/d' -e '/^[ 	]*\.rela\./d' ldscripts/dyntmp.$$
+    fi
+    if test -z "${NO_RELA_RELOCS}"; then
+      sed -e '/^[ 	]*\.rel\.[^}]*$/,/}/d' -e '/^[ 	]*\.rel\./d' ldscripts/dyntmp.$$
+    fi
+  fi
+  rm -f ldscripts/dyntmp.$$
+fi
+
+cat <<EOF
   ${RELOCATING-$INIT_LIT}
   ${RELOCATING-$INIT}
 
@@ -484,7 +510,23 @@
   ${RELOCATING+${OTHER_END_SYMBOLS}}
   ${RELOCATING+${END_SYMBOLS-${USER_LABEL_PREFIX}_end = .; PROVIDE (${USER_LABEL_PREFIX}end = .);}}
   ${RELOCATING+${DATA_SEGMENT_END}}
+EOF
 
+if test -n "${NON_ALLOC_DYN}"; then
+  if test -z "${NO_REL_RELOCS}${NO_RELA_RELOCS}"; then
+    cat ldscripts/dyntmp.$$
+  else
+    if test -z "${NO_REL_RELOCS}"; then
+      sed -e '/^[ 	]*\.rela\.[^}]*$/,/}/d' -e '/^[ 	]*\.rela\./d' ldscripts/dyntmp.$$
+    fi
+    if test -z "${NO_RELA_RELOCS}"; then
+      sed -e '/^[ 	]*\.rel\.[^}]*$/,/}/d' -e '/^[ 	]*\.rel\./d' ldscripts/dyntmp.$$
+    fi
+  fi
+  rm -f ldscripts/dyntmp.$$
+fi
+
+cat <<EOF
   /* Stabs debugging sections.  */
   .stab          0 : { *(.stab) }
   .stabstr       0 : { *(.stabstr) }

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