[binutils-gdb] ELF ld -r scripts

Alan Modra amodra@sourceware.org
Sat Oct 13 12:46:00 GMT 2018


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2bf2bf23da5237f465fdbb759657aeb7825a08a3

commit 2bf2bf23da5237f465fdbb759657aeb7825a08a3
Author: Alan Modra <amodra@gmail.com>
Date:   Fri Oct 12 12:06:40 2018 +1030

    ELF ld -r scripts
    
    "ld -r" generally should not combine object file sections with
    different names.  For example, "ld -r" should not combine ".text",
    ".text.hot" and ".text.cold" into an output ".text" section.  An
    exception needs to be made for linker created sections, for example,
    branch trampoline sections that might be created even for ld -r.
    
    "ld -r" also should not define symbols in linker scripts.  Any
    definitions are likely to conflict with those defined at final link.
    
    A MEMORY spec is also not needed for ld -r.
    
    	* Makefile.am (eelf32btsmip_fbsd.c, eelf32btsmipn32_fbsd.c),
    	(eelf32epiphany.c, eelf32epiphany_4x4.c, eelf32ltsmip_fbsd.c),
    	(eelf32ltsmipn32_fbsd.c, eelf32xc16x.c, eelf32xc16xl.c),
    	(eelf32xc16xs.c, emcorepe.c, enios2elf.c, enios2linux.c),
    	(eelf64btsmip_fbsd.c, eelf64ltsmip_fbsd.c): Correct dependencies.
    	* Makefile.in: Regenerate.
    	* emulparams/aarch64cloudabi.sh, * emulparams/aarch64fbsd.sh,
    	* emulparams/aarch64linux.sh, * emulparams/aarch64linux32.sh,
    	* emulparams/arc-nps.sh, * emulparams/elf32_spu.sh,
    	* emulparams/elf32_tic6x_le.sh, * emulparams/elf32bmip.sh,
    	* emulparams/elf32btsmipn32.sh, * emulparams/elf32lr5900n32.sh,
    	* emulparams/elf32mep.sh, * emulparams/elf32metag.sh,
    	* emulparams/elf64btsmip.sh, * emulparams/shelf_vxworks.sh,
    	* emulparams/shlelf_fd.sh, * scripttempl/DWARF.sc,
    	* scripttempl/alpha.sc, * scripttempl/alphavms.sc,
    	* scripttempl/arclinux.sc, * scripttempl/armbpabi.sc,
    	* scripttempl/avr.sc, * scripttempl/dlx.sc, * scripttempl/elf.sc,
    	* scripttempl/elf32cr16.sc, * scripttempl/elf32cr16c.sc,
    	* scripttempl/elf32crx.sc, * scripttempl/elf32msp430.sc,
    	* scripttempl/elf32msp430_3.sc, * scripttempl/elf32xc16x.sc,
    	* scripttempl/elf32xc16xl.sc, * scripttempl/elf32xc16xs.sc,
    	* scripttempl/elf64hppa.sc, * scripttempl/elf_chaos.sc,
    	* scripttempl/elfarc.sc, * scripttempl/elfarcv2.sc,
    	* scripttempl/elfd10v.sc, * scripttempl/elfd30v.sc,
    	* scripttempl/elfm68hc11.sc, * scripttempl/elfm68hc12.sc,
    	* scripttempl/elfm9s12z.sc, * scripttempl/elfmicroblaze.sc,
    	* scripttempl/elfxgate.sc, * scripttempl/elfxtensa.sc,
    	* scripttempl/epiphany_4x4.sc, * scripttempl/ft32.sc,
    	* scripttempl/hppaelf.sc, * scripttempl/ia64vms.sc,
    	* scripttempl/ip2k.sc, * scripttempl/iq2000.sc,
    	* scripttempl/mep.sc, * scripttempl/mmo.sc,
    	* scripttempl/nds32elf.sc, * scripttempl/pru.sc,
    	* scripttempl/sh.sc, * scripttempl/v850.sc,
    	* scripttempl/v850_rh850.sc, * scripttempl/visium.sc,
    	* scripttempl/xstormy16.sc: Condition various parts of scripts on
    	${RELOCATABLE} in order to prevent ld -r merging sections or
    	defining symbols.  Remove MEMORY and VERSION definitions from
    	ld -r scripts too.
    	* testsuite/ld-elf/group2.d, * testsuite/ld-elf/group4.d,
    	* testsuite/ld-elf/group5.d, * testsuite/ld-elf/group6.d,
    	* testsuite/ld-elf/group7.d, * testsuite/ld-elf/group8a.d,
    	* testsuite/ld-elf/group8b.d, * testsuite/ld-elf/group9a.d,
    	* testsuite/ld-elf/group9b.d, * testsuite/ld-elf/pr17550a.d,
    	* testsuite/ld-elf/pr17550b.d,
    	* testsuite/ld-elf/pr17550d.d: Don't xfail cr16 and crx.
    	* testsuite/ld-elf/init-fini-arrays.d,
    	* testsuite/ld-elf/pr22677.d: Likewise, and dont' xfail mep.

Diff:
---
 ld/ChangeLog                           | 50 +++++++++++++++++++
 ld/Makefile.am                         | 26 ++++++----
 ld/Makefile.in                         | 26 ++++++----
 ld/emulparams/aarch64cloudabi.sh       |  2 +-
 ld/emulparams/aarch64fbsd.sh           |  2 +-
 ld/emulparams/aarch64linux.sh          |  2 +-
 ld/emulparams/aarch64linux32.sh        |  2 +-
 ld/emulparams/arc-nps.sh               |  2 +
 ld/emulparams/elf32_spu.sh             |  4 +-
 ld/emulparams/elf32_tic6x_le.sh        |  4 +-
 ld/emulparams/elf32bmip.sh             |  8 ++--
 ld/emulparams/elf32btsmipn32.sh        |  8 ++--
 ld/emulparams/elf32lr5900n32.sh        |  8 ++--
 ld/emulparams/elf32mep.sh              |  3 ++
 ld/emulparams/elf32metag.sh            |  2 +-
 ld/emulparams/elf64btsmip.sh           |  8 ++--
 ld/emulparams/shelf_vxworks.sh         |  4 +-
 ld/emulparams/shlelf_fd.sh             |  2 +-
 ld/scripttempl/DWARF.sc                |  2 +-
 ld/scripttempl/alpha.sc                | 16 +++----
 ld/scripttempl/alphavms.sc             | 12 ++---
 ld/scripttempl/arclinux.sc             | 44 ++++++++---------
 ld/scripttempl/armbpabi.sc             | 38 ++++++++-------
 ld/scripttempl/avr.sc                  | 68 +++++++++++++-------------
 ld/scripttempl/dlx.sc                  |  6 +--
 ld/scripttempl/elf.sc                  | 88 +++++++++++++++++-----------------
 ld/scripttempl/elf32cr16.sc            | 38 +++++++++------
 ld/scripttempl/elf32cr16c.sc           | 40 +++++++++-------
 ld/scripttempl/elf32crx.sc             |  4 ++
 ld/scripttempl/elf32msp430.sc          | 73 +++++++++++++++-------------
 ld/scripttempl/elf32msp430_3.sc        | 37 ++++++++------
 ld/scripttempl/elf32xc16x.sc           | 16 +++++--
 ld/scripttempl/elf32xc16xl.sc          | 16 +++++--
 ld/scripttempl/elf32xc16xs.sc          | 17 +++++--
 ld/scripttempl/elf64hppa.sc            | 28 +++++------
 ld/scripttempl/elf_chaos.sc            | 28 +++++------
 ld/scripttempl/elfarc.sc               | 52 ++++++++++----------
 ld/scripttempl/elfarcv2.sc             | 25 +++++-----
 ld/scripttempl/elfd10v.sc              | 52 +++++++++++---------
 ld/scripttempl/elfd30v.sc              | 29 ++++++-----
 ld/scripttempl/elfm68hc11.sc           |  7 ++-
 ld/scripttempl/elfm68hc12.sc           |  7 ++-
 ld/scripttempl/elfm9s12z.sc            |  9 ++--
 ld/scripttempl/elfmicroblaze.sc        | 41 ++++++++--------
 ld/scripttempl/elfxgate.sc             |  7 ++-
 ld/scripttempl/elfxtensa.sc            | 26 +++++-----
 ld/scripttempl/epiphany_4x4.sc         | 72 ++++++++++++++--------------
 ld/scripttempl/ft32.sc                 | 26 +++++-----
 ld/scripttempl/hppaelf.sc              | 22 ++++-----
 ld/scripttempl/ia64vms.sc              |  4 ++
 ld/scripttempl/ip2k.sc                 |  3 ++
 ld/scripttempl/iq2000.sc               | 16 +++----
 ld/scripttempl/mep.sc                  | 16 +++----
 ld/scripttempl/mmo.sc                  |  4 +-
 ld/scripttempl/nds32elf.sc             | 36 +++++++-------
 ld/scripttempl/pru.sc                  | 23 +++++----
 ld/scripttempl/sh.sc                   |  8 +++-
 ld/scripttempl/v850.sc                 | 38 +++++++--------
 ld/scripttempl/v850_rh850.sc           | 48 +++++++++----------
 ld/scripttempl/visium.sc               | 25 +++++-----
 ld/scripttempl/xstormy16.sc            | 45 ++++++++---------
 ld/testsuite/ld-elf/group2.d           |  6 +--
 ld/testsuite/ld-elf/group4.d           |  6 +--
 ld/testsuite/ld-elf/group5.d           |  6 +--
 ld/testsuite/ld-elf/group6.d           |  6 +--
 ld/testsuite/ld-elf/group7.d           |  3 --
 ld/testsuite/ld-elf/group8a.d          |  6 +--
 ld/testsuite/ld-elf/group8b.d          |  6 +--
 ld/testsuite/ld-elf/group9a.d          |  6 +--
 ld/testsuite/ld-elf/group9b.d          |  6 +--
 ld/testsuite/ld-elf/init-fini-arrays.d |  4 --
 ld/testsuite/ld-elf/pr17550a.d         |  4 +-
 ld/testsuite/ld-elf/pr17550b.d         |  4 +-
 ld/testsuite/ld-elf/pr17550d.d         |  6 +--
 ld/testsuite/ld-elf/pr22677.d          |  7 +--
 75 files changed, 791 insertions(+), 660 deletions(-)

diff --git a/ld/ChangeLog b/ld/ChangeLog
index 3580a2b..0f28a2e 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,53 @@
+2018-10-13  Alan Modra  <amodra@gmail.com>
+
+	* Makefile.am (eelf32btsmip_fbsd.c, eelf32btsmipn32_fbsd.c),
+	(eelf32epiphany.c, eelf32epiphany_4x4.c, eelf32ltsmip_fbsd.c),
+	(eelf32ltsmipn32_fbsd.c, eelf32xc16x.c, eelf32xc16xl.c),
+	(eelf32xc16xs.c, emcorepe.c, enios2elf.c, enios2linux.c),
+	(eelf64btsmip_fbsd.c, eelf64ltsmip_fbsd.c): Correct dependencies.
+	* Makefile.in: Regenerate.
+	* emulparams/aarch64cloudabi.sh, * emulparams/aarch64fbsd.sh,
+	* emulparams/aarch64linux.sh, * emulparams/aarch64linux32.sh,
+	* emulparams/arc-nps.sh, * emulparams/elf32_spu.sh,
+	* emulparams/elf32_tic6x_le.sh, * emulparams/elf32bmip.sh,
+	* emulparams/elf32btsmipn32.sh, * emulparams/elf32lr5900n32.sh,
+	* emulparams/elf32mep.sh, * emulparams/elf32metag.sh,
+	* emulparams/elf64btsmip.sh, * emulparams/shelf_vxworks.sh,
+	* emulparams/shlelf_fd.sh, * scripttempl/DWARF.sc,
+	* scripttempl/alpha.sc, * scripttempl/alphavms.sc,
+	* scripttempl/arclinux.sc, * scripttempl/armbpabi.sc,
+	* scripttempl/avr.sc, * scripttempl/dlx.sc, * scripttempl/elf.sc,
+	* scripttempl/elf32cr16.sc, * scripttempl/elf32cr16c.sc,
+	* scripttempl/elf32crx.sc, * scripttempl/elf32msp430.sc,
+	* scripttempl/elf32msp430_3.sc, * scripttempl/elf32xc16x.sc,
+	* scripttempl/elf32xc16xl.sc, * scripttempl/elf32xc16xs.sc,
+	* scripttempl/elf64hppa.sc, * scripttempl/elf_chaos.sc,
+	* scripttempl/elfarc.sc, * scripttempl/elfarcv2.sc,
+	* scripttempl/elfd10v.sc, * scripttempl/elfd30v.sc,
+	* scripttempl/elfm68hc11.sc, * scripttempl/elfm68hc12.sc,
+	* scripttempl/elfm9s12z.sc, * scripttempl/elfmicroblaze.sc,
+	* scripttempl/elfxgate.sc, * scripttempl/elfxtensa.sc,
+	* scripttempl/epiphany_4x4.sc, * scripttempl/ft32.sc,
+	* scripttempl/hppaelf.sc, * scripttempl/ia64vms.sc,
+	* scripttempl/ip2k.sc, * scripttempl/iq2000.sc,
+	* scripttempl/mep.sc, * scripttempl/mmo.sc,
+	* scripttempl/nds32elf.sc, * scripttempl/pru.sc,
+	* scripttempl/sh.sc, * scripttempl/v850.sc,
+	* scripttempl/v850_rh850.sc, * scripttempl/visium.sc,
+	* scripttempl/xstormy16.sc: Condition various parts of scripts on
+	${RELOCATABLE} in order to prevent ld -r merging sections or
+	defining symbols.  Remove MEMORY and VERSION definitions from
+	ld -r scripts too.
+	* testsuite/ld-elf/group2.d, * testsuite/ld-elf/group4.d,
+	* testsuite/ld-elf/group5.d, * testsuite/ld-elf/group6.d,
+	* testsuite/ld-elf/group7.d, * testsuite/ld-elf/group8a.d,
+	* testsuite/ld-elf/group8b.d, * testsuite/ld-elf/group9a.d,
+	* testsuite/ld-elf/group9b.d, * testsuite/ld-elf/pr17550a.d,
+	* testsuite/ld-elf/pr17550b.d,
+	* testsuite/ld-elf/pr17550d.d: Don't xfail cr16 and crx.
+	* testsuite/ld-elf/init-fini-arrays.d,
+	* testsuite/ld-elf/pr22677.d: Likewise, and dont' xfail mep.
+
 2018-10-08  H.J. Lu  <hongjiu.lu@intel.com>
 
 	PR ld/23428
diff --git a/ld/Makefile.am b/ld/Makefile.am
index 9884110..98ba096 100644
--- a/ld/Makefile.am
+++ b/ld/Makefile.am
@@ -990,6 +990,7 @@ eelf32btsmip.c: $(srcdir)/emulparams/elf32btsmip.sh \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
 eelf32btsmip_fbsd.c: $(srcdir)/emulparams/elf32btsmip_fbsd.sh \
+  ${srcdir}/emulparams/elf32btsmip.sh ${srcdir}/emulparams/elf_fbsd.sh \
   $(srcdir)/emulparams/elf32bmip.sh $(ELF_DEPS) \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
@@ -998,6 +999,8 @@ eelf32btsmipn32.c: $(srcdir)/emulparams/elf32btsmipn32.sh \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
 eelf32btsmipn32_fbsd.c: $(srcdir)/emulparams/elf32btsmipn32_fbsd.sh \
+  ${srcdir}/emulparams/elf32ltsmipn32.sh ${srcdir}/emulparams/elf_fbsd.sh \
+  ${srcdir}/emulparams/elf32btsmipn32.sh \
   $(srcdir)/emulparams/elf32bmipn32-defs.sh $(ELF_DEPS) \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
@@ -1042,10 +1045,9 @@ eelf32lr5900n32.c: $(srcdir)/emulparams/elf32lr5900n32.sh \
   ${GEN_DEPENDS}
 
 eelf32epiphany.c: $(srcdir)/emulparams/elf32epiphany.sh \
-  $(ELF_DEPS) ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
 eelf32epiphany_4x4.c: $(srcdir)/emulparams/elf32epiphany_4x4.sh \
-  $(srcdir)/emultempl/elf32.em \
   $(ELF_DEPS) $(srcdir)/scripttempl/epiphany_4x4.sc ${GEN_DEPENDS}
 
 eelf32fr30.c: $(srcdir)/emulparams/elf32fr30.sh \
@@ -1059,7 +1061,7 @@ eelf32frvfd.c: $(srcdir)/emulparams/elf32frvfd.sh \
   $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
 eelf32ft32.c: $(srcdir)/emulparams/elf32ft32.sh \
-  $(ELF_GEN_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_GEN_DEPS) $(srcdir)/scripttempl/ft32.sc ${GEN_DEPENDS}
 
 eelf32ip2k.c: $(srcdir)/emulparams/elf32ip2k.sh \
   $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
@@ -1139,6 +1141,7 @@ eelf32ltsmip.c: $(srcdir)/emulparams/elf32ltsmip.sh \
   ${GEN_DEPENDS}
 
 eelf32ltsmip_fbsd.c: $(srcdir)/emulparams/elf32ltsmip_fbsd.sh \
+  ${srcdir}/emulparams/elf32ltsmip.sh ${srcdir}/emulparams/elf_fbsd.sh \
   $(srcdir)/emulparams/elf32btsmip.sh $(srcdir)/emulparams/elf32bmip.sh \
   $(ELF_DEPS) $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc \
   ${GEN_DEPENDS}
@@ -1149,6 +1152,7 @@ eelf32ltsmipn32.c: $(srcdir)/emulparams/elf32ltsmipn32.sh \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
 eelf32ltsmipn32_fbsd.c: $(srcdir)/emulparams/elf32ltsmipn32_fbsd.sh \
