* elf32-i386.c (elf_i386_finish_dynamic_sections): Fix signedness
[deliverable/binutils-gdb.git] / ld / genscripts.sh
1 #!/bin/sh
2 # genscripts.sh - generate the ld-emulation-target specific files
3 #
4 # Usage: genscripts_extra.sh \
5 # srcdir \
6 # libdir \
7 # exec_prefix \
8 # host \
9 # target \
10 # target_alias \
11 # default_emulation \
12 # native_lib_dirs \
13 # use_sysroot \
14 # this_emulation \
15 # optional:
16 # tool_dir \
17 # customizer_script
18 #
19 # Sample usage:
20 #
21 # genscripts_extra.sh \
22 # /sources/ld \
23 # /usr/local/lib \
24 # /usr/local \
25 # sparc-sun-sunos4.1.3 \
26 # sparc-sun-sunos4.1.3 \
27 # sparc-sun-sunos4.1.3 \
28 # sun4 \
29 # "" \
30 # no \
31 # sun3 \
32 # sparc-sun-sunos4.1.3 \
33 # sparc.sh
34 #
35 # produces the linker scripts:
36 #
37 # sun3.x [default linker script]
38 # sun3.xbn [used when the linker is invoked with "-N"]
39 # sun3.xn [used when the linker is invoked with "-n"]
40 # sun3.xr [used when the linker is invoked with "-r"]
41 # sun3.xu [used when the linker is invoked with "-Ur"]
42 # and maybe:
43 # sun3.xc [used when the linker is invoked with "-z combreloc"]
44 # sun3.xsc [used when the linker is invoked with "--shared"]
45 # sun3.xdc [used when the linker is invoked with "-pie"]
46 #
47 # It also produced the C source file:
48 #
49 # em_sun3.c
50 #
51 # which is then compiled into the linker.
52 #
53 # The linker scripts are created by running the shell script
54 # /sources/ld/emulparams/sparc.sh to set the value of ${SCRIPT_NAME}
55 # (and any other variables it wants to). ${SCRIPT_NAME} is then
56 # invoked with a variable called ${LD_FLAG} to tell it which version
57 # of the linker script to create.
58
59
60 srcdir=$1
61 libdir=$2
62 exec_prefix=$3
63 host=$4
64 target=$5
65 target_alias=$6
66 EMULATION_LIBPATH=$7
67 NATIVE_LIB_DIRS=$8
68 use_sysroot=$9
69 shift 9
70 EMULATION_NAME=$1
71 TOOL_LIB=$2
72 CUSTOMIZER_SCRIPT=$3
73
74 # Can't use ${TOOL_LIB:-$target_alias} here due to an Ultrix shell bug.
75 if [ "x${TOOL_LIB}" = "x" ] ; then
76 tool_lib=${exec_prefix}/${target_alias}/lib
77 else
78 tool_lib=${exec_prefix}/${TOOL_LIB}/lib
79 fi
80
81 if [ "x${CUSTOMIZER_SCRIPT}" = "x" ] ; then
82 CUSTOMIZER_SCRIPT=${EMULATION_NAME}
83 fi
84 CUSTOMIZER_SCRIPT="${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh"
85
86 # Include the emulation-specific parameters:
87 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
88
89 if test -d ldscripts; then
90 true
91 else
92 mkdir ldscripts
93 fi
94
95 # Set some flags for the emultempl scripts. USE_LIBPATH will
96 # be set for any libpath-using emulation; NATIVE will be set for a
97 # libpath-using emulation where ${host} = ${target}. NATIVE
98 # may already have been set by the emulparams file, but that's OK
99 # (it'll just get set to "yes" twice).
100
101 case " $EMULATION_LIBPATH " in
102 *" ${EMULATION_NAME} "*)
103 if [ "x${host}" = "x${target}" ] ; then
104 NATIVE=yes
105 USE_LIBPATH=yes
106 elif [ "x${use_sysroot}" = "xyes" ] ; then
107 USE_LIBPATH=yes
108 fi
109 ;;
110 esac
111
112 # If the emulparams file sets NATIVE, make sure USE_LIBPATH is set also.
113 if test "x$NATIVE" = "xyes" ; then
114 USE_LIBPATH=yes
115 fi
116
117 # Set the library search path, for libraries named by -lfoo.
118 # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used.
119 # Otherwise, the default is set here.
120 #
121 # The format is the usual list of colon-separated directories.
122 # To force a logically empty LIB_PATH, do LIBPATH=":".
123 #
124 # If we are using a sysroot, prefix library paths with "=" to indicate this.
125 #
126 # If the emulparams file set LIBPATH_SUFFIX, prepend an extra copy of
127 # the library path with the suffix applied.
128
129 if [ "x${LIB_PATH}" = "x" ] && [ "x${USE_LIBPATH}" = xyes ] ; then
130 LIB_PATH2=
131
132 libs=${NATIVE_LIB_DIRS}
133 if [ "x${use_sysroot}" != "xyes" ] ; then
134 case " ${libs} " in
135 *" ${libdir} "*) ;;
136 *) libs="${libdir} ${libs}" ;;
137 esac
138 case " ${libs} " in
139 *" ${tool_lib} "*) ;;
140 *) libs="${tool_lib} ${libs}" ;;
141 esac
142 fi
143
144 for lib in ${libs}; do
145 # The "=" is harmless if we aren't using a sysroot, but also needless.
146 if [ "x${use_sysroot}" = "xyes" ] ; then
147 lib="=${lib}"
148 fi
149 addsuffix=
150 case "${LIBPATH_SUFFIX}:${lib}" in
151 :*) ;;
152 *:*${LIBPATH_SUFFIX}) ;;
153 *) addsuffix=yes ;;
154 esac
155 if test -n "$addsuffix"; then
156 case :${LIB_PATH}: in
157 *:${lib}${LIBPATH_SUFFIX}:*) ;;
158 ::) LIB_PATH=${lib}${LIBPATH_SUFFIX} ;;
159 *) LIB_PATH=${LIB_PATH}:${lib}${LIBPATH_SUFFIX} ;;
160 esac
161 case :${LIB_PATH}:${LIB_PATH2}: in
162 *:${lib}:*) ;;
163 *::) LIB_PATH2=${lib} ;;
164 *) LIB_PATH2=${LIB_PATH2}:${lib} ;;
165 esac
166 else
167 case :${LIB_PATH2}: in
168 *:${lib}:*) ;;
169 ::) LIB_PATH2=${lib} ;;
170 *) LIB_PATH2=${LIB_PATH2}:${lib} ;;
171 esac
172 fi
173 done
174
175 case :${LIB_PATH}:${LIB_PATH2}: in
176 *:: | ::*) LIB_PATH=${LIB_PATH}${LIB_PATH2} ;;
177 *) LIB_PATH=${LIB_PATH}:${LIB_PATH2} ;;
178 esac
179 fi
180
181 # Always search $(tooldir)/lib, aka /usr/local/TARGET/lib, except for
182 # sysrooted configurations and when LIBPATH=":".
183 if [ "x${use_sysroot}" != "xyes" ] ; then
184 case :${LIB_PATH}: in
185 ::: | *:${tool_lib}:*) ;;
186 ::) LIB_PATH=${tool_lib} ;;
187 *) LIB_PATH=${tool_lib}:${LIB_PATH} ;;
188 esac
189 fi
190
191 LIB_SEARCH_DIRS=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'`
192
193 # We need it for testsuite.
194 set $EMULATION_LIBPATH
195 if [ "x$1" = "x$EMULATION_NAME" ]; then
196 test -d tmpdir || mkdir tmpdir
197 rm -f tmpdir/libpath.exp
198 echo "set libpath \"${LIB_PATH}\"" | sed -e 's/:/ /g' > tmpdir/libpath.exp
199 fi
200
201 # Generate 5 or 6 script files from a master script template in
202 # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6
203 # script files is actually used depends on command line options given
204 # to ld. (SCRIPT_NAME was set in the emulparams_file.)
205 #
206 # A .x script file is the default script.
207 # A .xr script is for linking without relocation (-r flag).
208 # A .xu script is like .xr, but *do* create constructors (-Ur flag).
209 # A .xn script is for linking with -n flag (mix text and data on same page).
210 # A .xbn script is for linking with -N flag (mix text and data on same page).
211 # A .xs script is for generating a shared library with the --shared
212 # flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the
213 # emulation parameters.
214 # A .xc script is for linking with -z combreloc; it is only generated if
215 # $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
216 # $SCRIPT_NAME is "elf".
217 # A .xsc script is for linking with --shared -z combreloc; it is generated
218 # if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or
219 # $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation
220 # parameters too.
221
222 if [ "x$SCRIPT_NAME" = "xelf" ]; then
223 GENERATE_COMBRELOC_SCRIPT=yes
224 fi
225
226 SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}}
227
228 # Determine DATA_ALIGNMENT for the 5 variants, using
229 # values specified in the emulparams/<script_to_run>.sh file or default.
230
231 DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}"
232 DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}"
233 DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}"
234 DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}"
235 DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}"
236
237 LD_FLAG=r
238 DATA_ALIGNMENT=${DATA_ALIGNMENT_r}
239 DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})"
240 ( echo "/* Script for ld -r: link without relocation */"
241 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
242 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
243 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xr
244
245 LD_FLAG=u
246 DATA_ALIGNMENT=${DATA_ALIGNMENT_u}
247 CONSTRUCTING=" "
248 ( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */"
249 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
250 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
251 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu
252
253 LD_FLAG=
254 DATA_ALIGNMENT=${DATA_ALIGNMENT_}
255 RELOCATING=" "
256 ( echo "/* Default linker script, for normal executables */"
257 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
258 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
259 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x
260
261 LD_FLAG=n
262 DATA_ALIGNMENT=${DATA_ALIGNMENT_n}
263 TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}}
264 ( echo "/* Script for -n: mix text and data on same page */"
265 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
266 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
267 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xn
268
269 LD_FLAG=N
270 DATA_ALIGNMENT=${DATA_ALIGNMENT_N}
271 ( echo "/* Script for -N: mix text and data on same page; don't align data */"
272 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
273 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
274 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xbn
275
276 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
277 DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}}
278 LD_FLAG=c
279 COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
280 ( echo "/* Script for -z combreloc: combine and sort reloc sections */"
281 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
282 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
283 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc
284 rm -f ${COMBRELOC}
285 LD_FLAG=w
286 RELRO_NOW=" "
287 COMBRELOC=ldscripts/${EMULATION_NAME}.xw.tmp
288 ( echo "/* Script for -z combreloc -z now -z relro: combine and sort reloc sections */"
289 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
290 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
291 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xw
292 rm -f ${COMBRELOC}
293 COMBRELOC=
294 unset RELRO_NOW
295 fi
296
297 if test -n "$GENERATE_SHLIB_SCRIPT"; then
298 LD_FLAG=shared
299 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
300 CREATE_SHLIB=" "
301 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
302 (
303 echo "/* Script for ld --shared: link shared library */"
304 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
305 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
306 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs
307 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
308 LD_FLAG=cshared
309 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
310 COMBRELOC=ldscripts/${EMULATION_NAME}.xsc.tmp
311 ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */"
312 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
313 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
314 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc
315 rm -f ${COMBRELOC}
316 LD_FLAG=wshared
317 RELRO_NOW=" "
318 COMBRELOC=ldscripts/${EMULATION_NAME}.xsw.tmp
319 ( echo "/* Script for --shared -z combreloc -z now -z relro: shared library, combine & sort relocs */"
320 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
321 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
322 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsw
323 rm -f ${COMBRELOC}
324 COMBRELOC=
325 unset RELRO_NOW
326 fi
327 unset CREATE_SHLIB
328 fi
329
330 if test -n "$GENERATE_PIE_SCRIPT"; then
331 LD_FLAG=pie
332 DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
333 CREATE_PIE=" "
334 # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
335 (
336 echo "/* Script for ld -pie: link position independent executable */"
337 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
338 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
339 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xd
340 if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
341 LD_FLAG=cpie
342 DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
343 COMBRELOC=ldscripts/${EMULATION_NAME}.xdc.tmp
344 ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */"
345 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
346 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
347 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdc
348 rm -f ${COMBRELOC}
349 LD_FLAG=wpie
350 RELRO_NOW=" "
351 COMBRELOC=ldscripts/${EMULATION_NAME}.xdw.tmp
352 ( echo "/* Script for -pie -z combreloc -z now -z relro: position independent executable, combine & sort relocs */"
353 . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME}
354 . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
355 ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdw
356 rm -f ${COMBRELOC}
357 COMBRELOC=
358 unset RELRO_NOW
359 fi
360 unset CREATE_PIE
361 fi
362
363 case " $EMULATION_LIBPATH " in
364 *" ${EMULATION_NAME} "*) COMPILE_IN=true;;
365 esac
366
367 # Generate e${EMULATION_NAME}.c.
368 . ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em
This page took 0.049161 seconds and 4 git commands to generate.