2 # genscripts.sh - generate the ld-emulation-target specific files
4 # Usage: genscripts_extra.sh \
22 # genscripts_extra.sh \
27 # sparc-sun-sunos4.1.3 \
28 # sparc-sun-sunos4.1.3 \
29 # sparc-sun-sunos4.1.3 \
34 # sparc-sun-sunos4.1.3 \
37 # produces the linker scripts:
39 # sun3.x [default linker script]
40 # sun3.xbn [used when the linker is invoked with "-N"]
41 # sun3.xn [used when the linker is invoked with "-n"]
42 # sun3.xr [used when the linker is invoked with "-r"]
43 # sun3.xu [used when the linker is invoked with "-Ur"]
45 # sun3.xc [used when the linker is invoked with "-z combreloc"]
46 # sun3.xsc [used when the linker is invoked with "--shared"]
47 # sun3.xdc [used when the linker is invoked with "-pie"]
49 # It also produced the C source file:
53 # which is then compiled into the linker.
55 # The linker scripts are created by running the shell script
56 # /sources/ld/emulparams/sparc.sh to set the value of ${SCRIPT_NAME}
57 # (and any other variables it wants to). ${SCRIPT_NAME} is then
58 # invoked with a variable called ${LD_FLAG} to tell it which version
59 # of the linker script to create.
77 # Can't use ${TOOL_LIB:-$target_alias} here due to an Ultrix shell bug.
78 if [ "x${TOOL_LIB}" = "x" ] ; then
79 tool_lib=${exec_prefix}/${target_alias}/lib
81 tool_lib=${exec_prefix}/${TOOL_LIB}/lib
84 if [ "x${CUSTOMIZER_SCRIPT}" = "x" ] ; then
85 CUSTOMIZER_SCRIPT=${EMULATION_NAME}
87 CUSTOMIZER_SCRIPT="${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh"
89 # Include the emulation-specific parameters:
90 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
92 if test -d ldscripts; then
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).
104 case " $EMULATION_LIBPATH " in
105 *" ${EMULATION_NAME} "*)
106 if [ "x${host}" = "x${target}" ] ; then
109 elif [ "x${use_sysroot}" = "xyes" ] ; then
115 # If the emulparams file sets NATIVE, make sure USE_LIBPATH is set also.
116 if test "x$NATIVE" = "xyes" ; then
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.
124 # The format is the usual list of colon-separated directories.
125 # To force a logically empty LIB_PATH, do LIBPATH=":".
127 # If we are using a sysroot, prefix library paths with "=" to indicate this.
129 # If the emulparams file set LIBPATH_SUFFIX, prepend an extra copy of
130 # the library path with the suffix applied.
132 if [ "x${LIB_PATH}" = "x" ] && [ "x${USE_LIBPATH}" = xyes ] ; then
135 libs=${NATIVE_LIB_DIRS}
136 if [ "x${use_sysroot}" != "xyes" ] ; then
139 *) libs="${libdir} ${libs}" ;;
142 *" ${tool_lib} "*) ;;
143 *) libs="${tool_lib} ${libs}" ;;
147 for lib in ${libs}; do
148 # The "=" is harmless if we aren't using a sysroot, but also needless.
149 if [ "x${use_sysroot}" = "xyes" ] ; then
153 case "${LIBPATH_SUFFIX}:${lib}" in
155 *:*${LIBPATH_SUFFIX}) ;;
158 if test -n "$addsuffix"; then
159 case :${LIB_PATH}: in
160 *:${lib}${LIBPATH_SUFFIX}:*) ;;
161 ::) LIB_PATH=${lib}${LIBPATH_SUFFIX} ;;
162 *) LIB_PATH=${LIB_PATH}:${lib}${LIBPATH_SUFFIX} ;;
164 case :${LIB_PATH}:${LIB_PATH2}: in
166 *::) LIB_PATH2=${lib} ;;
167 *) LIB_PATH2=${LIB_PATH2}:${lib} ;;
170 case :${LIB_PATH2}: in
172 ::) LIB_PATH2=${lib} ;;
173 *) LIB_PATH2=${LIB_PATH2}:${lib} ;;
178 case :${LIB_PATH}:${LIB_PATH2}: in
179 *:: | ::*) LIB_PATH=${LIB_PATH}${LIB_PATH2} ;;
180 *) LIB_PATH=${LIB_PATH}:${LIB_PATH2} ;;
184 # Always search $(tooldir)/lib, aka /usr/local/TARGET/lib, except for
185 # sysrooted configurations and when LIBPATH=":".
186 if [ "x${use_sysroot}" != "xyes" ] ; then
187 case :${LIB_PATH}: in
188 ::: | *:${tool_lib}:*) ;;
189 ::) LIB_PATH=${tool_lib} ;;
190 *) LIB_PATH=${tool_lib}:${LIB_PATH} ;;
192 # For multilib targets, search both $tool_lib dirs
193 if [ "x${LIBPATH_SUFFIX}" != "x" ] ; then
194 case :${LIB_PATH}: in
195 ::: | *:${tool_lib}${LIBPATH_SUFFIX}:*) ;;
196 ::) LIB_PATH=${tool_lib}${LIBPATH_SUFFIX} ;;
197 *) LIB_PATH=${tool_lib}${LIBPATH_SUFFIX}:${LIB_PATH} ;;
202 LIB_SEARCH_DIRS=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
204 # We need it for testsuite.
205 set $EMULATION_LIBPATH
206 if [ "x$1" = "x$EMULATION_NAME" ]; then
207 test -d tmpdir || mkdir tmpdir
208 rm -f tmpdir/libpath.exp
209 echo "set libpath \"${LIB_PATH}\"" | sed -e 's/:/ /g' > tmpdir/libpath.exp
212 # Generate 5 or 6 script files from a master script template in
213 # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6
214 # script files is actually used depends on command line options given
215 # to ld. (SCRIPT_NAME was set in the emulparams_file.)
217 # A .x script file is the default script.
218 # A .xr script is for linking without relocation (-r flag).
219 # A .xu script is like .xr, but *do* create constructors (-Ur flag).
220 # A .xn script is for linking with -n flag (mix text and data on same page).
221 # A .xbn script is for linking with -N flag (mix text and data on same page).
222 # A .xs script is for generating a shared library with the --shared
223 # flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
224 # emulation parameters.
225 # A .xc script is for linking with -z combreloc; it is only generated if
226 # $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
227 # $SCRIPT_NAME is "elf".
228 # A .xsc script is for linking with --shared -z combreloc; it is generated
229 # if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
230 # $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation
233 if [ "x$SCRIPT_NAME" = "xelf" ]; then
234 GENERATE_COMBRELOC_SCRIPT=yes
237 SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}}
239 # Determine DATA_ALIGNMENT for the 5 variants, using
240 # values specified in the emulparams/<script_to_run>.sh file or default.
242 DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
243 DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
244 DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
245 DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
246 DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
249 DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
250 DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
251 ( echo "/* Script for ld -r: link without relocation */"
252 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
253 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
254 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xr
257 DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
259 ( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */"
260 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
261 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
262 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu
265 DATA_ALIGNMENT=${DATA_ALIGNMENT_}
267 ( echo "/* Default linker script, for normal executables */"
268 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
269 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
270 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x
273 DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
274 TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
275 ( echo "/* Script for -n: mix text and data on same page */"
276 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
277 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
278 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xn
281 DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
282 ( echo "/* Script for -N: mix text and data on same page; don't align data */"
283 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
284 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
285 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xbn
287 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
288 DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}}
290 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
291 ( echo "/* Script for -z combreloc: combine and sort reloc sections */"
292 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
293 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
294 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc
298 COMBRELOC=ldscripts/${EMULATION_NAME}.xw.tmp
299 ( echo "/* Script for -z combreloc -z now -z relro: combine and sort reloc sections */"
300 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
301 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
302 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xw
308 if test -n "$GENERATE_SHLIB_SCRIPT"; then
310 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
312 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
314 echo "/* Script for ld --shared: link shared library */"
315 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
316 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
317 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs
318 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
320 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
321 COMBRELOC=ldscripts/${EMULATION_NAME}.xsc.tmp
322 ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */"
323 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
324 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
325 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc
329 COMBRELOC=ldscripts/${EMULATION_NAME}.xsw.tmp
330 ( echo "/* Script for --shared -z combreloc -z now -z relro: shared library, combine & sort relocs */"
331 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
332 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
333 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsw
341 if test -n "$GENERATE_PIE_SCRIPT"; then
343 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
345 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
347 echo "/* Script for ld -pie: link position independent executable */"
348 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
349 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
350 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xd
351 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
353 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
354 COMBRELOC=ldscripts/${EMULATION_NAME}.xdc.tmp
355 ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */"
356 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
357 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
358 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdc
362 COMBRELOC=ldscripts/${EMULATION_NAME}.xdw.tmp
363 ( echo "/* Script for -pie -z combreloc -z now -z relro: position independent executable, combine & sort relocs */"
364 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
365 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
366 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdw
374 case " $EMULATION_LIBPATH " in
375 *" ${EMULATION_NAME} "*) COMPILE_IN=true;;
378 # Generate e${EMULATION_NAME}.c.
379 . ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em