+  ${srcdir}/emulparams/elf32ltsmipn32.sh ${srcdir}/emulparams/elf_fbsd.sh \
   $(srcdir)/emulparams/elf32btsmipn32.sh \
   $(srcdir)/emulparams/elf32bmipn32-defs.sh $(ELF_DEPS) \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
@@ -1263,15 +1267,15 @@ eelf32visium.c: $(srcdir)/emulparams/elf32visium.sh \
 
 eelf32xc16x.c: $(srcdir)/emulparams/elf32xc16x.sh \
   $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
-  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/scripttempl/elf32xc16x.sc ${GEN_DEPENDS}
 
 eelf32xc16xl.c: $(srcdir)/emulparams/elf32xc16xl.sh \
   $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
-  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/scripttempl/elf32xc16xl.sc ${GEN_DEPENDS}
 
 eelf32xc16xs.c: $(srcdir)/emulparams/elf32xc16xs.sh \
   $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
-  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/scripttempl/elf32xc16xs.sc ${GEN_DEPENDS}
 
 eelf32xstormy16.c: $(srcdir)/emulparams/elf32xstormy16.sh \
   $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
@@ -1449,7 +1453,7 @@ em9s12zelf.c: $(srcdir)/emulparams/m9s12zelf.sh \
   $(srcdir)/scripttempl/elfm9s12z.sc ${GEN_DEPENDS}
 
 emcorepe.c: $(srcdir)/emulparams/mcorepe.sh \
-  $(srcdir)/emultempl/pe.em $(srcdir)/scripttempl/pe.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/pe.em $(srcdir)/scripttempl/mcorepe.sc ${GEN_DEPENDS}
 
 emn10200.c: $(srcdir)/emulparams/mn10200.sh \
   $(ELF_GEN_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
@@ -1492,11 +1496,11 @@ ends32belf_linux.c: $(srcdir)/emulparams/nds32belf_linux.sh \
 
 enios2elf.c: $(srcdir)/emulparams/nios2elf.sh \
   $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/nios2elf.em \
-  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/scripttempl/elf.sc $(srcdir)/scripttempl/DWARF.sc ${GEN_DEPENDS}
 
 enios2linux.c: $(srcdir)/emulparams/nios2linux.sh \
   $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/nios2elf.em \
-  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/scripttempl/elf.sc $(srcdir)/scripttempl/DWARF.sc ${GEN_DEPENDS}
 
 ens32knbsd.c:	$(srcdir)/emulparams/ns32knbsd.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/netbsd.em \
@@ -1758,6 +1762,7 @@ eelf64btsmip.c: $(srcdir)/emulparams/elf64btsmip.sh \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
 eelf64btsmip_fbsd.c: $(srcdir)/emulparams/elf64btsmip_fbsd.sh \
+  ${srcdir}/emulparams/elf64btsmip.sh ${srcdir}/emulparams/elf_fbsd.sh \
   $(srcdir)/emulparams/elf64bmip-defs.sh \
   $(srcdir)/emulparams/elf32bmipn32-defs.sh $(ELF_DEPS) \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
@@ -1795,7 +1800,8 @@ eelf64ltsmip.c: $(srcdir)/emulparams/elf64ltsmip.sh \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
 eelf64ltsmip_fbsd.c: $(srcdir)/emulparams/elf64ltsmip_fbsd.sh \
-  $(srcdir)/emulparams/elf64btsmip_fbsd.sh $(srcdir)/emulparams/elf64bmip-defs.sh \
+  ${srcdir}/emulparams/elf64ltsmip.sh ${srcdir}/emulparams/elf_fbsd.sh \
+  $(srcdir)/emulparams/elf64btsmip.sh $(srcdir)/emulparams/elf64bmip-defs.sh \
   $(srcdir)/emulparams/elf32bmipn32-defs.sh $(ELF_DEPS) \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
diff --git a/ld/Makefile.in b/ld/Makefile.in
index 3ddd581..e2fc674 100644
--- a/ld/Makefile.in
+++ b/ld/Makefile.in
@@ -2594,6 +2594,7 @@ eelf32btsmip.c: $(srcdir)/emulparams/elf32btsmip.sh \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
 eelf32btsmip_fbsd.c: $(srcdir)/emulparams/elf32btsmip_fbsd.sh \
+  ${srcdir}/emulparams/elf32btsmip.sh ${srcdir}/emulparams/elf_fbsd.sh \
   $(srcdir)/emulparams/elf32bmip.sh $(ELF_DEPS) \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
@@ -2602,6 +2603,8 @@ eelf32btsmipn32.c: $(srcdir)/emulparams/elf32btsmipn32.sh \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
 eelf32btsmipn32_fbsd.c: $(srcdir)/emulparams/elf32btsmipn32_fbsd.sh \
+  ${srcdir}/emulparams/elf32ltsmipn32.sh ${srcdir}/emulparams/elf_fbsd.sh \
+  ${srcdir}/emulparams/elf32btsmipn32.sh \
   $(srcdir)/emulparams/elf32bmipn32-defs.sh $(ELF_DEPS) \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
@@ -2646,10 +2649,9 @@ eelf32lr5900n32.c: $(srcdir)/emulparams/elf32lr5900n32.sh \
   ${GEN_DEPENDS}
 
 eelf32epiphany.c: $(srcdir)/emulparams/elf32epiphany.sh \
-  $(ELF_DEPS) ${GEN_DEPENDS}
+  $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
 eelf32epiphany_4x4.c: $(srcdir)/emulparams/elf32epiphany_4x4.sh \
-  $(srcdir)/emultempl/elf32.em \
   $(ELF_DEPS) $(srcdir)/scripttempl/epiphany_4x4.sc ${GEN_DEPENDS}
 
 eelf32fr30.c: $(srcdir)/emulparams/elf32fr30.sh \
@@ -2663,7 +2665,7 @@ eelf32frvfd.c: $(srcdir)/emulparams/elf32frvfd.sh \
   $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
 eelf32ft32.c: $(srcdir)/emulparams/elf32ft32.sh \
-  $(ELF_GEN_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(ELF_GEN_DEPS) $(srcdir)/scripttempl/ft32.sc ${GEN_DEPENDS}
 
 eelf32ip2k.c: $(srcdir)/emulparams/elf32ip2k.sh \
   $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
@@ -2743,6 +2745,7 @@ eelf32ltsmip.c: $(srcdir)/emulparams/elf32ltsmip.sh \
   ${GEN_DEPENDS}
 
 eelf32ltsmip_fbsd.c: $(srcdir)/emulparams/elf32ltsmip_fbsd.sh \
+  ${srcdir}/emulparams/elf32ltsmip.sh ${srcdir}/emulparams/elf_fbsd.sh \
   $(srcdir)/emulparams/elf32btsmip.sh $(srcdir)/emulparams/elf32bmip.sh \
   $(ELF_DEPS) $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc \
   ${GEN_DEPENDS}
@@ -2753,6 +2756,7 @@ eelf32ltsmipn32.c: $(srcdir)/emulparams/elf32ltsmipn32.sh \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
 eelf32ltsmipn32_fbsd.c: $(srcdir)/emulparams/elf32ltsmipn32_fbsd.sh \
+  ${srcdir}/emulparams/elf32ltsmipn32.sh ${srcdir}/emulparams/elf_fbsd.sh \
   $(srcdir)/emulparams/elf32btsmipn32.sh \
   $(srcdir)/emulparams/elf32bmipn32-defs.sh $(ELF_DEPS) \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
@@ -2867,15 +2871,15 @@ eelf32visium.c: $(srcdir)/emulparams/elf32visium.sh \
 
 eelf32xc16x.c: $(srcdir)/emulparams/elf32xc16x.sh \
   $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
-  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/scripttempl/elf32xc16x.sc ${GEN_DEPENDS}
 
 eelf32xc16xl.c: $(srcdir)/emulparams/elf32xc16xl.sh \
   $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
-  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/scripttempl/elf32xc16xl.sc ${GEN_DEPENDS}
 
 eelf32xc16xs.c: $(srcdir)/emulparams/elf32xc16xs.sh \
   $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
-  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/scripttempl/elf32xc16xs.sc ${GEN_DEPENDS}
 
 eelf32xstormy16.c: $(srcdir)/emulparams/elf32xstormy16.sh \
   $(ELF_DEPS) $(srcdir)/emultempl/needrelax.em \
@@ -3053,7 +3057,7 @@ em9s12zelf.c: $(srcdir)/emulparams/m9s12zelf.sh \
   $(srcdir)/scripttempl/elfm9s12z.sc ${GEN_DEPENDS}
 
 emcorepe.c: $(srcdir)/emulparams/mcorepe.sh \
-  $(srcdir)/emultempl/pe.em $(srcdir)/scripttempl/pe.sc ${GEN_DEPENDS}
+  $(srcdir)/emultempl/pe.em $(srcdir)/scripttempl/mcorepe.sc ${GEN_DEPENDS}
 
 emn10200.c: $(srcdir)/emulparams/mn10200.sh \
   $(ELF_GEN_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
@@ -3096,11 +3100,11 @@ ends32belf_linux.c: $(srcdir)/emulparams/nds32belf_linux.sh \
 
 enios2elf.c: $(srcdir)/emulparams/nios2elf.sh \
   $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/nios2elf.em \
-  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/scripttempl/elf.sc $(srcdir)/scripttempl/DWARF.sc ${GEN_DEPENDS}
 
 enios2linux.c: $(srcdir)/emulparams/nios2linux.sh \
   $(srcdir)/emultempl/elf32.em $(srcdir)/emultempl/nios2elf.em \
-  $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
+  $(srcdir)/scripttempl/elf.sc $(srcdir)/scripttempl/DWARF.sc ${GEN_DEPENDS}
 
 ens32knbsd.c:	$(srcdir)/emulparams/ns32knbsd.sh \
   $(srcdir)/emultempl/generic.em $(srcdir)/emultempl/netbsd.em \
@@ -3362,6 +3366,7 @@ eelf64btsmip.c: $(srcdir)/emulparams/elf64btsmip.sh \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
 eelf64btsmip_fbsd.c: $(srcdir)/emulparams/elf64btsmip_fbsd.sh \
+  ${srcdir}/emulparams/elf64btsmip.sh ${srcdir}/emulparams/elf_fbsd.sh \
   $(srcdir)/emulparams/elf64bmip-defs.sh \
   $(srcdir)/emulparams/elf32bmipn32-defs.sh $(ELF_DEPS) \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
@@ -3399,7 +3404,8 @@ eelf64ltsmip.c: $(srcdir)/emulparams/elf64ltsmip.sh \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
 eelf64ltsmip_fbsd.c: $(srcdir)/emulparams/elf64ltsmip_fbsd.sh \
-  $(srcdir)/emulparams/elf64btsmip_fbsd.sh $(srcdir)/emulparams/elf64bmip-defs.sh \
+  ${srcdir}/emulparams/elf64ltsmip.sh ${srcdir}/emulparams/elf_fbsd.sh \
+  $(srcdir)/emulparams/elf64btsmip.sh $(srcdir)/emulparams/elf64bmip-defs.sh \
   $(srcdir)/emulparams/elf32bmipn32-defs.sh $(ELF_DEPS) \
   $(srcdir)/emultempl/mipself.em $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
 
diff --git a/ld/emulparams/aarch64cloudabi.sh b/ld/emulparams/aarch64cloudabi.sh
index 1b8ca15..983a92b 100644
--- a/ld/emulparams/aarch64cloudabi.sh
+++ b/ld/emulparams/aarch64cloudabi.sh
@@ -34,4 +34,4 @@ OTHER_END_SYMBOLS="${CREATE_SHLIB+PROVIDE (}__end__ = .${CREATE_SHLIB+)};"
 OTHER_SECTIONS='.note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }'
 ATTRS_SECTIONS='.ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }'
 # Ensure each PLT entry is aligned to a cache line.
-PLT=".plt          ${RELOCATING-0} : ALIGN(16) { *(.plt)${IREL_IN_PLT+ *(.iplt)} }"
+PLT=".plt          ${RELOCATING-0} : ALIGN(16) { *(.plt)${RELOCATING+${IREL_IN_PLT+ *(.iplt)}} }"
diff --git a/ld/emulparams/aarch64fbsd.sh b/ld/emulparams/aarch64fbsd.sh
index 4a307cd..3a7a2e1 100644
--- a/ld/emulparams/aarch64fbsd.sh
+++ b/ld/emulparams/aarch64fbsd.sh
@@ -34,4 +34,4 @@ OTHER_END_SYMBOLS="${CREATE_SHLIB+PROVIDE (}__end__ = .${CREATE_SHLIB+)};"
 OTHER_SECTIONS='.note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }'
 ATTRS_SECTIONS='.ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }'
 # Ensure each PLT entry is aligned to a cache line.
-PLT=".plt          ${RELOCATING-0} : ALIGN(16) { *(.plt)${IREL_IN_PLT+ *(.iplt)} }"
+PLT=".plt          ${RELOCATING-0} : ALIGN(16) { *(.plt)${RELOCATING+${IREL_IN_PLT+ *(.iplt)}} }"
diff --git a/ld/emulparams/aarch64linux.sh b/ld/emulparams/aarch64linux.sh
index 2ba1d79..5df6ae1 100644
--- a/ld/emulparams/aarch64linux.sh
+++ b/ld/emulparams/aarch64linux.sh
@@ -34,7 +34,7 @@ OTHER_END_SYMBOLS="${CREATE_SHLIB+PROVIDE (}__end__ = .${CREATE_SHLIB+)};"
 OTHER_SECTIONS='.note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }'
 ATTRS_SECTIONS='.ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }'
 # Ensure each PLT entry is aligned to a cache line.
-PLT=".plt          ${RELOCATING-0} : ALIGN(16) { *(.plt)${IREL_IN_PLT+ *(.iplt)} }"
+PLT=".plt          ${RELOCATING-0} : ALIGN(16) { *(.plt)${RELOCATING+${IREL_IN_PLT+ *(.iplt)}} }"
 
 # Linux modifies the default library search path to first include
 # a 64-bit specific directory.
diff --git a/ld/emulparams/aarch64linux32.sh b/ld/emulparams/aarch64linux32.sh
index 0b4d4c9..3c60de0 100644
--- a/ld/emulparams/aarch64linux32.sh
+++ b/ld/emulparams/aarch64linux32.sh
@@ -34,7 +34,7 @@ OTHER_END_SYMBOLS="${CREATE_SHLIB+PROVIDE (}__end__ = .${CREATE_SHLIB+)};"
 OTHER_SECTIONS='.note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }'
 ATTRS_SECTIONS='.ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }'
 # Ensure each PLT entry is aligned to a cache line.
-PLT=".plt          ${RELOCATING-0} : ALIGN(16) { *(.plt)${IREL_IN_PLT+ *(.iplt)} }"
+PLT=".plt          ${RELOCATING-0} : ALIGN(16) { *(.plt)${RELOCATING+${IREL_IN_PLT+ *(.iplt)}} }"
 
 # Linux modifies the default library search path to first include
 # a 32-bit specific directory.
diff --git a/ld/emulparams/arc-nps.sh b/ld/emulparams/arc-nps.sh
index 615e6d5..ecca2fe 100644
--- a/ld/emulparams/arc-nps.sh
+++ b/ld/emulparams/arc-nps.sh
@@ -1,3 +1,4 @@
+if test -n "${RELOCATING}"; then
 OTHER_SECTIONS="
   /* Start of symbols and sections required to support CMEM instructions
      on NPS targets.  */
@@ -76,3 +77,4 @@ OTHER_SECTIONS="
   /* End of nps specific sections and symbols.  */
 
   ${OTHER_SECTIONS}"
+fi
diff --git a/ld/emulparams/elf32_spu.sh b/ld/emulparams/elf32_spu.sh
index 6993ca7..235455f 100644
--- a/ld/emulparams/elf32_spu.sh
+++ b/ld/emulparams/elf32_spu.sh
@@ -19,9 +19,9 @@ MAXPAGESIZE=0x80
 DATA_ADDR="ALIGN(${MAXPAGESIZE})"
 OTHER_BSS_SECTIONS=".toe ALIGN(128) : { *(.toe) } = 0"
 OTHER_SECTIONS=".note.spu_name 0 : { KEEP(*(.note.spu_name)) }
-  ._ea 0 : { KEEP(*(._ea)) KEEP(*(._ea.*)) }"
+  ._ea 0 : { KEEP(*(._ea))${RELOCATING+ KEEP(*(._ea.*))} }"
 OTHER_READONLY_SECTIONS="
   .fixup ${RELOCATING-0} : {
-    PROVIDE (__fixup_start = .);
+    ${RELOCATING+PROVIDE (__fixup_start = .);}
     KEEP(*(.fixup))
   }"
diff --git a/ld/emulparams/elf32_tic6x_le.sh b/ld/emulparams/elf32_tic6x_le.sh
index d9ebe58..62ea9eb 100644
--- a/ld/emulparams/elf32_tic6x_le.sh
+++ b/ld/emulparams/elf32_tic6x_le.sh
@@ -15,8 +15,8 @@ case ${target} in
 	TEXT_START_ADDR=0x0
 	GOT="
 .got ${RELOCATING-0} : {
-  *(.dsbt)
-  *(.got.plt) *(.igot.plt) *(.got) *(.igot)
+  ${RELOCATING+*(.dsbt)
+  *(.got.plt) *(.igot.plt) }*(.got)${RELOCATING+ *(.igot)}
 }"
 	;;
 esac
diff --git a/ld/emulparams/elf32bmip.sh b/ld/emulparams/elf32bmip.sh
index da5e7fb..abbcb5b 100644
--- a/ld/emulparams/elf32bmip.sh
+++ b/ld/emulparams/elf32bmip.sh
@@ -58,9 +58,9 @@ OTHER_SDATA_SECTIONS="
 TEXT_START_SYMBOLS="${CREATE_SHLIB+PROVIDE (}_ftext = .${CREATE_SHLIB+)};"
 DATA_START_SYMBOLS="${CREATE_SHLIB+PROVIDE (}_fdata = .${CREATE_SHLIB+)};"
 OTHER_BSS_SYMBOLS="${CREATE_SHLIB+PROVIDE (}_fbss = .${CREATE_SHLIB+)};"
-OTHER_SECTIONS='
-  .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }
-  .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }
+OTHER_SECTIONS="
+  .gptab.sdata : {${RELOCATING+ *(.gptab.data)} *(.gptab.sdata) }
+  .gptab.sbss : {${RELOCATING+ *(.gptab.bss)} *(.gptab.sbss) }
   .mdebug.abi32 0 : { KEEP(*(.mdebug.abi32)) }
   .mdebug.abiN32 0 : { KEEP(*(.mdebug.abiN32)) }
   .mdebug.abi64 0 : { KEEP(*(.mdebug.abi64)) }
@@ -69,7 +69,7 @@ OTHER_SECTIONS='
   .mdebug.eabi64 0 : { KEEP(*(.mdebug.eabi64)) }
   .gcc_compiled_long32 0 : { KEEP(*(.gcc_compiled_long32)) }
   .gcc_compiled_long64 0 : { KEEP(*(.gcc_compiled_long64)) }
-'
+"
 ARCH=mips
 MACHINE=
 TEMPLATE_NAME=elf32
diff --git a/ld/emulparams/elf32btsmipn32.sh b/ld/emulparams/elf32btsmipn32.sh
index 10c5565..5fc325f 100644
--- a/ld/emulparams/elf32btsmipn32.sh
+++ b/ld/emulparams/elf32btsmipn32.sh
@@ -9,7 +9,7 @@ COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
 
 # Magic sections.
 OTHER_TEXT_SECTIONS='*(.mips16.fn.*) *(.mips16.call.*)'
-OTHER_SECTIONS='
-  .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }
-  .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }
-'
+OTHER_SECTIONS="
+  .gptab.sdata : {${RELOCATING+ *(.gptab.data)} *(.gptab.sdata) }
+  .gptab.sbss : {${RELOCATING+ *(.gptab.bss)} *(.gptab.sbss) }
+"
diff --git a/ld/emulparams/elf32lr5900n32.sh b/ld/emulparams/elf32lr5900n32.sh
index 69f7afb..7a3c6d7 100644
--- a/ld/emulparams/elf32lr5900n32.sh
+++ b/ld/emulparams/elf32lr5900n32.sh
@@ -12,10 +12,10 @@ EMBEDDED=yes
 DYNAMIC_LINK=FALSE
 
 OTHER_TEXT_SECTIONS='*(.mips16.fn.*) *(.mips16.call.*)'
