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.
8 # Usage: genscripts_extra.sh \
25 # genscripts_extra.sh \
29 # sparc-sun-sunos4.1.3 \
30 # sparc-sun-sunos4.1.3 \
31 # sparc-sun-sunos4.1.3 \
36 # sparc-sun-sunos4.1.3
39 # produces the linker scripts:
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"]
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"]
51 # It also produced the C source file:
55 # which is then compiled into the linker.
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.
78 # Can't use ${1:-$target_alias} here due to an Ultrix shell bug.
79 if [ "x$TOOL_LIB" = "x" ] ; then
80 tool_lib
=${exec_prefix}/${target_alias}/lib
82 tool_lib
=${exec_prefix}/$TOOL_LIB/lib
85 if [ "x${CUSTOMIZER_SCRIPT}" = "x" ] ; then
86 CUSTOMIZER_SCRIPT
=${EMULATION_NAME}
89 # Include the emulation-specific parameters:
90 .
${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh ${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
134 if [ x
"$use_sysroot" != xyes
] ; then
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
143 case "${LIBPATH_SUFFIX}:${lib}" in
145 *:*${LIBPATH_SUFFIX}) ;;
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} ;;
154 case :${LIB_PATH}:${LIB_PATH2}: in
156 *::) LIB_PATH2
=${lib} ;;
157 *) LIB_PATH2
=${LIB_PATH2}:${lib} ;;
160 case :${LIB_PATH2}: in
162 ::) LIB_PATH2
=${lib} ;;
163 *) LIB_PATH2
=${LIB_PATH2}:${lib} ;;
167 case :${LIB_PATH}:${LIB_PATH2}: in
168 *:: |
::*) LIB_PATH
=${LIB_PATH}${LIB_PATH2} ;;
169 *) LIB_PATH
=${LIB_PATH}:${LIB_PATH2} ;;
174 # Always search $(tooldir)/lib, aka /usr/local/TARGET/lib, except for
175 # sysrooted configurations and when LIBPATH=":".
176 if [ "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} ;;
184 LIB_SEARCH_DIRS
=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
186 # We need it for testsuite.
187 case " $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
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.)
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
216 if [ "x$SCRIPT_NAME" = "xelf" ]; then
217 GENERATE_COMBRELOC_SCRIPT
=yes
220 SEGMENT_SIZE
=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}}
222 # Determine DATA_ALIGNMENT for the 5 variants, using
223 # values specified in the emulparams/<script_to_run>.sh file or default.
225 DATA_ALIGNMENT_
="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
226 DATA_ALIGNMENT_n
="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
227 DATA_ALIGNMENT_N
="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
228 DATA_ALIGNMENT_r
="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
229 DATA_ALIGNMENT_u
="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
232 DATA_ALIGNMENT
=${DATA_ALIGNMENT_r}
233 DEFAULT_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
240 DATA_ALIGNMENT
=${DATA_ALIGNMENT_u}
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
248 DATA_ALIGNMENT
=${DATA_ALIGNMENT_}
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
256 DATA_ALIGNMENT
=${DATA_ALIGNMENT_n}
257 TEXT_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
264 DATA_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
270 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
271 DATA_ALIGNMENT
=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}}
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
282 if test -n "$GENERATE_SHLIB_SCRIPT"; then
284 DATA_ALIGNMENT
=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
286 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
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
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
306 if test -n "$GENERATE_PIE_SCRIPT"; then
308 DATA_ALIGNMENT
=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
310 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
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
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
330 case " $EMULATION_LIBPATH " in
331 *" ${EMULATION_NAME} "*) COMPILE_IN
=true
;;
334 # Generate e${EMULATION_NAME}.c.
335 .
${srcdir}/emultempl
/${TEMPLATE_NAME-generic}.em