2 # genscripts.sh - generate the ld-emulation-target specific files
4 # Usage: genscripts.sh srcdir libdir exec_prefix \
5 # host target target_alias default_emulation \
6 # native_lib_dirs use_sysroot this_emulation tool_dir
9 # genscripts.sh /djm/ld-devo/devo/ld /usr/local/lib /usr/local \
10 # sparc-sun-sunos4.1.3 sparc-sun-sunos4.1.3 sparc-sun-sunos4.1.3 sun4 \
11 # "" no sun3 sparc-sun-sunos4.1.3
12 # produces sun3.x sun3.xbn sun3.xn sun3.xr sun3.xu em_sun3.c
26 # Can't use ${1:-$target_alias} here due to an Ultrix shell bug.
27 if [ "x$1" = "x" ] ; then
28 tool_lib
=${exec_prefix}/${target_alias}/lib
30 tool_lib
=${exec_prefix}/$1/lib
33 # Include the emulation-specific parameters:
34 .
${srcdir}/emulparams
/${EMULATION_NAME}.sh
36 if test -d ldscripts
; then
42 # Set some flags for the emultempl scripts. USE_LIBPATH will
43 # be set for any libpath-using emulation; NATIVE will be set for a
44 # libpath-using emulation where ${host} = ${target}. NATIVE
45 # may already have been set by the emulparams file, but that's OK
46 # (it'll just get set to "yes" twice).
48 case " $EMULATION_LIBPATH " in
49 *" ${EMULATION_NAME} "*)
50 if [ "x${host}" = "x${target}" ] ; then
53 elif [ "x${use_sysroot}" = "xyes" ] ; then
59 # If the emulparams file sets NATIVE, make sure USE_LIBPATH is set also.
60 if test "x$NATIVE" = "xyes" ; then
64 # Set the library search path, for libraries named by -lfoo.
65 # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
66 # Otherwise, the default is set here.
68 # The format is the usual list of colon-separated directories.
69 # To force a logically empty LIB_PATH, do LIBPATH=":".
71 # If we are using a sysroot, prefix library paths with "=" to indicate this.
73 # If the emulparams file set LIBPATH_SUFFIX, prepend an extra copy of
74 # the library path with the suffix applied.
76 if [ "x${LIB_PATH}" = "x" ] && [ "x${USE_LIBPATH}" = xyes
] ; then
77 if [ x
"$use_sysroot" != xyes
] ; then
81 for lib
in ${NATIVE_LIB_DIRS}; do
82 # The "=" is harmless if we aren't using a sysroot, but also needless.
83 if [ "x${use_sysroot}" = "xyes" ] ; then
87 case "${LIBPATH_SUFFIX}:${lib}" in
89 *:*${LIBPATH_SUFFIX}) ;;
92 if test -n "$addsuffix"; then
94 *:${lib}${LIBPATH_SUFFIX}:*) ;;
95 ::) LIB_PATH
=${lib}${LIBPATH_SUFFIX} ;;
96 *) LIB_PATH
=${LIB_PATH}:${lib}${LIBPATH_SUFFIX} ;;
98 case :${LIB_PATH}${LIB_PATH2}: in
100 *) LIB_PATH2
=${LIB_PATH2}:${lib} ;;
103 case :${LIB_PATH}: in
105 ::) LIB_PATH
=${lib} ;;
106 *) LIB_PATH
=${LIB_PATH}:${lib} ;;
110 LIB_PATH
=${LIB_PATH}${LIB_PATH2}
114 # Always search $(tooldir)/lib, aka /usr/local/TARGET/lib, except for
115 # sysrooted configurations.
116 if [ "x${use_sysroot}" != "xyes" ] ; then
117 LIB_PATH
=${tool_lib}:${LIB_PATH}
120 LIB_SEARCH_DIRS
=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
122 # We need it for testsuite.
123 case " $EMULATION_LIBPATH " in
124 *" ${EMULATION_NAME} "*)
125 test -d tmpdir || mkdir tmpdir
127 echo "set libpath \"${LIB_PATH}\"" |
sed -e 's/:/ /g' > tmpdir
/libpath.exp
131 # Generate 5 or 6 script files from a master script template in
132 # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6
133 # script files is actually used depends on command line options given
134 # to ld. (SCRIPT_NAME was set in the emulparams_file.)
136 # A .x script file is the default script.
137 # A .xr script is for linking without relocation (-r flag).
138 # A .xu script is like .xr, but *do* create constructors (-Ur flag).
139 # A .xn script is for linking with -n flag (mix text and data on same page).
140 # A .xbn script is for linking with -N flag (mix text and data on same page).
141 # A .xs script is for generating a shared library with the --shared
142 # flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
143 # emulation parameters.
144 # A .xc script is for linking with -z combreloc; it is only generated if
145 # $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
146 # $SCRIPT_NAME is "elf".
147 # A .xsc script is for linking with --shared -z combreloc; it is generated
148 # if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
149 # $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation
152 if [ "x$SCRIPT_NAME" = "xelf" ]; then
153 GENERATE_COMBRELOC_SCRIPT
=yes
156 SEGMENT_SIZE
=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}}
158 # Determine DATA_ALIGNMENT for the 5 variants, using
159 # values specified in the emulparams/<emulation>.sh file or default.
161 DATA_ALIGNMENT_
="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
162 DATA_ALIGNMENT_n
="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
163 DATA_ALIGNMENT_N
="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
164 DATA_ALIGNMENT_r
="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
165 DATA_ALIGNMENT_u
="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
168 DATA_ALIGNMENT
=${DATA_ALIGNMENT_r}
169 DEFAULT_DATA_ALIGNMENT
="ALIGN(${SEGMENT_SIZE})"
170 ( echo "/* Script for ld -r: link without relocation */"
171 .
${srcdir}/emulparams
/${EMULATION_NAME}.sh
172 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
173 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xr
176 DATA_ALIGNMENT
=${DATA_ALIGNMENT_u}
178 ( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */"
179 .
${srcdir}/emulparams
/${EMULATION_NAME}.sh
180 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
181 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xu
184 DATA_ALIGNMENT
=${DATA_ALIGNMENT_}
186 ( echo "/* Default linker script, for normal executables */"
187 .
${srcdir}/emulparams
/${EMULATION_NAME}.sh
188 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
189 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.x
192 DATA_ALIGNMENT
=${DATA_ALIGNMENT_n}
193 TEXT_START_ADDR
=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
194 ( echo "/* Script for -n: mix text and data on same page */"
195 .
${srcdir}/emulparams
/${EMULATION_NAME}.sh
196 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
197 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xn
200 DATA_ALIGNMENT
=${DATA_ALIGNMENT_N}
201 ( echo "/* Script for -N: mix text and data on same page; don't align data */"
202 .
${srcdir}/emulparams
/${EMULATION_NAME}.sh
203 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
204 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xbn
206 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
207 DATA_ALIGNMENT
=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}}
209 COMBRELOC
=ldscripts
/${EMULATION_NAME}.xc.tmp
210 ( echo "/* Script for -z combreloc: combine and sort reloc sections */"
211 .
${srcdir}/emulparams
/${EMULATION_NAME}.sh
212 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
213 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xc
218 if test -n "$GENERATE_SHLIB_SCRIPT"; then
220 DATA_ALIGNMENT
=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
222 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
224 echo "/* Script for ld --shared: link shared library */"
225 .
${srcdir}/emulparams
/${EMULATION_NAME}.sh
226 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
227 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xs
228 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
230 DATA_ALIGNMENT
=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
231 COMBRELOC
=ldscripts
/${EMULATION_NAME}.xc.tmp
232 ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */"
233 .
${srcdir}/emulparams
/${EMULATION_NAME}.sh
234 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
235 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xsc
242 if test -n "$GENERATE_PIE_SCRIPT"; then
244 DATA_ALIGNMENT
=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
246 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
248 echo "/* Script for ld -pie: link position independent executable */"
249 .
${srcdir}/emulparams
/${EMULATION_NAME}.sh
250 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
251 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xd
252 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
254 DATA_ALIGNMENT
=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
255 COMBRELOC
=ldscripts
/${EMULATION_NAME}.xc.tmp
256 ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */"
257 .
${srcdir}/emulparams
/${EMULATION_NAME}.sh
258 .
${srcdir}/scripttempl
/${SCRIPT_NAME}.sc
259 ) |
sed -e '/^ *$/d;s/[ ]*$//' > ldscripts
/${EMULATION_NAME}.xdc
266 case " $EMULATION_LIBPATH " in
267 *" ${EMULATION_NAME} "*) COMPILE_IN
=true
;;
270 # Generate e${EMULATION_NAME}.c.
271 .
${srcdir}/emultempl
/${TEMPLATE_NAME-generic}.em