-OTHER_SECTIONS='
-  .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }
-  .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }
-'
+OTHER_SECTIONS="
+  .gptab.sdata : {${RELOCATING+ *(.gptab.data)} *(.gptab.sdata) }
+  .gptab.sbss : {${RELOCATING+ *(.gptab.bss)} *(.gptab.sbss) }
+"
 
 unset DATA_ADDR
 SHLIB_TEXT_START_ADDR=0
diff --git a/ld/emulparams/elf32mep.sh b/ld/emulparams/elf32mep.sh
index 2ebbda1..7d93aba 100644
--- a/ld/emulparams/elf32mep.sh
+++ b/ld/emulparams/elf32mep.sh
@@ -7,6 +7,8 @@ MAXPAGESIZE=256
 ENTRY=_start
 EMBEDDED=yes
 TEMPLATE_NAME=elf32
+
+if test -n "${RELOCATING}"; then
 DATA_START_SYMBOLS='__data_start = . ;'
 OTHER_GOT_SYMBOLS='
   . = ALIGN(4);
@@ -53,3 +55,4 @@ OTHER_BSS_SECTIONS='
   __assert_near_size = ASSERT (. <= 0x1000000, "near section overflow");
   .farbss : { PROVIDE (__farbss_start = .); *(.farbss) *(.farbss.*) PROVIDE (__farbss_end = .); }
 '
+fi
diff --git a/ld/emulparams/elf32metag.sh b/ld/emulparams/elf32metag.sh
index 2a1d072..9d71d7a 100644
--- a/ld/emulparams/elf32metag.sh
+++ b/ld/emulparams/elf32metag.sh
@@ -12,7 +12,7 @@ ENTRY=__start
 NOP=0xa0fffffe
 EXTRA_EM_FILE=metagelf
 USER_LABEL_PREFIX=_
-OTHER_SECTIONS="
+test -n "${RELOCATING}" && OTHER_SECTIONS="
   .core_text 0x80000000	:
   {
     *(.core_text)
diff --git a/ld/emulparams/elf64btsmip.sh b/ld/emulparams/elf64btsmip.sh
index b9e80bb..202585f 100644
--- a/ld/emulparams/elf64btsmip.sh
+++ b/ld/emulparams/elf64btsmip.sh
@@ -8,9 +8,9 @@ LITTLE_OUTPUT_FORMAT="elf64-tradlittlemips"
 
 # Magic sections.
 OTHER_TEXT_SECTIONS='*(.mips16.fn.*) *(.mips16.call.*)'
-OTHER_SECTIONS='
-  .gptab.sdata : { *(.gptab.data) *(.gptab.sdata) }
-  .gptab.sbss : { *(.gptab.bss) *(.gptab.sbss) }
-'
+OTHER_SECTIONS="
+  .gptab.sdata : {${RELOCATING+ *(.gptab.data)} *(.gptab.sdata) }
+  .gptab.sbss : {${RELOCATING+ *(.gptab.bss)} *(.gptab.sbss) }
+"
 
 TEXT_START_ADDR="0x120000000"
diff --git a/ld/emulparams/shelf_vxworks.sh b/ld/emulparams/shelf_vxworks.sh
index c450990..4b82e36 100644
--- a/ld/emulparams/shelf_vxworks.sh
+++ b/ld/emulparams/shelf_vxworks.sh
@@ -16,6 +16,6 @@ ENTRY=__start
 SYMPREFIX=_
 
 GOT=".got          ${RELOCATING-0} : {
-  PROVIDE(__GLOBAL_OFFSET_TABLE_ = .);
-  *(.got.plt) *(.got) }"
+  ${RELOCATING+PROVIDE(__GLOBAL_OFFSET_TABLE_ = .);
+  *(.got.plt) }*(.got) }"
 . ${srcdir}/emulparams/vxworks.sh
diff --git a/ld/emulparams/shlelf_fd.sh b/ld/emulparams/shlelf_fd.sh
index f1f4107..cf827e5 100644
--- a/ld/emulparams/shlelf_fd.sh
+++ b/ld/emulparams/shlelf_fd.sh
@@ -3,7 +3,7 @@
 
 . ${srcdir}/emulparams/shlelf_linux.sh
 OUTPUT_FORMAT="elf32-sh-fdpic"
-GOT=".got          ${RELOCATING-0} : { *(.got.funcdesc) *(.got.plt) *(.got) }"
+GOT=".got          ${RELOCATING-0} : {${RELOCATING+ *(.got.funcdesc) *(.got.plt)} *(.got) }"
 OTHER_GOT_RELOC_SECTIONS="
   .rela.got.funcdesc      ${RELOCATING-0} : { *(.rela.got.funcdesc) }
 "
diff --git a/ld/scripttempl/DWARF.sc b/ld/scripttempl/DWARF.sc
index f8b6f22..e6396ec 100644
--- a/ld/scripttempl/DWARF.sc
+++ b/ld/scripttempl/DWARF.sc
@@ -24,7 +24,7 @@ cat <<EOF
   /* DWARF 2 */
   .debug_info     0 : { *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*}) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
-  .debug_line     0 : { *(.debug_line .debug_line.* .debug_line_end ) }
+  .debug_line     0 : { *(.debug_line${RELOCATING+ .debug_line.* .debug_line_end}) }
   .debug_frame    0 : { *(.debug_frame) }
   .debug_str      0 : { *(.debug_str) }
   .debug_loc      0 : { *(.debug_loc) }
diff --git a/ld/scripttempl/alpha.sc b/ld/scripttempl/alpha.sc
index 245838c..5f3a8bf 100644
--- a/ld/scripttempl/alpha.sc
+++ b/ld/scripttempl/alpha.sc
@@ -32,16 +32,16 @@ SECTIONS
 {
   ${RELOCATING+. = ${TEXT_START_ADDR};}
   .text : {
-    ${RELOCATING+ _ftext = . };
-    ${RELOCATING+ __istart = . };
-    ${RELOCATING+ *(.init) }
+    ${RELOCATING+ _ftext = .;}
+    ${RELOCATING+ __istart = .;}
+    ${RELOCATING+ *(.init)}
     ${RELOCATING+ LONG (0x6bfa8001)}
-    ${RELOCATING+ eprol  =  .};
+    ${RELOCATING+ eprol = .;}
     *(.text)
-    ${RELOCATING+ __fstart = . };
+    ${RELOCATING+ __fstart = .;}
     ${RELOCATING+ *(.fini)}
     ${RELOCATING+ LONG (0x6bfa8001)}
-    ${RELOCATING+ _etext  =  .};
+    ${RELOCATING+ _etext = .;}
   }
   .rdata : {
     *(.rdata)
@@ -76,11 +76,11 @@ SECTIONS
   ${RELOCATING+ _FBSS = .;}
   .sbss : {
     *(.sbss)
-    *(.scommon)
+    ${RELOCATING+*(.scommon)}
   }
   .bss : {
     *(.bss)
-    *(COMMON)
+    ${RELOCATING+*(COMMON)}
   }
   ${RELOCATING+ _end = .;}
 }
diff --git a/ld/scripttempl/alphavms.sc b/ld/scripttempl/alphavms.sc
index 764cc3d..f681899 100644
--- a/ld/scripttempl/alphavms.sc
+++ b/ld/scripttempl/alphavms.sc
@@ -33,13 +33,13 @@ SECTIONS
   }
   /* RO, executable code.  */
   \$CODE\$ ALIGN (${PAGESIZE}) : {
-    *(\$CODE\$ *\$CODE*)
+    *(\$CODE\$${RELOCATING+ *\$CODE*})
   }
   /* RO initialized data.  */
   \$LITERAL\$ ALIGN (${PAGESIZE}) : {
-    *(\$LINK\$)
+    ${RELOCATING+*(\$LINK\$)}
     *(\$LITERAL\$)
-    *(\$READONLY\$)
+    ${RELOCATING+*(\$READONLY\$)
     *(\$READONLY_ADDR\$)
     *(eh_frame)
     *(jcr)
@@ -51,11 +51,11 @@ SECTIONS
     *(LIB\$INITIALIZDZ)	/* Start marker.  */
     *(LIB\$INITIALIZD_)	/* Hi priority.  */
     *(LIB\$INITIALIZE)	/* User.  */
-    *(LIB\$INITIALIZE$)	/* End marker.  */
+    *(LIB\$INITIALIZE$)	/* End marker.  */}
   }
 
   \$DWARF\$ ALIGN (${PAGESIZE}) : {
-    \$dwarf2.debug_pubtypes = .;
+    ${RELOCATING+\$dwarf2.debug_pubtypes = .;
     *(debug_pubtypes)
     \$dwarf2.debug_ranges = .;
     *(debug_ranges)
@@ -80,7 +80,7 @@ SECTIONS
     *(debug_pubnames)
     \$dwarf2.debug_str = .;
     *(debug_str)
-    \$dwarf2.debug_zzzzzz = .;
+    \$dwarf2.debug_zzzzzz = .;}
   }
 
   \$DST\$ 0 : {
diff --git a/ld/scripttempl/arclinux.sc b/ld/scripttempl/arclinux.sc
index 9c23786..931d7a5 100644
--- a/ld/scripttempl/arclinux.sc
+++ b/ld/scripttempl/arclinux.sc
@@ -141,16 +141,16 @@ if test -z "${INITIAL_READONLY_SECTIONS}${CREATE_SHLIB}"; then
 fi
 if test -z "$PLT"; then
   IPLT=".iplt         ${RELOCATING-0} : { *(.iplt) }"
-  PLT=".plt          ${RELOCATING-0} : { *(.plt)${IREL_IN_PLT+ *(.iplt)} }
+  PLT=".plt          ${RELOCATING-0} : { *(.plt)${RELOCATING+${IREL_IN_PLT+ *(.iplt)}} }
   ${IREL_IN_PLT-$IPLT}"
 fi
 test -n "${DATA_PLT-${BSS_PLT-text}}" && TEXT_PLT=
 if test -z "$GOT"; then
   if test -z "$SEPARATE_GOTPLT"; then
-    GOT=".got          ${RELOCATING-0} : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) }"
+    GOT=".got          ${RELOCATING-0} : {${RELOCATING+ *(.got.plt) *(.igot.plt)} *(.got)${RELOCATING+ *(.igot)} }"
   else
-    GOT=".got          ${RELOCATING-0} : { *(.got) *(.igot) }"
-    GOTPLT=".got.plt      ${RELOCATING-0} : { *(.got.plt)  *(.igot.plt) }"
+    GOT=".got          ${RELOCATING-0} : { *(.got)${RELOCATING+ *(.igot)} }"
+    GOTPLT=".got.plt      ${RELOCATING-0} : { *(.got.plt)${RELOCATING+ *(.igot.plt)} }"
   fi
 fi
 REL_IFUNC=".rel.ifunc    ${RELOCATING-0} : { *(.rel.ifunc) }"
@@ -176,9 +176,9 @@ if test -z "${NO_SMALL_DATA}"; then
   {
     ${RELOCATING+${SBSS_START_SYMBOLS}}
     ${CREATE_SHLIB+*(.${SBSS_NAME}2 .${SBSS_NAME}2.* .gnu.linkonce.sb2.*)}
-    *(.dyn${SBSS_NAME})
+    ${RELOCATING+*(.dyn${SBSS_NAME})}
     *(.${SBSS_NAME}${RELOCATING+ .${SBSS_NAME}.* .gnu.linkonce.sb.*})
-    *(.scommon)
+    ${RELOCATING+*(.scommon)}
     ${RELOCATING+${SBSS_END_SYMBOLS}}
   }"
   SBSS2=".${SBSS_NAME}2        ${RELOCATING-0} : { *(.${SBSS_NAME}2${RELOCATING+ .${SBSS_NAME}2.* .gnu.linkonce.sb2.*}) }"
@@ -541,12 +541,10 @@ cat <<EOF
   ${OTHER_READONLY_SECTIONS}
   .eh_frame_hdr : { *(.eh_frame_hdr) ${RELOCATING+*(.eh_frame_entry .eh_frame_entry.*)} }
   .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame)) ${RELOCATING+*(.eh_frame.*)} }
-  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table
-  .gcc_except_table.*) }
+  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
   .gnu_extab ${RELOCATING-0} : ONLY_IF_RO { *(.gnu_extab*) }
   /* These sections are generated by the Sun/Oracle C++ compiler.  */
-  .exception_ranges ${RELOCATING-0} : ONLY_IF_RO { *(.exception_ranges
-  .exception_ranges*) }
+  .exception_ranges ${RELOCATING-0} : ONLY_IF_RO { *(.exception_ranges${RELOCATING+*}) }
   ${TEXT_PLT+${PLT_NEXT_DATA+${PLT}}}
 
   /* Adjust the address for the data segment.  We want to adjust up to
@@ -558,12 +556,12 @@ cat <<EOF
   /* Exception handling  */
   .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) ${RELOCATING+*(.eh_frame.*)} }
   .gnu_extab    ${RELOCATING-0} : ONLY_IF_RW { *(.gnu_extab) }
-  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
-  .exception_ranges ${RELOCATING-0} : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) }
+  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
+  .exception_ranges ${RELOCATING-0} : ONLY_IF_RW { *(.exception_ranges${RELOCATING+*}) }
 
   /* Thread Local Storage sections  */
