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