Rewrite SPU overlay handling code. Put overlay calls stubs in the
[deliverable/binutils-gdb.git] / ld / genscripts.sh
CommitLineData
252b5132
RH
1#!/bin/sh
2# genscripts.sh - generate the ld-emulation-target specific files
f96b4a7b
NC
3# Copyright 2007 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.
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 \
33# this_emulation \
34# optional:
35# tool_dir \
36# customizer_script
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"]
62# and maybe:
63# sun3.xc [used when the linker is invoked with "-z combreloc"]
64# sun3.xsc [used when the linker is invoked with "--shared"]
65# sun3.xdc [used when the linker is invoked with "-pie"]
e2a83dd0 66# sun3.xa [used when the linker is invoked with "--enable-auto-import"]
8fbdf3ab
AM
67#
68# It also produced the C source file:
69#
70# em_sun3.c
71#
72# which is then compiled into the linker.
73#
74# The linker scripts are created by running the shell script
75# /sources/ld/emulparams/sparc.sh to set the value of ${SCRIPT_NAME}
76# (and any other variables it wants to). ${SCRIPT_NAME} is then
77# invoked with a variable called ${LD_FLAG} to tell it which version
78# of the linker script to create.
79
252b5132
RH
80
81srcdir=$1
82libdir=$2
dfcffada
AM
83prefix=$3
84exec_prefix=$4
85host=$5
86target=$6
87target_alias=$7
88EMULATION_LIBPATH=$8
89NATIVE_LIB_DIRS=$9
d9fc3714 90shift 9
dfcffada
AM
91use_sysroot=$1
92EMULATION_NAME=$2
93TOOL_LIB=$3
94CUSTOMIZER_SCRIPT=$4
8fbdf3ab
AM
95
96# Can't use ${TOOL_LIB:-$target_alias} here due to an Ultrix shell bug.
97if [ "x${TOOL_LIB}" = "x" ] ; then
d9fc3714
AM
98 tool_lib=${exec_prefix}/${target_alias}/lib
99else
8fbdf3ab
AM
100 tool_lib=${exec_prefix}/${TOOL_LIB}/lib
101fi
102
103if [ "x${CUSTOMIZER_SCRIPT}" = "x" ] ; then
104 CUSTOMIZER_SCRIPT=${EMULATION_NAME}
d9fc3714 105fi
8fbdf3ab 106CUSTOMIZER_SCRIPT="${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh"
252b5132
RH
107
108# Include the emulation-specific parameters:
8fbdf3ab 109. ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
252b5132
RH
110
111if test -d ldscripts; then
112 true
113else
114 mkdir ldscripts
115fi
116
9c8ebd6a
DJ
117# Set some flags for the emultempl scripts. USE_LIBPATH will
118# be set for any libpath-using emulation; NATIVE will be set for a
119# libpath-using emulation where ${host} = ${target}. NATIVE
120# may already have been set by the emulparams file, but that's OK
121# (it'll just get set to "yes" twice).
122
123case " $EMULATION_LIBPATH " in
124 *" ${EMULATION_NAME} "*)
125 if [ "x${host}" = "x${target}" ] ; then
126 NATIVE=yes
127 USE_LIBPATH=yes
128 elif [ "x${use_sysroot}" = "xyes" ] ; then
129 USE_LIBPATH=yes
130 fi
131 ;;
132esac
133
134# If the emulparams file sets NATIVE, make sure USE_LIBPATH is set also.
135if test "x$NATIVE" = "xyes" ; then
136 USE_LIBPATH=yes
137fi
138
252b5132
RH
139# Set the library search path, for libraries named by -lfoo.
140# If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
141# Otherwise, the default is set here.
142#
143# The format is the usual list of colon-separated directories.
144# To force a logically empty LIB_PATH, do LIBPATH=":".
9c8ebd6a
DJ
145#
146# If we are using a sysroot, prefix library paths with "=" to indicate this.
147#
148# If the emulparams file set LIBPATH_SUFFIX, prepend an extra copy of
149# the library path with the suffix applied.
252b5132 150
9c8ebd6a 151if [ "x${LIB_PATH}" = "x" ] && [ "x${USE_LIBPATH}" = xyes ] ; then
f22f5fcd 152 LIB_PATH2=
1dd3bf68
AM
153
154 libs=${NATIVE_LIB_DIRS}
155 if [ "x${use_sysroot}" != "xyes" ] ; then
156 case " ${libs} " in
157 *" ${libdir} "*) ;;
586196d5 158 *) libs="${libdir} ${libs}" ;;
1dd3bf68
AM
159 esac
160 case " ${libs} " in
161 *" ${tool_lib} "*) ;;
586196d5 162 *) libs="${tool_lib} ${libs}" ;;
1dd3bf68 163 esac
9c8ebd6a 164 fi
1dd3bf68
AM
165
166 for lib in ${libs}; do
9c8ebd6a
DJ
167 # The "=" is harmless if we aren't using a sysroot, but also needless.
168 if [ "x${use_sysroot}" = "xyes" ] ; then
169 lib="=${lib}"
170 fi
d460ab58
JJ
171 addsuffix=
172 case "${LIBPATH_SUFFIX}:${lib}" in
173 :*) ;;
174 *:*${LIBPATH_SUFFIX}) ;;
175 *) addsuffix=yes ;;
3336653a 176 esac
d460ab58
JJ
177 if test -n "$addsuffix"; then
178 case :${LIB_PATH}: in
179 *:${lib}${LIBPATH_SUFFIX}:*) ;;
180 ::) LIB_PATH=${lib}${LIBPATH_SUFFIX} ;;
181 *) LIB_PATH=${LIB_PATH}:${lib}${LIBPATH_SUFFIX} ;;
182 esac
f22f5fcd 183 case :${LIB_PATH}:${LIB_PATH2}: in
d460ab58 184 *:${lib}:*) ;;
f22f5fcd
AM
185 *::) LIB_PATH2=${lib} ;;
186 *) LIB_PATH2=${LIB_PATH2}:${lib} ;;
d460ab58
JJ
187 esac
188 else
f22f5fcd
AM
189 case :${LIB_PATH2}: in
190 *:${lib}:*) ;;
191 ::) LIB_PATH2=${lib} ;;
192 *) LIB_PATH2=${LIB_PATH2}:${lib} ;;
d460ab58
JJ
193 esac
194 fi
9c8ebd6a 195 done
1dd3bf68 196
f22f5fcd
AM
197 case :${LIB_PATH}:${LIB_PATH2}: in
198 *:: | ::*) LIB_PATH=${LIB_PATH}${LIB_PATH2} ;;
199 *) LIB_PATH=${LIB_PATH}:${LIB_PATH2} ;;
200 esac
9b168ece
NC
201
202 # For multilib'ed targets, ensure both ${target_alias}/lib${LIBPATH_SUFFIX}
203 # and ${TOOL_LIB}/lib${LIBPATH_SUFFIX} are in the default search path, because
204 # 64bit libraries may be in both places, depending on cross-development
205 # setup method (e.g.: /usr/s390x-linux/lib64 vs /usr/s390-linux/lib64)
206 case "${LIBPATH_SUFFIX}:${tool_lib}" in
207 :*) ;;
208 *:*${LIBPATH_SUFFIX}) ;;
209 *)
210 paths="${exec_prefix}/${target_alias}/lib${LIBPATH_SUFFIX}"
211 if [ x"${TOOL_LIB}" != x ]; then
212 paths="${paths} ${exec_prefix}/${TOOL_LIB}/lib${LIBPATH_SUFFIX}"
213 fi
214 for path in $paths; do
215 case :${LIB_PATH}: in
216 ::: | *:${path}:*) ;;
217 *) LIB_PATH=${path}:${LIB_PATH} ;;
218 esac
219 done
220 ;;
221 esac
252b5132
RH
222fi
223
9c8ebd6a 224# Always search $(tooldir)/lib, aka /usr/local/TARGET/lib, except for
f22f5fcd 225# sysrooted configurations and when LIBPATH=":".
9c8ebd6a 226if [ "x${use_sysroot}" != "xyes" ] ; then
f22f5fcd
AM
227 case :${LIB_PATH}: in
228 ::: | *:${tool_lib}:*) ;;
229 ::) LIB_PATH=${tool_lib} ;;
230 *) LIB_PATH=${tool_lib}:${LIB_PATH} ;;
231 esac
33423b7f
MF
232 # For multilib targets, search both $tool_lib dirs
233 if [ "x${LIBPATH_SUFFIX}" != "x" ] ; then
234 case :${LIB_PATH}: in
235 ::: | *:${tool_lib}${LIBPATH_SUFFIX}:*) ;;
236 ::) LIB_PATH=${tool_lib}${LIBPATH_SUFFIX} ;;
237 *) LIB_PATH=${tool_lib}${LIBPATH_SUFFIX}:${LIB_PATH} ;;
238 esac
239 fi
9c8ebd6a 240fi
252b5132 241
eb3d6bb8 242LIB_SEARCH_DIRS=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
252b5132 243
cdaeef2e 244# We need it for testsuite.
dc4f76f8
L
245set $EMULATION_LIBPATH
246if [ "x$1" = "x$EMULATION_NAME" ]; then
cdaeef2e 247 test -d tmpdir || mkdir tmpdir
dc4f76f8 248 rm -f tmpdir/libpath.exp
cdaeef2e 249 echo "set libpath \"${LIB_PATH}\"" | sed -e 's/:/ /g' > tmpdir/libpath.exp
dc4f76f8 250fi
cdaeef2e 251
252b5132
RH
252# Generate 5 or 6 script files from a master script template in
253# ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6
254# script files is actually used depends on command line options given
255# to ld. (SCRIPT_NAME was set in the emulparams_file.)
256#
257# A .x script file is the default script.
258# A .xr script is for linking without relocation (-r flag).
259# A .xu script is like .xr, but *do* create constructors (-Ur flag).
260# A .xn script is for linking with -n flag (mix text and data on same page).
261# A .xbn script is for linking with -N flag (mix text and data on same page).
262# A .xs script is for generating a shared library with the --shared
263# flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
264# emulation parameters.
db6751f2
JJ
265# A .xc script is for linking with -z combreloc; it is only generated if
266# $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
267# $SCRIPT_NAME is "elf".
268# A .xsc script is for linking with --shared -z combreloc; it is generated
269# if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
270# $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation
271# parameters too.
272
273if [ "x$SCRIPT_NAME" = "xelf" ]; then
274 GENERATE_COMBRELOC_SCRIPT=yes
275fi
252b5132 276
1ddd7b13 277SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}}
252b5132
RH
278
279# Determine DATA_ALIGNMENT for the 5 variants, using
8fbdf3ab 280# values specified in the emulparams/<script_to_run>.sh file or default.
252b5132
RH
281
282DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
283DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
284DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
285DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
286DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
287
288LD_FLAG=r
289DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
290DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
cedd6b0d 291( echo "/* Script for ld -r: link without relocation */"
8fbdf3ab 292 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
179c732c 293 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2 294) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xr
252b5132
RH
295
296LD_FLAG=u
297DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
298CONSTRUCTING=" "
cedd6b0d 299( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */"
8fbdf3ab 300 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
179c732c 301 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2 302) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu
252b5132
RH
303
304LD_FLAG=
305DATA_ALIGNMENT=${DATA_ALIGNMENT_}
306RELOCATING=" "
cedd6b0d 307( echo "/* Default linker script, for normal executables */"
8fbdf3ab 308 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
179c732c 309 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2 310) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x
252b5132
RH
311
312LD_FLAG=n
313DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
cedd6b0d 314( echo "/* Script for -n: mix text and data on same page */"
8fbdf3ab 315 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
179c732c 316 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2 317) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xn
252b5132
RH
318
319LD_FLAG=N
320DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
cedd6b0d 321( echo "/* Script for -N: mix text and data on same page; don't align data */"
8fbdf3ab 322 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
179c732c 323 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2
JJ
324) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xbn
325
326if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
327 DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}}
328 LD_FLAG=c
329 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
e24d7c12 330 ( echo "/* Script for -z combreloc: combine and sort reloc sections */"
8fbdf3ab 331 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
db6751f2
JJ
332 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
333 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc
334 rm -f ${COMBRELOC}
8c37241b
JJ
335 LD_FLAG=w
336 RELRO_NOW=" "
337 COMBRELOC=ldscripts/${EMULATION_NAME}.xw.tmp
338 ( echo "/* Script for -z combreloc -z now -z relro: combine and sort reloc sections */"
339 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
340 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
341 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xw
342 rm -f ${COMBRELOC}
db6751f2 343 COMBRELOC=
8c37241b 344 unset RELRO_NOW
db6751f2 345fi
252b5132
RH
346
347if test -n "$GENERATE_SHLIB_SCRIPT"; then
348 LD_FLAG=shared
349 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
350 CREATE_SHLIB=" "
cedd6b0d
JB
351 (
352 echo "/* Script for ld --shared: link shared library */"
8fbdf3ab 353 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
179c732c 354 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
db6751f2
JJ
355 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs
356 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
357 LD_FLAG=cshared
358 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
8c37241b 359 COMBRELOC=ldscripts/${EMULATION_NAME}.xsc.tmp
cedd6b0d 360 ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */"
8fbdf3ab 361 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
db6751f2
JJ
362 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
363 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc
364 rm -f ${COMBRELOC}
8c37241b
JJ
365 LD_FLAG=wshared
366 RELRO_NOW=" "
367 COMBRELOC=ldscripts/${EMULATION_NAME}.xsw.tmp
368 ( echo "/* Script for --shared -z combreloc -z now -z relro: shared library, combine & sort relocs */"
369 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
370 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
371 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsw
372 rm -f ${COMBRELOC}
db6751f2 373 COMBRELOC=
8c37241b 374 unset RELRO_NOW
db6751f2 375 fi
36af4a4e
JJ
376 unset CREATE_SHLIB
377fi
378
379if test -n "$GENERATE_PIE_SCRIPT"; then
380 LD_FLAG=pie
381 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
382 CREATE_PIE=" "
36af4a4e
JJ
383 (
384 echo "/* Script for ld -pie: link position independent executable */"
8fbdf3ab 385 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
36af4a4e
JJ
386 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
387 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xd
388 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
389 LD_FLAG=cpie
390 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
8c37241b 391 COMBRELOC=ldscripts/${EMULATION_NAME}.xdc.tmp
36af4a4e 392 ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */"
8fbdf3ab 393 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
36af4a4e
JJ
394 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
395 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdc
396 rm -f ${COMBRELOC}
8c37241b
JJ
397 LD_FLAG=wpie
398 RELRO_NOW=" "
399 COMBRELOC=ldscripts/${EMULATION_NAME}.xdw.tmp
400 ( echo "/* Script for -pie -z combreloc -z now -z relro: position independent executable, combine & sort relocs */"
401 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
402 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
403 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdw
404 rm -f ${COMBRELOC}
36af4a4e 405 COMBRELOC=
8c37241b 406 unset RELRO_NOW
36af4a4e
JJ
407 fi
408 unset CREATE_PIE
252b5132
RH
409fi
410
e2a83dd0
NC
411if test -n "$GENERATE_AUTO_IMPORT_SCRIPT"; then
412 LD_FLAG=auto_import
413 DATA_ALIGNMENT=${DATA_ALIGNMENT_}
414 (
415 echo "/* Script for ld --enable-auto-import: Like the default script except read only data is placed into .data */"
416 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
417 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
418 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xa
419fi
420
eb3d6bb8
AM
421case " $EMULATION_LIBPATH " in
422 *" ${EMULATION_NAME} "*) COMPILE_IN=true;;
423esac
252b5132 424
92b93329 425if test -n "${BASH+set}"; then
c43cc9ff 426 . ${srcdir}/genscrba.sh
92b93329
RM
427else
428 source_em()
429 {
430 . $1
431 }
432 fragment()
433 {
434 cat >> e${EMULATION_NAME}.c
435 }
436fi
437
252b5132 438# Generate e${EMULATION_NAME}.c.
92b93329
RM
439# Start with an empty file, then the sourced .em script
440# can use the "fragment" function to append.
441> e${EMULATION_NAME}.c
442source_em ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em
This page took 0.507625 seconds and 4 git commands to generate.