-  .tdata	${RELOCATING-0} : { PROVIDE_HIDDEN(.tdata = .); *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
-  .tbss		${RELOCATING-0} : { PROVIDE_HIDDEN(.tbss = .); *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
+  .tdata	${RELOCATING-0} : { ${RELOCATING+PROVIDE_HIDDEN(.tdata = .); }*(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
+  .tbss		${RELOCATING-0} : { ${RELOCATING+PROVIDE_HIDDEN(.tbss = .); }*(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
 
   .preinit_array   ${RELOCATING-0} :
   {
@@ -621,15 +619,15 @@ cat <<EOF
   ${BSS_PLT+${PLT}}
   .${BSS_NAME}          ${RELOCATING-0} :
   {
-   *(.dyn${BSS_NAME})
-   *(.${BSS_NAME}${RELOCATING+ .${BSS_NAME}.* .gnu.linkonce.b.*})
-   *(COMMON)
-   /* Align here to ensure that the .bss section occupies space up to
-      _end.  Align after .bss to ensure correct alignment even if the
-      .bss section disappears because there are no input sections.
-      FIXME: Why do we need it? When there is no .bss section, we don't
-      pad the .data section.  */
-   ${RELOCATING+. = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
+    ${RELOCATING+*(.dyn${BSS_NAME})}
+    *(.${BSS_NAME}${RELOCATING+ .${BSS_NAME}.* .gnu.linkonce.b.*})
+    ${RELOCATING+*(COMMON)
+    /* Align here to ensure that the .bss section occupies space up to
+       _end.  Align after .bss to ensure correct alignment even if the
+       .bss section disappears because there are no input sections.
+       FIXME: Why do we need it? When there is no .bss section, we do not
+       pad the .data section.  */
+    . = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
   }
   ${OTHER_BSS_SECTIONS}
   ${LARGE_BSS_AFTER_BSS+${LARGE_BSS}}
diff --git a/ld/scripttempl/armbpabi.sc b/ld/scripttempl/armbpabi.sc
index a12cd3d..8eed447 100644
--- a/ld/scripttempl/armbpabi.sc
+++ b/ld/scripttempl/armbpabi.sc
@@ -42,9 +42,9 @@ if test -z "${NO_SMALL_DATA}"; then
   {
     ${RELOCATING+PROVIDE (__sbss_start = .);}
     ${RELOCATING+PROVIDE (___sbss_start = .);}
-    *(.dynsbss)
+    ${RELOCATING+*(.dynsbss)}
     *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
-    *(.scommon)
+    ${RELOCATING+*(.scommon)}
     ${RELOCATING+PROVIDE (__sbss_end = .);}
     ${RELOCATING+PROVIDE (___sbss_end = .);}
   }"
@@ -154,17 +154,16 @@ cat <<EOF
 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
 	      "${LITTLE_OUTPUT_FORMAT}")
 OUTPUT_ARCH(${OUTPUT_ARCH})
-${RELOCATING+ENTRY(${ENTRY})}
-
-${RELOCATING+${LIB_SEARCH_DIRS}}
-${RELOCATING+/* Do we need any of these for elf?
-   __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}}  */}
-${RELOCATING+${EXECUTABLE_SYMBOLS}}
-${RELOCATING+${INPUT_FILES}}
-${RELOCATING- /* For some reason, the Solaris linker makes bad executables
-  if gld -r is used and the intermediate file has sections starting
-  at non-zero addresses.  Could be a Solaris ld bug, could be a GNU ld
-  bug.  But for now assigning the zero vmas works.  */}
+EOF
+
+test -n "${RELOCATING}" && cat <<EOF
+ENTRY(${ENTRY})
+
+${LIB_SEARCH_DIRS}
+/* Do we need any of these for elf?
+   __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}}  */
+${EXECUTABLE_SYMBOLS}
+${INPUT_FILES}
 
 /* ARM's proprietary toolchain generate these symbols to match the start
    and end of particular sections of the image.  SymbianOS uses these
@@ -187,6 +186,9 @@ VERSION
   };
 }
 
+EOF
+
+cat <<EOF
 SECTIONS
 {
   /* Read-only sections, merged into text segment: */
@@ -254,7 +256,7 @@ cat <<EOF
   ${OTHER_READONLY_SECTIONS}
   .eh_frame_hdr : { *(.eh_frame_hdr) }
   .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame)) }
-  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.gcc_except_table)) *(.gcc_except_table.*) }
+  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.gcc_except_table${RELOCATING+ .gcc_except_table.*})) }
 
   /* Adjust the address for the data segment.  We want to adjust up to
      the same address within the page on the next page up.  */
@@ -264,7 +266,7 @@ cat <<EOF
 
   /* Exception handling  */
   .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) }
-  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.gcc_except_table)) *(.gcc_except_table.*) }
+  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.gcc_except_table${RELOCATING+ .gcc_except_table.*})) }
 
   /* Thread Local Storage sections  */
   .tdata	${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
@@ -303,13 +305,13 @@ cat <<EOF
   ${BSS_PLT+${PLT}}
   .bss          ${RELOCATING-0} :
   {
-   *(.dynbss)
+   ${RELOCATING+*(.dynbss)}
    *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
-   *(COMMON)
+   ${RELOCATING+*(COMMON)
    /* Align here to ensure that the .bss section occupies space up to
       _end.  Align after .bss to ensure correct alignment even if the
       .bss section disappears because there are no input sections.  */
-   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
+   . = ALIGN(${ALIGNMENT});}
   }
   ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
diff --git a/ld/scripttempl/avr.sc b/ld/scripttempl/avr.sc
index 5d0a3a1..931ef40 100644
--- a/ld/scripttempl/avr.sc
+++ b/ld/scripttempl/avr.sc
@@ -24,7 +24,9 @@ cat <<EOF
 
 OUTPUT_FORMAT("${OUTPUT_FORMAT}","${OUTPUT_FORMAT}","${OUTPUT_FORMAT}")
 OUTPUT_ARCH(${ARCH})
+EOF
 
+test -n "${RELOCATING}" && cat <<EOF
 __TEXT_REGION_LENGTH__ = DEFINED(__TEXT_REGION_LENGTH__) ? __TEXT_REGION_LENGTH__ : $TEXT_LENGTH;
 __DATA_REGION_LENGTH__ = DEFINED(__DATA_REGION_LENGTH__) ? __DATA_REGION_LENGTH__ : $DATA_LENGTH;
 ${EEPROM_LENGTH+__EEPROM_REGION_LENGTH__ = DEFINED(__EEPROM_REGION_LENGTH__) ? __EEPROM_REGION_LENGTH__ : $EEPROM_LENGTH;}
@@ -43,7 +45,9 @@ ${EEPROM_LENGTH+  eeprom (rw!x) : ORIGIN = 0x810000, LENGTH = __EEPROM_REGION_LE
   signature (rw!x) : ORIGIN = 0x840000, LENGTH = __SIGNATURE_REGION_LENGTH__
 ${USER_SIGNATURE_LENGTH+  user_signatures (rw!x) : ORIGIN = 0x850000, LENGTH = __USER_SIGNATURE_REGION_LENGTH__}
 }
+EOF
 
+cat <<EOF
 SECTIONS
 {
   /* Read-only sections, merged into text segment: */
@@ -109,32 +113,32 @@ SECTIONS
   /* Internal text space or external memory.  */
   .text ${RELOCATING-0} :
   {
-    *(.vectors)
+    ${RELOCATING+*(.vectors)
     KEEP(*(.vectors))
 
     /* For data that needs to reside in the lower 64k of progmem.  */
-    ${RELOCATING+ *(.progmem.gcc*)}
+    *(.progmem.gcc*)
 
     /* PR 13812: Placing the trampolines here gives a better chance
        that they will be in range of the code that uses them.  */
-    ${RELOCATING+. = ALIGN(2);}
-    ${CONSTRUCTING+ __trampolines_start = . ; }
+    . = ALIGN(2);
+    __trampolines_start = . ;
     /* The jump trampolines for the 16-bit limited relocs will reside here.  */
     *(.trampolines)
-    ${RELOCATING+ *(.trampolines*)}
-    ${CONSTRUCTING+ __trampolines_end = . ; }
+    *(.trampolines*)
+    __trampolines_end = . ;
 
     /* avr-libc expects these data to reside in lower 64K. */
-    ${RELOCATING+ *libprintf_flt.a:*(.progmem.data)}
-    ${RELOCATING+ *libc.a:*(.progmem.data)}
+    *libprintf_flt.a:*(.progmem.data)
+    *libc.a:*(.progmem.data)
 
-    ${RELOCATING+ *(.progmem.*)}
+    *(.progmem.*)
 
-    ${RELOCATING+. = ALIGN(2);}
+    . = ALIGN(2);
 
     /* For code that needs to reside in the lower 128k progmem.  */
     *(.lowtext)
-    ${RELOCATING+ *(.lowtext*)}
+    *(.lowtext*)}
 
     ${CONSTRUCTING+ __ctors_start = . ; }
     ${CONSTRUCTING+ *(.ctors) }
@@ -142,10 +146,10 @@ SECTIONS
     ${CONSTRUCTING+ __dtors_start = . ; }
     ${CONSTRUCTING+ *(.dtors) }
     ${CONSTRUCTING+ __dtors_end = . ; }
-    KEEP(SORT(*)(.ctors))
+    ${RELOCATING+KEEP(SORT(*)(.ctors))
     KEEP(SORT(*)(.dtors))
 
-    /* From this point on, we don't bother about wether the insns are
+    /* From this point on, we do not bother about whether the insns are
        below or above the 16 bits boundary.  */
     *(.init0)  /* Start here after reset.  */
     KEEP (*(.init0))
@@ -166,11 +170,11 @@ SECTIONS
     *(.init8)
     KEEP (*(.init8))
     *(.init9)  /* Call main().  */
-    KEEP (*(.init9))
+    KEEP (*(.init9))}
     *(.text)
-    ${RELOCATING+. = ALIGN(2);}
-    ${RELOCATING+ *(.text.*)}
-    ${RELOCATING+. = ALIGN(2);}
+    ${RELOCATING+. = ALIGN(2);
+    *(.text.*)
+    . = ALIGN(2);
     *(.fini9)  /* _exit() starts here.  */
     KEEP (*(.fini9))
     *(.fini8)
@@ -194,18 +198,18 @@ SECTIONS
 
     /* For code that needs not to reside in the lower progmem.  */
     *(.hightext)
-    ${RELOCATING+ *(.hightext*)}
+    *(.hightext*)
 
-    ${RELOCATING+ *(.progmemx.*)}
+    *(.progmemx.*)
 
-    ${RELOCATING+. = ALIGN(2);}
+    . = ALIGN(2);
 
-    /* For tablejump instruction arrays.  We don't relax
+    /* For tablejump instruction arrays.  We do not relax
        JMP / CALL instructions within these sections.  */
     *(.jumptables)
-    ${RELOCATING+ *(.jumptables*)}
+    *(.jumptables*)
 
-    ${RELOCATING+ _etext = . ; }
+    _etext = . ;}
   } ${RELOCATING+ > text}
 EOF
 
@@ -218,8 +222,8 @@ if test -n "$RODATA_PM_OFFSET"; then
   .rodata ${RELOCATING+ ADDR(.text) + SIZEOF (.text) + __RODATA_PM_OFFSET__ } ${RELOCATING-0} :
   {
     *(.rodata)
-    ${RELOCATING+ *(.rodata*)}
-    *(.gnu.linkonce.r*)
+    ${RELOCATING+ *(.rodata*)
+    *(.gnu.linkonce.r*)}
   } ${RELOCATING+AT> text}
 EOF
 fi
@@ -229,18 +233,18 @@ cat <<EOF
   {
     ${RELOCATING+ PROVIDE (__data_start = .) ; }
     *(.data)
-    ${RELOCATING+ *(.data*)}
-    *(.gnu.linkonce.d*)
+    ${RELOCATING+ *(.data*)
+    *(.gnu.linkonce.d*)}
 EOF
 
 # Classical devices that don't show flash memory in the SRAM address space
 # need .rodata to be part of .data because the compiler will use LD*
 # instructions and LD* cannot access flash.
 
-if test -z "$RODATA_PM_OFFSET"; then
+if test -z "$RODATA_PM_OFFSET" && test -n "${RELOCATING}"; then
     cat <<EOF
     *(.rodata)  /* We need to include .rodata here if gcc is used */
-    ${RELOCATING+ *(.rodata*)} /* with -fdata-sections.  */
+    *(.rodata*) /* with -fdata-sections.  */
     *(.gnu.linkonce.r*)
 EOF
 fi
@@ -256,7 +260,7 @@ cat <<EOF
     ${RELOCATING+ PROVIDE (__bss_start = .) ; }
     *(.bss)
     ${RELOCATING+ *(.bss*)}
-    *(COMMON)
+    ${RELOCATING+ *(COMMON)}
     ${RELOCATING+ PROVIDE (__bss_end = .) ; }
   } ${RELOCATING+ > data}
 
@@ -292,9 +296,9 @@ cat <<EOF
   .fuse ${RELOCATING-0}:
   {
     KEEP(*(.fuse))
-    KEEP(*(.lfuse))
+    ${RELOCATING+KEEP(*(.lfuse))
     KEEP(*(.hfuse))
-    KEEP(*(.efuse))
+    KEEP(*(.efuse))}
   } ${RELOCATING+ > fuse}
 EOF
 fi
diff --git a/ld/scripttempl/dlx.sc b/ld/scripttempl/dlx.sc
index 175ceb3..0741893 100644
--- a/ld/scripttempl/dlx.sc
+++ b/ld/scripttempl/dlx.sc
@@ -21,7 +21,7 @@ SECTIONS
   ${RELOCATING+. = ${TEXT_START_ADDR};}
   .text :
   {
-    CREATE_OBJECT_SYMBOLS
+    ${RELOCATING+CREATE_OBJECT_SYMBOLS}
     *(.text)
     ${RELOCATING+etext = ${DATA_ALIGNMENT};}
   }
@@ -35,8 +35,8 @@ SECTIONS
   .bss :
   {
    *(.bss)
-   *(COMMON)
-   ${RELOCATING+end = . };
+   ${RELOCATING+*(COMMON)}
+   ${RELOCATING+end = .;}
   }
 }
 EOF
diff --git a/ld/scripttempl/elf.sc b/ld/scripttempl/elf.sc
index b10e330..d3e1828 100644
--- a/ld/scripttempl/elf.sc
+++ b/ld/scripttempl/elf.sc
@@ -144,16 +144,16 @@ if test -z "${INITIAL_READONLY_SECTIONS}${CREATE_SHLIB}"; then
 fi
 if test -z "$PLT"; then
   IPLT=".iplt         ${RELOCATING-0} : { *(.iplt) }"
-  PLT=".plt          ${RELOCATING-0} : { *(.plt)${IREL_IN_PLT+ *(.iplt)} }
+  PLT=".plt          ${RELOCATING-0} : { *(.plt)${RELOCATING+${IREL_IN_PLT+ *(.iplt)}} }
   ${IREL_IN_PLT-$IPLT}"
 fi
 test -n "${DATA_PLT-${BSS_PLT-text}}" && TEXT_PLT=
 if test -z "$GOT"; then
   if test -z "$SEPARATE_GOTPLT"; then
-    GOT=".got          ${RELOCATING-0} : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) }"
+    GOT=".got          ${RELOCATING-0} : {${RELOCATING+ *(.got.plt) *(.igot.plt)} *(.got)${RELOCATING+ *(.igot)} }"
   else
-    GOT=".got          ${RELOCATING-0} : { *(.got) *(.igot) }"
-    GOTPLT=".got.plt      ${RELOCATING-0} : { *(.got.plt)  *(.igot.plt) }"
+    GOT=".got          ${RELOCATING-0} : { *(.got)${RELOCATING+ *(.igot)} }"
+    GOTPLT=".got.plt      ${RELOCATING-0} : { *(.got.plt)${RELOCATING+ *(.igot.plt)} }"
   fi
 fi
 REL_IFUNC=".rel.ifunc    ${RELOCATING-0} : { *(.rel.ifunc) }"
@@ -179,9 +179,9 @@ if test -z "${NO_SMALL_DATA}"; then
   {
     ${RELOCATING+${SBSS_START_SYMBOLS}}
     ${CREATE_SHLIB+*(.${SBSS_NAME}2 .${SBSS_NAME}2.* .gnu.linkonce.sb2.*)}
-    *(.dyn${SBSS_NAME})
+    ${RELOCATING+*(.dyn${SBSS_NAME})}
     *(.${SBSS_NAME}${RELOCATING+ .${SBSS_NAME}.* .gnu.linkonce.sb.*})
-    *(.scommon)
+    ${RELOCATING+*(.scommon)}
     ${RELOCATING+${SBSS_END_SYMBOLS}}
   }"
   SBSS2=".${SBSS_NAME}2        ${RELOCATING-0} : { *(.${SBSS_NAME}2${RELOCATING+ .${SBSS_NAME}2.* .gnu.linkonce.sb2.*}) }"
@@ -231,9 +231,9 @@ test "${LARGE_SECTIONS}" = "yes" && REL_LARGE="
 test "${LARGE_SECTIONS}" = "yes" && LARGE_BSS="
   .lbss ${RELOCATING-0} :
   {
-    *(.dynlbss)
+    ${RELOCATING+*(.dynlbss)}
     *(.lbss${RELOCATING+ .lbss.* .gnu.linkonce.lb.*})
-    *(LARGE_COMMON)
+    ${RELOCATING+*(LARGE_COMMON)}
   }"
 test "${LARGE_SECTIONS}" = "yes" && LARGE_SECTIONS="
   .lrodata ${RELOCATING-0} ${RELOCATING+ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))} :
@@ -245,12 +245,6 @@ test "${LARGE_SECTIONS}" = "yes" && LARGE_SECTIONS="
     *(.ldata${RELOCATING+ .ldata.* .gnu.linkonce.l.*})
     ${RELOCATING+. = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
   }"
-PREINIT_ARRAY=".preinit_array   ${RELOCATING-0} :
-  {
-    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_start = .);}}
-    KEEP (*(.preinit_array))
-    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_end = .);}}
-  }"
 if test "${ENABLE_INITFINI_ARRAY}" = "yes"; then
   SORT_INIT_ARRAY="KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))"
   SORT_FINI_ARRAY="KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))"
@@ -262,19 +256,25 @@ else
   CTORS_IN_INIT_ARRAY=
   DTORS_IN_FINI_ARRAY=
 fi
-INIT_ARRAY=".init_array   ${RELOCATING-0} :
+PREINIT_ARRAY=".preinit_array    :
   {
-    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_start = .);}}
+    ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_start = .);}
+    KEEP (*(.preinit_array))
+    ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_end = .);}
+  }"
+INIT_ARRAY=".init_array    :
+  {
+    ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_start = .);}
     ${SORT_INIT_ARRAY}
     KEEP (*(.init_array ${CTORS_IN_INIT_ARRAY}))
-    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_end = .);}}
+    ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_end = .);}
   }"
-FINI_ARRAY=".fini_array   ${RELOCATING-0} :
+FINI_ARRAY=".fini_array    :
   {
-    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_start = .);}}
+    ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_start = .);}
     ${SORT_FINI_ARRAY}
     KEEP (*(.fini_array ${DTORS_IN_FINI_ARRAY}))
