2 # genscripts.sh - generate the ld-emulation-target specific files
3 # Copyright 2004, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
5 # This file is part of the Gnu Linker.
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)
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.
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
22 # Usage: genscripts_extra.sh \
33 # enable_initfini_array \
41 # genscripts_extra.sh \
46 # sparc-sun-sunos4.1.3 \
47 # sparc-sun-sunos4.1.3 \
48 # sparc-sun-sunos4.1.3 \
53 # sparc-sun-sunos4.1.3 \
56 # produces the linker scripts:
58 # sun3.x [default linker script]
59 # sun3.xbn [used when the linker is invoked with "-N"]
60 # sun3.xn [used when the linker is invoked with "-n"]
61 # sun3.xr [used when the linker is invoked with "-r"]
62 # sun3.xu [used when the linker is invoked with "-Ur"]
64 # sun3.xc [used when the linker is invoked with "-z combreloc"]
65 # sun3.xsc [used when the linker is invoked with "--shared"]
66 # sun3.xdc [used when the linker is invoked with "-pie"]
67 # sun3.xa [used when the linker is invoked with "--enable-auto-import"]
69 # It also produced the C source file:
73 # which is then compiled into the linker.
75 # The linker scripts are created by running the shell script
76 # /sources/ld/emulparams/sparc.sh to set the value of ${SCRIPT_NAME}
77 # (and any other variables it wants to). ${SCRIPT_NAME} is then
78 # invoked with a variable called ${LD_FLAG} to tell it which version
79 # of the linker script to create.
93 ENABLE_INITFINI_ARRAY
=$2
98 if [ "x${CUSTOMIZER_SCRIPT}" = "x" ] ; then
99 CUSTOMIZER_SCRIPT
=${EMULATION_NAME}
101 CUSTOMIZER_SCRIPT
="${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh"
103 # Include the emulation-specific parameters:
104 .
${CUSTOMIZER_SCRIPT}
106 if test -d ldscripts
; then
112 # Set some flags for the emultempl scripts. USE_LIBPATH will
113 # be set for any libpath-using emulation; NATIVE will be set for a
114 # libpath-using emulation where ${host} = ${target}. NATIVE
115 # may already have been set by the emulparams file, but that's OK
116 # (it'll just get set to "yes" twice).
118 case " $EMULATION_LIBPATH " in
119 *" ${EMULATION_NAME} "*)
120 if [ "x${host}" = "x${target}" ] ; then
123 elif [ "x${use_sysroot}" = "xyes" ] ; then
129 # If the emulparams file sets NATIVE, make sure USE_LIBPATH is set also.
130 if test "x$NATIVE" = "xyes" ; then
134 # Set the library search path, for libraries named by -lfoo.
135 # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
136 # Otherwise, the default is set here.
138 # The format is the usual list of colon-separated directories.
139 # To force a logically empty LIB_PATH, do LIBPATH=":".
141 # If we are using a sysroot, prefix library paths with "=" to indicate this.
143 # If the emulparams file set LIBPATH_SUFFIX, prepend an extra copy of
144 # the library path with the suffix applied.
146 # Paths with LIBPATH_SUFFIX
148 # Paths without LIBPATH_SUFFIX
150 if [ "${LIB_PATH}" != ":" ] ; then
151 lib_path2
=${LIB_PATH}
154 # Add args to lib_path1 and lib_path2, discarding any duplicates
159 # The "=" is harmless if we aren't using a sysroot, but also needless.
160 if [ "x${use_sysroot}" = "xyes" ] ; then
163 if test -n "${LIBPATH_SUFFIX}"; then
166 case :${lib_path1}: in
168 ::) lib_path1
=${lib} ;;
169 *) lib_path1
=${lib_path1}:${lib} ;;
172 case :${lib_path1}: in
173 *:${lib}${LIBPATH_SUFFIX}:*) ;;
174 ::) lib_path1
=${lib}${LIBPATH_SUFFIX} ;;
175 *) lib_path1
=${lib_path1}:${lib}${LIBPATH_SUFFIX} ;;
179 case :${lib_path1}:${lib_path2}: in
181 *::) lib_path2
=${lib} ;;
182 *) lib_path2
=${lib_path2}:${lib} ;;
188 # Always search $(tooldir)/lib, aka /usr/local/TARGET/lib when native
189 # except when LIBPATH=":".
190 if [ "${LIB_PATH}" != ":" ] ; then
192 if [ "x${TOOL_LIB}" = "x" ] ; then
193 if [ "x${NATIVE}" = "xyes" ] ; then
194 libs
="${exec_prefix}/${target_alias}/lib"
197 # For multilib'ed targets, ensure both ${target_alias}/lib${LIBPATH_SUFFIX}
198 # and ${TOOL_LIB}/lib${LIBPATH_SUFFIX} are in the default search path,
199 # because 64bit libraries may be in both places, depending on
200 # cross-development setup method (e.g.: /usr/s390x-linux/lib64
201 # vs. /usr/s390-linux/lib64)
202 case "${NATIVE}:${LIBPATH_SUFFIX}:${TOOL_LIB}" in
203 :* |
*::* |
*:*:*${LIBPATH_SUFFIX}) ;;
204 *) libs
="${exec_prefix}/${target_alias}/lib${LIBPATH_SUFFIX}" ;;
206 libs
="${exec_prefix}/${TOOL_LIB}/lib ${libs}"
208 append_to_lib_path
${libs}
211 if [ "x${LIB_PATH}" = "x" ] && [ "x${USE_LIBPATH}" = xyes
] ; then
212 libs
=${NATIVE_LIB_DIRS}
213 if [ "x${NATIVE}" = "xyes" ] ; then
216 *) libs
="${libdir} ${libs}" ;;
219 append_to_lib_path
${libs}
222 case :${lib_path1}:${lib_path2}: in
223 *:: |
::*) LIB_PATH
=${lib_path1}${lib_path2} ;;
224 *) LIB_PATH
=${lib_path1}:${lib_path2} ;;
227 LIB_SEARCH_DIRS
=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
229 # We need it for testsuite.
230 set $EMULATION_LIBPATH
231 if [ "x$1" = "x$EMULATION_NAME" ]; then
232 test -d tmpdir || mkdir tmpdir
233 rm -f tmpdir
/libpath.exp
234 echo "set libpath \"${LIB_PATH}\"" |
sed -e 's/:/ /g' > tmpdir
/libpath.exp
237 # Generate 5 or 6 script files from a master script template in
238 # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6
239 # script files is actually used depends on command line options given
240 # to ld. (SCRIPT_NAME was set in the emulparams_file.)
242 # A .x script file is the default script.
243 # A .xr script is for linking without relocation (-r flag).
244 # A .xu script is like .xr, but *do* create constructors (-Ur flag).
245 # A .xn script is for linking with -n flag (mix text and data on same page).
246 # A .xbn script is for linking with -N flag (mix text and data on same page).
247 # A .xs script is for generating a shared library with the --shared
248 # flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
249 # emulation parameters.
250 # A .xc script is for linking with -z combreloc; it is only generated if
251 # $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
252 # $SCRIPT_NAME is "elf".
253 # A .xsc script is for linking with --shared -z combreloc; it is generated
254 # if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
255 # $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation
258 if [ "x$SCRIPT_NAME" = "xelf" ]; then
259 GENERATE_COMBRELOC_SCRIPT
=yes
262 SEGMENT_SIZE
=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}}
264 # Determine DATA_ALIGNMENT for the 5 variants, using
265 # values specified in the emulparams/<script_to_run>.sh file or default.
267 DATA_ALIGNMENT_
="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
268 DATA_ALIGNMENT_n
="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
269 DATA_ALIGNMENT_N
="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
270 DATA_ALIGNMENT_r
="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
271 DATA_ALIGNMENT_u
="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
274 DATA_ALIGNMENT
=${DATA_ALIGNMENT_r}
275 DEFAULT_DATA_ALIGNMENT
="ALIGN(${SEGMENT_SIZE})"
276 ( echo "/* Script for ld -r: link without relocation */"
277 .
${CUSTOMIZER_SCRIPT}
278 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
279 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xr
282 DATA_ALIGNMENT
=${DATA_ALIGNMENT_u}
284 ( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */"
285 .
${CUSTOMIZER_SCRIPT}
286 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
287 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xu
290 DATA_ALIGNMENT
=${DATA_ALIGNMENT_}
292 ( echo "/* Default linker script, for normal executables */"
293 .
${CUSTOMIZER_SCRIPT}
294 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
295 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.x
298 DATA_ALIGNMENT
=${DATA_ALIGNMENT_n}
299 ( echo "/* Script for -n: mix text and data on same page */"
300 .
${CUSTOMIZER_SCRIPT}
301 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
302 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xn
305 DATA_ALIGNMENT
=${DATA_ALIGNMENT_N}
306 ( echo "/* Script for -N: mix text and data on same page; don't align data */"
307 .
${CUSTOMIZER_SCRIPT}
308 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
309 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xbn
311 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
312 DATA_ALIGNMENT
=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}}
314 COMBRELOC
=ldscripts
/${EMULATION_NAME}.xc.tmp
315 ( echo "/* Script for -z combreloc: combine and sort reloc sections */"
316 .
${CUSTOMIZER_SCRIPT}
317 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
318 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xc
322 COMBRELOC
=ldscripts
/${EMULATION_NAME}.xw.tmp
323 ( echo "/* Script for -z combreloc -z now -z relro: combine and sort reloc sections */"
324 .
${CUSTOMIZER_SCRIPT}
325 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
326 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xw
332 if test -n "$GENERATE_SHLIB_SCRIPT"; then
334 DATA_ALIGNMENT
=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
337 echo "/* Script for ld --shared: link shared library */"
338 .
${CUSTOMIZER_SCRIPT}
339 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
340 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xs
341 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
343 DATA_ALIGNMENT
=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
344 COMBRELOC
=ldscripts
/${EMULATION_NAME}.xsc.tmp
345 ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */"
346 .
${CUSTOMIZER_SCRIPT}
347 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
348 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xsc
352 COMBRELOC
=ldscripts
/${EMULATION_NAME}.xsw.tmp
353 ( echo "/* Script for --shared -z combreloc -z now -z relro: shared library, combine & sort relocs */"
354 .
${CUSTOMIZER_SCRIPT}
355 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
356 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xsw
364 if test -n "$GENERATE_PIE_SCRIPT"; then
366 DATA_ALIGNMENT
=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
369 echo "/* Script for ld -pie: link position independent executable */"
370 .
${CUSTOMIZER_SCRIPT}
371 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
372 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xd
373 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
375 DATA_ALIGNMENT
=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
376 COMBRELOC
=ldscripts
/${EMULATION_NAME}.xdc.tmp
377 ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */"
378 .
${CUSTOMIZER_SCRIPT}
379 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
380 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xdc
384 COMBRELOC
=ldscripts
/${EMULATION_NAME}.xdw.tmp
385 ( echo "/* Script for -pie -z combreloc -z now -z relro: position independent executable, combine & sort relocs */"
386 .
${CUSTOMIZER_SCRIPT}
387 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
388 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xdw
396 if test -n "$GENERATE_AUTO_IMPORT_SCRIPT"; then
398 DATA_ALIGNMENT
=${DATA_ALIGNMENT_}
400 echo "/* Script for ld --enable-auto-import: Like the default script except read only data is placed into .data */"
401 .
${CUSTOMIZER_SCRIPT}
402 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
403 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xa
406 case " $EMULATION_LIBPATH " in
407 *" ${EMULATION_NAME} "*) COMPILE_IN
=true
;;
411 # Determine if the shell has support for the variable BASH_LINENO.
412 # When it is the case, it is only available inside functions.
415 test "x$BASH_LINENO" != "x"
418 # Enable accruate error source in the compiler error messages, if possible.
420 .
${srcdir}/genscrba.sh
428 cat >> e
${EMULATION_NAME}.c
432 # Generate e${EMULATION_NAME}.c.
433 # Start with an empty file, then the sourced .em script
434 # can use the "fragment" function to append.
435 > e
${EMULATION_NAME}.c
436 source_em
${srcdir}/emultempl
/${TEMPLATE_NAME-generic}.em