.init/.text/.fini vs. .text/.init/.fini

Geoff Keating geoffk@cygnus.com
Thu Apr 13 16:45:00 GMT 2000


If the .init section is before .text, then when users write
(say) -Ttext=0x70000000, they discover to their surprise that

(a) relocs from .init to .text may now overflow; and
(b) their program now needs more PHDRs than before,
    which results in a very unhelpful error message
    from ld and an unsuccessful link.

because the option just changes the start of the .text section,
and the .init section stays where it was at the default address.

This patch fixes this.  OK to install?

-- 
- Geoffrey Keating <geoffk@cygnus.com>

===File ~/patches/cygnus/rs6000-crtS-elfsc2.patch===========
2000-04-13  Geoff Keating  <geoffk@cygnus.com>

	* scripttempl/elf.sc: Move .init after .text.

Index: elf.sc
===================================================================
RCS file: /cvs/src/src/ld/scripttempl/elf.sc,v
retrieving revision 1.11
diff -p -u -u -p -r1.11 elf.sc
--- elf.sc	2000/04/13 23:38:46	1.11
+++ elf.sc	2000/04/13 23:39:27
@@ -124,8 +124,6 @@ SECTIONS
   .gnu.version_d ${RELOCATING-0} : { *(.gnu.version_d)	}
   .gnu.version_r ${RELOCATING-0} : { *(.gnu.version_r)	}
 
-  .rel.init    ${RELOCATING-0} : { *(.rel.init)	}
-  .rela.init   ${RELOCATING-0} : { *(.rela.init)	}
   .rel.text    ${RELOCATING-0} :
     {
       *(.rel.text)
@@ -138,6 +136,8 @@ SECTIONS
       ${RELOCATING+*(.rela.text.*)}
       ${RELOCATING+*(.rela.gnu.linkonce.t*)}
     }
+  .rel.init    ${RELOCATING-0} : { *(.rel.init)	}
+  .rela.init   ${RELOCATING-0} : { *(.rela.init)	}
   .rel.fini    ${RELOCATING-0} : { *(.rel.fini)	}
   .rela.fini   ${RELOCATING-0} : { *(.rela.fini)	}
   .rel.rodata  ${RELOCATING-0} :
@@ -196,14 +196,9 @@ SECTIONS
   .rela.plt    ${RELOCATING-0} : { *(.rela.plt)		}
   ${OTHER_PLT_RELOC_SECTIONS}
 
-  .init        ${RELOCATING-0} : 
-  { 
-    ${INIT_START}
-    KEEP (*(.init))
-    ${INIT_END}
-  } =${NOP-0}
-
   ${DATA_PLT-${BSS_PLT-${PLT}}}
+  /* .text should be before .init and so on, so that -Ttext=0x1234
+     will work.  */
   .text    ${RELOCATING-0} :
   {
     ${RELOCATING+${TEXT_START_SYMBOLS}}
@@ -214,6 +209,12 @@ SECTIONS
     *(.gnu.warning)
     ${RELOCATING+*(.gnu.linkonce.t*)}
     ${RELOCATING+${OTHER_TEXT_SECTIONS}}
+  } =${NOP-0}
+  .init        ${RELOCATING-0} : 
+  { 
+    ${INIT_START}
+    KEEP (*(.init))
+    ${INIT_END}
   } =${NOP-0}
   .fini    ${RELOCATING-0} :
   {
============================================================


More information about the Binutils mailing list