]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - ld/genscripts_extra.sh
* emultempl/ia64elf.em (gld${EMULATION_NAME}_after_parse): Don't
[thirdparty/binutils-gdb.git] / ld / genscripts_extra.sh
CommitLineData
aafdb207
NC
1#!/bin/sh
2# genscripts_extra.sh - A copy of genscripts.sh with the ability to accept
3# a second optional parameter - the name of the script to run in order to
4# customise the linker scripts generated for a particular emulation.
5# This allows targets with large numbers of similar emulations to only
6# have one script to customise them all.
7#
8# Usage: genscripts_extra.sh \
9# srcdir \
10# libdir \
11# exec_prefix \
12# host \
13# target \
14# target_alias \
15# default_emulation \
16# native_lib_dirs \
17# use_sysroot \
18# this_emulation
19# optional:
20# tool_dir
21# customizer_script
22#
23# Sample usage:
24#
25# genscripts_extra.sh \
26# /sources/ld \
27# /usr/local/lib \
28# /usr/local \
29# sparc-sun-sunos4.1.3 \
30# sparc-sun-sunos4.1.3 \
31# sparc-sun-sunos4.1.3 \
32# sun4 \
33# "" \
34# no \
35# sun3 \
36# sparc-sun-sunos4.1.3
37# sparc.sh
38#
39# produces the linker scripts:
40#
41# sun3.x [default linker script]
42# sun3.xbn [used when the linker is invoked with "-N"]
43# sun3.xn [used when the linker is invoked with "-n"]
44# sun3.xr [used when the linker is invoked with "-r"]
45# sun3.xu [used when the linker is invoked with "-Ur"]
46# and maybe:
47# sun3.xc [used when the linker is invoked with "-z combreloc"]
48# sun3.xsc [used when the linker is invoked with "--shared"]
49# sun3.xdc [used when the linker is invoked with "-pie"]
50#
51# It also produced the C source file:
52#
53# em_sun3.c
54#
55# which is then compiled into the linker.
56#
57# The linker scripts are created by running the shell script
58# /sources/ld/emulparams/sparc.sh to set the value of ${SCRIPT_NAME}
59# (and any other variables it wants to). ${SCRIPT_NAME} is then
60# invoked with a variable called ${LD_FLAG} to tell it which version
61# of the linker script to create.
62
63
64srcdir=$1
65libdir=$2
66exec_prefix=$3
67host=$4
68target=$5
69target_alias=$6
70EMULATION_LIBPATH=$7
71NATIVE_LIB_DIRS=$8
72use_sysroot=$9
73shift 9
74EMULATION_NAME=$1
75TOOL_LIB=$2
76CUSTOMIZER_SCRIPT=$3
77shift
78# Can't use ${1:-$target_alias} here due to an Ultrix shell bug.
79if [ "x$TOOL_LIB" = "x" ] ; then
80 tool_lib=${exec_prefix}/${target_alias}/lib
81else
82 tool_lib=${exec_prefix}/$TOOL_LIB/lib
83fi
84
85if [ "x${CUSTOMIZER_SCRIPT}" = "x" ] ; then
86 CUSTOMIZER_SCRIPT=${EMULATION_NAME}
87fi
88
89# Include the emulation-specific parameters:
90. ${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh ${EMULATION_NAME}
91
92if test -d ldscripts; then
93 true
94else
95 mkdir ldscripts
96fi
97
98# Set some flags for the emultempl scripts. USE_LIBPATH will
99# be set for any libpath-using emulation; NATIVE will be set for a
100# libpath-using emulation where ${host} = ${target}. NATIVE
101# may already have been set by the emulparams file, but that's OK
102# (it'll just get set to "yes" twice).
103
104case " $EMULATION_LIBPATH " in
105 *" ${EMULATION_NAME} "*)
106 if [ "x${host}" = "x${target}" ] ; then
107 NATIVE=yes
108 USE_LIBPATH=yes
109 elif [ "x${use_sysroot}" = "xyes" ] ; then
110 USE_LIBPATH=yes
111 fi
112 ;;
113esac
114
115# If the emulparams file sets NATIVE, make sure USE_LIBPATH is set also.
116if test "x$NATIVE" = "xyes" ; then
117 USE_LIBPATH=yes
118fi
119
120# Set the library search path, for libraries named by -lfoo.
121# If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
122# Otherwise, the default is set here.
123#
124# The format is the usual list of colon-separated directories.
125# To force a logically empty LIB_PATH, do LIBPATH=":".
126#
127# If we are using a sysroot, prefix library paths with "=" to indicate this.
128#
129# If the emulparams file set LIBPATH_SUFFIX, prepend an extra copy of
130# the library path with the suffix applied.
131
132if [ "x${LIB_PATH}" = "x" ] && [ "x${USE_LIBPATH}" = xyes ] ; then
133 LIB_PATH2=
134 if [ x"$use_sysroot" != xyes ] ; then
135 LIB_PATH2=${libdir}
136 fi
137 for lib in ${NATIVE_LIB_DIRS}; do
138 # The "=" is harmless if we aren't using a sysroot, but also needless.
139 if [ "x${use_sysroot}" = "xyes" ] ; then
140 lib="=${lib}"
141 fi
142 addsuffix=
143 case "${LIBPATH_SUFFIX}:${lib}" in
144 :*) ;;
145 *:*${LIBPATH_SUFFIX}) ;;
146 *) addsuffix=yes ;;
147 esac
148 if test -n "$addsuffix"; then
149 case :${LIB_PATH}: in
150 *:${lib}${LIBPATH_SUFFIX}:*) ;;
151 ::) LIB_PATH=${lib}${LIBPATH_SUFFIX} ;;
152 *) LIB_PATH=${LIB_PATH}:${lib}${LIBPATH_SUFFIX} ;;
153 esac
154 case :${LIB_PATH}:${LIB_PATH2}: in
155 *:${lib}:*) ;;
156 *::) LIB_PATH2=${lib} ;;
157 *) LIB_PATH2=${LIB_PATH2}:${lib} ;;
158 esac
159 else
160 case :${LIB_PATH2}: in
161 *:${lib}:*) ;;
162 ::) LIB_PATH2=${lib} ;;
163 *) LIB_PATH2=${LIB_PATH2}:${lib} ;;
164 esac
165 fi
166 done
167 case :${LIB_PATH}:${LIB_PATH2}: in
168 *:: | ::*) LIB_PATH=${LIB_PATH}${LIB_PATH2} ;;
169 *) LIB_PATH=${LIB_PATH}:${LIB_PATH2} ;;
170 esac
171fi
172
173
174# Always search $(tooldir)/lib, aka /usr/local/TARGET/lib, except for
175# sysrooted configurations and when LIBPATH=":".
176if [ "x${use_sysroot}" != "xyes" ] ; then
177 case :${LIB_PATH}: in
178 ::: | *:${tool_lib}:*) ;;
179 ::) LIB_PATH=${tool_lib} ;;
180 *) LIB_PATH=${tool_lib}:${LIB_PATH} ;;
181 esac
182fi
183
184LIB_SEARCH_DIRS=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
185
186# We need it for testsuite.
187case " $EMULATION_LIBPATH " in
188 *" ${EMULATION_NAME} "*)
189 test -d tmpdir || mkdir tmpdir
190 test -f tmpdir/libpath.exp || \
191 echo "set libpath \"${LIB_PATH}\"" | sed -e 's/:/ /g' > tmpdir/libpath.exp
192 ;;
193esac
194
195# Generate 5 or 6 script files from a master script template in
196# ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6
197# script files is actually used depends on command line options given
198# to ld. (SCRIPT_NAME was set in the emulparams_file.)
199#
200# A .x script file is the default script.
201# A .xr script is for linking without relocation (-r flag).
202# A .xu script is like .xr, but *do* create constructors (-Ur flag).
203# A .xn script is for linking with -n flag (mix text and data on same page).
204# A .xbn script is for linking with -N flag (mix text and data on same page).
205# A .xs script is for generating a shared library with the --shared
206# flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
207# emulation parameters.
208# A .xc script is for linking with -z combreloc; it is only generated if
209# $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
210# $SCRIPT_NAME is "elf".
211# A .xsc script is for linking with --shared -z combreloc; it is generated
212# if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
213# $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation
214# parameters too.
215
216if [ "x$SCRIPT_NAME" = "xelf" ]; then
217 GENERATE_COMBRELOC_SCRIPT=yes
218fi
219
220SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}}
221
222# Determine DATA_ALIGNMENT for the 5 variants, using
223# values specified in the emulparams/<script_to_run>.sh file or default.
224
225DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
226DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
227DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
228DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
229DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
230
231LD_FLAG=r
232DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
233DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
234( echo "/* Script for ld -r: link without relocation */"
235 . ${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh ${EMULATION_NAME}
236 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
237) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xr
238
239LD_FLAG=u
240DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
241CONSTRUCTING=" "
242( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */"
243 . ${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh ${EMULATION_NAME}
244 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
245) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu
246
247LD_FLAG=
248DATA_ALIGNMENT=${DATA_ALIGNMENT_}
249RELOCATING=" "
250( echo "/* Default linker script, for normal executables */"
251 . ${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh ${EMULATION_NAME}
252 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
253) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x
254
255LD_FLAG=n
256DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
257TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
258( echo "/* Script for -n: mix text and data on same page */"
259 . ${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh ${EMULATION_NAME}
260 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
261) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xn
262
263LD_FLAG=N
264DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
265( echo "/* Script for -N: mix text and data on same page; don't align data */"
266 . ${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh ${EMULATION_NAME}
267 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
268) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xbn
269
270if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
271 DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}}
272 LD_FLAG=c
273 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
274 ( echo "/* Script for -z combreloc: combine and sort reloc sections */"
275 . ${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh ${EMULATION_NAME}
276 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
277 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc
278 rm -f ${COMBRELOC}
279 COMBRELOC=
280fi
281
282if test -n "$GENERATE_SHLIB_SCRIPT"; then
283 LD_FLAG=shared
284 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
285 CREATE_SHLIB=" "
286 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
287 (
288 echo "/* Script for ld --shared: link shared library */"
289 . ${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh ${EMULATION_NAME}
290 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
291 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs
292 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
293 LD_FLAG=cshared
294 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
295 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
296 ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */"
297 . ${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh ${EMULATION_NAME}
298 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
299 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc
300 rm -f ${COMBRELOC}
301 COMBRELOC=
302 fi
303 unset CREATE_SHLIB
304fi
305
306if test -n "$GENERATE_PIE_SCRIPT"; then
307 LD_FLAG=pie
308 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
309 CREATE_PIE=" "
310 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
311 (
312 echo "/* Script for ld -pie: link position independent executable */"
313 . ${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh ${EMULATION_NAME}
314 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
315 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xd
316 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
317 LD_FLAG=cpie
318 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
319 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
320 ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */"
321 . ${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh ${EMULATION_NAME}
322 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
323 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdc
324 rm -f ${COMBRELOC}
325 COMBRELOC=
326 fi
327 unset CREATE_PIE
328fi
329
330case " $EMULATION_LIBPATH " in
331 *" ${EMULATION_NAME} "*) COMPILE_IN=true;;
332esac
333
334# Generate e${EMULATION_NAME}.c.
335. ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em