Treat the .gnu.debuglink and .gnu.debugaltlink sections as debug sections when readin...
[external/binutils.git] / ld / genscripts.sh
1 #!/bin/sh
2 # genscripts.sh - generate the ld-emulation-target specific files
3 # Copyright (C) 2004-2019 Free Software Foundation, Inc.
4 #
5 # This file is part of the Gnu Linker.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
10 # any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with GLD; see the file COPYING.  If not, write to the Free
19 # Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
20 # 02110-1301, USA.
21 #
22 # Usage: genscripts_extra.sh \
23 #          srcdir \
24 #          libdir \
25 #          prefix \
26 #          exec_prefix \
27 #          host \
28 #          target \
29 #          target_alias \
30 #          default_emulation \
31 #          native_lib_dirs \
32 #          use_sysroot \
33 #          enable_initfini_array \
34 #          this_emulation \
35 # optional:
36 #          tool_dir
37 #
38 # Sample usage:
39 #
40 #   genscripts_extra.sh \
41 #    /sources/ld \
42 #    /usr/local/lib \
43 #    /usr/local \
44 #    /usr/local \
45 #    sparc-sun-sunos4.1.3 \
46 #    sparc-sun-sunos4.1.3 \
47 #    sparc-sun-sunos4.1.3 \
48 #    sun4 \
49 #    "" \
50 #    no \
51 #    sun3 \
52 #    sparc-sun-sunos4.1.3 \
53 #    sparc.sh
54 #
55 # produces the linker scripts:
56 #
57 #   sun3.x       [default linker script]
58 #   sun3.xbn     [used when the linker is invoked with "-N"]
59 #   sun3.xn      [used when the linker is invoked with "-n"]
60 #   sun3.xr      [used when the linker is invoked with "-r"]
61 #   sun3.xu      [used when the linker is invoked with "-Ur"]
62 #
63 # depending on platform specific settings linker scripts with the
64 # following suffixes might be generated as well:
65 #
66 # xdwe:   -pie    -z combreloc -z separate-code          -z now
67 # xdw:    -pie    -z combreloc                  -z relro -z now
68 # xdceo:  -pie    -z combreloc -z separate-code -z relro
69 # xdce:   -pie    -z combreloc -z separate-code
70 # xdco:   -pie    -z combreloc                  -z relro
71 # xdc:    -pie    -z combreloc
72 # xdeo:   -pie                 -z separate-code -z relro
73 # xde:    -pie                 -z separate-code
74 # xdo:    -pie                                  -z relro
75 # xd:     -pie
76 #
77 # xswe:   -shared -z combreloc -z separate-code          -z now
78 # xsw:    -shared -z combreloc                  -z relro -z now
79 # xsceo:  -shared -z combreloc -z separate-code -z relro
80 # xsce:   -shared -z combreloc -z separate-code
81 # xsco:   -shared -z combreloc                  -z relro
82 # xsc:    -shared -z combreloc
83 # xseo:   -shared              -z separate-code -z relro
84 # xse:    -shared              -z separate-code
85 # xso:    -shared                               -z relro
86 # xs:     -shared
87 #
88 # xwe:            -z combreloc -z separate-code          -z now
89 # xw:             -z combreloc                  -z relro -z now
90 # xceo:           -z combreloc -z separate-code -z relro
91 # xce:            -z combreloc -z separate-code
92 # xco:            -z combreloc                  -z relro
93 # xc:             -z combreloc
94 # xeo:                         -z separate-code -z relro
95 # xe:                          -z separate-code
96 # xo:                                           -z relro
97 #
98 #
99 # It also produced the C source file:
100 #
101 #   em_sun3.c
102 #
103 # which is then compiled into the linker.
104 #
105 # The linker scripts are created by running the shell script
106 # /sources/ld/emulparams/sparc.sh to set the value of ${SCRIPT_NAME}
107 # (and any other variables it wants to).  ${SCRIPT_NAME} is then
108 # invoked with a variable called ${LD_FLAG} to tell it which version
109 # of the linker script to create.
110
111
112 srcdir=$1
113 libdir=$2
114 prefix=$3
115 exec_prefix=$4
116 host=$5
117 target=$6
118 target_alias=$7
119 DEPDIR=$8
120 shift 8
121 LIB_PATH=$1
122 EMULATION_LIBPATH=$2
123 NATIVE_LIB_DIRS=$3
124 use_sysroot=$4
125 ENABLE_INITFINI_ARRAY=$5
126 shift 5
127 EMULATION_NAME=$1
128 TOOL_LIB=$2
129
130 source_sh()
131 {
132   if test -n "${DEPDIR}"; then
133     echo $1 >> ${DEPDIR}/e${EMULATION_NAME}.Tc
134   fi
135   . $1
136 }
137
138 if test -n "${DEPDIR}"; then
139   rm -f ${DEPDIR}/e${EMULATION_NAME}.Tc
140 fi
141
142 # Include the emulation-specific parameters:
143 CUSTOMIZER_SCRIPT="${srcdir}/emulparams/${EMULATION_NAME}.sh"
144 source_sh ${CUSTOMIZER_SCRIPT}
145
146 if test -d ldscripts; then
147   true
148 else
149   mkdir ldscripts
150 fi
151
152 # Set some flags for the emultempl scripts.  USE_LIBPATH will
153 # be set for any libpath-using emulation; NATIVE will be set for a
154 # libpath-using emulation where ${host} = ${target}.  NATIVE
155 # may already have been set by the emulparams file, but that's OK
156 # (it'll just get set to "yes" twice).
157
158 case " $EMULATION_LIBPATH " in
159   *" ${EMULATION_NAME} "*)
160     if [ "x${host}" = "x${target}" ] ; then
161       NATIVE=yes
162       USE_LIBPATH=yes
163     elif [ "x${use_sysroot}" = "xyes" ] ; then
164       USE_LIBPATH=yes
165     fi
166     ;;
167 esac
168
169 # If the emulparams file sets NATIVE, make sure USE_LIBPATH is set also.
170 if test "x$NATIVE" = "xyes" ; then
171   USE_LIBPATH=yes
172 fi
173
174 # Set the library search path, for libraries named by -lfoo.
175 # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
176 # Otherwise, the default is set here.
177 #
178 # The format is the usual list of colon-separated directories.
179 # To force a logically empty LIB_PATH, do LIBPATH=":".
180 #
181 # If we are using a sysroot, prefix library paths with "=" to indicate this.
182 #
183 # If the emulparams file set LIBPATH_SUFFIX, prepend an extra copy of
184 # the library path with the suffix applied.
185
186 # Paths with LIBPATH_SUFFIX
187 lib_path1=
188 # Paths without LIBPATH_SUFFIX
189 lib_path2=
190 if [ "${LIB_PATH}" != ":" ] ; then
191   lib_path2=${LIB_PATH}
192 fi
193
194 # Add args to lib_path1 and lib_path2, discarding any duplicates
195 append_to_lib_path()
196 {
197   if [ $# != 0 ]; then
198     for lib in "$@"; do
199       # The "=" is harmless if we aren't using a sysroot, but also needless.
200       if [ "x${use_sysroot}" = "xyes" ] ; then
201         lib="=${lib}"
202       fi
203       skip_lib=no
204       for libpath_suffix in ${LIBPATH_SUFFIX}; do
205         case "${lib}" in
206           *${libpath_suffix})
207             case :${lib_path1}: in
208               *:${lib}:*) ;;
209               ::) lib_path1=${lib} ;;
210               *) lib_path1=${lib_path1}:${lib} ;;
211             esac ;;
212           *)
213             if test -n "${LIBPATH_SUFFIX_SKIP}"; then
214               case "${lib}" in
215                 *${LIBPATH_SUFFIX_SKIP}) skip_lib=yes ;;
216               esac
217             fi
218             if test "${skip_lib}" = "no"; then
219               case :${lib_path1}: in
220                 *:${lib}${libpath_suffix}:*) ;;
221                 ::) lib_path1=${lib}${libpath_suffix} ;;
222                 *) lib_path1=${lib_path1}:${lib}${libpath_suffix} ;;
223               esac
224             fi ;;
225         esac
226       done
227       if test "${skip_lib}" = "no"; then
228         case :${lib_path1}:${lib_path2}: in
229           *:${lib}:*) ;;
230           *::) lib_path2=${lib} ;;
231           *) lib_path2=${lib_path2}:${lib} ;;
232         esac
233       fi
234     done
235   fi
236 }
237
238 # Always search $(tooldir)/lib, aka /usr/local/TARGET/lib when native
239 # except when LIBPATH=":".
240 if [ "${LIB_PATH}" != ":" ] ; then
241   libs=
242   if [ "x${TOOL_LIB}" = "x" ] ; then
243     if [ "x${NATIVE}" = "xyes" ] ; then
244       libs="${exec_prefix}/${target_alias}/lib"
245     fi
246   else
247     # For multilib'ed targets, ensure both ${target_alias}/lib${LIBPATH_SUFFIX}
248     # and ${TOOL_LIB}/lib${LIBPATH_SUFFIX} are in the default search path,
249     # because 64bit libraries may be in both places, depending on
250     # cross-development setup method (e.g.: /usr/s390x-linux/lib64
251     # vs. /usr/s390-linux/lib64)
252     for libpath_suffix in ${LIBPATH_SUFFIX}; do
253       case "${NATIVE}:${libpath_suffix}:${TOOL_LIB}" in
254         :* | *::* | *:*:*${libpath_suffix}) ;;
255         *) libs="${exec_prefix}/${target_alias}/lib${libpath_suffix}" ;;
256       esac
257     done
258     libs="${exec_prefix}/${TOOL_LIB}/lib ${libs}"
259   fi
260   append_to_lib_path ${libs}
261 fi
262
263 if [ "x${LIB_PATH}" = "x" ] && [ "x${USE_LIBPATH}" = xyes ] ; then
264   libs=${NATIVE_LIB_DIRS}
265   if [ "x${NATIVE}" = "xyes" ] ; then
266     case " ${libs} " in
267       *" ${libdir} "*) ;;
268       *) libs="${libdir} ${libs}" ;;
269     esac
270   fi
271   append_to_lib_path ${libs}
272 fi
273
274 case :${lib_path1}:${lib_path2}: in
275   *:: | ::*) LIB_PATH=${lib_path1}${lib_path2} ;;
276   *) LIB_PATH=${lib_path1}:${lib_path2} ;;
277 esac
278
279 LIB_SEARCH_DIRS=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
280
281 # We need it for testsuite.
282 set $EMULATION_LIBPATH
283 if [ "x$1" = "x$EMULATION_NAME" ]; then
284     test -d tmpdir || mkdir tmpdir
285     rm -f tmpdir/libpath.exp
286     echo "set libpath \"${LIB_PATH}\"" | sed -e 's/:/ /g' > tmpdir/libpath.exp
287 fi
288
289 # Generate 5 or 6 script files from a master script template in
290 # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh.  Which one of the 5 or 6
291 # script files is actually used depends on command line options given
292 # to ld.  (SCRIPT_NAME was set in the emulparams_file.)
293 #
294 # A .x script file is the default script.
295 # A .xr script is for linking without relocation (-r flag).
296 # A .xu script is like .xr, but *do* create constructors (-Ur flag).
297 # A .xn script is for linking with -n flag (mix text and data on same page).
298 # A .xbn script is for linking with -N flag (mix text and data on same page).
299 # A .xs script is for generating a shared library with the --shared
300 #   flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
301 #   emulation parameters.
302 # A .xc script is for linking with -z combreloc; it is only generated if
303 #   $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
304 #   $SCRIPT_NAME is "elf".
305 # A .xsc script is for linking with --shared -z combreloc; it is generated
306 #   if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
307 #   $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation
308 #   parameters too.
309
310 if [ "x$SCRIPT_NAME" = "xelf" ]; then
311   GENERATE_COMBRELOC_SCRIPT=yes
312 fi
313
314 SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}}
315
316 # Determine DATA_ALIGNMENT for the 5 variants, using
317 # values specified in the emulparams/<script_to_run>.sh file or default.
318
319 DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
320 DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
321 DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
322 DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
323 DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
324
325 LD_FLAG=r
326 DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
327 DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
328 ( echo "/* Script for ld -r: link without relocation */"
329   source_sh ${CUSTOMIZER_SCRIPT}
330   source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
331 ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xr
332
333 LD_FLAG=u
334 DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
335 CONSTRUCTING=" "
336 ( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */"
337   source_sh ${CUSTOMIZER_SCRIPT}
338   source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
339 ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xu
340
341 DATA_ALIGNMENT=${DATA_ALIGNMENT_}
342 RELOCATING=" "
343 LD_FLAG=
344 ( echo "/* Default linker script, for normal executables */"
345   source_sh ${CUSTOMIZER_SCRIPT}
346   source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
347 ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.x
348
349 LD_FLAG=textonly
350 ( echo "/* Script for -z separate-code: generate normal executables with separate code segment */"
351   source_sh ${CUSTOMIZER_SCRIPT}
352   source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
353 ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xe
354
355 if test -n "$GENERATE_RELRO_SCRIPT"; then
356     LD_FLAG=
357     RELRO=" "
358     ( echo "/* Script for -z relo: generate normal executables with separate code segment */"
359       source_sh ${CUSTOMIZER_SCRIPT}
360       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
361     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xo
362     LD_FLAG=textonly
363     ( echo "/* Script for -z separate-code -z relo: generate normal executables with separate code segment */"
364       source_sh ${CUSTOMIZER_SCRIPT}
365       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
366     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xeo
367     unset RELRO
368 fi
369 LD_FLAG=n
370 DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
371 ( echo "/* Script for -n: mix text and data on same page */"
372   source_sh ${CUSTOMIZER_SCRIPT}
373   source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
374 ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xn
375
376 LD_FLAG=N
377 DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
378 ( echo "/* Script for -N: mix text and data on same page; don't align data */"
379   source_sh ${CUSTOMIZER_SCRIPT}
380   source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
381 ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xbn
382
383 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
384   DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}}
385   LD_FLAG=c
386   COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
387   ( echo "/* Script for -z combreloc: combine and sort reloc sections */"
388     source_sh ${CUSTOMIZER_SCRIPT}
389     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
390   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xc
391   rm -f ${COMBRELOC}
392   LD_FLAG=ctextonly
393   COMBRELOC=ldscripts/${EMULATION_NAME}.xce.tmp
394   ( echo "/* Script for -z combreloc -z separate-code: combine and sort reloc sections with separate code segment */"
395     source_sh ${CUSTOMIZER_SCRIPT}
396     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
397   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xce
398   rm -f ${COMBRELOC}
399   RELRO_NOW=" "
400   LD_FLAG=w
401   COMBRELOC=ldscripts/${EMULATION_NAME}.xw.tmp
402   ( echo "/* Script for -z combreloc -z now -z relro: combine and sort reloc sections */"
403     source_sh ${CUSTOMIZER_SCRIPT}
404     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
405   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xw
406   rm -f ${COMBRELOC}
407   LD_FLAG=wtextonly
408   COMBRELOC=ldscripts/${EMULATION_NAME}.xwe.tmp
409   ( echo "/* Script for -z combreloc -z now -z relro -z separate-code: combine and sort reloc sections with separate code segment */"
410     source_sh ${CUSTOMIZER_SCRIPT}
411     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
412   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xwe
413   rm -f ${COMBRELOC}
414   COMBRELOC=
415   unset RELRO_NOW
416   if test -n "$GENERATE_RELRO_SCRIPT"; then
417       LD_FLAG=c
418       RELRO=" "
419       COMBRELOC=ldscripts/${EMULATION_NAME}.xco.tmp
420       ( echo "/* Script for -z combreloc -z relro: combine and sort reloc sections */"
421         source_sh ${CUSTOMIZER_SCRIPT}
422         source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
423       ) | sed -e '/^ *$/d;s/[    ]*$//' > ldscripts/${EMULATION_NAME}.xco
424       rm -f ${COMBRELOC}
425       LD_FLAG=ctextonly
426       COMBRELOC=ldscripts/${EMULATION_NAME}.xceo.tmp
427       ( echo "/* Script for -z combreloc -z separate-code -z relro: combine and sort reloc sections */"
428         source_sh ${CUSTOMIZER_SCRIPT}
429         source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
430       ) | sed -e '/^ *$/d;s/[    ]*$//' > ldscripts/${EMULATION_NAME}.xceo
431       rm -f ${COMBRELOC}
432       COMBRELOC=
433       unset RELRO
434   fi
435 fi
436
437 if test -n "$GENERATE_SHLIB_SCRIPT"; then
438   DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
439   CREATE_SHLIB=" "
440   LD_FLAG=shared
441   ( echo "/* Script for ld --shared: link shared library */"
442     source_sh ${CUSTOMIZER_SCRIPT}
443     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
444   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xs
445   LD_FLAG=sharedtextonly
446   ( echo "/* Script for ld --shared -z separate-code: link shared library with separate code segment */"
447     source_sh ${CUSTOMIZER_SCRIPT}
448     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
449   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xse
450
451   if test -n "$GENERATE_RELRO_SCRIPT"; then
452       RELRO=" "
453       LD_FLAG=shared
454       ( echo "/* Script for ld --shared -z relro: link shared library */"
455         source_sh ${CUSTOMIZER_SCRIPT}
456         source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
457       ) | sed -e '/^ *$/d;s/[    ]*$//' > ldscripts/${EMULATION_NAME}.xso
458       LD_FLAG=sharedtextonly
459       ( echo "/* Script for ld --shared -z relro -z separate-code: link shared library with separate code segment */"
460         source_sh ${CUSTOMIZER_SCRIPT}
461         source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
462       ) | sed -e '/^ *$/d;s/[    ]*$//' > ldscripts/${EMULATION_NAME}.xseo
463       unset RELRO
464   fi
465   if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
466     DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
467     LD_FLAG=cshared
468     COMBRELOC=ldscripts/${EMULATION_NAME}.xsc.tmp
469     ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */"
470       source_sh ${CUSTOMIZER_SCRIPT}
471       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
472     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xsc
473     rm -f ${COMBRELOC}
474     LD_FLAG=csharedtextonly
475     COMBRELOC=ldscripts/${EMULATION_NAME}.xsce.tmp
476     ( echo "/* Script for --shared -z combreloc -z separate-code: shared library, combine & sort relocs with separate code segment */"
477       source_sh ${CUSTOMIZER_SCRIPT}
478       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
479     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xsce
480     rm -f ${COMBRELOC}
481     RELRO_NOW=" "
482     LD_FLAG=wshared
483     COMBRELOC=ldscripts/${EMULATION_NAME}.xsw.tmp
484     ( echo "/* Script for --shared -z combreloc -z now -z relro: shared library, combine & sort relocs */"
485       source_sh ${CUSTOMIZER_SCRIPT}
486       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
487     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xsw
488     rm -f ${COMBRELOC}
489     LD_FLAG=wsharedtextonly
490     COMBRELOC=ldscripts/${EMULATION_NAME}.xswe.tmp
491     ( echo "/* Script for --shared -z combreloc -z now -z relro -z separate-code: shared library, combine & sort relocs with separate code segment */"
492       source_sh ${CUSTOMIZER_SCRIPT}
493       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
494     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xswe
495     rm -f ${COMBRELOC}
496     unset RELRO_NOW
497
498     if test -n "$GENERATE_RELRO_SCRIPT"; then
499         LD_FLAG=wshared
500         RELRO=" "
501         COMBRELOC=ldscripts/${EMULATION_NAME}.xsco.tmp
502         ( echo "/* Script for --shared -z combreloc -z relro: shared library, combine & sort relocs with separate code segment */"
503           source_sh ${CUSTOMIZER_SCRIPT}
504           source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
505         ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xsco
506         rm -f ${COMBRELOC}
507         LD_FLAG=wsharedtextonly
508         COMBRELOC=ldscripts/${EMULATION_NAME}.xsceo.tmp
509         ( echo "/* Script for --shared -z combreloc -z relro -z separate-code: shared library, combine & sort relocs with separate code segment */"
510           source_sh ${CUSTOMIZER_SCRIPT}
511           source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
512         ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xsceo
513         rm -f ${COMBRELOC}
514         unset RELRO
515     fi
516     COMBRELOC=
517   fi
518   unset CREATE_SHLIB
519 fi
520
521 if test -n "$GENERATE_PIE_SCRIPT"; then
522   DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
523   CREATE_PIE=" "
524   LD_FLAG=pie
525   ( echo "/* Script for ld -pie: link position independent executable */"
526     source_sh ${CUSTOMIZER_SCRIPT}
527     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
528   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xd
529   LD_FLAG=pietextonly
530   ( echo "/* Script for ld -pie -z separate-code: link position independent executable with separate code segment */"
531     source_sh ${CUSTOMIZER_SCRIPT}
532     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
533   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xde
534   if test -n "$GENERATE_RELRO_SCRIPT"; then
535       RELRO=" "
536       LD_FLAG=pie
537       ( echo "/* Script for ld -pie -z relro: link position independent executable */"
538         source_sh ${CUSTOMIZER_SCRIPT}
539         source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
540       ) | sed -e '/^ *$/d;s/[    ]*$//' > ldscripts/${EMULATION_NAME}.xdo
541       LD_FLAG=pietextonly
542       ( echo "/* Script for ld -pie -z relro -z separate-code: link position independent executable with separate code segment */"
543         source_sh ${CUSTOMIZER_SCRIPT}
544         source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
545       ) | sed -e '/^ *$/d;s/[    ]*$//' > ldscripts/${EMULATION_NAME}.xdeo
546       unset RELRO
547   fi
548   if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
549     DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
550     COMBRELOC=ldscripts/${EMULATION_NAME}.xdc.tmp
551     LD_FLAG=cpie
552     ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */"
553       source_sh ${CUSTOMIZER_SCRIPT}
554       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
555     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xdc
556     rm -f ${COMBRELOC}
557     LD_FLAG=cpietextonly
558     COMBRELOC=ldscripts/${EMULATION_NAME}.xdce.tmp
559     ( echo "/* Script for -pie -z combreloc -z separate-code: position independent executable, combine & sort relocs with separate code segment */"
560       source_sh ${CUSTOMIZER_SCRIPT}
561       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
562     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xdce
563     rm -f ${COMBRELOC}
564     RELRO_NOW=" "
565     LD_FLAG=wpie
566     COMBRELOC=ldscripts/${EMULATION_NAME}.xdw.tmp
567     ( echo "/* Script for -pie -z combreloc -z now -z relro: position independent executable, combine & sort relocs */"
568       source_sh ${CUSTOMIZER_SCRIPT}
569       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
570     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xdw
571     rm -f ${COMBRELOC}
572     LD_FLAG=wpietextonly
573     COMBRELOC=ldscripts/${EMULATION_NAME}.xdwe.tmp
574     ( echo "/* Script for -pie -z combreloc -z now -z relro -z separate-code: position independent executable, combine & sort relocs with separate code segment */"
575       source_sh ${CUSTOMIZER_SCRIPT}
576       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
577     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xdwe
578     rm -f ${COMBRELOC}
579     unset RELRO_NOW
580
581     if test -n "$GENERATE_RELRO_SCRIPT"; then
582         LD_FLAG=wpie
583         RELRO=" "
584         COMBRELOC=ldscripts/${EMULATION_NAME}.xdco.tmp
585         ( echo "/* Script for -pie -z combreloc -z relro: position independent executable, combine & sort relocs with separate code segment */"
586           source_sh ${CUSTOMIZER_SCRIPT}
587           source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
588         ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xdco
589         rm -f ${COMBRELOC}
590         LD_FLAG=wpietextonly
591         COMBRELOC=ldscripts/${EMULATION_NAME}.xdceo.tmp
592         ( echo "/* Script for -pie -z combreloc -z relro -z separate-code: position independent executable, combine & sort relocs with separate code segment */"
593           source_sh ${CUSTOMIZER_SCRIPT}
594           source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
595         ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xdceo
596         rm -f ${COMBRELOC}
597
598         unset RELRO
599     fi
600     COMBRELOC=
601   fi
602   unset CREATE_PIE
603 fi
604
605 if test -n "$GENERATE_AUTO_IMPORT_SCRIPT"; then
606   LD_FLAG=auto_import
607   DATA_ALIGNMENT=${DATA_ALIGNMENT_}
608   ( echo "/* Script for ld --enable-auto-import: Like the default script except read only data is placed into .data  */"
609     source_sh ${CUSTOMIZER_SCRIPT}
610     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
611   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xa
612 fi
613
614 case "$COMPILE_IN: $EMULATION_LIBPATH " in
615     :*" ${EMULATION_NAME} "*) COMPILE_IN=yes;;
616 esac
617
618 # PR ld/5652:
619 # Determine if the shell has support for the variable BASH_LINENO.
620 # When it is the case, it is only available inside functions.
621 has_lineno()
622 {
623   test "x$BASH_LINENO" != "x"
624 }
625
626 # Enable accruate error source in the compiler error messages, if possible.
627 if has_lineno; then
628   . ${srcdir}/genscrba.sh
629 else
630   source_em()
631   {
632     source_sh $1
633   }
634   fragment()
635   {
636     cat >> e${EMULATION_NAME}.c
637   }
638 fi
639
640 # Generate e${EMULATION_NAME}.c.
641 # Start with an empty file, then the sourced .em script
642 # can use the "fragment" function to append.
643 > e${EMULATION_NAME}.c
644 source_em ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em
645
646 if test -n "${DEPDIR}"; then
647   ecdeps=
648   for dep in `cat ${DEPDIR}/e${EMULATION_NAME}.Tc`; do
649     case " $ecdeps " in
650       *" $dep "*): ;;
651       *) ecdeps="$ecdeps $dep" ;;
652     esac
653   done
654   rm -f ${DEPDIR}/e${EMULATION_NAME}.Tc
655   echo "e${EMULATION_NAME}.c:${ecdeps}" > ${DEPDIR}/e${EMULATION_NAME}.Pc
656 fi