-    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_end = .);}}
+    ${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_end = .);}
   }"
 CTOR=".ctors        ${CONSTRUCTING-0} :
   {
@@ -327,7 +327,7 @@ SHLIB_TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${SHLIB_TEXT_START_ADDR:-
 if test -z "$TINY_READONLY_SECTION"; then
   case "$LD_FLAG" in
     *textonly*)
-      SEPARATE_TEXT=yes
+      SEPARATE_TEXT=" "
       TEXT_SEGMENT_ALIGN=". = ALIGN(${MAXPAGESIZE});"
       ;;
   esac
@@ -368,7 +368,7 @@ ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
 
 SECTIONS
 {
-  /* Read-only sections, merged into text segment: */
+  ${RELOCATING+${SEPARATE_TEXT-/* Read-only sections, merged into text segment: */}}
   ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+PROVIDE (__executable_start = ${TEXT_START_ADDR}); . = ${TEXT_BASE_ADDRESS};}}}
   ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR}${SIZEOF_HEADERS_CODE};}}
   ${CREATE_PIE+${RELOCATING+PROVIDE (__executable_start = ${SHLIB_TEXT_START_ADDR}); . = ${SHLIB_TEXT_START_ADDR}${SIZEOF_HEADERS_CODE};}}
@@ -546,11 +546,11 @@ SEGMENT_START(\"rodata-segment\", ${SHLIB_RODATA_ADDR}) + SIZEOF_HEADERS"
     SHLIB_RODATA_ADDR="SEGMENT_START(\"rodata-segment\", ${SHLIB_RODATA_ADDR})"
   fi
   cat <<EOF
-  /* Adjust the address for the rodata segment.  We want to adjust up to
+  ${RELOCATING+/* Adjust the address for the rodata segment.  We want to adjust up to
      the same address within the page on the next page up.  */
-  ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${RODATA_ADDR};}}}
-  ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_RODATA_ADDR};}}
-  ${CREATE_PIE+${RELOCATING+. = ${SHLIB_RODATA_ADDR};}}
+  ${CREATE_SHLIB-${CREATE_PIE-. = ${RODATA_ADDR};}}
+  ${CREATE_SHLIB+. = ${SHLIB_RODATA_ADDR};}
+  ${CREATE_PIE+. = ${SHLIB_RODATA_ADDR};}}
 EOF
   if test -n "${SEPARATE_CODE}"; then
     emit_early_ro
@@ -564,27 +564,25 @@ cat <<EOF
   ${CREATE_SHLIB-${SDATA2}}
   ${CREATE_SHLIB-${SBSS2}}
   ${OTHER_READONLY_SECTIONS}
-  .eh_frame_hdr : { *(.eh_frame_hdr) ${RELOCATING+*(.eh_frame_entry .eh_frame_entry.*)} }
-  .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame)) ${RELOCATING+*(.eh_frame.*)} }
-  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table
-  .gcc_except_table.*) }
+  .eh_frame_hdr : { *(.eh_frame_hdr)${RELOCATING+ *(.eh_frame_entry .eh_frame_entry.*)} }
+  .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame))${RELOCATING+ *(.eh_frame.*)} }
+  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
   .gnu_extab ${RELOCATING-0} : ONLY_IF_RO { *(.gnu_extab*) }
   /* These sections are generated by the Sun/Oracle C++ compiler.  */
-  .exception_ranges ${RELOCATING-0} : ONLY_IF_RO { *(.exception_ranges
-  .exception_ranges*) }
+  .exception_ranges ${RELOCATING-0} : ONLY_IF_RO { *(.exception_ranges${RELOCATING+*}) }
   ${TEXT_PLT+${PLT_NEXT_DATA+${PLT} ${OTHER_PLT_SECTIONS}}}
 
-  /* Adjust the address for the data segment.  We want to adjust up to
-     the same address within the page on the next page up.  */
+  ${RELOCATING+/* Adjust the address for the data segment.  We want to adjust up to
+     the same address within the page on the next page up.  */}
   ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}}
-  ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
-  ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
+  ${CREATE_SHLIB+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}
+  ${CREATE_PIE+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}
 
   /* Exception handling  */
-  .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) ${RELOCATING+*(.eh_frame.*)} }
+  .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame))${RELOCATING+ *(.eh_frame.*)} }
   .gnu_extab    ${RELOCATING-0} : ONLY_IF_RW { *(.gnu_extab) }
-  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
-  .exception_ranges ${RELOCATING-0} : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) }
+  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
+  .exception_ranges ${RELOCATING-0} : ONLY_IF_RW { *(.exception_ranges${RELOCATING+*}) }
 
   /* Thread Local Storage sections  */
   .tdata	${RELOCATING-0} :
@@ -647,13 +645,13 @@ cat <<EOF
   {
    ${RELOCATING+*(.dynbss)}
    *(.${BSS_NAME}${RELOCATING+ .${BSS_NAME}.* .gnu.linkonce.b.*})
-   *(COMMON)
+   ${RELOCATING+*(COMMON)
    /* Align here to ensure that the .bss section occupies space up to
       _end.  Align after .bss to ensure correct alignment even if the
       .bss section disappears because there are no input sections.
-      FIXME: Why do we need it? When there is no .bss section, we don't
+      FIXME: Why do we need it? When there is no .bss section, we do not
       pad the .data section.  */
-   ${RELOCATING+. = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
+   . = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
   }
   ${OTHER_BSS_SECTIONS}
   ${LARGE_BSS_AFTER_BSS+${LARGE_BSS}}
@@ -666,8 +664,8 @@ SHLIB_LARGE_DATA_ADDR=". = SEGMENT_START(\"ldata-segment\", ${SHLIB_LARGE_DATA_A
 
 cat <<EOF
   ${RELOCATING+${CREATE_SHLIB-${CREATE_PIE-${LARGE_DATA_ADDR}}}}
-  ${RELOCATING+${CREATE_SHLIB+${SHLIB_LARGE_DATA_ADDR}}}
-  ${RELOCATING+${CREATE_PIE+${SHLIB_LARGE_DATA_ADDR}}}
+  ${CREATE_SHLIB+${SHLIB_LARGE_DATA_ADDR}}
+  ${CREATE_PIE+${SHLIB_LARGE_DATA_ADDR}}
   ${LARGE_SECTIONS}
   ${LARGE_BSS_AFTER_BSS-${LARGE_BSS}}
   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
@@ -692,7 +690,7 @@ cat <<EOF
 
   .comment       0 : { *(.comment) }
 
-  .gnu.build.attributes : { *(.gnu.build.attributes .gnu.build.attributes.*) }
+  .gnu.build.attributes : { *(.gnu.build.attributes${RELOCATING+ .gnu.build.attributes.*}) }
 
 EOF
 
diff --git a/ld/scripttempl/elf32cr16.sc b/ld/scripttempl/elf32cr16.sc
index cdabd9c..936c03a 100644
--- a/ld/scripttempl/elf32cr16.sc
+++ b/ld/scripttempl/elf32cr16.sc
@@ -6,6 +6,10 @@
 # are permitted in any medium without royalty provided the copyright
 # notice and this notice are preserved.
 
+# Using an empty script for ld -r is better than mashing together
+# sections.  This hack likely leaves ld -Ur broken.
+test -n "${RELOCATING}" || exit 0
+
 # The next line should be uncommented if it is desired to link
 # without libstart.o and directly enter main.
 
@@ -23,7 +27,10 @@ cat <<EOF
 
 OUTPUT_FORMAT("${OUTPUT_FORMAT}")
 OUTPUT_ARCH(${ARCH})
-${RELOCATING+ENTRY(${ENTRY})}
+EOF
+
+test -n "${RELOCATING}" && cat <<EOF
+ENTRY(${ENTRY})
 
 /* Define memory regions.  */
 MEMORY
@@ -32,6 +39,9 @@ MEMORY
 	ram	    : ORIGIN = 4M,	    LENGTH = 10M
 }
 
+EOF
+
+cat <<EOF
 /*  Many sections come in three flavours.  There is the 'real' section,
     like ".data".  Then there are the per-procedure or per-variable
     sections, generated by -ffunction-sections and -fdata-sections in GCC,
@@ -54,33 +64,33 @@ SECTIONS
     __INIT_START = .;
     KEEP (*(.init))
     __INIT_END = .;
-  } > rom
+  }${RELOCATING+ > rom}
 
   .fini :
   {
     __FINI_START = .;
     KEEP (*(.fini))
     __FINI_END = .;
-  } > rom
+  }${RELOCATING+ > rom}
 
   .jcr :
   {
     KEEP (*(.jcr))
-  } > rom
+  }${RELOCATING+ > rom}
 
   .text :
   {
     __TEXT_START = .;
     *(.text) *(.text.*) *(.gnu.linkonce.t.*)
     __TEXT_END = .;
-  } > rom
+  }${RELOCATING+ > rom}
 
   .rdata :
   {
     __RDATA_START = .;
     *(.rdata_4) *(.rdata_2) *(.rdata_1) *(.rdata.*) *(.gnu.linkonce.r.*) *(.rodata*)
     __RDATA_END = .;
-  } > rom
+  }${RELOCATING+ > rom}
 
   .ctor ALIGN(4) :
   {
@@ -106,7 +116,7 @@ SECTIONS
     KEEP (*(SORT(.ctors.*)))
     KEEP (*(.ctors))
     __CTOR_END = .;
-  } > rom
+  }${RELOCATING+ > rom}
 
   .dtor ALIGN(4) :
   {
@@ -116,21 +126,21 @@ SECTIONS
     KEEP (*(SORT(.dtors.*)))
     KEEP (*(.dtors))
     __DTOR_END = .;
-  } > rom
+  }${RELOCATING+ > rom}
 
   .data :
   {
     __DATA_START = .;
     *(.data_4) *(.data_2) *(.data_1) *(.data) *(.data.*) *(.gnu.linkonce.d.*)
     __DATA_END = .;
-  } > ram AT > rom
+  }${RELOCATING+ > ram AT > rom}
 
   .bss (NOLOAD) :
   {
     __BSS_START = .;
     *(.bss_4) *(.bss_2) *(.bss_1) *(.bss) *(COMMON) *(.bss.*) *(.gnu.linkonce.b.*)
     __BSS_END = .;
-  } > ram
+  }${RELOCATING+ > ram}
 
 /* You may change the sizes of the following sections to fit the actual
    size your program requires.
@@ -143,21 +153,21 @@ SECTIONS
     . = ALIGN(4);
     __HEAP_START = .;
     . += 0x2000; __HEAP_MAX = .;
-  } > ram
+  }${RELOCATING+ > ram}
 
   .stack (NOLOAD) :
   {
     . = ALIGN(4);
     . += 0x6000;
     __STACK_START = .;
-  } > ram
+  }${RELOCATING+ > ram}
 
   .istack (NOLOAD) :
   {
     . = ALIGN(4);
     . += 0x100;
     __ISTACK_START = .;
-  } > ram
+  }${RELOCATING+ > ram}
 
   .comment        0 : { *(.comment) }
 
@@ -168,5 +178,5 @@ EOF
 cat <<EOF
 }
 
-__DATA_IMAGE_START = LOADADDR(.data);
+${RELOCATING+__DATA_IMAGE_START = LOADADDR(.data);}
 EOF
diff --git a/ld/scripttempl/elf32cr16c.sc b/ld/scripttempl/elf32cr16c.sc
index 637302e..55645c6 100644
--- a/ld/scripttempl/elf32cr16c.sc
+++ b/ld/scripttempl/elf32cr16c.sc
@@ -6,6 +6,10 @@
 # are permitted in any medium without royalty provided the copyright
 # notice and this notice are preserved.
 
+# Using an empty script for ld -r is better than mashing together
+# sections.  This hack likely leaves ld -Ur broken.
+test -n "${RELOCATING}" || exit 0
+
 test -z "$ENTRY" && ENTRY=_start
 cat <<EOF
 
@@ -19,8 +23,9 @@ cat <<EOF
    are permitted in any medium without royalty provided the copyright
    notice and this notice are preserved.  */
 
-
-${RELOCATING+ENTRY(${ENTRY})}
+EOF
+test -n "${RELOCATING}" && cat <<EOF
+ENTRY(${ENTRY})
 
 MEMORY
 {
@@ -30,6 +35,9 @@ MEMORY
   ram	    : ORIGIN = 4M,      LENGTH = 10M
 }
 
+EOF
+
+cat <<EOF
 SECTIONS
 {
 /* The heap is located in near memory, to suit both the near and
@@ -38,21 +46,21 @@ SECTIONS
    there. The alignment to 4 bytes is compatible for both the CR16C
    bus width (2 bytes) and CR16CPlus bus width (4 bytes).  */
 
-  .text            : { __TEXT_START = .;   *(.text)                                        __TEXT_END = .; } > rom
-  .rdata           : { __RDATA_START = .;  *(.rdata_4) *(.rdata_2) *(.rdata_1)             __RDATA_END = .; } > near_rom
-  .ctor ALIGN(4)   : { __CTOR_LIST = .;    *(.ctors)                                       __CTOR_END = .; } > near_rom
-  .dtor ALIGN(4)   : { __DTOR_LIST = .;    *(.dtors)                                       __DTOR_END = .; } > near_rom
-  .data            : { __DATA_START = .;   *(.data_4) *(.data_2) *(.data_1) *(.data)       __DATA_END = .; } > ram AT > rom
-  .bss (NOLOAD)    : { __BSS_START = .;    *(.bss_4) *(.bss_2) *(.bss_1) *(.bss) *(COMMON) __BSS_END = .; } > ram
-  .nrdata          : { __NRDATA_START = .; *(.nrdat_4) *(.nrdat_2) *(.nrdat_1)             __NRDATA_END =  .; } > near_rom
-  .ndata           : { __NDATA_START = .;  *(.ndata_4) *(.ndata_2) *(.ndata_1)             __NDATA_END = .; } > near_ram AT > rom
-  .nbss (NOLOAD)   : { __NBSS_START = .;   *(.nbss_4) *(.nbss_2) *(.nbss_1) *(.ncommon)    __NBSS_END = .; } > near_ram
-  .heap (NOLOAD)   : { . = ALIGN(4); __HEAP_START = .; . += 0x2000;                        __HEAP_MAX = .; } > near_ram
-  .stack (NOLOAD)  : { . = ALIGN(4); . += 0x6000; __STACK_START = .; } > ram
-  .istack (NOLOAD) : { . = ALIGN(2); . += 0x100; __ISTACK_START = .; } > ram
+  .text            : { __TEXT_START = .;   *(.text)                                        __TEXT_END = .; }${RELOCATING+ > rom}
+  .rdata           : { __RDATA_START = .;  *(.rdata_4) *(.rdata_2) *(.rdata_1)             __RDATA_END = .; }${RELOCATING+ > near_rom}
+  .ctor ALIGN(4)   : { __CTOR_LIST = .;    *(.ctors)                                       __CTOR_END = .; }${RELOCATING+ > near_rom}
+  .dtor ALIGN(4)   : { __DTOR_LIST = .;    *(.dtors)                                       __DTOR_END = .; }${RELOCATING+ > near_rom}
+  .data            : { __DATA_START = .;   *(.data_4) *(.data_2) *(.data_1) *(.data)       __DATA_END = .; }${RELOCATING+ > ram AT > rom}
+  .bss (NOLOAD)    : { __BSS_START = .;    *(.bss_4) *(.bss_2) *(.bss_1) *(.bss) *(COMMON) __BSS_END = .; }${RELOCATING+ > ram}
+  .nrdata          : { __NRDATA_START = .; *(.nrdat_4) *(.nrdat_2) *(.nrdat_1)             __NRDATA_END =  .; }${RELOCATING+ > near_rom}
+  .ndata           : { __NDATA_START = .;  *(.ndata_4) *(.ndata_2) *(.ndata_1)             __NDATA_END = .; }${RELOCATING+ > near_ram AT > rom}
+  .nbss (NOLOAD)   : { __NBSS_START = .;   *(.nbss_4) *(.nbss_2) *(.nbss_1) *(.ncommon)    __NBSS_END = .; }${RELOCATING+ > near_ram}
+  .heap (NOLOAD)   : { . = ALIGN(4); __HEAP_START = .; . += 0x2000;                        __HEAP_MAX = .; }${RELOCATING+ > near_ram}
+  .stack (NOLOAD)  : { . = ALIGN(4); . += 0x6000; __STACK_START = .; }${RELOCATING+ > ram}
+  .istack (NOLOAD) : { . = ALIGN(2); . += 0x100; __ISTACK_START = .; }${RELOCATING+ > ram}
 }
 
-__DATA_IMAGE_START = LOADADDR(.data);
-__NDATA_IMAGE_START = LOADADDR(.ndata);
+${RELOCATING+__DATA_IMAGE_START = LOADADDR(.data);}
+${RELOCATING+__NDATA_IMAGE_START = LOADADDR(.ndata);}
 
 EOF
diff --git a/ld/scripttempl/elf32crx.sc b/ld/scripttempl/elf32crx.sc
index 89aafa6..319a867 100644
--- a/ld/scripttempl/elf32crx.sc
+++ b/ld/scripttempl/elf32crx.sc
@@ -6,6 +6,10 @@
 # are permitted in any medium without royalty provided the copyright
 # notice and this notice are preserved.
 
+# Using an empty script for ld -r is better than mashing together
+# sections.  This hack likely leaves ld -Ur broken.
+test -n "${RELOCATING}" || exit 0
+
 # The next line should be uncommented if it is desired to link
 # without libstart.o and directly enter main.
 
diff --git a/ld/scripttempl/elf32msp430.sc b/ld/scripttempl/elf32msp430.sc
index 1f69a12..b35f0ef 100644
--- a/ld/scripttempl/elf32msp430.sc
+++ b/ld/scripttempl/elf32msp430.sc
@@ -32,6 +32,9 @@ cat <<EOF
 OUTPUT_FORMAT("${OUTPUT_FORMAT}","${OUTPUT_FORMAT}","${OUTPUT_FORMAT}")
 OUTPUT_ARCH(${ARCH})
 
+EOF
+
+test -n "${RELOCATING}" && cat <<EOF
 MEMORY
 {
   text   (rx)		: ORIGIN = $ROM_START,  LENGTH = $ROM_SIZE
@@ -43,6 +46,9 @@ MEMORY
   ${HEAP_MEMORY_MSP430}
 }
 
+EOF
+
+cat <<EOF
 SECTIONS
 {
   /* Bootloader.  */
@@ -51,7 +57,7 @@ SECTIONS
     ${RELOCATING+ PROVIDE (__boot_start = .) ; }
     *(.bootloader)
     ${RELOCATING+. = ALIGN(2);}
-    *(.bootloader.*)
+    ${RELOCATING+*(.bootloader.*)}
   } ${RELOCATING+ > bootloader}
 
   /* Information memory.  */
@@ -59,7 +65,7 @@ SECTIONS
   {
     *(.infomem)
     ${RELOCATING+. = ALIGN(2);}
-    *(.infomem.*)
+    ${RELOCATING+*(.infomem.*)}
   } ${RELOCATING+ > infomem}
 
   /* Information memory (not loaded into MPU).  */
@@ -67,7 +73,7 @@ SECTIONS
   {
     *(.infomemnobits)
     ${RELOCATING+. = ALIGN(2);}
-    *(.infomemnobits.*)
+    ${RELOCATING+*(.infomemnobits.*)}
   } ${RELOCATING+ > infomemnobits}
 
   /* Read-only sections, merged into text segment.  */
@@ -133,7 +139,7 @@ SECTIONS
   /* Internal text space.  */
   .text :
   {
-    ${RELOCATING+. = ALIGN(2);}
+    ${RELOCATING+. = ALIGN(2);
     *(SORT_NONE(.init))
     *(SORT_NONE(.init0))  /* Start here after reset.  */
     *(SORT_NONE(.init1))
@@ -144,7 +150,7 @@ SECTIONS
     *(SORT_NONE(.init6))  /* C++ constructors.  */
     *(SORT_NONE(.init7))
     *(SORT_NONE(.init8))
-    *(SORT_NONE(.init9))  /* Call main().  */
+    *(SORT_NONE(.init9))  /* Call main().  */}
 
     ${CONSTRUCTING+ __ctors_start = . ; }
     ${CONSTRUCTING+ *(.ctors) }
@@ -153,19 +159,19 @@ SECTIONS
     ${CONSTRUCTING+ *(.dtors) }
     ${CONSTRUCTING+ __dtors_end = . ; }
 
-    ${RELOCATING+. = ALIGN(2);}
+    ${RELOCATING+. = ALIGN(2);
     *(.lower.text.* .lower.text)
 
-    ${RELOCATING+. = ALIGN(2);}
+    . = ALIGN(2);}
     *(.text)
-    ${RELOCATING+. = ALIGN(2);}
+    ${RELOCATING+. = ALIGN(2);
     *(.text.*)
-    ${RELOCATING+. = ALIGN(2);}
+    . = ALIGN(2);
     *(.text:*)
 
     *(.either.text.* .either.text)
 
-    ${RELOCATING+. = ALIGN(2);}
+    . = ALIGN(2);
     *(SORT_NONE(.fini9))
     *(SORT_NONE(.fini8))
     *(SORT_NONE(.fini7))
@@ -178,18 +184,18 @@ SECTIONS
     *(SORT_NONE(.fini0))  /* Infinite loop after program termination.  */
     *(SORT_NONE(.fini))
 
-    _etext = .;
+    _etext = .;}
   } ${RELOCATING+ > text}
 
   .rodata :
   {
-    ${RELOCATING+. = ALIGN(2);}
+    ${RELOCATING+. = ALIGN(2);
     *(.lower.rodata.* .lower.rodata)
 
     . = ALIGN(2);
-    *(.plt)
-    *(.rodata .rodata.* .gnu.linkonce.r.* .const .const:*)
-    *(.rodata1)
+    *(.plt)}
+    *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.* .const .const:*})
+    ${RELOCATING+*(.rodata1)
 
     *(.either.rodata.*) *(.either.rodata)
     *(.eh_frame_hdr)
@@ -230,13 +236,13 @@ SECTIONS
     KEEP (*crtbegin*.o(.dtors))
     KEEP (*(EXCLUDE_FILE (*crtend*.o ) .dtors))
     KEEP (*(SORT(.dtors.*)))
-    KEEP (*(.dtors))
+    KEEP (*(.dtors))}
   } ${RELOCATING+ > text}
 
   .vectors ${RELOCATING-0}:
   {
     ${RELOCATING+ PROVIDE (__vectors_start = .) ; }
-    *(.vectors*)
+    *(.vectors${RELOCATING+*})
     ${RELOCATING+ _vectors_end = . ; }
   } ${RELOCATING+ > vectors}
 
