1diff --git a/bfd/config.bfd b/bfd/config.bfd
2index 5324d39a21cb..3f0119ab2649 100644
3--- a/bfd/config.bfd
4+++ b/bfd/config.bfd
5@@ -630,6 +630,10 @@ case "${targ}" in
6     targ64_selvecs="bfd_elf64_x86_64_nacl_vec bfd_elf32_x86_64_nacl_vec"
7     targ_archs="$targ_archs bfd_arm_arch"
8     ;;
9+  i[3-7]86-*-barrelfish*)
10+    targ_defvec=bfd_elf32_i386_vec
11+    targ_selvecs=bfd_elf32_i386_vec
12+    ;;
13 #ifdef BFD64
14   x86_64-*-darwin*)
15     targ_defvec=mach_o_x86_64_vec
16@@ -673,6 +677,11 @@ case "${targ}" in
17     targ_archs="$targ_archs bfd_arm_arch"
18     want64=true
19     ;;
20+  x86_64-*-barrelfish*)
21+    targ_defvec=bfd_elf64_x86_64_vec
22+    targ_selvecs=bfd_elf64_x86_64_vec
23+    want64=true
24+    ;;
25   x86_64-*-mingw* | x86_64-*-pe | x86_64-*-pep | x86_64-*-cygwin)
26     targ_defvec=x86_64pe_vec
27     targ_selvecs="x86_64pe_vec x86_64pei_vec bfd_elf64_x86_64_vec bfd_elf64_l1om_vec bfd_elf64_k1om_vec i386pe_vec i386pei_vec bfd_elf32_i386_vec"
28diff --git a/config.sub b/config.sub
29index 61cb4bc22db8..bc3ec8c48906 100755
30--- a/config.sub
31+++ b/config.sub
32@@ -1357,6 +1357,7 @@ case $os in
33 	      | -sym* | -kopensolaris* | -plan9* \
34 	      | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
35 	      | -aos* | -aros* \
36+	      | -barrelfish* \
37 	      | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
38 	      | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
39 	      | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
40diff --git a/configure b/configure
41index ee45e1b00f90..5bb841e5899d 100755
42--- a/configure
43+++ b/configure
44@@ -2953,7 +2953,7 @@ case "${ENABLE_GOLD}" in
45       *-*-elf* | *-*-sysv4* | *-*-unixware* | *-*-eabi* | hppa*64*-*-hpux* \
46       | *-*-linux* | *-*-gnu* | frv-*-uclinux* | *-*-irix5* | *-*-irix6* \
47       | *-*-netbsd* | *-*-openbsd* | *-*-freebsd* | *-*-dragonfly* \
48-      | *-*-solaris2* | *-*-nto* | *-*-nacl*)
49+      | *-*-solaris2* | *-*-nto* | *-*-nacl* | *-*-barrelfish*)
50         case "${target}" in
51           *-*-linux*aout* | *-*-linux*oldld*)
52             ;;
53diff --git a/gas/configure.tgt b/gas/configure.tgt
54index 77c1d9b59246..5b32ae8f8a0c 100644
55--- a/gas/configure.tgt
56+++ b/gas/configure.tgt
57@@ -270,6 +270,7 @@ case ${generic_target} in
58   i386-*-chaos)				fmt=elf ;;
59   i386-*-rdos*)				fmt=elf ;;
60   i386-*-darwin*)			fmt=macho ;;
61+  i386-*-barrelfish*)			fmt=elf ;;
62 
63   i860-*-*)				fmt=elf endian=little ;;
64 
65diff --git a/ld/Makefile.am b/ld/Makefile.am
66index b2b2a6ebe362..c01570b158ba 100644
67--- a/ld/Makefile.am
68+++ b/ld/Makefile.am
69@@ -263,6 +263,7 @@ ALL_EMULATION_SOURCES = \
70 	eelf32xstormy16.c \
71 	eelf32xtensa.c \
72 	eelf_i386.c \
73+	ebarrelfish_i386.c \
74 	eelf_i386_be.c \
75 	eelf_i386_chaos.c \
76 	eelf_i386_fbsd.c \
77@@ -1268,6 +1269,12 @@ eelf32xtensa.c: $(srcdir)/emulparams/elf32xtensa.sh $(ELF_DEPS) \
78 eelf_i386.c: $(srcdir)/emulparams/elf_i386.sh \
79   $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
80 	${GENSCRIPTS} elf_i386 "$(tdir_elf_i386)"
81+ebarrelfish_i386.c: $(srcdir)/emulparams/barrelfish_i386.sh \
82+  $(ELF_DEPS) $(srcdir)/scripttempl/elf-barrelfish.sc ${GEN_DEPENDS}
83+	${GENSCRIPTS} barrelfish_i386 "$(tdir_barrelfish_i386)"
84+ebarrelfish_x86_64.c: $(srcdir)/emulparams/barrelfish_x86_64.sh \
85+  $(ELF_DEPS) $(srcdir)/scripttempl/elf-barrelfish.sc ${GEN_DEPENDS}
86+	${GENSCRIPTS} barrelfish_x86_64 "$(tdir_barrelfish_x86_64)"
87 eelf_i386_be.c: $(srcdir)/emulparams/elf_i386_be.sh \
88   $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
89 	${GENSCRIPTS} elf_i386_be "$(tdir_elf_i386_be)"
90diff --git a/ld/Makefile.in b/ld/Makefile.in
91index b95a3d103de4..d41557b3334c 100644
92--- a/ld/Makefile.in
93+++ b/ld/Makefile.in
94@@ -571,6 +571,7 @@ ALL_EMULATION_SOURCES = \
95 	eelf32xstormy16.c \
96 	eelf32xtensa.c \
97 	eelf_i386.c \
98+	ebarrelfish_i386.c \
99 	eelf_i386_be.c \
100 	eelf_i386_chaos.c \
101 	eelf_i386_fbsd.c \
102@@ -830,6 +831,7 @@ ALL_64_EMULATION_SOURCES = \
103 	eelf_k1om.c \
104 	eelf_k1om_fbsd.c \
105 	eelf_x86_64.c \
106+	ebarrelfish_x86_64.c \
107 	eelf_x86_64_fbsd.c \
108 	eelf_x86_64_nacl.c \
109 	eelf_x86_64_sol2.c \
110@@ -3619,6 +3621,12 @@ eelf_k1om_fbsd.c: $(srcdir)/emulparams/elf_k1om_fbsd.sh \
111   $(srcdir)/emulparams/elf_k1om.sh \
112   $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
113 	${GENSCRIPTS} elf_k1om_fbsd "$(tdir_elf_k1om_fbsd)"
114+ebarrelfish_i386.c: $(srcdir)/emulparams/barrelfish_i386.sh \
115+  $(ELF_DEPS) $(srcdir)/scripttempl/elf-barrelfish.sc ${GEN_DEPENDS}
116+	${GENSCRIPTS} barrelfish_i386 "$(tdir_barrelfish_i386)"
117+ebarrelfish_x86_64.c: $(srcdir)/emulparams/barrelfish_x86_64.sh \
118+  $(ELF_DEPS) $(srcdir)/scripttempl/elf-barrelfish.sc ${GEN_DEPENDS}
119+	${GENSCRIPTS} barrelfish_x86_64 "$(tdir_barrelfish_x86_64)"
120 eelf_x86_64.c: $(srcdir)/emulparams/elf_x86_64.sh \
121   $(ELF_DEPS) $(srcdir)/scripttempl/elf.sc ${GEN_DEPENDS}
122 	${GENSCRIPTS} elf_x86_64 "$(tdir_elf_x86_64)"
123diff --git a/ld/configure.tgt b/ld/configure.tgt
124index c50730b9c514..27702cbedc3a 100644
125--- a/ld/configure.tgt
126+++ b/ld/configure.tgt
127@@ -224,6 +224,7 @@ i[3-7]86-*-bsd)		targ_emul=i386bsd ;;
128 i[3-7]86-*-bsd386)	targ_emul=i386bsd ;;
129 i[3-7]86-*-bsdi*)	targ_emul=i386bsd ;;
130 i[3-7]86-*-aout)	targ_emul=i386aout ;;
131+i[3-7]86-*-barrelfish*)	targ_emul=barrelfish_i386 ;;
132 i[3-7]86-*-linux*aout*)	targ_emul=i386linux
133 			targ_extra_emuls=elf_i386
134 			tdir_elf_i386=`echo ${targ_alias} | sed -e 's/aout//'` ;;
135@@ -244,6 +245,7 @@ x86_64-*-linux-*)	targ_emul=elf_x86_64
136 			targ_extra_libpath="elf_i386 elf32_x86_64 elf_l1om elf_k1om"
137 			tdir_i386linux=`echo ${targ_alias}aout | sed -e 's/x86_64/i386/'`
138 			tdir_elf_i386=`echo ${targ_alias} | sed -e 's/x86_64/i386/'` ;;
139+x86_64-*-barrelfish*)	targ_emul=barrelfish_x86_64 ;;
140 i[3-7]86-*-sysv[45]*)	targ_emul=elf_i386 ;;
141 i[3-7]86-*-solaris2*)	targ_emul=elf_i386_sol2
142                         targ_extra_emuls="elf_i386_ldso elf_i386 elf_x86_64_sol2 elf_x86_64 elf_l1om elf_k1om"
143diff --git a/ld/emulparams/barrelfish_i386.sh b/ld/emulparams/barrelfish_i386.sh
144new file mode 100644
145index 000000000000..032dd5ae18a3
146--- /dev/null
147+++ b/ld/emulparams/barrelfish_i386.sh
148@@ -0,0 +1,14 @@
149+. ${srcdir}/emulparams/plt_unwind.sh
150+SCRIPT_NAME=elf-barrelfish
151+OUTPUT_FORMAT="elf32-i386"
152+NO_RELA_RELOCS=yes
153+TEXT_START_ADDR=0x400000
154+MAXPAGESIZE=0x1000
155+COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
156+ARCH=i386
157+MACHINE=
158+TEMPLATE_NAME=elf32
159+GENERATE_SHLIB_SCRIPT=no
160+GENERATE_PIE_SCRIPT=yes
161+NO_SMALL_DATA=yes
162+SEPARATE_GOTPLT="SIZEOF (.got.plt) >= 12 ? 12 : 0"
163diff --git a/ld/emulparams/barrelfish_x86_64.sh b/ld/emulparams/barrelfish_x86_64.sh
164new file mode 100644
165index 000000000000..bf4dafdd6b2b
166--- /dev/null
167+++ b/ld/emulparams/barrelfish_x86_64.sh
168@@ -0,0 +1,16 @@
169+. ${srcdir}/emulparams/plt_unwind.sh
170+SCRIPT_NAME=elf-barrelfish
171+ELFSIZE=64
172+OUTPUT_FORMAT="elf64-x86-64"
173+NO_RELA_RELOCS=yes
174+TEXT_START_ADDR=0x400000
175+MAXPAGESIZE=0x1000
176+COMMONPAGESIZE="CONSTANT (COMMONPAGESIZE)"
177+ARCH="i386:x86-64"
178+MACHINE=
179+TEMPLATE_NAME=elf32
180+GENERATE_SHLIB_SCRIPT=no
181+GENERATE_PIE_SCRIPT=yes
182+NO_SMALL_DATA=yes
183+LARGE_SECTIONS=yes
184+SEPARATE_GOTPLT="SIZEOF (.got.plt) >= 24 ? 24 : 0"
185diff --git a/ld/scripttempl/elf-barrelfish.sc b/ld/scripttempl/elf-barrelfish.sc
186new file mode 100644
187index 000000000000..51a655eed65c
188--- /dev/null
189+++ b/ld/scripttempl/elf-barrelfish.sc
190@@ -0,0 +1,664 @@
191+#
192+# Unusual variables checked by this code:
193+#	NOP - four byte opcode for no-op (defaults to none)
194+#	NO_SMALL_DATA - no .sbss/.sbss2/.sdata/.sdata2 sections if not
195+#		empty.
196+#	SMALL_DATA_CTOR - .ctors contains small data.
197+#	SMALL_DATA_DTOR - .dtors contains small data.
198+#	DATA_ADDR - if end-of-text-plus-one-page isn't right for data start
199+#	INITIAL_READONLY_SECTIONS - at start of text segment
200+#	OTHER_READONLY_SECTIONS - other than .text .init .rodata ...
201+#		(e.g., .PARISC.milli)
202+#	OTHER_TEXT_SECTIONS - these get put in .text when relocating
203+#	OTHER_READWRITE_SECTIONS - other than .data .bss .ctors .sdata ...
204+#		(e.g., .PARISC.global)
205+#	OTHER_RELRO_SECTIONS - other than .data.rel.ro ...
206+#		(e.g. PPC32 .fixup, .got[12])
207+#	OTHER_BSS_SECTIONS - other than .bss .sbss ...
208+#	ATTRS_SECTIONS - at the end
209+#	OTHER_SECTIONS - at the end
210+#	EXECUTABLE_SYMBOLS - symbols that must be defined for an
211+#		executable (e.g., _DYNAMIC_LINK)
212+#       TEXT_START_ADDR - the first byte of the text segment, after any
213+#               headers.
214+#       TEXT_BASE_ADDRESS - the first byte of the text segment.
215+#	TEXT_START_SYMBOLS - symbols that appear at the start of the
216+#		.text section.
217+#	DATA_START_SYMBOLS - symbols that appear at the start of the
218+#		.data section.
219+#	DATA_END_SYMBOLS - symbols that appear at the end of the
220+#		writeable data sections.
221+#	OTHER_GOT_SYMBOLS - symbols defined just before .got.
222+#	OTHER_GOT_SECTIONS - sections just after .got.
223+#	OTHER_SDATA_SECTIONS - sections just after .sdata.
224+#	OTHER_BSS_SYMBOLS - symbols that appear at the start of the
225+#		.bss section besides __bss_start.
226+#	DATA_PLT - .plt should be in data segment, not text segment.
227+#	PLT_BEFORE_GOT - .plt just before .got when .plt is in data segement.
228+#	BSS_PLT - .plt should be in bss segment
229+#	NO_REL_RELOCS - Don't include .rel.* sections in script
230+#	NO_RELA_RELOCS - Don't include .rela.* sections in script
231+#	NON_ALLOC_DYN - Place dynamic sections after data segment.
232+#	TEXT_DYNAMIC - .dynamic in text segment, not data segment.
233+#	EMBEDDED - whether this is for an embedded system.
234+#	SHLIB_TEXT_START_ADDR - if set, add to SIZEOF_HEADERS to set
235+#		start address of shared library.
236+#	INPUT_FILES - INPUT command of files to always include
237+#	WRITABLE_RODATA - if set, the .rodata section should be writable
238+#	INIT_START, INIT_END -  statements just before and just after
239+# 	combination of .init sections.
240+#	FINI_START, FINI_END - statements just before and just after
241+# 	combination of .fini sections.
242+#	STACK_ADDR - start of a .stack section.
243+#	OTHER_SYMBOLS - symbols to place right at the end of the script.
244+#	ETEXT_NAME - name of a symbol for the end of the text section,
245+#		normally etext.
246+#	SEPARATE_CODE - if set, .text and similar sections containing
247+#		actual machine instructions must be in wholly disjoint
248+#		pages from any other data, including headers
249+#	SEPARATE_GOTPLT - if set, .got.plt should be separate output section,
250+#		so that .got can be in the RELRO area.  It should be set to
251+#		the number of bytes in the beginning of .got.plt which can be
252+#		in the RELRO area as well.
253+#	USER_LABEL_PREFIX - prefix to add to user-visible symbols.
254+#	RODATA_NAME, SDATA_NAME, SBSS_NAME, BSS_NAME - base parts of names
255+#		for standard sections, without initial "." or suffixes.
256+#
257+# When adding sections, do note that the names of some sections are used
258+# when specifying the start address of the next.
259+#
260+
261+#  Many sections come in three flavours.  There is the 'real' section,
262+#  like ".data".  Then there are the per-procedure or per-variable
263+#  sections, generated by -ffunction-sections and -fdata-sections in GCC,
264+#  and useful for --gc-sections, which for a variable "foo" might be
265+#  ".data.foo".  Then there are the linkonce sections, for which the linker
266+#  eliminates duplicates, which are named like ".gnu.linkonce.d.foo".
267+#  The exact correspondences are:
268+#
269+#  Section	Linkonce section
270+#  .text	.gnu.linkonce.t.foo
271+#  .rodata	.gnu.linkonce.r.foo
272+#  .data	.gnu.linkonce.d.foo
273+#  .bss		.gnu.linkonce.b.foo
274+#  .sdata	.gnu.linkonce.s.foo
275+#  .sbss	.gnu.linkonce.sb.foo
276+#  .sdata2	.gnu.linkonce.s2.foo
277+#  .sbss2	.gnu.linkonce.sb2.foo
278+#  .debug_info	.gnu.linkonce.wi.foo
279+#  .tdata	.gnu.linkonce.td.foo
280+#  .tbss	.gnu.linkonce.tb.foo
281+#  .lrodata	.gnu.linkonce.lr.foo
282+#  .ldata	.gnu.linkonce.l.foo
283+#  .lbss	.gnu.linkonce.lb.foo
284+#
285+#  Each of these can also have corresponding .rel.* and .rela.* sections.
286+
287+if test -n "$NOP"; then
288+  FILL="=$NOP"
289+else
290+  FILL=
291+fi
292+
293+test -z "$RODATA_NAME" && RODATA_NAME=rodata
294+test -z "$SDATA_NAME" && SDATA_NAME=sdata
295+test -z "$SBSS_NAME" && SBSS_NAME=sbss
296+test -z "$BSS_NAME" && BSS_NAME=bss
297+test -z "$ENTRY" && ENTRY=${USER_LABEL_PREFIX}_start
298+test -z "${BIG_OUTPUT_FORMAT}" && BIG_OUTPUT_FORMAT=${OUTPUT_FORMAT}
299+test -z "${LITTLE_OUTPUT_FORMAT}" && LITTLE_OUTPUT_FORMAT=${OUTPUT_FORMAT}
300+if [ -z "$MACHINE" ]; then OUTPUT_ARCH=${ARCH}; else OUTPUT_ARCH=${ARCH}:${MACHINE}; fi
301+test -z "${ELFSIZE}" && ELFSIZE=32
302+test -z "${ALIGNMENT}" && ALIGNMENT="${ELFSIZE} / 8"
303+test "$LD_FLAG" = "N" && DATA_ADDR=.
304+test -z "${ETEXT_NAME}" && ETEXT_NAME=${USER_LABEL_PREFIX}etext
305+test -n "$CREATE_SHLIB$CREATE_PIE" && test -n "$SHLIB_DATA_ADDR" && COMMONPAGESIZE=""
306+test -z "$CREATE_SHLIB$CREATE_PIE" && test -n "$DATA_ADDR" && COMMONPAGESIZE=""
307+test -n "$RELRO_NOW" && unset SEPARATE_GOTPLT
308+test -z "$ATTRS_SECTIONS" && ATTRS_SECTIONS=".gnu.attributes 0 : { KEEP (*(.gnu.attributes)) }"
309+DATA_SEGMENT_ALIGN="ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))"
310+DATA_SEGMENT_RELRO_END=""
311+DATA_SEGMENT_END=""
312+if test -n "${COMMONPAGESIZE}"; then
313+  DATA_SEGMENT_ALIGN="ALIGN (${SEGMENT_SIZE}) - ((${MAXPAGESIZE} - .) & (${MAXPAGESIZE} - 1)); . = DATA_SEGMENT_ALIGN (${MAXPAGESIZE}, ${COMMONPAGESIZE})"
314+  DATA_SEGMENT_END=". = DATA_SEGMENT_END (.);"
315+  DATA_SEGMENT_RELRO_END=". = DATA_SEGMENT_RELRO_END (${SEPARATE_GOTPLT-0}, .);"
316+fi
317+if test -z "${INITIAL_READONLY_SECTIONS}${CREATE_SHLIB}"; then
318+  INITIAL_READONLY_SECTIONS=".interp       ${RELOCATING-0} : { *(.interp) }"
319+fi
320+if test -z "$PLT"; then
321+  IPLT=".iplt         ${RELOCATING-0} : { *(.iplt) }"
322+  PLT=".plt          ${RELOCATING-0} : { *(.plt)${IREL_IN_PLT+ *(.iplt)} }
323+  ${IREL_IN_PLT-$IPLT}"
324+fi
325+test -n "${DATA_PLT-${BSS_PLT-text}}" && TEXT_PLT=yes
326+if test -z "$GOT"; then
327+  if test -z "$SEPARATE_GOTPLT"; then
328+    GOT=".got          ${RELOCATING-0} : { *(.got.plt) *(.igot.plt) *(.got) *(.igot) }"
329+  else
330+    GOT=".got          ${RELOCATING-0} : { *(.got) *(.igot) }"
331+    GOTPLT=".got.plt      ${RELOCATING-0} : { *(.got.plt)  *(.igot.plt) }"
332+  fi
333+fi
334+REL_IFUNC=".rel.ifunc    ${RELOCATING-0} : { *(.rel.ifunc) }"
335+RELA_IFUNC=".rela.ifunc   ${RELOCATING-0} : { *(.rela.ifunc) }"
336+REL_IPLT=".rel.iplt     ${RELOCATING-0} :
337+    {
338+      ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rel_iplt_start = .);}}
339+      *(.rel.iplt)
340+      ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rel_iplt_end = .);}}
341+    }"
342+RELA_IPLT=".rela.iplt    ${RELOCATING-0} :
343+    {
344+      ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rela_iplt_start = .);}}
345+      *(.rela.iplt)
346+      ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rela_iplt_end = .);}}
347+    }"
348+DYNAMIC=".dynamic      ${RELOCATING-0} : { *(.dynamic) }"
349+RODATA=".${RODATA_NAME}       ${RELOCATING-0} : { *(.${RODATA_NAME}${RELOCATING+ .${RODATA_NAME}.* .gnu.linkonce.r.*}) }"
350+DATARELRO=".data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }"
351+DISCARDED="/DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }"
352+if test -z "${NO_SMALL_DATA}"; then
353+  SBSS=".${SBSS_NAME}         ${RELOCATING-0} :
354+  {
355+    ${RELOCATING+${SBSS_START_SYMBOLS}}
356+    ${CREATE_SHLIB+*(.${SBSS_NAME}2 .${SBSS_NAME}2.* .gnu.linkonce.sb2.*)}
357+    *(.dyn${SBSS_NAME})
358+    *(.${SBSS_NAME}${RELOCATING+ .${SBSS_NAME}.* .gnu.linkonce.sb.*})
359+    *(.scommon)
360+    ${RELOCATING+${SBSS_END_SYMBOLS}}
361+  }"
362+  SBSS2=".${SBSS_NAME}2        ${RELOCATING-0} : { *(.${SBSS_NAME}2${RELOCATING+ .${SBSS_NAME}2.* .gnu.linkonce.sb2.*}) }"
363+  SDATA="/* We want the small data sections together, so single-instruction offsets
364+     can access them all, and initialized data all before uninitialized, so
365+     we can shorten the on-disk segment size.  */
366+  .${SDATA_NAME}        ${RELOCATING-0} :
367+  {
368+    ${RELOCATING+${SDATA_START_SYMBOLS}}
369+    ${CREATE_SHLIB+*(.${SDATA_NAME}2 .${SDATA_NAME}2.* .gnu.linkonce.s2.*)}
370+    *(.${SDATA_NAME}${RELOCATING+ .${SDATA_NAME}.* .gnu.linkonce.s.*})
371+  }"
372+  SDATA2=".${SDATA_NAME}2       ${RELOCATING-0} :
373+  {
374+    ${RELOCATING+${SDATA2_START_SYMBOLS}}
375+    *(.${SDATA_NAME}2${RELOCATING+ .${SDATA_NAME}2.* .gnu.linkonce.s2.*})
376+  }"
377+  REL_SDATA=".rel.${SDATA_NAME}    ${RELOCATING-0} : { *(.rel.${SDATA_NAME}${RELOCATING+ .rel.${SDATA_NAME}.* .rel.gnu.linkonce.s.*}) }
378+  .rela.${SDATA_NAME}   ${RELOCATING-0} : { *(.rela.${SDATA_NAME}${RELOCATING+ .rela.${SDATA_NAME}.* .rela.gnu.linkonce.s.*}) }"
379+  REL_SBSS=".rel.${SBSS_NAME}     ${RELOCATING-0} : { *(.rel.${SBSS_NAME}${RELOCATING+ .rel.${SBSS_NAME}.* .rel.gnu.linkonce.sb.*}) }
380+  .rela.${SBSS_NAME}    ${RELOCATING-0} : { *(.rela.${SBSS_NAME}${RELOCATING+ .rela.${SBSS_NAME}.* .rela.gnu.linkonce.sb.*}) }"
381+  REL_SDATA2=".rel.${SDATA_NAME}2   ${RELOCATING-0} : { *(.rel.${SDATA_NAME}2${RELOCATING+ .rel.${SDATA_NAME}2.* .rel.gnu.linkonce.s2.*}) }
382+  .rela.${SDATA_NAME}2  ${RELOCATING-0} : { *(.rela.${SDATA_NAME}2${RELOCATING+ .rela.${SDATA_NAME}2.* .rela.gnu.linkonce.s2.*}) }"
383+  REL_SBSS2=".rel.${SBSS_NAME}2    ${RELOCATING-0} : { *(.rel.${SBSS_NAME}2${RELOCATING+ .rel.${SBSS_NAME}2.* .rel.gnu.linkonce.sb2.*}) }
384+  .rela.${SBSS_NAME}2   ${RELOCATING-0} : { *(.rela.${SBSS_NAME}2${RELOCATING+ .rela.${SBSS_NAME}2.* .rela.gnu.linkonce.sb2.*}) }"
385+else
386+  NO_SMALL_DATA=" "
387+fi
388+if test -z "${DATA_GOT}"; then
389+  if test -n "${NO_SMALL_DATA}"; then
390+    DATA_GOT=" "
391+  fi
392+fi
393+if test -z "${SDATA_GOT}"; then
394+  if test -z "${NO_SMALL_DATA}"; then
395+    SDATA_GOT=" "
396+  fi
397+fi
398+test -n "$SEPARATE_GOTPLT" && SEPARATE_GOTPLT=" "
399+test "${LARGE_SECTIONS}" = "yes" && REL_LARGE="
400+  .rel.ldata    ${RELOCATING-0} : { *(.rel.ldata${RELOCATING+ .rel.ldata.* .rel.gnu.linkonce.l.*}) }
401+  .rela.ldata   ${RELOCATING-0} : { *(.rela.ldata${RELOCATING+ .rela.ldata.* .rela.gnu.linkonce.l.*}) }
402+  .rel.lbss     ${RELOCATING-0} : { *(.rel.lbss${RELOCATING+ .rel.lbss.* .rel.gnu.linkonce.lb.*}) }
403+  .rela.lbss    ${RELOCATING-0} : { *(.rela.lbss${RELOCATING+ .rela.lbss.* .rela.gnu.linkonce.lb.*}) }
404+  .rel.lrodata  ${RELOCATING-0} : { *(.rel.lrodata${RELOCATING+ .rel.lrodata.* .rel.gnu.linkonce.lr.*}) }
405+  .rela.lrodata ${RELOCATING-0} : { *(.rela.lrodata${RELOCATING+ .rela.lrodata.* .rela.gnu.linkonce.lr.*}) }"
406+test "${LARGE_SECTIONS}" = "yes" && OTHER_BSS_SECTIONS="
407+  ${OTHER_BSS_SECTIONS}
408+  .lbss ${RELOCATING-0} :
409+  {
410+    *(.dynlbss)
411+    *(.lbss${RELOCATING+ .lbss.* .gnu.linkonce.lb.*})
412+    *(LARGE_COMMON)
413+  }"
414+test "${LARGE_SECTIONS}" = "yes" && LARGE_SECTIONS="
415+  .lrodata ${RELOCATING-0} ${RELOCATING+ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))} :
416+  {
417+    *(.lrodata${RELOCATING+ .lrodata.* .gnu.linkonce.lr.*})
418+  }
419+  .ldata ${RELOCATING-0} ${RELOCATING+ALIGN(${MAXPAGESIZE}) + (. & (${MAXPAGESIZE} - 1))} :
420+  {
421+    *(.ldata${RELOCATING+ .ldata.* .gnu.linkonce.l.*})
422+    ${RELOCATING+. = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
423+  }"
424+if test "${ENABLE_INITFINI_ARRAY}" = "yes"; then
425+  SORT_INIT_ARRAY="KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))"
426+  SORT_FINI_ARRAY="KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))"
427+  CTORS_IN_INIT_ARRAY="KEEP (*(EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))"
428+  DTORS_IN_FINI_ARRAY="KEEP (*(EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))"
429+else
430+  SORT_INIT_ARRAY="KEEP (*(SORT(.init_array.*)))"
431+  SORT_FINI_ARRAY="KEEP (*(SORT(.fini_array.*)))"
432+  CTORS_IN_INIT_ARRAY=
433+  DTORS_IN_FINI_ARRAY=
434+fi
435+INIT_ARRAY=".init_array   ${RELOCATING-0} :
436+  {
437+    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_start = .);}}
438+    ${SORT_INIT_ARRAY}
439+    KEEP (*(.init_array))
440+    ${CTORS_IN_INIT_ARRAY}
441+    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__init_array_end = .);}}
442+  }"
443+FINI_ARRAY=".fini_array   ${RELOCATING-0} :
444+  {
445+    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_start = .);}}
446+    ${SORT_FINI_ARRAY}
447+    KEEP (*(.fini_array))
448+    ${DTORS_IN_FINI_ARRAY}
449+    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__fini_array_end = .);}}
450+  }"
451+CTOR=".ctors        ${CONSTRUCTING-0} :
452+  {
453+    ${CONSTRUCTING+${CTOR_START}}
454+    /* gcc uses crtbegin.o to find the start of
455+       the constructors, so we make sure it is
456+       first.  Because this is a wildcard, it
457+       doesn't matter if the user does not
458+       actually link against crtbegin.o; the
459+       linker won't look for a file to match a
460+       wildcard.  The wildcard also means that it
461+       doesn't matter which directory crtbegin.o
462+       is in.  */
463+
464+    KEEP (*crtbegin.o(.ctors))
465+    KEEP (*crtbegin?.o(.ctors))
466+
467+    /* We don't want to include the .ctor section from
468+       the crtend.o file until after the sorted ctors.
469+       The .ctor section from the crtend file contains the
470+       end of ctors marker and it must be last */
471+
472+    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .ctors))
473+    KEEP (*(SORT(.ctors.*)))
474+    KEEP (*(.ctors))
475+    ${CONSTRUCTING+${CTOR_END}}
476+  }"
477+DTOR=".dtors        ${CONSTRUCTING-0} :
478+  {
479+    ${CONSTRUCTING+${DTOR_START}}
480+    KEEP (*crtbegin.o(.dtors))
481+    KEEP (*crtbegin?.o(.dtors))
482+    KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o $OTHER_EXCLUDE_FILES) .dtors))
483+    KEEP (*(SORT(.dtors.*)))
484+    KEEP (*(.dtors))
485+    ${CONSTRUCTING+${DTOR_END}}
486+  }"
487+STACK="  .stack        ${RELOCATING-0}${RELOCATING+${STACK_ADDR}} :
488+  {
489+    ${RELOCATING+${USER_LABEL_PREFIX}_stack = .;}
490+    *(.stack)
491+  }"
492+
493+TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${TEXT_START_ADDR})"
494+SHLIB_TEXT_START_ADDR="SEGMENT_START(\"text-segment\", ${SHLIB_TEXT_START_ADDR:-0})"
495+
496+if [ -z "$SEPARATE_CODE" ]; then
497+  SIZEOF_HEADERS_CODE=" + SIZEOF_HEADERS"
498+else
499+  SIZEOF_HEADERS_CODE=
500+fi
501+
502+# if this is for an embedded system, don't add SIZEOF_HEADERS.
503+if [ -z "$EMBEDDED" ]; then
504+   test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}${SIZEOF_HEADERS_CODE}"
505+else
506+   test -z "${TEXT_BASE_ADDRESS}" && TEXT_BASE_ADDRESS="${TEXT_START_ADDR}"
507+fi
508+
509+cat <<EOF
510+OUTPUT_FORMAT("${OUTPUT_FORMAT}", "${BIG_OUTPUT_FORMAT}",
511+	      "${LITTLE_OUTPUT_FORMAT}")
512+OUTPUT_ARCH(${OUTPUT_ARCH})
513+${RELOCATING+ENTRY(${ENTRY})}
514+
515+${RELOCATING+${LIB_SEARCH_DIRS}}
516+${RELOCATING+${EXECUTABLE_SYMBOLS}}
517+${RELOCATING+${INPUT_FILES}}
518+${RELOCATING- /* For some reason, the Solaris linker makes bad executables
519+  if gld -r is used and the intermediate file has sections starting
520+  at non-zero addresses.  Could be a Solaris ld bug, could be a GNU ld
521+  bug.  But for now assigning the zero vmas works.  */}
522+
523+SECTIONS
524+{
525+  /* Read-only sections, merged into text segment: */
526+  ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+PROVIDE (__executable_start = ${TEXT_START_ADDR}); . = ${TEXT_BASE_ADDRESS};}}}
527+  ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR}${SIZEOF_HEADERS_CODE};}}
528+  ${CREATE_PIE+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR}${SIZEOF_HEADERS_CODE};}}
529+EOF
530+
531+emit_early_ro()
532+{
533+  cat <<EOF
534+  ${INITIAL_READONLY_SECTIONS}
535+  .note.gnu.build-id : { *(.note.gnu.build-id) }
536+EOF
537+}
538+
539+test -n "${SEPARATE_CODE}" || emit_early_ro
540+
541+test -n "${RELOCATING+0}" || unset NON_ALLOC_DYN
542+test -z "${NON_ALLOC_DYN}" || TEXT_DYNAMIC=
543+cat > ldscripts/dyntmp.$$ <<EOF
544+  ${TEXT_DYNAMIC+${DYNAMIC}}
545+  .hash         ${RELOCATING-0} : { *(.hash) }
546+  .gnu.hash     ${RELOCATING-0} : { *(.gnu.hash) }
547+  .dynsym       ${RELOCATING-0} : { *(.dynsym) }
548+  .dynstr       ${RELOCATING-0} : { *(.dynstr) }
549+  .gnu.version  ${RELOCATING-0} : { *(.gnu.version) }
550+  .gnu.version_d ${RELOCATING-0}: { *(.gnu.version_d) }
551+  .gnu.version_r ${RELOCATING-0}: { *(.gnu.version_r) }
552+EOF
553+
554+if [ "x$COMBRELOC" = x ]; then
555+  COMBRELOCCAT="cat >> ldscripts/dyntmp.$$"
556+else
557+  COMBRELOCCAT="cat > $COMBRELOC"
558+fi
559+eval $COMBRELOCCAT <<EOF
560+  ${INITIAL_RELOC_SECTIONS}
561+  .rel.init     ${RELOCATING-0} : { *(.rel.init) }
562+  .rela.init    ${RELOCATING-0} : { *(.rela.init) }
563+  .rel.text     ${RELOCATING-0} : { *(.rel.text${RELOCATING+ .rel.text.* .rel.gnu.linkonce.t.*}) }
564+  .rela.text    ${RELOCATING-0} : { *(.rela.text${RELOCATING+ .rela.text.* .rela.gnu.linkonce.t.*}) }
565+  .rel.fini     ${RELOCATING-0} : { *(.rel.fini) }
566+  .rela.fini    ${RELOCATING-0} : { *(.rela.fini) }
567+  .rel.${RODATA_NAME}   ${RELOCATING-0} : { *(.rel.${RODATA_NAME}${RELOCATING+ .rel.${RODATA_NAME}.* .rel.gnu.linkonce.r.*}) }
568+  .rela.${RODATA_NAME}  ${RELOCATING-0} : { *(.rela.${RODATA_NAME}${RELOCATING+ .rela.${RODATA_NAME}.* .rela.gnu.linkonce.r.*}) }
569+  ${OTHER_READONLY_RELOC_SECTIONS}
570+  .rel.data.rel.ro ${RELOCATING-0} : { *(.rel.data.rel.ro${RELOCATING+ .rel.data.rel.ro.* .rel.gnu.linkonce.d.rel.ro.*}) }
571+  .rela.data.rel.ro ${RELOCATING-0} : { *(.rela.data.rel.ro${RELOCATING+ .rela.data.rel.ro.* .rela.gnu.linkonce.d.rel.ro.*}) }
572+  .rel.data     ${RELOCATING-0} : { *(.rel.data${RELOCATING+ .rel.data.* .rel.gnu.linkonce.d.*}) }
573+  .rela.data    ${RELOCATING-0} : { *(.rela.data${RELOCATING+ .rela.data.* .rela.gnu.linkonce.d.*}) }
574+  ${OTHER_READWRITE_RELOC_SECTIONS}
575+  .rel.tdata	${RELOCATING-0} : { *(.rel.tdata${RELOCATING+ .rel.tdata.* .rel.gnu.linkonce.td.*}) }
576+  .rela.tdata	${RELOCATING-0} : { *(.rela.tdata${RELOCATING+ .rela.tdata.* .rela.gnu.linkonce.td.*}) }
577+  .rel.tbss	${RELOCATING-0} : { *(.rel.tbss${RELOCATING+ .rel.tbss.* .rel.gnu.linkonce.tb.*}) }
578+  .rela.tbss	${RELOCATING-0} : { *(.rela.tbss${RELOCATING+ .rela.tbss.* .rela.gnu.linkonce.tb.*}) }
579+  .rel.ctors    ${RELOCATING-0} : { *(.rel.ctors) }
580+  .rela.ctors   ${RELOCATING-0} : { *(.rela.ctors) }
581+  .rel.dtors    ${RELOCATING-0} : { *(.rel.dtors) }
582+  .rela.dtors   ${RELOCATING-0} : { *(.rela.dtors) }
583+  .rel.got      ${RELOCATING-0} : { *(.rel.got) }
584+  .rela.got     ${RELOCATING-0} : { *(.rela.got) }
585+  ${OTHER_GOT_RELOC_SECTIONS}
586+  ${REL_SDATA}
587+  ${REL_SBSS}
588+  ${REL_SDATA2}
589+  ${REL_SBSS2}
590+  .rel.${BSS_NAME}      ${RELOCATING-0} : { *(.rel.${BSS_NAME}${RELOCATING+ .rel.${BSS_NAME}.* .rel.gnu.linkonce.b.*}) }
591+  .rela.${BSS_NAME}     ${RELOCATING-0} : { *(.rela.${BSS_NAME}${RELOCATING+ .rela.${BSS_NAME}.* .rela.gnu.linkonce.b.*}) }
592+  ${REL_LARGE}
593+  ${IREL_IN_PLT+$REL_IFUNC}
594+  ${IREL_IN_PLT+$RELA_IFUNC}
595+  ${IREL_IN_PLT-$REL_IPLT}
596+  ${IREL_IN_PLT-$RELA_IPLT}
597+EOF
598+
599+if [ -n "$COMBRELOC" ]; then
600+cat >> ldscripts/dyntmp.$$ <<EOF
601+  .rel.dyn      ${RELOCATING-0} :
602+    {
603+EOF
604+sed -e '/^[ 	]*[{}][ 	]*$/d;/:[ 	]*$/d;/\.rela\./d;s/^.*: { *\(.*\)}$/      \1/' $COMBRELOC >> ldscripts/dyntmp.$$
605+cat >> ldscripts/dyntmp.$$ <<EOF
606+    }
607+  .rela.dyn     ${RELOCATING-0} :
608+    {
609+EOF
610+sed -e '/^[ 	]*[{}][ 	]*$/d;/:[ 	]*$/d;/\.rel\./d;s/^.*: { *\(.*\)}/      \1/' $COMBRELOC >> ldscripts/dyntmp.$$
611+cat >> ldscripts/dyntmp.$$ <<EOF
612+    }
613+EOF
614+fi
615+
616+cat >> ldscripts/dyntmp.$$ <<EOF
617+  .rel.plt      ${RELOCATING-0} :
618+    {
619+      *(.rel.plt)
620+      ${IREL_IN_PLT+${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rel_iplt_start = .);}}}
621+      ${IREL_IN_PLT+${RELOCATING+*(.rel.iplt)}}
622+      ${IREL_IN_PLT+${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rel_iplt_end = .);}}}
623+    }
624+  .rela.plt     ${RELOCATING-0} :
625+    {
626+      *(.rela.plt)
627+      ${IREL_IN_PLT+${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rela_iplt_start = .);}}}
628+      ${IREL_IN_PLT+${RELOCATING+*(.rela.iplt)}}
629+      ${IREL_IN_PLT+${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__rela_iplt_end = .);}}}
630+    }
631+  ${OTHER_PLT_RELOC_SECTIONS}
632+EOF
633+
634+emit_dyn()
635+{
636+  if test -z "${NO_REL_RELOCS}${NO_RELA_RELOCS}"; then
637+    cat ldscripts/dyntmp.$$
638+  else
639+    if test -z "${NO_REL_RELOCS}"; then
640+      sed -e '/^[ 	]*\.rela\.[^}]*$/,/}/d' -e '/^[ 	]*\.rela\./d' ldscripts/dyntmp.$$
641+    fi
642+    if test -z "${NO_RELA_RELOCS}"; then
643+      sed -e '/^[ 	]*\.rel\.[^}]*$/,/}/d' -e '/^[ 	]*\.rel\./d' ldscripts/dyntmp.$$
644+    fi
645+  fi
646+  rm -f ldscripts/dyntmp.$$
647+}
648+
649+test -n "${NON_ALLOC_DYN}${SEPARATE_CODE}" || emit_dyn
650+
651+cat <<EOF
652+  .init         ${RELOCATING-0} :
653+  {
654+    ${RELOCATING+${INIT_START}}
655+    KEEP (*(SORT_NONE(.init)))
656+    ${RELOCATING+${INIT_END}}
657+  } ${FILL}
658+
659+  ${TEXT_PLT+${PLT}}
660+  ${TINY_READONLY_SECTION}
661+  .text         ${RELOCATING-0} :
662+  {
663+    ${RELOCATING+${TEXT_START_SYMBOLS}}
664+    ${RELOCATING+*(.text.unlikely .text.*_unlikely)}
665+    ${RELOCATING+*(.text.exit .text.exit.*)}
666+    ${RELOCATING+*(.text.startup .text.startup.*)}
667+    ${RELOCATING+*(.text.hot .text.hot.*)}
668+    *(.text .stub${RELOCATING+ .text.* .gnu.linkonce.t.*})
669+    /* .gnu.warning sections are handled specially by elf32.em.  */
670+    *(.gnu.warning)
671+    ${RELOCATING+${OTHER_TEXT_SECTIONS}}
672+  } ${FILL}
673+  .fini         ${RELOCATING-0} :
674+  {
675+    ${RELOCATING+${FINI_START}}
676+    KEEP (*(SORT_NONE(.fini)))
677+    ${RELOCATING+${FINI_END}}
678+  } ${FILL}
679+  ${RELOCATING+PROVIDE (__${ETEXT_NAME} = .);}
680+  ${RELOCATING+PROVIDE (_${ETEXT_NAME} = .);}
681+  ${RELOCATING+PROVIDE (${ETEXT_NAME} = .);}
682+EOF
683+
684+if test -n "${SEPARATE_CODE}"; then
685+  cat <<EOF
686+  /* Adjust the address for the rodata segment.  We want to adjust up to
687+     the same address within the page on the next page up.  */
688+  ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${RODATA_ADDR-ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))};}}}
689+  ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_RODATA_ADDR-ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
690+  ${CREATE_PIE+${RELOCATING+. = ${SHLIB_RODATA_ADDR-ALIGN(${SEGMENT_SIZE}) + (. & (${MAXPAGESIZE} - 1))};}}
691+EOF
692+  emit_early_ro
693+  emit_dyn
694+fi
695+
696+cat <<EOF
697+  ${WRITABLE_RODATA-${RODATA}}
698+  .${RODATA_NAME}1      ${RELOCATING-0} : { *(.${RODATA_NAME}1) }
699+  ${CREATE_SHLIB-${SDATA2}}
700+  ${CREATE_SHLIB-${SBSS2}}
701+  ${OTHER_READONLY_SECTIONS}
702+  .eh_frame_hdr : { *(.eh_frame_hdr) }
703+  .eh_frame     ${RELOCATING-0} : ONLY_IF_RO { KEEP (*(.eh_frame)) }
704+  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RO { *(.gcc_except_table
705+  .gcc_except_table.*) }
706+  /* These sections are generated by the Sun/Oracle C++ compiler.  */
707+  .exception_ranges ${RELOCATING-0} : ONLY_IF_RO { *(.exception_ranges
708+  .exception_ranges*) }
709+
710+  /* Adjust the address for the data segment.  We want to adjust up to
711+     the same address within the page on the next page up.  */
712+  ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}}
713+  ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
714+  ${CREATE_PIE+${RELOCATING+. = ${SHLIB_DATA_ADDR-${DATA_SEGMENT_ALIGN}};}}
715+
716+  /* Exception handling  */
717+  .eh_frame     ${RELOCATING-0} : ONLY_IF_RW { KEEP (*(.eh_frame)) }
718+  .gcc_except_table ${RELOCATING-0} : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }
719+  .exception_ranges ${RELOCATING-0} : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) }
720+
721+  /* Thread Local Storage sections  */
722+  .tdata	${RELOCATING-0} : { *(.tdata${RELOCATING+ .tdata.* .gnu.linkonce.td.*}) }
723+  .tbss		${RELOCATING-0} : { *(.tbss${RELOCATING+ .tbss.* .gnu.linkonce.tb.*})${RELOCATING+ *(.tcommon)} }
724+
725+  .preinit_array   ${RELOCATING-0} :
726+  {
727+    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_start = .);}}
728+    KEEP (*(.preinit_array))
729+    ${RELOCATING+${CREATE_SHLIB-PROVIDE_HIDDEN (${USER_LABEL_PREFIX}__preinit_array_end = .);}}
730+  }
731+  ${RELOCATING+${INIT_ARRAY}}
732+  ${RELOCATING+${FINI_ARRAY}}
733+  ${SMALL_DATA_CTOR-${RELOCATING+${CTOR}}}
734+  ${SMALL_DATA_DTOR-${RELOCATING+${DTOR}}}
735+  .jcr          ${RELOCATING-0} : { KEEP (*(.jcr)) }
736+
737+  ${RELOCATING+${DATARELRO}}
738+  ${OTHER_RELRO_SECTIONS}
739+  ${TEXT_DYNAMIC-${DYNAMIC}}
740+  ${DATA_GOT+${RELRO_NOW+${GOT}}}
741+  ${DATA_GOT+${RELRO_NOW+${GOTPLT}}}
742+  ${DATA_GOT+${RELRO_NOW-${SEPARATE_GOTPLT+${GOT}}}}
743+  ${RELOCATING+${DATA_SEGMENT_RELRO_END}}
744+  ${DATA_GOT+${RELRO_NOW-${SEPARATE_GOTPLT-${GOT}}}}
745+  ${DATA_GOT+${RELRO_NOW-${GOTPLT}}}
746+
747+  ${DATA_PLT+${PLT_BEFORE_GOT-${PLT}}}
748+
749+  .data         ${RELOCATING-0} :
750+  {
751+    ${RELOCATING+${DATA_START_SYMBOLS}}
752+    *(.data${RELOCATING+ .data.* .gnu.linkonce.d.*})
753+    ${CONSTRUCTING+SORT(CONSTRUCTORS)}
754+  }
755+  .data1        ${RELOCATING-0} : { *(.data1) }
756+  ${WRITABLE_RODATA+${RODATA}}
757+  ${OTHER_READWRITE_SECTIONS}
758+  ${SMALL_DATA_CTOR+${RELOCATING+${CTOR}}}
759+  ${SMALL_DATA_DTOR+${RELOCATING+${DTOR}}}
760+  ${DATA_PLT+${PLT_BEFORE_GOT+${PLT}}}
761+  ${SDATA_GOT+${RELOCATING+${OTHER_GOT_SYMBOLS+. = .; ${OTHER_GOT_SYMBOLS}}}}
762+  ${SDATA_GOT+${GOT}}
763+  ${SDATA_GOT+${OTHER_GOT_SECTIONS}}
764+  ${SDATA}
765+  ${OTHER_SDATA_SECTIONS}
766+  ${RELOCATING+${DATA_END_SYMBOLS-${USER_LABEL_PREFIX}_edata = .; PROVIDE (${USER_LABEL_PREFIX}edata = .);}}
767+  ${RELOCATING+. = .;}
768+  ${RELOCATING+${USER_LABEL_PREFIX}__bss_start = .;}
769+  ${RELOCATING+${OTHER_BSS_SYMBOLS}}
770+  ${SBSS}
771+  ${BSS_PLT+${PLT}}
772+  .${BSS_NAME}          ${RELOCATING-0} :
773+  {
774+   *(.dyn${BSS_NAME})
775+   *(.${BSS_NAME}${RELOCATING+ .${BSS_NAME}.* .gnu.linkonce.b.*})
776+   *(COMMON)
777+   /* Align here to ensure that the .bss section occupies space up to
778+      _end.  Align after .bss to ensure correct alignment even if the
779+      .bss section disappears because there are no input sections.
780+      FIXME: Why do we need it? When there is no .bss section, we don't
781+      pad the .data section.  */
782+   ${RELOCATING+. = ALIGN(. != 0 ? ${ALIGNMENT} : 1);}
783+  }
784+  ${OTHER_BSS_SECTIONS}
785+  ${RELOCATING+${OTHER_BSS_END_SYMBOLS}}
786+  ${RELOCATING+. = ALIGN(${ALIGNMENT});}
787+  ${LARGE_SECTIONS}
788+  ${RELOCATING+. = ALIGN(${ALIGNMENT});}
789+  ${RELOCATING+${OTHER_END_SYMBOLS}}
790+  ${RELOCATING+${END_SYMBOLS-${USER_LABEL_PREFIX}_end = .; PROVIDE (${USER_LABEL_PREFIX}end = .);}}
791+  ${RELOCATING+${DATA_SEGMENT_END}}
792+EOF
793+
794+test -z "${NON_ALLOC_DYN}" || emit_dyn
795+
796+cat <<EOF
797+  /* Stabs debugging sections.  */
798+  .stab          0 : { *(.stab) }
799+  .stabstr       0 : { *(.stabstr) }
800+  .stab.excl     0 : { *(.stab.excl) }
801+  .stab.exclstr  0 : { *(.stab.exclstr) }
802+  .stab.index    0 : { *(.stab.index) }
803+  .stab.indexstr 0 : { *(.stab.indexstr) }
804+
805+  .comment       0 : { *(.comment) }
806+
807+  /* DWARF debug sections.
808+     Symbols in the DWARF debugging sections are relative to the beginning
809+     of the section so we begin them at 0.  */
810+
811+  /* DWARF 1 */
812+  .debug          0 : { *(.debug) }
813+  .line           0 : { *(.line) }
814+
815+  /* GNU DWARF 1 extensions */
816+  .debug_srcinfo  0 : { *(.debug_srcinfo) }
817+  .debug_sfnames  0 : { *(.debug_sfnames) }
818+
819+  /* DWARF 1.1 and DWARF 2 */
820+  .debug_aranges  0 : { *(.debug_aranges) }
821+  .debug_pubnames 0 : { *(.debug_pubnames) }
822+
823+  /* DWARF 2 */
824+  .debug_info     0 : { *(.debug_info${RELOCATING+ .gnu.linkonce.wi.*}) }
825+  .debug_abbrev   0 : { *(.debug_abbrev) }
826+  .debug_line     0 : { *(.debug_line) }
827+  .debug_frame    0 : { *(.debug_frame) }
828+  .debug_str      0 : { *(.debug_str) }
829+  .debug_loc      0 : { *(.debug_loc) }
830+  .debug_macinfo  0 : { *(.debug_macinfo) }
831+
832+  /* SGI/MIPS DWARF 2 extensions */
833+  .debug_weaknames 0 : { *(.debug_weaknames) }
834+  .debug_funcnames 0 : { *(.debug_funcnames) }
835+  .debug_typenames 0 : { *(.debug_typenames) }
836+  .debug_varnames  0 : { *(.debug_varnames) }
837+
838+  /* DWARF 3 */
839+  .debug_pubtypes 0 : { *(.debug_pubtypes) }
840+  .debug_ranges   0 : { *(.debug_ranges) }
841+
842+  /* DWARF Extension.  */
843+  .debug_macro    0 : { *(.debug_macro) } 
844+  
845+  ${TINY_DATA_SECTION}
846+  ${TINY_BSS_SECTION}
847+
848+  ${STACK_ADDR+${STACK}}
849+  ${ATTRS_SECTIONS}
850+  ${OTHER_SECTIONS}
851+  ${RELOCATING+${OTHER_SYMBOLS}}
852+  ${RELOCATING+${DISCARDED}}
853+}
854+EOF
855