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