[binutils, ARM, 9/16] New BFL instruction for Armv8.1-M Mainline
[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   echo $1 >> ${DEPDIR}/e${EMULATION_NAME}.Tc
133   . $1
134 }
135
136 rm -f ${DEPDIR}/e${EMULATION_NAME}.Tc
137
138 # Include the emulation-specific parameters:
139 CUSTOMIZER_SCRIPT="${srcdir}/emulparams/${EMULATION_NAME}.sh"
140 source_sh ${CUSTOMIZER_SCRIPT}
141
142 if test -d ldscripts; then
143   true
144 else
145   mkdir ldscripts
146 fi
147
148 # Set some flags for the emultempl scripts.  USE_LIBPATH will
149 # be set for any libpath-using emulation; NATIVE will be set for a
150 # libpath-using emulation where ${host} = ${target}.  NATIVE
151 # may already have been set by the emulparams file, but that's OK
152 # (it'll just get set to "yes" twice).
153
154 case " $EMULATION_LIBPATH " in
155   *" ${EMULATION_NAME} "*)
156     if [ "x${host}" = "x${target}" ] ; then
157       NATIVE=yes
158       USE_LIBPATH=yes
159     elif [ "x${use_sysroot}" = "xyes" ] ; then
160       USE_LIBPATH=yes
161     fi
162     ;;
163 esac
164
165 # If the emulparams file sets NATIVE, make sure USE_LIBPATH is set also.
166 if test "x$NATIVE" = "xyes" ; then
167   USE_LIBPATH=yes
168 fi
169
170 # Set the library search path, for libraries named by -lfoo.
171 # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
172 # Otherwise, the default is set here.
173 #
174 # The format is the usual list of colon-separated directories.
175 # To force a logically empty LIB_PATH, do LIBPATH=":".
176 #
177 # If we are using a sysroot, prefix library paths with "=" to indicate this.
178 #
179 # If the emulparams file set LIBPATH_SUFFIX, prepend an extra copy of
180 # the library path with the suffix applied.
181
182 # Paths with LIBPATH_SUFFIX
183 lib_path1=
184 # Paths without LIBPATH_SUFFIX
185 lib_path2=
186 if [ "${LIB_PATH}" != ":" ] ; then
187   lib_path2=${LIB_PATH}
188 fi
189
190 # Add args to lib_path1 and lib_path2, discarding any duplicates
191 append_to_lib_path()
192 {
193   if [ $# != 0 ]; then
194     for lib in "$@"; do
195       # The "=" is harmless if we aren't using a sysroot, but also needless.
196       if [ "x${use_sysroot}" = "xyes" ] ; then
197         lib="=${lib}"
198       fi
199       skip_lib=no
200       for libpath_suffix in ${LIBPATH_SUFFIX}; do
201         case "${lib}" in
202           *${libpath_suffix})
203             case :${lib_path1}: in
204               *:${lib}:*) ;;
205               ::) lib_path1=${lib} ;;
206               *) lib_path1=${lib_path1}:${lib} ;;
207             esac ;;
208           *)
209             if test -n "${LIBPATH_SUFFIX_SKIP}"; then
210               case "${lib}" in
211                 *${LIBPATH_SUFFIX_SKIP}) skip_lib=yes ;;
212               esac
213             fi
214             if test "${skip_lib}" = "no"; then
215               case :${lib_path1}: in
216                 *:${lib}${libpath_suffix}:*) ;;
217                 ::) lib_path1=${lib}${libpath_suffix} ;;
218                 *) lib_path1=${lib_path1}:${lib}${libpath_suffix} ;;
219               esac
220             fi ;;
221         esac
222       done
223       if test "${skip_lib}" = "no"; then
224         case :${lib_path1}:${lib_path2}: in
225           *:${lib}:*) ;;
226           *::) lib_path2=${lib} ;;
227           *) lib_path2=${lib_path2}:${lib} ;;
228         esac
229       fi
230     done
231   fi
232 }
233
234 # Always search $(tooldir)/lib, aka /usr/local/TARGET/lib when native
235 # except when LIBPATH=":".
236 if [ "${LIB_PATH}" != ":" ] ; then
237   libs=
238   if [ "x${TOOL_LIB}" = "x" ] ; then
239     if [ "x${NATIVE}" = "xyes" ] ; then
240       libs="${exec_prefix}/${target_alias}/lib"
241     fi
242   else
243     # For multilib'ed targets, ensure both ${target_alias}/lib${LIBPATH_SUFFIX}
244     # and ${TOOL_LIB}/lib${LIBPATH_SUFFIX} are in the default search path,
245     # because 64bit libraries may be in both places, depending on
246     # cross-development setup method (e.g.: /usr/s390x-linux/lib64
247     # vs. /usr/s390-linux/lib64)
248     for libpath_suffix in ${LIBPATH_SUFFIX}; do
249       case "${NATIVE}:${libpath_suffix}:${TOOL_LIB}" in
250         :* | *::* | *:*:*${libpath_suffix}) ;;
251         *) libs="${exec_prefix}/${target_alias}/lib${libpath_suffix}" ;;
252       esac
253     done
254     libs="${exec_prefix}/${TOOL_LIB}/lib ${libs}"
255   fi
256   append_to_lib_path ${libs}
257 fi
258
259 if [ "x${LIB_PATH}" = "x" ] && [ "x${USE_LIBPATH}" = xyes ] ; then
260   libs=${NATIVE_LIB_DIRS}
261   if [ "x${NATIVE}" = "xyes" ] ; then
262     case " ${libs} " in
263       *" ${libdir} "*) ;;
264       *) libs="${libdir} ${libs}" ;;
265     esac
266   fi
267   append_to_lib_path ${libs}
268 fi
269
270 case :${lib_path1}:${lib_path2}: in
271   *:: | ::*) LIB_PATH=${lib_path1}${lib_path2} ;;
272   *) LIB_PATH=${lib_path1}:${lib_path2} ;;
273 esac
274
275 LIB_SEARCH_DIRS=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
276
277 # We need it for testsuite.
278 set $EMULATION_LIBPATH
279 if [ "x$1" = "x$EMULATION_NAME" ]; then
280     test -d tmpdir || mkdir tmpdir
281     rm -f tmpdir/libpath.exp
282     echo "set libpath \"${LIB_PATH}\"" | sed -e 's/:/ /g' > tmpdir/libpath.exp
283 fi
284
285 # Generate 5 or 6 script files from a master script template in
286 # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh.  Which one of the 5 or 6
287 # script files is actually used depends on command line options given
288 # to ld.  (SCRIPT_NAME was set in the emulparams_file.)
289 #
290 # A .x script file is the default script.
291 # A .xr script is for linking without relocation (-r flag).
292 # A .xu script is like .xr, but *do* create constructors (-Ur flag).
293 # A .xn script is for linking with -n flag (mix text and data on same page).
294 # A .xbn script is for linking with -N flag (mix text and data on same page).
295 # A .xs script is for generating a shared library with the --shared
296 #   flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
297 #   emulation parameters.
298 # A .xc script is for linking with -z combreloc; it is only generated if
299 #   $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
300 #   $SCRIPT_NAME is "elf".
301 # A .xsc script is for linking with --shared -z combreloc; it is generated
302 #   if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
303 #   $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation
304 #   parameters too.
305
306 if [ "x$SCRIPT_NAME" = "xelf" ]; then
307   GENERATE_COMBRELOC_SCRIPT=yes
308 fi
309
310 SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}}
311
312 # Determine DATA_ALIGNMENT for the 5 variants, using
313 # values specified in the emulparams/<script_to_run>.sh file or default.
314
315 DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
316 DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
317 DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
318 DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
319 DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
320
321 LD_FLAG=r
322 DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
323 DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
324 ( echo "/* Script for ld -r: link without relocation */"
325   source_sh ${CUSTOMIZER_SCRIPT}
326   source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
327 ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xr
328
329 LD_FLAG=u
330 DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
331 CONSTRUCTING=" "
332 ( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */"
333   source_sh ${CUSTOMIZER_SCRIPT}
334   source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
335 ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xu
336
337 DATA_ALIGNMENT=${DATA_ALIGNMENT_}
338 RELOCATING=" "
339 LD_FLAG=
340 ( echo "/* Default linker script, for normal executables */"
341   source_sh ${CUSTOMIZER_SCRIPT}
342   source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
343 ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.x
344
345 LD_FLAG=textonly
346 ( echo "/* Script for -z separate-code: generate normal executables with separate code segment */"
347   source_sh ${CUSTOMIZER_SCRIPT}
348   source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
349 ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xe
350
351 if test -n "$GENERATE_RELRO_SCRIPT"; then
352     LD_FLAG=
353     RELRO=" "
354     ( echo "/* Script for -z relo: generate normal executables with separate code segment */"
355       source_sh ${CUSTOMIZER_SCRIPT}
356       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
357     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xo
358     LD_FLAG=textonly
359     ( echo "/* Script for -z separate-code -z relo: generate normal executables with separate code segment */"
360       source_sh ${CUSTOMIZER_SCRIPT}
361       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
362     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xeo
363     unset RELRO
364 fi
365 LD_FLAG=n
366 DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
367 ( echo "/* Script for -n: mix text and data on same page */"
368   source_sh ${CUSTOMIZER_SCRIPT}
369   source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
370 ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xn
371
372 LD_FLAG=N
373 DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
374 ( echo "/* Script for -N: mix text and data on same page; don't align data */"
375   source_sh ${CUSTOMIZER_SCRIPT}
376   source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
377 ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xbn
378
379 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
380   DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}}
381   LD_FLAG=c
382   COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
383   ( echo "/* Script for -z combreloc: combine and sort reloc sections */"
384     source_sh ${CUSTOMIZER_SCRIPT}
385     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
386   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xc
387   rm -f ${COMBRELOC}
388   LD_FLAG=ctextonly
389   COMBRELOC=ldscripts/${EMULATION_NAME}.xce.tmp
390   ( echo "/* Script for -z combreloc -z separate-code: combine and sort reloc sections with separate code segment */"
391     source_sh ${CUSTOMIZER_SCRIPT}
392     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
393   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xce
394   rm -f ${COMBRELOC}
395   RELRO_NOW=" "
396   LD_FLAG=w
397   COMBRELOC=ldscripts/${EMULATION_NAME}.xw.tmp
398   ( echo "/* Script for -z combreloc -z now -z relro: combine and sort reloc sections */"
399     source_sh ${CUSTOMIZER_SCRIPT}
400     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
401   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xw
402   rm -f ${COMBRELOC}
403   LD_FLAG=wtextonly
404   COMBRELOC=ldscripts/${EMULATION_NAME}.xwe.tmp
405   ( echo "/* Script for -z combreloc -z now -z relro -z separate-code: combine and sort reloc sections with separate code segment */"
406     source_sh ${CUSTOMIZER_SCRIPT}
407     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
408   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xwe
409   rm -f ${COMBRELOC}
410   COMBRELOC=
411   unset RELRO_NOW
412   if test -n "$GENERATE_RELRO_SCRIPT"; then
413       LD_FLAG=c
414       RELRO=" "
415       COMBRELOC=ldscripts/${EMULATION_NAME}.xco.tmp
416       ( echo "/* Script for -z combreloc -z relro: combine and sort reloc sections */"
417         source_sh ${CUSTOMIZER_SCRIPT}
418         source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
419       ) | sed -e '/^ *$/d;s/[    ]*$//' > ldscripts/${EMULATION_NAME}.xco
420       rm -f ${COMBRELOC}
421       LD_FLAG=ctextonly
422       COMBRELOC=ldscripts/${EMULATION_NAME}.xceo.tmp
423       ( echo "/* Script for -z combreloc -z separate-code -z relro: combine and sort reloc sections */"
424         source_sh ${CUSTOMIZER_SCRIPT}
425         source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
426       ) | sed -e '/^ *$/d;s/[    ]*$//' > ldscripts/${EMULATION_NAME}.xceo
427       rm -f ${COMBRELOC}
428       COMBRELOC=
429       unset RELRO
430   fi
431 fi
432
433 if test -n "$GENERATE_SHLIB_SCRIPT"; then
434   DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
435   CREATE_SHLIB=" "
436   LD_FLAG=shared
437   ( echo "/* Script for ld --shared: link shared library */"
438     source_sh ${CUSTOMIZER_SCRIPT}
439     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
440   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xs
441   LD_FLAG=sharedtextonly
442   ( echo "/* Script for ld --shared -z separate-code: link shared library with separate code segment */"
443     source_sh ${CUSTOMIZER_SCRIPT}
444     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
445   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xse
446
447   if test -n "$GENERATE_RELRO_SCRIPT"; then
448       RELRO=" "
449       LD_FLAG=shared
450       ( echo "/* Script for ld --shared -z relro: link shared library */"
451         source_sh ${CUSTOMIZER_SCRIPT}
452         source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
453       ) | sed -e '/^ *$/d;s/[    ]*$//' > ldscripts/${EMULATION_NAME}.xso
454       LD_FLAG=sharedtextonly
455       ( echo "/* Script for ld --shared -z relro -z separate-code: link shared library with separate code segment */"
456         source_sh ${CUSTOMIZER_SCRIPT}
457         source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
458       ) | sed -e '/^ *$/d;s/[    ]*$//' > ldscripts/${EMULATION_NAME}.xseo
459       unset RELRO
460   fi
461   if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
462     DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
463     LD_FLAG=cshared
464     COMBRELOC=ldscripts/${EMULATION_NAME}.xsc.tmp
465     ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */"
466       source_sh ${CUSTOMIZER_SCRIPT}
467       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
468     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xsc
469     rm -f ${COMBRELOC}
470     LD_FLAG=csharedtextonly
471     COMBRELOC=ldscripts/${EMULATION_NAME}.xsce.tmp
472     ( echo "/* Script for --shared -z combreloc -z separate-code: shared library, combine & sort relocs with separate code segment */"
473       source_sh ${CUSTOMIZER_SCRIPT}
474       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
475     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xsce
476     rm -f ${COMBRELOC}
477     RELRO_NOW=" "
478     LD_FLAG=wshared
479     COMBRELOC=ldscripts/${EMULATION_NAME}.xsw.tmp
480     ( echo "/* Script for --shared -z combreloc -z now -z relro: shared library, combine & sort relocs */"
481       source_sh ${CUSTOMIZER_SCRIPT}
482       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
483     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xsw
484     rm -f ${COMBRELOC}
485     LD_FLAG=wsharedtextonly
486     COMBRELOC=ldscripts/${EMULATION_NAME}.xswe.tmp
487     ( echo "/* Script for --shared -z combreloc -z now -z relro -z separate-code: shared library, combine & sort relocs with separate code segment */"
488       source_sh ${CUSTOMIZER_SCRIPT}
489       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
490     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xswe
491     rm -f ${COMBRELOC}
492     unset RELRO_NOW
493
494     if test -n "$GENERATE_RELRO_SCRIPT"; then
495         LD_FLAG=wshared
496         RELRO=" "
497         COMBRELOC=ldscripts/${EMULATION_NAME}.xsco.tmp
498         ( echo "/* Script for --shared -z combreloc -z relro: shared library, combine & sort relocs with separate code segment */"
499           source_sh ${CUSTOMIZER_SCRIPT}
500           source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
501         ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xsco
502         rm -f ${COMBRELOC}
503         LD_FLAG=wsharedtextonly
504         COMBRELOC=ldscripts/${EMULATION_NAME}.xsceo.tmp
505         ( echo "/* Script for --shared -z combreloc -z relro -z separate-code: shared library, combine & sort relocs with separate code segment */"
506           source_sh ${CUSTOMIZER_SCRIPT}
507           source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
508         ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xsceo
509         rm -f ${COMBRELOC}
510         unset RELRO
511     fi
512     COMBRELOC=
513   fi
514   unset CREATE_SHLIB
515 fi
516
517 if test -n "$GENERATE_PIE_SCRIPT"; then
518   DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
519   CREATE_PIE=" "
520   LD_FLAG=pie
521   ( echo "/* Script for ld -pie: link position independent executable */"
522     source_sh ${CUSTOMIZER_SCRIPT}
523     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
524   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xd
525   LD_FLAG=pietextonly
526   ( echo "/* Script for ld -pie -z separate-code: link position independent executable with separate code segment */"
527     source_sh ${CUSTOMIZER_SCRIPT}
528     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
529   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xde
530   if test -n "$GENERATE_RELRO_SCRIPT"; then
531       RELRO=" "
532       LD_FLAG=pie
533       ( echo "/* Script for ld -pie -z relro: link position independent executable */"
534         source_sh ${CUSTOMIZER_SCRIPT}
535         source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
536       ) | sed -e '/^ *$/d;s/[    ]*$//' > ldscripts/${EMULATION_NAME}.xdo
537       LD_FLAG=pietextonly
538       ( echo "/* Script for ld -pie -z relro -z separate-code: link position independent executable with separate code segment */"
539         source_sh ${CUSTOMIZER_SCRIPT}
540         source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
541       ) | sed -e '/^ *$/d;s/[    ]*$//' > ldscripts/${EMULATION_NAME}.xdeo
542       unset RELRO
543   fi
544   if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
545     DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
546     COMBRELOC=ldscripts/${EMULATION_NAME}.xdc.tmp
547     LD_FLAG=cpie
548     ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */"
549       source_sh ${CUSTOMIZER_SCRIPT}
550       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
551     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xdc
552     rm -f ${COMBRELOC}
553     LD_FLAG=cpietextonly
554     COMBRELOC=ldscripts/${EMULATION_NAME}.xdce.tmp
555     ( echo "/* Script for -pie -z combreloc -z separate-code: position independent executable, combine & sort relocs with separate code segment */"
556       source_sh ${CUSTOMIZER_SCRIPT}
557       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
558     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xdce
559     rm -f ${COMBRELOC}
560     RELRO_NOW=" "
561     LD_FLAG=wpie
562     COMBRELOC=ldscripts/${EMULATION_NAME}.xdw.tmp
563     ( echo "/* Script for -pie -z combreloc -z now -z relro: position independent executable, combine & sort relocs */"
564       source_sh ${CUSTOMIZER_SCRIPT}
565       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
566     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xdw
567     rm -f ${COMBRELOC}
568     LD_FLAG=wpietextonly
569     COMBRELOC=ldscripts/${EMULATION_NAME}.xdwe.tmp
570     ( echo "/* Script for -pie -z combreloc -z now -z relro -z separate-code: position independent executable, combine & sort relocs with separate code segment */"
571       source_sh ${CUSTOMIZER_SCRIPT}
572       source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
573     ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xdwe
574     rm -f ${COMBRELOC}
575     unset RELRO_NOW
576
577     if test -n "$GENERATE_RELRO_SCRIPT"; then
578         LD_FLAG=wpie
579         RELRO=" "
580         COMBRELOC=ldscripts/${EMULATION_NAME}.xdco.tmp
581         ( echo "/* Script for -pie -z combreloc -z relro: position independent executable, combine & sort relocs with separate code segment */"
582           source_sh ${CUSTOMIZER_SCRIPT}
583           source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
584         ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xdco
585         rm -f ${COMBRELOC}
586         LD_FLAG=wpietextonly
587         COMBRELOC=ldscripts/${EMULATION_NAME}.xdceo.tmp
588         ( echo "/* Script for -pie -z combreloc -z relro -z separate-code: position independent executable, combine & sort relocs with separate code segment */"
589           source_sh ${CUSTOMIZER_SCRIPT}
590           source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
591         ) | sed -e '/^ *$/d;s/[  ]*$//' > ldscripts/${EMULATION_NAME}.xdceo
592         rm -f ${COMBRELOC}
593
594         unset RELRO
595     fi
596     COMBRELOC=
597   fi
598   unset CREATE_PIE
599 fi
600
601 if test -n "$GENERATE_AUTO_IMPORT_SCRIPT"; then
602   LD_FLAG=auto_import
603   DATA_ALIGNMENT=${DATA_ALIGNMENT_}
604   ( echo "/* Script for ld --enable-auto-import: Like the default script except read only data is placed into .data  */"
605     source_sh ${CUSTOMIZER_SCRIPT}
606     source_sh ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
607   ) | sed -e '/^ *$/d;s/[        ]*$//' > ldscripts/${EMULATION_NAME}.xa
608 fi
609
610 case "$COMPILE_IN: $EMULATION_LIBPATH " in
611     :*" ${EMULATION_NAME} "*) COMPILE_IN=yes;;
612 esac
613
614 # PR ld/5652:
615 # Determine if the shell has support for the variable BASH_LINENO.
616 # When it is the case, it is only available inside functions.
617 has_lineno()
618 {
619   test "x$BASH_LINENO" != "x"
620 }
621
622 # Enable accruate error source in the compiler error messages, if possible.
623 if has_lineno; then
624   . ${srcdir}/genscrba.sh
625 else
626   source_em()
627   {
628     source_sh $1
629   }
630   fragment()
631   {
632     cat >> e${EMULATION_NAME}.c
633   }
634 fi
635
636 # Generate e${EMULATION_NAME}.c.
637 # Start with an empty file, then the sourced .em script
638 # can use the "fragment" function to append.
639 > e${EMULATION_NAME}.c
640 source_em ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em
641
642 ecdeps=
643 for dep in `cat ${DEPDIR}/e${EMULATION_NAME}.Tc`; do
644   case " $ecdeps " in
645     *" $dep "*): ;;
646     *) ecdeps="$ecdeps $dep" ;;
647   esac
648 done
649 rm -f ${DEPDIR}/e${EMULATION_NAME}.Tc
650 echo "e${EMULATION_NAME}.c:${ecdeps}" > ${DEPDIR}/e${EMULATION_NAME}.Pc