@@ -244,17 +250,17 @@ SECTIONS
   {
     ${RELOCATING+ PROVIDE (__data_start = .) ; }
     ${RELOCATING+ PROVIDE (__datastart = .) ; }
-    ${RELOCATING+. = ALIGN(2);}
+    ${RELOCATING+. = ALIGN(2);
 
     KEEP (*(.jcr))
     *(.data.rel.ro.local) *(.data.rel.ro*)
     *(.dynamic)
 
-    ${RELOCATING+. = ALIGN(2);}
-    *(.lower.data.* .lower.data)
+    . = ALIGN(2);
+    *(.lower.data.* .lower.data)}
 
     *(.data)
-    *(.data.*)
+    ${RELOCATING+*(.data.*)
     *(.gnu.linkonce.d*)
     KEEP (*(.gnu.linkonce.d.*personality*))
     *(.data1)
@@ -262,26 +268,26 @@ SECTIONS
     *(.either.data.* .either.data)
 
     *(.got.plt) *(.got)
-    ${RELOCATING+. = ALIGN(2);}
+    . = ALIGN(2);
     *(.sdata .sdata.* .gnu.linkonce.s.*)
-    ${RELOCATING+. = ALIGN(2);}
-    ${RELOCATING+ _edata = . ; }
-  } ${RELOCATING+ > data ${RELOCATING+AT> text}}
+    . = ALIGN(2);
+    _edata = .;}
+  } ${RELOCATING+ > data AT> text}
 
-  __romdatastart = LOADADDR(.data);
-  __romdatacopysize = SIZEOF(.data);
+  ${RELOCATING+__romdatastart = LOADADDR(.data);
+  __romdatacopysize = SIZEOF(.data);}
 
   .bss ${RELOCATING+ SIZEOF(.data) + ADDR(.data)} :
   {
     ${RELOCATING+. = ALIGN(2);}
     ${RELOCATING+ PROVIDE (__bss_start = .); }
-    ${RELOCATING+ PROVIDE (__bssstart = .); }
+    ${RELOCATING+ PROVIDE (__bssstart = .);
     *(.lower.bss.* .lower.bss)
-    ${RELOCATING+. = ALIGN(2);}
+    . = ALIGN(2);}
     *(.bss)
-    *(.either.bss.* .either.bss)
+    ${RELOCATING+*(.either.bss.* .either.bss)
     *(COMMON)
-    ${RELOCATING+ PROVIDE (__bss_end = .) ; }
+    PROVIDE (__bss_end = .);}
   } ${RELOCATING+ > data}
   ${RELOCATING+ PROVIDE (__bsssize = SIZEOF(.bss)); }
 
@@ -317,7 +323,7 @@ EOF
 
 . $srcdir/scripttempl/DWARF.sc
 
-cat <<EOF
+test -n "${RELOCATING}" && cat <<EOF
   .MSP430.attributes 0 :
   {
     KEEP (*(.MSP430.attributes))
@@ -331,5 +337,8 @@ cat <<EOF
   PROVIDE (__noinit_start_rom = _etext + SIZEOF (.data)) ;
   PROVIDE (__noinit_end_rom = _etext + SIZEOF (.data) + SIZEOF (.noinit)) ;
   PROVIDE (__subdevice_has_heap = ${GOT_HEAP_MSP-0}) ;
+EOF
+
+cat <<EOF
 }
 EOF
diff --git a/ld/scripttempl/elf32msp430_3.sc b/ld/scripttempl/elf32msp430_3.sc
index 0ed56e5..d808a52 100644
--- a/ld/scripttempl/elf32msp430_3.sc
+++ b/ld/scripttempl/elf32msp430_3.sc
@@ -14,6 +14,9 @@ cat <<EOF
 OUTPUT_FORMAT("${OUTPUT_FORMAT}","${OUTPUT_FORMAT}","${OUTPUT_FORMAT}")
 OUTPUT_ARCH(${ARCH})
 
+EOF
+
+test -n "${RELOCATING}" && cat <<EOF
 MEMORY
 {
   text   (rx)   : ORIGIN = $ROM_START,  LENGTH = $ROM_SIZE
@@ -21,6 +24,9 @@ MEMORY
   vectors (rw)  : ORIGIN = 0xffe0,      LENGTH = 0x20
 }
 
+EOF
+
+cat <<EOF
 SECTIONS
 {
   /* Read-only sections, merged into text segment.  */
@@ -86,7 +92,7 @@ SECTIONS
   /* Internal text space.  */
   .text :
   {
-    ${RELOCATING+. = ALIGN(2);}
+    ${RELOCATING+. = ALIGN(2);
     *(SORT_NONE(.init))
     *(SORT_NONE(.init0))  /* Start here after reset.  */
     *(SORT_NONE(.init1))
@@ -97,7 +103,7 @@ SECTIONS
     *(SORT_NONE(.init6)) /* C++ constructors.  */
     *(SORT_NONE(.init7))
     *(SORT_NONE(.init8))
-    *(SORT_NONE(.init9))  /* Call main().  */
+    *(SORT_NONE(.init9))  /* Call main().  */}
 
     ${CONSTRUCTING+ __ctors_start = . ; }
     ${CONSTRUCTING+ *(.ctors) }
@@ -108,12 +114,12 @@ SECTIONS
 
     ${RELOCATING+. = ALIGN(2);}
     *(.text)
-    ${RELOCATING+. = ALIGN(2);}
+    ${RELOCATING+. = ALIGN(2);
     *(.text.*)
-    ${RELOCATING+. = ALIGN(2);}
+    . = ALIGN(2);
     *(.text:*)
 
-    ${RELOCATING+. = ALIGN(2);}
+    . = ALIGN(2);
     *(SORT_NONE(.fini9))
     *(SORT_NONE(.fini8))
     *(SORT_NONE(.fini7))
@@ -126,14 +132,14 @@ SECTIONS
     *(SORT_NONE(.fini0))  /* Infinite loop after program termination.  */
     *(SORT_NONE(.fini))
 
-    ${RELOCATING+ _etext = . ; }
+    _etext = . ;}
   } ${RELOCATING+ > text}
 
   .rodata :
   {
-    *(.rodata .rodata.* .gnu.linkonce.r.*)
-    *(.const)
-    *(.const:*)
+    *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*})
+    ${RELOCATING+*(.const)}
+    ${RELOCATING+*(.const:*)}
   } ${RELOCATING+ > text}
 
   .data ${RELOCATING-0} :
@@ -141,11 +147,11 @@ SECTIONS
     ${RELOCATING+ PROVIDE (__data_start = .) ; }
     ${RELOCATING+. = ALIGN(2);}
     *(.data)
-    *(.data.*)
-    *(.gnu.linkonce.d*)
+    ${RELOCATING+*(.data.*)}
+    ${RELOCATING+*(.gnu.linkonce.d*)}
     ${RELOCATING+. = ALIGN(2);}
     ${RELOCATING+ _edata = . ; }
-  } ${RELOCATING+ > data ${RELOCATING+AT> text}}
+  } ${RELOCATING+ > data AT> text}
 
   __romdatastart = LOADADDR(.data);
   __romdatacopysize = SIZEOF(.data);
@@ -181,7 +187,7 @@ SECTIONS
   .vectors ${RELOCATING-0}:
   {
     ${RELOCATING+ PROVIDE (__vectors_start = .) ; }
-    *(.vectors*)
+    *(.vectors${RELOCATING+*})
     ${RELOCATING+ _vectors_end = . ; }
   } ${RELOCATING+ > vectors}
 
@@ -205,11 +211,14 @@ EOF
 
 . $srcdir/scripttempl/DWARF.sc
 
-cat <<EOF
+test -n "${RELOCATING}" && cat <<EOF
   PROVIDE (__stack = ${STACK}) ;
   PROVIDE (__data_start_rom = _etext) ;
   PROVIDE (__data_end_rom   = _etext + SIZEOF (.data)) ;
   PROVIDE (__noinit_start_rom = _etext + SIZEOF (.data)) ;
   PROVIDE (__noinit_end_rom = _etext + SIZEOF (.data) + SIZEOF (.noinit)) ;
+EOF
+
+cat <<EOF
 }
 EOF
diff --git a/ld/scripttempl/elf32xc16x.sc b/ld/scripttempl/elf32xc16x.sc
index 3a2c7b5..4c7cc36 100644
--- a/ld/scripttempl/elf32xc16x.sc
+++ b/ld/scripttempl/elf32xc16x.sc
@@ -13,7 +13,10 @@ cat <<EOF
 
 OUTPUT_FORMAT("${OUTPUT_FORMAT}")
 OUTPUT_ARCH(${ARCH})
-${RELOCATING+ENTRY ("_start")}
+EOF
+
+test -n "${RELOCATING}" && cat <<EOF
+ENTRY ("_start")
 MEMORY
 {
 
@@ -28,6 +31,9 @@ MEMORY
 	ldata  : o =0x4000 ,l = 0x0200
 }
 
+ELF
+
+cat <<EOF
 SECTIONS
 {
 .init :
@@ -37,15 +43,15 @@ SECTIONS
 
 .text :
 	{
-	  *(.rodata)
-	  *(.text.*)
+	  ${RELOCATING+*(.rodata)}
+	  ${RELOCATING+*(.text.*)}
 	  *(.text)
 	  ${RELOCATING+ _etext = . ; }
 	} ${RELOCATING+ > introm}
 .data :
 	{
 	  *(.data)
-	  *(.data.*)
+	  ${RELOCATING+*(.data.*)}
 
 	  ${RELOCATING+ _edata = . ; }
 	} ${RELOCATING+ > dram}
@@ -54,7 +60,7 @@ SECTIONS
 	{
 	  ${RELOCATING+ _bss_start = . ;}
 	  *(.bss)
-	  *(COMMON)
+	  ${RELOCATING+*(COMMON)}
 	  ${RELOCATING+ _end = . ;  }
 	} ${RELOCATING+ > dram}
 
diff --git a/ld/scripttempl/elf32xc16xl.sc b/ld/scripttempl/elf32xc16xl.sc
index 545df67..0b47319 100644
--- a/ld/scripttempl/elf32xc16xl.sc
+++ b/ld/scripttempl/elf32xc16xl.sc
@@ -13,7 +13,10 @@ cat <<EOF
 
 OUTPUT_FORMAT("${OUTPUT_FORMAT}")
 OUTPUT_ARCH(${ARCH})
-${RELOCATING+ENTRY ("_start")}
+EOF
+
+test -n "${RELOCATING}" && cat <<EOF
+ENTRY ("_start")
 MEMORY
 {
 	vectarea : o =0xc00000, l = 0x0300
@@ -26,6 +29,9 @@ MEMORY
 
 	ldata	: o =0x4000 ,l = 0x0200
 }
+EOF
+
+cat <<EOF
 SECTIONS
 {
 /*.vects :
@@ -39,15 +45,15 @@ SECTIONS
 
 .text :
 	{
-	  *(.rodata)
-	  *(.text.*)
+	  ${RELOCATING+*(.rodata)}
+	  ${RELOCATING+*(.text.*)}
 	  *(.text)
 	  ${RELOCATING+ _etext = . ; }
 	} ${RELOCATING+ > introm}
 .data :
 	{
 	  *(.data)
-	  *(.data.*)
+	  ${RELOCATING+*(.data.*)}
 
 	  ${RELOCATING+ _edata = . ; }
 	} ${RELOCATING+ > dram}
@@ -56,7 +62,7 @@ SECTIONS
 	{
 	  ${RELOCATING+ _bss_start = . ;}
 	  *(.bss)
-	  *(COMMON)
+	  ${RELOCATING+*(COMMON)}
 	  ${RELOCATING+ _end = . ;  }
 	} ${RELOCATING+ > dram}
 
diff --git a/ld/scripttempl/elf32xc16xs.sc b/ld/scripttempl/elf32xc16xs.sc
index 545df67..89672f9 100644
--- a/ld/scripttempl/elf32xc16xs.sc
+++ b/ld/scripttempl/elf32xc16xs.sc
@@ -13,7 +13,10 @@ cat <<EOF
 
 OUTPUT_FORMAT("${OUTPUT_FORMAT}")
 OUTPUT_ARCH(${ARCH})
-${RELOCATING+ENTRY ("_start")}
+EOF
+
+test -n "${RELOCATING}" && cat <<EOF
+ENTRY ("_start")
 MEMORY
 {
 	vectarea : o =0xc00000, l = 0x0300
@@ -26,6 +29,10 @@ MEMORY
 
 	ldata	: o =0x4000 ,l = 0x0200
 }
+
+EOF
+
+cat <<EOF
 SECTIONS
 {
 /*.vects :
@@ -39,15 +46,15 @@ SECTIONS
 
 .text :
 	{
-	  *(.rodata)
-	  *(.text.*)
+	  ${RELOCATING+*(.rodata)}
+	  ${RELOCATING+*(.text.*)}
 	  *(.text)
 	  ${RELOCATING+ _etext = . ; }
 	} ${RELOCATING+ > introm}
 .data :
 	{
 	  *(.data)
-	  *(.data.*)
+	  ${RELOCATING+*(.data.*)}
 
 	  ${RELOCATING+ _edata = . ; }
 	} ${RELOCATING+ > dram}
@@ -56,7 +63,7 @@ SECTIONS
 	{
 	  ${RELOCATING+ _bss_start = . ;}
 	  *(.bss)
-	  *(COMMON)
+	  ${RELOCATING+*(COMMON)}
 	  ${RELOCATING+ _end = . ;  }
 	} ${RELOCATING+ > dram}
 
diff --git a/ld/scripttempl/elf64hppa.sc b/ld/scripttempl/elf64hppa.sc
index 9b1d34e..1bed674 100644
--- a/ld/scripttempl/elf64hppa.sc
+++ b/ld/scripttempl/elf64hppa.sc
@@ -123,7 +123,7 @@ fi
 test -n "${DATA_PLT-${BSS_PLT-text}}" && TEXT_PLT=yes
 if test -z "$GOT"; then
   if test -z "$SEPARATE_GOTPLT"; then
-    GOT=".got          ${RELOCATING-0} : { *(.got.plt) *(.got) }"
+    GOT=".got          ${RELOCATING-0} : {${RELOCATING+ *(.got.plt)} *(.got) }"
   else
     GOT=".got          ${RELOCATING-0} : { *(.got) }"
     GOTPLT=".got.plt      ${RELOCATING-0} : { *(.got.plt) }"
@@ -138,9 +138,9 @@ if test -z "${NO_SMALL_DATA}"; then
   {
     ${RELOCATING+${SBSS_START_SYMBOLS}}
     ${CREATE_SHLIB+*(.sbss2 .sbss2.* .gnu.linkonce.sb2.*)}
-    *(.dynsbss)
+    ${RELOCATING+*(.dynsbss)}
     *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
-    *(.scommon)
+    ${RELOCATING+*(.scommon)}
     ${RELOCATING+${SBSS_END_SYMBOLS}}
   }"
   SBSS2=".sbss2        ${RELOCATING-0} : { *(.sbss2${RELOCATING+ .sbss2.* .gnu.linkonce.sb2.*}) }"
@@ -433,7 +433,7 @@ cat <<EOF
   ${OTHER_READONLY_SECTIONS}
   .eh_frame_hdr : { *(.eh_frame_hdr) }
   .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame)) }
-  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
+  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
 
   /* Adjust the address for the data segment.  We want to adjust up to
      the same address within the page on the next page up.  */
@@ -443,7 +443,7 @@ cat <<EOF
 
   /* Exception handling  */
   .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) }
