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 \ | |
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 | |
252b5132 RH |
18 | # |
19 | # Sample usage: | |
8fbdf3ab AM |
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 | ||
252b5132 RH |
59 | |
60 | srcdir=$1 | |
61 | libdir=$2 | |
d9fc3714 AM |
62 | exec_prefix=$3 |
63 | host=$4 | |
64 | target=$5 | |
65 | target_alias=$6 | |
66 | EMULATION_LIBPATH=$7 | |
67 | NATIVE_LIB_DIRS=$8 | |
9c8ebd6a | 68 | use_sysroot=$9 |
d9fc3714 | 69 | shift 9 |
9c8ebd6a | 70 | EMULATION_NAME=$1 |
8fbdf3ab AM |
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 | |
d9fc3714 AM |
76 | tool_lib=${exec_prefix}/${target_alias}/lib |
77 | else | |
8fbdf3ab AM |
78 | tool_lib=${exec_prefix}/${TOOL_LIB}/lib |
79 | fi | |
80 | ||
81 | if [ "x${CUSTOMIZER_SCRIPT}" = "x" ] ; then | |
82 | CUSTOMIZER_SCRIPT=${EMULATION_NAME} | |
d9fc3714 | 83 | fi |
8fbdf3ab | 84 | CUSTOMIZER_SCRIPT="${srcdir}/emulparams/${CUSTOMIZER_SCRIPT}.sh" |
252b5132 RH |
85 | |
86 | # Include the emulation-specific parameters: | |
8fbdf3ab | 87 | . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} |
252b5132 RH |
88 | |
89 | if test -d ldscripts; then | |
90 | true | |
91 | else | |
92 | mkdir ldscripts | |
93 | fi | |
94 | ||
9c8ebd6a DJ |
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 | ||
252b5132 RH |
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=":". | |
9c8ebd6a DJ |
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. | |
252b5132 | 128 | |
9c8ebd6a | 129 | if [ "x${LIB_PATH}" = "x" ] && [ "x${USE_LIBPATH}" = xyes ] ; then |
f22f5fcd | 130 | LIB_PATH2= |
1dd3bf68 AM |
131 | |
132 | libs=${NATIVE_LIB_DIRS} | |
133 | if [ "x${use_sysroot}" != "xyes" ] ; then | |
134 | case " ${libs} " in | |
135 | *" ${libdir} "*) ;; | |
586196d5 | 136 | *) libs="${libdir} ${libs}" ;; |
1dd3bf68 AM |
137 | esac |
138 | case " ${libs} " in | |
139 | *" ${tool_lib} "*) ;; | |
586196d5 | 140 | *) libs="${tool_lib} ${libs}" ;; |
1dd3bf68 | 141 | esac |
9c8ebd6a | 142 | fi |
1dd3bf68 AM |
143 | |
144 | for lib in ${libs}; do | |
9c8ebd6a DJ |
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 | |
d460ab58 JJ |
149 | addsuffix= |
150 | case "${LIBPATH_SUFFIX}:${lib}" in | |
151 | :*) ;; | |
152 | *:*${LIBPATH_SUFFIX}) ;; | |
153 | *) addsuffix=yes ;; | |
3336653a | 154 | esac |
d460ab58 JJ |
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 | |
f22f5fcd | 161 | case :${LIB_PATH}:${LIB_PATH2}: in |
d460ab58 | 162 | *:${lib}:*) ;; |
f22f5fcd AM |
163 | *::) LIB_PATH2=${lib} ;; |
164 | *) LIB_PATH2=${LIB_PATH2}:${lib} ;; | |
d460ab58 JJ |
165 | esac |
166 | else | |
f22f5fcd AM |
167 | case :${LIB_PATH2}: in |
168 | *:${lib}:*) ;; | |
169 | ::) LIB_PATH2=${lib} ;; | |
170 | *) LIB_PATH2=${LIB_PATH2}:${lib} ;; | |
d460ab58 JJ |
171 | esac |
172 | fi | |
9c8ebd6a | 173 | done |
1dd3bf68 | 174 | |
f22f5fcd AM |
175 | case :${LIB_PATH}:${LIB_PATH2}: in |
176 | *:: | ::*) LIB_PATH=${LIB_PATH}${LIB_PATH2} ;; | |
177 | *) LIB_PATH=${LIB_PATH}:${LIB_PATH2} ;; | |
178 | esac | |
252b5132 RH |
179 | fi |
180 | ||
9c8ebd6a | 181 | # Always search $(tooldir)/lib, aka /usr/local/TARGET/lib, except for |
f22f5fcd | 182 | # sysrooted configurations and when LIBPATH=":". |
9c8ebd6a | 183 | if [ "x${use_sysroot}" != "xyes" ] ; then |
f22f5fcd AM |
184 | case :${LIB_PATH}: in |
185 | ::: | *:${tool_lib}:*) ;; | |
186 | ::) LIB_PATH=${tool_lib} ;; | |
187 | *) LIB_PATH=${tool_lib}:${LIB_PATH} ;; | |
188 | esac | |
9c8ebd6a | 189 | fi |
252b5132 | 190 | |
eb3d6bb8 | 191 | LIB_SEARCH_DIRS=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'` |
252b5132 | 192 | |
cdaeef2e L |
193 | # We need it for testsuite. |
194 | case " $EMULATION_LIBPATH " in | |
195 | *" ${EMULATION_NAME} "*) | |
196 | test -d tmpdir || mkdir tmpdir | |
f22f5fcd | 197 | test -f tmpdir/libpath.exp || \ |
cdaeef2e L |
198 | echo "set libpath \"${LIB_PATH}\"" | sed -e 's/:/ /g' > tmpdir/libpath.exp |
199 | ;; | |
200 | esac | |
201 | ||
252b5132 RH |
202 | # Generate 5 or 6 script files from a master script template in |
203 | # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6 | |
204 | # script files is actually used depends on command line options given | |
205 | # to ld. (SCRIPT_NAME was set in the emulparams_file.) | |
206 | # | |
207 | # A .x script file is the default script. | |
208 | # A .xr script is for linking without relocation (-r flag). | |
209 | # A .xu script is like .xr, but *do* create constructors (-Ur flag). | |
210 | # A .xn script is for linking with -n flag (mix text and data on same page). | |
211 | # A .xbn script is for linking with -N flag (mix text and data on same page). | |
212 | # A .xs script is for generating a shared library with the --shared | |
213 | # flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the | |
214 | # emulation parameters. | |
db6751f2 JJ |
215 | # A .xc script is for linking with -z combreloc; it is only generated if |
216 | # $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or | |
217 | # $SCRIPT_NAME is "elf". | |
218 | # A .xsc script is for linking with --shared -z combreloc; it is generated | |
219 | # if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or | |
220 | # $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation | |
221 | # parameters too. | |
222 | ||
223 | if [ "x$SCRIPT_NAME" = "xelf" ]; then | |
224 | GENERATE_COMBRELOC_SCRIPT=yes | |
225 | fi | |
252b5132 | 226 | |
1ddd7b13 | 227 | SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}} |
252b5132 RH |
228 | |
229 | # Determine DATA_ALIGNMENT for the 5 variants, using | |
8fbdf3ab | 230 | # values specified in the emulparams/<script_to_run>.sh file or default. |
252b5132 RH |
231 | |
232 | DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}" | |
233 | DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}" | |
234 | DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}" | |
235 | DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}" | |
236 | DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}" | |
237 | ||
238 | LD_FLAG=r | |
239 | DATA_ALIGNMENT=${DATA_ALIGNMENT_r} | |
240 | DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})" | |
cedd6b0d | 241 | ( echo "/* Script for ld -r: link without relocation */" |
8fbdf3ab | 242 | . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} |
179c732c | 243 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 | 244 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xr |
252b5132 RH |
245 | |
246 | LD_FLAG=u | |
247 | DATA_ALIGNMENT=${DATA_ALIGNMENT_u} | |
248 | CONSTRUCTING=" " | |
cedd6b0d | 249 | ( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */" |
8fbdf3ab | 250 | . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} |
179c732c | 251 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 | 252 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu |
252b5132 RH |
253 | |
254 | LD_FLAG= | |
255 | DATA_ALIGNMENT=${DATA_ALIGNMENT_} | |
256 | RELOCATING=" " | |
cedd6b0d | 257 | ( echo "/* Default linker script, for normal executables */" |
8fbdf3ab | 258 | . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} |
179c732c | 259 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 | 260 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x |
252b5132 RH |
261 | |
262 | LD_FLAG=n | |
263 | DATA_ALIGNMENT=${DATA_ALIGNMENT_n} | |
264 | TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}} | |
cedd6b0d | 265 | ( echo "/* Script for -n: mix text and data on same page */" |
8fbdf3ab | 266 | . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} |
179c732c | 267 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 | 268 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xn |
252b5132 RH |
269 | |
270 | LD_FLAG=N | |
271 | DATA_ALIGNMENT=${DATA_ALIGNMENT_N} | |
cedd6b0d | 272 | ( echo "/* Script for -N: mix text and data on same page; don't align data */" |
8fbdf3ab | 273 | . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} |
179c732c | 274 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 JJ |
275 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xbn |
276 | ||
277 | if test -n "$GENERATE_COMBRELOC_SCRIPT"; then | |
278 | DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}} | |
279 | LD_FLAG=c | |
280 | COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp | |
e24d7c12 | 281 | ( echo "/* Script for -z combreloc: combine and sort reloc sections */" |
8fbdf3ab | 282 | . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} |
db6751f2 JJ |
283 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
284 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc | |
285 | rm -f ${COMBRELOC} | |
8c37241b JJ |
286 | LD_FLAG=w |
287 | RELRO_NOW=" " | |
288 | COMBRELOC=ldscripts/${EMULATION_NAME}.xw.tmp | |
289 | ( echo "/* Script for -z combreloc -z now -z relro: combine and sort reloc sections */" | |
290 | . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} | |
291 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | |
292 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xw | |
293 | rm -f ${COMBRELOC} | |
db6751f2 | 294 | COMBRELOC= |
8c37241b | 295 | unset RELRO_NOW |
db6751f2 | 296 | fi |
252b5132 RH |
297 | |
298 | if test -n "$GENERATE_SHLIB_SCRIPT"; then | |
299 | LD_FLAG=shared | |
300 | DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} | |
301 | CREATE_SHLIB=" " | |
302 | # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR. | |
cedd6b0d JB |
303 | ( |
304 | echo "/* Script for ld --shared: link shared library */" | |
8fbdf3ab | 305 | . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} |
179c732c | 306 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 JJ |
307 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs |
308 | if test -n "$GENERATE_COMBRELOC_SCRIPT"; then | |
309 | LD_FLAG=cshared | |
310 | DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}} | |
8c37241b | 311 | COMBRELOC=ldscripts/${EMULATION_NAME}.xsc.tmp |
cedd6b0d | 312 | ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */" |
8fbdf3ab | 313 | . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} |
db6751f2 JJ |
314 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
315 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc | |
316 | rm -f ${COMBRELOC} | |
8c37241b JJ |
317 | LD_FLAG=wshared |
318 | RELRO_NOW=" " | |
319 | COMBRELOC=ldscripts/${EMULATION_NAME}.xsw.tmp | |
320 | ( echo "/* Script for --shared -z combreloc -z now -z relro: shared library, combine & sort relocs */" | |
321 | . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} | |
322 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | |
323 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsw | |
324 | rm -f ${COMBRELOC} | |
db6751f2 | 325 | COMBRELOC= |
8c37241b | 326 | unset RELRO_NOW |
db6751f2 | 327 | fi |
36af4a4e JJ |
328 | unset CREATE_SHLIB |
329 | fi | |
330 | ||
331 | if test -n "$GENERATE_PIE_SCRIPT"; then | |
332 | LD_FLAG=pie | |
333 | DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} | |
334 | CREATE_PIE=" " | |
335 | # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR. | |
336 | ( | |
337 | echo "/* Script for ld -pie: link position independent executable */" | |
8fbdf3ab | 338 | . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} |
36af4a4e JJ |
339 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
340 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xd | |
341 | if test -n "$GENERATE_COMBRELOC_SCRIPT"; then | |
342 | LD_FLAG=cpie | |
343 | DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}} | |
8c37241b | 344 | COMBRELOC=ldscripts/${EMULATION_NAME}.xdc.tmp |
36af4a4e | 345 | ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */" |
8fbdf3ab | 346 | . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} |
36af4a4e JJ |
347 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
348 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdc | |
349 | rm -f ${COMBRELOC} | |
8c37241b JJ |
350 | LD_FLAG=wpie |
351 | RELRO_NOW=" " | |
352 | COMBRELOC=ldscripts/${EMULATION_NAME}.xdw.tmp | |
353 | ( echo "/* Script for -pie -z combreloc -z now -z relro: position independent executable, combine & sort relocs */" | |
354 | . ${CUSTOMIZER_SCRIPT} ${EMULATION_NAME} | |
355 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | |
356 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdw | |
357 | rm -f ${COMBRELOC} | |
36af4a4e | 358 | COMBRELOC= |
8c37241b | 359 | unset RELRO_NOW |
36af4a4e JJ |
360 | fi |
361 | unset CREATE_PIE | |
252b5132 RH |
362 | fi |
363 | ||
eb3d6bb8 AM |
364 | case " $EMULATION_LIBPATH " in |
365 | *" ${EMULATION_NAME} "*) COMPILE_IN=true;; | |
366 | esac | |
252b5132 RH |
367 | |
368 | # Generate e${EMULATION_NAME}.c. | |
369 | . ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em |