-  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
+  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
 
   /* Thread Local Storage sections  */
   .tdata	${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
@@ -496,15 +496,15 @@ cat <<EOF
   ${BSS_PLT+${PLT}}
   .bss          ${RELOCATING-0} :
   {
-   *(.dynbss)
-   *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
-   *(COMMON)
-   /* Align here to ensure that the .bss section occupies space up to
-      _end.  Align after .bss to ensure correct alignment even if the
-      .bss section disappears because there are no input sections.
-      FIXME: Why do we need it? When there is no .bss section, we don't
-      pad the .data section.  */
-   ${RELOCATING+. = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
+    ${RELOCATING+*(.dynbss)}
+    *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
+    ${RELOCATING+*(COMMON)
+    /* Align here to ensure that the .bss section occupies space up to
+       _end.  Align after .bss to ensure correct alignment even if the
+       .bss section disappears because there are no input sections.
+       FIXME: Why do we need it? When there is no .bss section, we do not
+       pad the .data section.  */
+    . = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
   }
   ${OTHER_BSS_SECTIONS}
   ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
diff --git a/ld/scripttempl/elf_chaos.sc b/ld/scripttempl/elf_chaos.sc
index 85f40ab..9db5b73 100644
--- a/ld/scripttempl/elf_chaos.sc
+++ b/ld/scripttempl/elf_chaos.sc
@@ -238,7 +238,7 @@ cat <<EOF
 EOF
 fi
 cat <<EOF
-  . = ALIGN(0x1000);
+  ${RELOCATING+. = ALIGN(0x1000);}
   .rel.plt      ${RELOCATING-0} : { *(.rel.plt) }
   .rela.plt     ${RELOCATING-0} : { *(.rela.plt) }
   ${OTHER_PLT_RELOC_SECTIONS}
@@ -260,36 +260,36 @@ cat <<EOF
   ${RELOCATING+PROVIDE (__etext = .);}
   ${RELOCATING+PROVIDE (_etext = .);}
   ${RELOCATING+PROVIDE (etext = .);}
-  . = ALIGN(0x1000);
+  ${RELOCATING+. = ALIGN(0x1000);}
   ${CREATE_SHLIB-${SDATA2}}
   ${CREATE_SHLIB-${SBSS2}}
   ${OTHER_READONLY_SECTIONS}
   .eh_frame_hdr : { *(.eh_frame_hdr) }
 
-  . = ALIGN(0x1000);
+  ${RELOCATING+. = ALIGN(0x1000);}
   .data         ${RELOCATING-0} :
   {
-    *(.rodata .rodata.*)
+    ${RELOCATING+*(.rodata .rodata.*)
     *(.rodata1)
     *(.gnu.linkonce.r.*)
-    ${RELOCATING+${DATA_START_SYMBOLS}}
+    ${DATA_START_SYMBOLS}}
     *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
     ${CONSTRUCTING+SORT(CONSTRUCTORS)}
-    KEEP (*(.eh_frame))
+    ${RELOCATING+KEEP (*(.eh_frame))
     *(.gcc_except_table)
     ${CTOR}
     ${DTOR}
-    KEEP (*(.jcr))
+    KEEP (*(.jcr))}
   }
   .data1        ${RELOCATING-0} : { *(.data1) }
-  . = ALIGN(0x1000);
+  ${RELOCATING+. = ALIGN(0x1000);}
   .gcc_except_table ${RELOCATING-0} : { *(.gcc_except_table) }
   ${WRITABLE_RODATA+${RODATA}}
   ${OTHER_READWRITE_SECTIONS}
   ${TEXT_DYNAMIC-${DYNAMIC}}
   ${DATA_PLT+${PLT}}
   ${RELOCATING+${OTHER_GOT_SYMBOLS}}
-  .got          ${RELOCATING-0} : { *(.got.plt) *(.got) }
+  .got          ${RELOCATING-0} : {${RELOCATING+ *(.got.plt)} *(.got) }
   ${OTHER_GOT_SECTIONS}
   ${CREATE_SHLIB+${SDATA2}}
   ${CREATE_SHLIB+${SBSS2}}
@@ -301,16 +301,16 @@ cat <<EOF
   ${RELOCATING+${OTHER_BSS_SYMBOLS}}
   ${SBSS}
   ${BSS_PLT+${PLT}}
-  . = ALIGN(0x1000);
+  ${RELOCATING+. = ALIGN(0x1000);}
   .bss          ${RELOCATING-0} :
   {
-   *(.dynbss)
+   ${RELOCATING+*(.dynbss)}
    *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
-   *(COMMON)
+   ${RELOCATING+*(COMMON)
    /* Align here to ensure that the .bss section occupies space up to
       _end.  Align after .bss to ensure correct alignment even if the
       .bss section disappears because there are no input sections.  */
-   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
+   . = ALIGN(${ALIGNMENT});}
   }
   ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
@@ -320,7 +320,6 @@ cat <<EOF
   ${STACK_ADDR+${STACK}}
 
   /* Stabs debugging sections.  */
-  . = ALIGN(0x1000);
   .stab          0 : { *(.stab) }
   .stabstr       0 : { *(.stabstr) }
   .stab.excl     0 : { *(.stab.excl) }
@@ -328,7 +327,6 @@ cat <<EOF
   .stab.index    0 : { *(.stab.index) }
   .stab.indexstr 0 : { *(.stab.indexstr) }
 
-  . = ALIGN(0x1000);
   .comment       0 : { *(.comment) }
 
 EOF
diff --git a/ld/scripttempl/elfarc.sc b/ld/scripttempl/elfarc.sc
index 802ef91..c1a0b3c 100644
--- a/ld/scripttempl/elfarc.sc
+++ b/ld/scripttempl/elfarc.sc
@@ -84,7 +84,7 @@ if test -n "${COMMONPAGESIZE}"; then
 fi
 INTERP=".interp       ${RELOCATING-0} : { *(.interp) }"
 PLT=".plt          ${RELOCATING-0} : { *(.plt) }"
-test -z "$GOT" && GOT=".got          ${RELOCATING-0} : { *(.got.plt) *(.got) }"
+test -z "$GOT" && GOT=".got          ${RELOCATING-0} : {${RELOCATING+ *(.got.plt)} *(.got) }"
 DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
 RODATA=".rodata       ${RELOCATING-0} : { *(.rodata${RELOCATING+ .rodata.* .gnu.linkonce.r.*}) }"
 STACKNOTE="/DISCARD/ : { *(.note.GNU-stack) }"
@@ -93,9 +93,9 @@ if test -z "${NO_SMALL_DATA}"; then
   {
     ${RELOCATING+PROVIDE (__sbss_start = .);}
     ${RELOCATING+PROVIDE (___sbss_start = .);}
-    *(.dynsbss)
+    ${RELOCATING+*(.dynsbss)}
     *(.sbss${RELOCATING+ .sbss.* .gnu.linkonce.sb.*})
-    *(.scommon)
+    ${RELOCATING+*(.scommon)}
     ${RELOCATING+PROVIDE (__sbss_end = .);}
     ${RELOCATING+PROVIDE (___sbss_end = .);}
   }"
@@ -265,8 +265,8 @@ cat <<EOF
   .jlitab       ${RELOCATING-0} :
   {
     ${RELOCATING+${JLI_START_TABLE}}
-    jlitab*.o(.jlitab*)
-    *(.jlitab*)
+    ${RELOCATING+jlitab*.o(.jlitab*)}
+    *(.jlitab${RELOCATING+*})
   } =${NOP-0}
   .text         ${RELOCATING-0} :
   {
@@ -295,7 +295,7 @@ cat <<EOF
   ${CREATE_SHLIB-${SBSS2}}
   ${OTHER_READONLY_SECTIONS}
   .eh_frame_hdr : { *(.eh_frame_hdr) }
-  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table .gcc_except_table.*) }
+  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
 
   /* Adjust the address for the data segment.  We want to adjust up to
      the same address within the page on the next page up.  */
@@ -304,7 +304,7 @@ cat <<EOF
   ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
 
   /* Exception handling  */
-  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
+  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) }
 
   /* Ensure the __preinit_array_start label is properly aligned.  We
      could instead move the label definition inside the section, but
@@ -360,13 +360,13 @@ cat <<EOF
   ${BSS_PLT+${PLT}}
   .bss          ${RELOCATING-0} :
   {
-   *(.dynbss)
-   *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
-   *(COMMON)
-   /* Align here to ensure that the .bss section occupies space up to
-      _end.  Align after .bss to ensure correct alignment even if the
-      .bss section disappears because there are no input sections.  */
-   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
+    ${RELOCATING+*(.dynbss)}
+    *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
+    ${RELOCATING+*(COMMON)
+    /* Align here to ensure that the .bss section occupies space up to
+       _end.  Align after .bss to ensure correct alignment even if the
+       .bss section disappears because there are no input sections.  */
+    . = ALIGN(${ALIGNMENT});}
   }
   ${OTHER_BSS_SECTIONS}
   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
@@ -374,27 +374,31 @@ cat <<EOF
   ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
   ${RELOCATING+PROVIDE (end = .);}
   ${RELOCATING+${DATA_SEGMENT_END}}
+EOF
 
+test -n "${RELOCATING}" && cat <<EOF
   /* We want to be able to set a default stack / heap size in a dejagnu
      board description file, but override it for selected test cases.
      The options appear in the wrong order to do this with a single symbol -
      ldflags comes after flags injected with per-file stanzas, and thus
      the setting from ldflags prevails.  */
-  .heap ${RELOCATING-0} :
+  .heap :
   {
-	${RELOCATING+ __start_heap = . ; }
-	${RELOCATING+ . = . + (DEFINED(__HEAP_SIZE) ? __HEAP_SIZE : (DEFINED(__DEFAULT_HEAP_SIZE) ? __DEFAULT_HEAP_SIZE : 20k)) ; }
-	${RELOCATING+ __end_heap = . ; }
+	__start_heap = . ;
+	. = . + (DEFINED(__HEAP_SIZE) ? __HEAP_SIZE : (DEFINED(__DEFAULT_HEAP_SIZE) ? __DEFAULT_HEAP_SIZE : 20k)) ;
+	__end_heap = . ;
   }
 
-  ${RELOCATING+. = ALIGN(0x8);}
-  .stack ${RELOCATING-0} :
+  . = ALIGN(0x8);
+  .stack :
   {
-	${RELOCATING+ __stack = . ; }
-	${RELOCATING+ . = . + (DEFINED(__STACK_SIZE) ? __STACK_SIZE : (DEFINED(__DEFAULT_STACK_SIZE) ? __DEFAULT_STACK_SIZE : 64k)) ; }
-	${RELOCATING+ __stack_top = . ; }
+	__stack = . ;
+	. = . + (DEFINED(__STACK_SIZE) ? __STACK_SIZE : (DEFINED(__DEFAULT_STACK_SIZE) ? __DEFAULT_STACK_SIZE : 64k)) ;
+	__stack_top = . ;
   }
+EOF
 
+cat <<EOF
   /* Stabs debugging sections.  */
   .stab          0 : { *(.stab) }
   .stabstr       0 : { *(.stabstr) }
@@ -422,7 +426,7 @@ cat <<EOF
   .debug_pubnames 0 : { *(.debug_pubnames) }
 
   /* DWARF 2 */
-  .debug_info     0 : { *(.debug_info .gnu.linkonce.wi.*) }
+  .debug_info     0 : { *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*}) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
   .debug_frame    0 : { *(.debug_frame) }
diff --git a/ld/scripttempl/elfarcv2.sc b/ld/scripttempl/elfarcv2.sc
index ccc608e..1027123 100644
--- a/ld/scripttempl/elfarcv2.sc
+++ b/ld/scripttempl/elfarcv2.sc
@@ -12,7 +12,7 @@ test -z "$ENTRY" && ENTRY=start
 test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
 test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
 # If we request a big endian toolchain, give a big endian linker
-test -z "$GOT" && GOT=".got          ${RELOCATING-0} : { *(.got.plt) *(.got) } ${RELOCATING+ > ${DATA_MEMORY}}"
+test -z "$GOT" && GOT=".got          ${RELOCATING-0} : {${RELOCATING+ *(.got.plt)} *(.got) } ${RELOCATING+ > ${DATA_MEMORY}}"
 test "${ARC_ENDIAN}" == "big" && OUTPUT_FORMAT=${BIG_OUTPUT_FORMAT}
 if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
 test -z "${ELFSIZE}" && ELFSIZE=32
@@ -177,12 +177,13 @@ SECTIONS
 
   .jcr : { KEEP (*(.jcr)) } ${RELOCATING+> ${TEXT_MEMORY}}
   .eh_frame : { KEEP (*(.eh_frame)) } ${RELOCATING+> ${TEXT_MEMORY}}
-  .gcc_except_table : { *(.gcc_except_table) *(.gcc_except_table.*) } ${RELOCATING+> ${TEXT_MEMORY}}
+  .gcc_except_table : { *(.gcc_except_table${RELOCATING+ .gcc_except_table.*}) } ${RELOCATING+> ${TEXT_MEMORY}}
   .plt : { *(.plt) } ${RELOCATING+> ${TEXT_MEMORY}}
   .jlitab :
   {
     ${RELOCATING+${JLI_START_TABLE}}
-     jlitab*.o:(.jlitab*) *(.jlitab*)
+    ${RELOCATING+jlitab*.o:(.jlitab*)}
+    *(.jlitab${RELOCATING+*})
   } ${RELOCATING+> ${TEXT_MEMORY}}
 
   .rodata ${RELOCATING-0} :
@@ -236,7 +237,7 @@ SECTIONS
        line will have no effect, see PR13697.  Thus, keep .data  */
     KEEP (*(.data))
     ${RELOCATING+${DATA_START_SYMBOLS}}
-    *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
+    ${RELOCATING+*(.data.* .gnu.linkonce.d.*)}
     ${CONSTRUCTING+SORT(CONSTRUCTORS)}
 
   } ${RELOCATING+ > ${DATA_MEMORY}}
@@ -251,13 +252,13 @@ SECTIONS
   ${RELOCATING+${SBSS2}}
   .bss          ${RELOCATING-0} :
   {
-   *(.dynbss)
-   *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
-   *(COMMON)
-   /* Align here to ensure that the .bss section occupies space up to
-      _end.  Align after .bss to ensure correct alignment even if the
-      .bss section disappears because there are no input sections.  */
-   ${RELOCATING+. = ALIGN(${ALIGNMENT});}
+    ${RELOCATING+*(.dynbss)}
+    *(.bss${RELOCATING+ .bss.* .gnu.linkonce.b.*})
+    ${RELOCATING+*(COMMON)
+    /* Align here to ensure that the .bss section occupies space up to
+       _end.  Align after .bss to ensure correct alignment even if the
+       .bss section disappears because there are no input sections.  */
+    . = ALIGN(${ALIGNMENT});}
    ${RELOCATING+_end = .;}
    ${RELOCATING+PROVIDE (end = .);}
   } ${RELOCATING+ > ${DATA_MEMORY}}
@@ -298,7 +299,7 @@ SECTIONS
   .debug_pubnames 0 : { *(.debug_pubnames) }
 
   /* DWARF 2 */
-  .debug_info     0 : { *(.debug_info) *(.gnu.linkonce.wi.*) }
+  .debug_info     0 : { *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*}) }
   .debug_abbrev   0 : { *(.debug_abbrev) }
   .debug_line     0 : { *(.debug_line) }
   .debug_frame    0 : { *(.debug_frame) }
diff --git a/ld/scripttempl/elfd10v.sc b/ld/scripttempl/elfd10v.sc
index d21f580..b79e95e 100644
--- a/ld/scripttempl/elfd10v.sc
+++ b/ld/scripttempl/elfd10v.sc
@@ -70,12 +70,15 @@ cat <<EOF
 OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
 	      "${LITTLE_OUTPUT_FORMAT}")
 OUTPUT_ARCH(${OUTPUT_ARCH})
-${RELOCATING+ENTRY(${ENTRY})}
+EOF
+
+test -n "${RELOCATING}" && cat <<EOF
+ENTRY(${ENTRY})
 
-${RELOCATING+${LIB_SEARCH_DIRS}}
-${RELOCATING+/* Do we need any of these for elf?
-   __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}}  */}
-${RELOCATING+${EXECUTABLE_SYMBOLS}}
+${LIB_SEARCH_DIRS}
+/* Do we need any of these for elf?
+   __DYNAMIC = 0; ${STACKZERO+${STACKZERO}} ${SHLIB_PATH+${SHLIB_PATH}}  */
+${EXECUTABLE_SYMBOLS}
 
 MEMORY
 {
@@ -94,47 +97,50 @@ MEMORY
   STACK      : org = 0x0200BFFC, len = 4
 }
 
+EOF
+
+cat <<EOF
 SECTIONS
 {
   .text ${RELOCATING+${TEXT_START_ADDR}} :
   {
-    ${RELOCATING+${TEXT_START_SYMBOLS}}
+    ${RELOCATING+${TEXT_START_SYMBOLS}
     KEEP (*(SORT_NONE(.init)))
     KEEP (*(SORT_NONE(.init.*)))
     KEEP (*(SORT_NONE(.fini)))
-    KEEP (*(SORT_NONE(.fini.*)))
+    KEEP (*(SORT_NONE(.fini.*)))}
     *(.text)
-    *(.text.*)
+    ${RELOCATING+*(.text.*)}
     /* .gnu.warning sections are handled specially by elf32.em.  */
     *(.gnu.warning)
-    *(.gnu.linkonce.t*)
-    ${RELOCATING+_etext = .;}
-    ${RELOCATING+PROVIDE (etext = .);}
+    ${RELOCATING+*(.gnu.linkonce.t*)
+    _etext = .;
+    PROVIDE (etext = .);}
   } ${RELOCATING+ >INSN} =${NOP-0}
 
   .rodata ${RELOCATING+${READONLY_START_ADDR}} : {
     *(.rodata)
-    *(.gnu.linkonce.r*)
-    *(.rodata.*)
+    ${RELOCATING+*(.gnu.linkonce.r*)
+    *(.rodata.*)}
   } ${RELOCATING+ >DATA}
 
   .rodata1 ${RELOCATING-0} : {
     *(.rodata1)
-    *(.rodata1.*)
+    ${RELOCATING+*(.rodata1.*)}
    } ${RELOCATING+ >DATA}
 
   .data  ${RELOCATING-0} :
   {
     ${RELOCATING+${DATA_START_SYMBOLS}}
     *(.data)
-    *(.data.*)
-    *(.gnu.linkonce.d*)
+    ${RELOCATING+*(.data.*)
+    *(.gnu.linkonce.d*)}
     ${CONSTRUCTING+CONSTRUCTORS}
   } ${RELOCATING+ >DATA}
 
   .data1 ${RELOCATING-0} : {
     *(.data1)
-    *(.data1.*)
+    ${RELOCATING+*(.data1.*)}
   } ${RELOCATING+ >DATA}
 
   ${RELOCATING+${CTOR} >DATA}
@@ -145,20 +151,20 @@ SECTIONS
      we can shorten the on-disk segment size.  */
   .sdata   ${RELOCATING-0} : {
     *(.sdata)
-    *(.sdata.*)
+    ${RELOCATING+*(.sdata.*)}
   } ${RELOCATING+ >DATA}
 
   ${RELOCATING+_edata = .;}
   ${RELOCATING+PROVIDE (edata = .);}
   ${RELOCATING+__bss_start = .;}
-  .sbss    ${RELOCATING-0} : { *(.sbss) *(.scommon) } ${RELOCATING+ >DATA}
+  .sbss    ${RELOCATING-0} : { *(.sbss)${RELOCATING+ *(.scommon)} } ${RELOCATING+ >DATA}
   .bss     ${RELOCATING-0} :
   {
-   *(.dynbss)
-   *(.dynbss.*)
+   ${RELOCATING+*(.dynbss)
+   *(.dynbss.*)}
    *(.bss)
-   *(.bss.*)
-   *(COMMON)
+   ${RELOCATING+*(.bss.*)
+   *(COMMON)}
   } ${RELOCATING+ >DATA}
 
   ${RELOCATING+_end = . ;}
diff --git a/ld/scripttempl/elfd30v.sc b/ld/scripttempl/elfd30v.sc
index 388a578..8e306ca 100644
--- a/ld/scripttempl/elfd30v.sc
+++ b/ld/scripttempl/elfd30v.sc
@@ -52,6 +52,9 @@ cat <<EOF
 OUTPUT_FORMAT("${OUTPUT_FORMAT}")
 OUTPUT_ARCH(${ARCH})
 
+EOF
+
+test -n "${RELOCATING}" && cat <<EOF
 MEMORY
 {
   text ${TEXT_DEF_SECTION} : ORIGIN = ${TEXT_START_ADDR}, LENGTH = ${TEXT_SIZE}
@@ -60,6 +63,9 @@ MEMORY
   eit			   : ORIGIN = ${EIT_START_ADDR},  LENGTH = ${EIT_SIZE}
 }
 
+EOF
+
+cat <<EOF
 SECTIONS
 {
   /* Read-only sections, merged into text segment: */
@@ -71,12 +77,12 @@ SECTIONS
   .gnu.version_d	${RELOCATING-0} : { *(.gnu.version_d) }
   .gnu.version_r	${RELOCATING-0} : { *(.gnu.version_r) }
 
-  .rel.text		${RELOCATING-0} : { *(.rel.text) *(.rel.gnu.linkonce.t*) }
-  .rela.text		${RELOCATING-0} : { *(.rela.text) *(.rela.gnu.linkonce.t*) }
-  .rel.data		${RELOCATING-0} : { *(.rel.data) *(.rel.gnu.linkonce.d*) }
-  .rela.data		${RELOCATING-0} : { *(.rela.data) *(.rela.gnu.linkonce.d*) }
-  .rel.rodata		${RELOCATING-0} : { *(.rel.rodata) *(.rel.gnu.linkonce.r*) }
-  .rela.rodata		${RELOCATING-0} : { *(.rela.rodata) *(.rela.gnu.linkonce.r*) }
+  .rel.text		${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.gnu.linkonce.t*}) }
+  .rela.text		${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.gnu.linkonce.t*}) }
+  .rel.data		${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.gnu.linkonce.d*}) }
+  .rela.data		${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.gnu.linkonce.d*}) }
+  .rel.rodata		${RELOCATING-0} : { *(.rel.rodata${RELOCATING+ .rel.gnu.linkonce.r*}) }
+  .rela.rodata		${RELOCATING-0} : { *(.rela.rodata${RELOCATING+ .rela.gnu.linkonce.r*}) }
   .rel.stext		${RELOCATING-0} : { *(.rel.stest) }
   .rela.stext		${RELOCATING-0} : { *(.rela.stest) }
   .rel.etext		${RELOCATING-0} : { *(.rel.etest) }
@@ -120,10 +126,10 @@ SECTIONS
   .text :
   {
     *(.text)
-    *(.gnu.linkonce.t*)
+    ${RELOCATING+*(.gnu.linkonce.t*)
     *(SORT_NONE(.init))
     *(SORT_NONE(.fini))
-    ${RELOCATING+ _etext = . ; }
+    _etext = . ;}
   } ${RELOCATING+ > ${TEXT_MEMORY}}
 
   /* Internal data space */
@@ -146,7 +152,7 @@ SECTIONS
   .data		${RELOCATING-0} :
   {
     *(.data)
-    *(.gnu.linkonce.d*)
+    ${RELOCATING+*(.gnu.linkonce.d*)}
     ${CONSTRUCTING+CONSTRUCTORS}
     ${RELOCATING+ _edata = . ; }
   } ${RELOCATING+ > ${DATA_MEMORY}}
@@ -180,7 +186,7 @@ SECTIONS
   {
     ${RELOCATING+ PROVIDE (__bss_start = .) ; }
     *(.bss)
-    *(COMMON)
+    ${RELOCATING+*(COMMON)}
     ${RELOCATING+ PROVIDE (__bss_end = .) ; }
     ${RELOCATING+ _end = . ;  }
   } ${RELOCATING+ > ${DATA_MEMORY}}
@@ -207,10 +213,9 @@ EOF
 . $srcdir/scripttempl/DWARF.sc
 
 cat <<EOF
-  PROVIDE (__stack = ${STACK_START_ADDR});
+  ${RELOCATING+PROVIDE (__stack = ${STACK_START_ADDR});}
 }
 EOF
 
 
 
-
diff --git a/ld/scripttempl/elfm68hc11.sc b/ld/scripttempl/elfm68hc11.sc
index df7694f..ae1bfd6 100644
--- a/ld/scripttempl/elfm68hc11.sc
+++ b/ld/scripttempl/elfm68hc11.sc
@@ -410,12 +410,11 @@ SECTIONS
     ${RELOCATING+__bss_start = .;}
     ${RELOCATING+*(.sbss)}
     ${RELOCATING+*(.scommon)}
-
-    *(.dynbss)
+    ${RELOCATING+*(.dynbss)}
     *(.bss)
     ${RELOCATING+*(.bss.*)}
     ${RELOCATING+*(.gnu.linkonce.b.*)}
-    *(COMMON)
+    ${RELOCATING+*(COMMON)}
     ${RELOCATING+PROVIDE (_end = .);}
   } ${RELOCATING+ > ${DATA_MEMORY}}
   ${RELOCATING+__bss_size = SIZEOF(.bss);}
@@ -424,7 +423,7 @@ SECTIONS
   .eeprom ${RELOCATING-0} :
   {
     *(.eeprom)
-    *(.eeprom.*)
+    ${RELOCATING+*(.eeprom.*)}
   } ${RELOCATING+ > ${EEPROM_MEMORY}}
 
   ${RELOCATING+${VECTORS}}
diff --git a/ld/scripttempl/elfm68hc12.sc b/ld/scripttempl/elfm68hc12.sc
index 4b8154a..4690ab6 100644
--- a/ld/scripttempl/elfm68hc12.sc
+++ b/ld/scripttempl/elfm68hc12.sc
@@ -413,12 +413,11 @@ SECTIONS
     ${RELOCATING+*(.softregs)}
     ${RELOCATING+*(.sbss)}
     ${RELOCATING+*(.scommon)}
-
-    *(.dynbss)
+    ${RELOCATING+*(.dynbss)}
     *(.bss)
     ${RELOCATING+*(.bss.*)}
     ${RELOCATING+*(.gnu.linkonce.b.*)}
-    *(COMMON)
+    ${RELOCATING+*(COMMON)}
     ${RELOCATING+PROVIDE (_end = .);}
   } ${RELOCATING+ > ${DATA_MEMORY}}
   ${RELOCATING+__bss_size = SIZEOF(.bss);}
@@ -427,7 +426,7 @@ SECTIONS
   .eeprom ${RELOCATING-0} :
   {
     *(.eeprom)
-    *(.eeprom.*)
+    ${RELOCATING+*(.eeprom.*)}
   } ${RELOCATING+ > ${EEPROM_MEMORY}}
 
   ${RELOCATING+${VECTORS}}
diff --git a/ld/scripttempl/elfm9s12z.sc b/ld/scripttempl/elfm9s12z.sc
index 5553aeb..b14c68b 100644
--- a/ld/scripttempl/elfm9s12z.sc
+++ b/ld/scripttempl/elfm9s12z.sc
@@ -173,7 +173,7 @@ ${RELOCATING+${LIB_SEARCH_DIRS}}
 ${RELOCATING+${EXECUTABLE_SYMBOLS}}
 ${RELOCATING+${MEMORY_DEF}}
 
-PROVIDE (_start = $[$ROM_TOP - $ROM_SIZE + 1]);
+${RELOCATING+PROVIDE (_start = $[$ROM_TOP - $ROM_SIZE + 1]);}
 SECTIONS
 {
   .hash        ${RELOCATING-0} : { *(.hash)		}
@@ -403,12 +403,11 @@ SECTIONS
     ${RELOCATING+*(.sbss)}
     ${RELOCATING+*(.common)}
     ${RELOCATING+*(.scommon)}
-
-    *(.dynbss)
+    ${RELOCATING+*(.dynbss)}
     *(.bss)
     ${RELOCATING+*(.bss.*)}
     ${RELOCATING+*(.gnu.linkonce.b.*)}
-    *(COMMON)
+    ${RELOCATING+*(COMMON)}
     ${RELOCATING+PROVIDE (_end = .);}
   } ${RELOCATING+ > ${DATA_MEMORY}}
   ${RELOCATING+__bss_size = SIZEOF(.bss);}
@@ -417,7 +416,7 @@ SECTIONS
   .eeprom ${RELOCATING-0} :
   {
     *(.eeprom)
-    *(.eeprom.*)
+    ${RELOCATING+*(.eeprom.*)}
   } ${RELOCATING+ > ${EEPROM_MEMORY}}
 
   ${RELOCATING+${VECTORS}}
diff --git a/ld/scripttempl/elfmicroblaze.sc b/ld/scripttempl/elfmicroblaze.sc
index d8f7569..4a7c196 100644
--- a/ld/scripttempl/elfmicroblaze.sc
+++ b/ld/scripttempl/elfmicroblaze.sc
@@ -63,9 +63,9 @@ ${RELOCATING+${LIB_SEARCH_DIRS}}
 
 ${RELOCATING+ENTRY (${ENTRY})}
 
-_TEXT_START_ADDR = DEFINED(_TEXT_START_ADDR) ? _TEXT_START_ADDR : 0x50;
+${RELOCATING+_TEXT_START_ADDR = DEFINED(_TEXT_START_ADDR) ? _TEXT_START_ADDR : 0x50;
 _HEAP_SIZE = DEFINED(_HEAP_SIZE) ? _HEAP_SIZE : 0x0;
-_STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x400;
+_STACK_SIZE = DEFINED(_STACK_SIZE) ? _STACK_SIZE : 0x400;}
 
 SECTIONS
 {
@@ -79,7 +79,7 @@ SECTIONS
 
   ${RELOCATING+ _ftext  =  .;}
   .text : {
-    ${RELOCATING+*(.text)}
+    *(.text)
     ${RELOCATING+*(.text.*)}
     ${RELOCATING+*(.gnu.linkonce.t.*)}
   }
@@ -103,10 +103,10 @@ SECTIONS
   ${RELOCATING+ . = ALIGN(4);}
    ${RELOCATING+ _frodata = . ;}
   .rodata : {
-    ${RELOCATING+*(.rodata)}
+    *(.rodata)
     ${RELOCATING+*(.rodata.*)}
     ${RELOCATING+*(.gnu.linkonce.r.*)}
-    ${CONSTRUCTING+CONSTRUCTORS}; /* Is this needed? */
+    ${CONSTRUCTING+CONSTRUCTORS;} /* Is this needed? */
   }
   ${RELOCATING+ _erodata = .;}
 
@@ -115,14 +115,14 @@ SECTIONS
   ${RELOCATING+. = ALIGN(8);}
   ${RELOCATING+ _ssrw = .;}
   .sdata2 : {
-    ${RELOCATING+*(.sdata2)}
+    *(.sdata2)
     ${RELOCATING+*(.sdata2.*)}
     ${RELOCATING+*(.gnu.linkonce.s2.*)}
   }
   ${RELOCATING+. = ALIGN(4);}
   .sbss2 : {
     ${RELOCATING+PROVIDE (__sbss2_start = .);}
-    ${RELOCATING+*(.sbss2)}
+    *(.sbss2)
     ${RELOCATING+*(.sbss2.*)}
     ${RELOCATING+*(.gnu.linkonce.sb2.*)}
     ${RELOCATING+PROVIDE (__sbss2_end = .);}
@@ -135,36 +135,36 @@ SECTIONS
   ${RELOCATING+ . = ALIGN(4);}
   ${RELOCATING+ _fdata = .;}
   .data : {
-    ${RELOCATING+*(.data)}
+    *(.data)
     ${RELOCATING+*(.gnu.linkonce.d.*)}
-    ${CONSTRUCTING+CONSTRUCTORS}; /* Is this needed? */
+    ${CONSTRUCTING+CONSTRUCTORS;} /* Is this needed? */
   }
   ${RELOCATING+ _edata = . ;}
 
    /* Added to handle pic code */
   .got : {
-    ${RELOCATING+*(.got)}
+    *(.got)
   }
 
   .got1 : {
-    ${RELOCATING+*(.got1)}
+    *(.got1)
   }
 
   .got2 : {
-    ${RELOCATING+*(.got2)}
+    *(.got2)
   }
 
   /* Added by Sathya to handle C++ exceptions */
   .eh_frame : {
-    ${RELOCATING+*(.eh_frame)}
+    *(.eh_frame)
   }
 
   .jcr : {
-    $[...]

[diff truncated at 100000 bytes]



More information about the Binutils-cvs mailing list