Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | #!/bin/sh |
2 | # genscripts.sh - generate the ld-emulation-target specific files | |
219d1afa | 3 | # Copyright (C) 2004-2018 Free Software Foundation, Inc. |
f96b4a7b NC |
4 | # |
5 | # This file is part of the Gnu Linker. | |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
8 | # it under the terms of the GNU General Public License as published by | |
9 | # the Free Software Foundation; either version 3, or (at your option) | |
10 | # any later version. | |
11 | # | |
12 | # This program is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU General Public License | |
18 | # along with GLD; see the file COPYING. If not, write to the Free | |
19 | # Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA | |
20 | # 02110-1301, USA. | |
252b5132 | 21 | # |
8fbdf3ab AM |
22 | # Usage: genscripts_extra.sh \ |
23 | # srcdir \ | |
24 | # libdir \ | |
dfcffada | 25 | # prefix \ |
8fbdf3ab AM |
26 | # exec_prefix \ |
27 | # host \ | |
28 | # target \ | |
29 | # target_alias \ | |
30 | # default_emulation \ | |
31 | # native_lib_dirs \ | |
32 | # use_sysroot \ | |
02ecc8e9 | 33 | # enable_initfini_array \ |
8fbdf3ab AM |
34 | # this_emulation \ |
35 | # optional: | |
ce46249c | 36 | # tool_dir |
252b5132 RH |
37 | # |
38 | # Sample usage: | |
8fbdf3ab AM |
39 | # |
40 | # genscripts_extra.sh \ | |
41 | # /sources/ld \ | |
42 | # /usr/local/lib \ | |
43 | # /usr/local \ | |
dfcffada | 44 | # /usr/local \ |
8fbdf3ab AM |
45 | # sparc-sun-sunos4.1.3 \ |
46 | # sparc-sun-sunos4.1.3 \ | |
47 | # sparc-sun-sunos4.1.3 \ | |
48 | # sun4 \ | |
49 | # "" \ | |
50 | # no \ | |
51 | # sun3 \ | |
52 | # sparc-sun-sunos4.1.3 \ | |
53 | # sparc.sh | |
54 | # | |
55 | # produces the linker scripts: | |
56 | # | |
57 | # sun3.x [default linker script] | |
58 | # sun3.xbn [used when the linker is invoked with "-N"] | |
59 | # sun3.xn [used when the linker is invoked with "-n"] | |
60 | # sun3.xr [used when the linker is invoked with "-r"] | |
61 | # sun3.xu [used when the linker is invoked with "-Ur"] | |
62 | # and maybe: | |
63 | # sun3.xc [used when the linker is invoked with "-z combreloc"] | |
64 | # sun3.xsc [used when the linker is invoked with "--shared"] | |
65 | # sun3.xdc [used when the linker is invoked with "-pie"] | |
e2a83dd0 | 66 | # sun3.xa [used when the linker is invoked with "--enable-auto-import"] |
8fbdf3ab AM |
67 | # |
68 | # It also produced the C source file: | |
69 | # | |
70 | # em_sun3.c | |
71 | # | |
72 | # which is then compiled into the linker. | |
73 | # | |
74 | # The linker scripts are created by running the shell script | |
75 | # /sources/ld/emulparams/sparc.sh to set the value of ${SCRIPT_NAME} | |
76 | # (and any other variables it wants to). ${SCRIPT_NAME} is then | |
77 | # invoked with a variable called ${LD_FLAG} to tell it which version | |
78 | # of the linker script to create. | |
79 | ||
252b5132 RH |
80 | |
81 | srcdir=$1 | |
82 | libdir=$2 | |
dfcffada AM |
83 | prefix=$3 |
84 | exec_prefix=$4 | |
85 | host=$5 | |
86 | target=$6 | |
87 | target_alias=$7 | |
88 | EMULATION_LIBPATH=$8 | |
89 | NATIVE_LIB_DIRS=$9 | |
d9fc3714 | 90 | shift 9 |
dfcffada | 91 | use_sysroot=$1 |
02ecc8e9 L |
92 | ENABLE_INITFINI_ARRAY=$2 |
93 | EMULATION_NAME=$3 | |
94 | TOOL_LIB=$4 | |
252b5132 RH |
95 | |
96 | # Include the emulation-specific parameters: | |
ce46249c | 97 | CUSTOMIZER_SCRIPT="${srcdir}/emulparams/${EMULATION_NAME}.sh" |
f50230ae | 98 | . ${CUSTOMIZER_SCRIPT} |
252b5132 RH |
99 | |
100 | if test -d ldscripts; then | |
101 | true | |
102 | else | |
103 | mkdir ldscripts | |
104 | fi | |
105 | ||
9c8ebd6a DJ |
106 | # Set some flags for the emultempl scripts. USE_LIBPATH will |
107 | # be set for any libpath-using emulation; NATIVE will be set for a | |
108 | # libpath-using emulation where ${host} = ${target}. NATIVE | |
109 | # may already have been set by the emulparams file, but that's OK | |
110 | # (it'll just get set to "yes" twice). | |
111 | ||
112 | case " $EMULATION_LIBPATH " in | |
113 | *" ${EMULATION_NAME} "*) | |
114 | if [ "x${host}" = "x${target}" ] ; then | |
115 | NATIVE=yes | |
116 | USE_LIBPATH=yes | |
117 | elif [ "x${use_sysroot}" = "xyes" ] ; then | |
118 | USE_LIBPATH=yes | |
119 | fi | |
120 | ;; | |
121 | esac | |
122 | ||
123 | # If the emulparams file sets NATIVE, make sure USE_LIBPATH is set also. | |
124 | if test "x$NATIVE" = "xyes" ; then | |
125 | USE_LIBPATH=yes | |
126 | fi | |
127 | ||
252b5132 RH |
128 | # Set the library search path, for libraries named by -lfoo. |
129 | # If LIB_PATH is defined (e.g., by Makefile) and non-empty, it is used. | |
130 | # Otherwise, the default is set here. | |
131 | # | |
132 | # The format is the usual list of colon-separated directories. | |
133 | # To force a logically empty LIB_PATH, do LIBPATH=":". | |
9c8ebd6a DJ |
134 | # |
135 | # If we are using a sysroot, prefix library paths with "=" to indicate this. | |
136 | # | |
137 | # If the emulparams file set LIBPATH_SUFFIX, prepend an extra copy of | |
138 | # the library path with the suffix applied. | |
252b5132 | 139 | |
0f70b6b5 AM |
140 | # Paths with LIBPATH_SUFFIX |
141 | lib_path1= | |
142 | # Paths without LIBPATH_SUFFIX | |
143 | lib_path2= | |
144 | if [ "${LIB_PATH}" != ":" ] ; then | |
145 | lib_path2=${LIB_PATH} | |
146 | fi | |
1dd3bf68 | 147 | |
0f70b6b5 AM |
148 | # Add args to lib_path1 and lib_path2, discarding any duplicates |
149 | append_to_lib_path() | |
150 | { | |
151 | if [ $# != 0 ]; then | |
152 | for lib in "$@"; do | |
153 | # The "=" is harmless if we aren't using a sysroot, but also needless. | |
154 | if [ "x${use_sysroot}" = "xyes" ] ; then | |
155 | lib="=${lib}" | |
156 | fi | |
f6f6c679 | 157 | skip_lib=no |
10d98088 | 158 | for libpath_suffix in ${LIBPATH_SUFFIX}; do |
0f70b6b5 | 159 | case "${lib}" in |
10d98088 | 160 | *${libpath_suffix}) |
0f70b6b5 AM |
161 | case :${lib_path1}: in |
162 | *:${lib}:*) ;; | |
163 | ::) lib_path1=${lib} ;; | |
164 | *) lib_path1=${lib_path1}:${lib} ;; | |
165 | esac ;; | |
166 | *) | |
f6f6c679 L |
167 | if test -n "${LIBPATH_SUFFIX_SKIP}"; then |
168 | case "${lib}" in | |
169 | *${LIBPATH_SUFFIX_SKIP}) skip_lib=yes ;; | |
170 | esac | |
171 | fi | |
172 | if test "${skip_lib}" = "no"; then | |
173 | case :${lib_path1}: in | |
10d98088 JW |
174 | *:${lib}${libpath_suffix}:*) ;; |
175 | ::) lib_path1=${lib}${libpath_suffix} ;; | |
176 | *) lib_path1=${lib_path1}:${lib}${libpath_suffix} ;; | |
f6f6c679 L |
177 | esac |
178 | fi ;; | |
179 | esac | |
10d98088 | 180 | done |
f6f6c679 L |
181 | if test "${skip_lib}" = "no"; then |
182 | case :${lib_path1}:${lib_path2}: in | |
183 | *:${lib}:*) ;; | |
184 | *::) lib_path2=${lib} ;; | |
185 | *) lib_path2=${lib_path2}:${lib} ;; | |
0f70b6b5 AM |
186 | esac |
187 | fi | |
0f70b6b5 AM |
188 | done |
189 | fi | |
190 | } | |
191 | ||
192 | # Always search $(tooldir)/lib, aka /usr/local/TARGET/lib when native | |
193 | # except when LIBPATH=":". | |
194 | if [ "${LIB_PATH}" != ":" ] ; then | |
195 | libs= | |
196 | if [ "x${TOOL_LIB}" = "x" ] ; then | |
197 | if [ "x${NATIVE}" = "xyes" ] ; then | |
198 | libs="${exec_prefix}/${target_alias}/lib" | |
d460ab58 | 199 | fi |
0f70b6b5 AM |
200 | else |
201 | # For multilib'ed targets, ensure both ${target_alias}/lib${LIBPATH_SUFFIX} | |
202 | # and ${TOOL_LIB}/lib${LIBPATH_SUFFIX} are in the default search path, | |
203 | # because 64bit libraries may be in both places, depending on | |
204 | # cross-development setup method (e.g.: /usr/s390x-linux/lib64 | |
205 | # vs. /usr/s390-linux/lib64) | |
10d98088 JW |
206 | for libpath_suffix in ${LIBPATH_SUFFIX}; do |
207 | case "${NATIVE}:${libpath_suffix}:${TOOL_LIB}" in | |
208 | :* | *::* | *:*:*${libpath_suffix}) ;; | |
209 | *) libs="${exec_prefix}/${target_alias}/lib${libpath_suffix}" ;; | |
210 | esac | |
211 | done | |
0f70b6b5 AM |
212 | libs="${exec_prefix}/${TOOL_LIB}/lib ${libs}" |
213 | fi | |
214 | append_to_lib_path ${libs} | |
252b5132 RH |
215 | fi |
216 | ||
0f70b6b5 AM |
217 | if [ "x${LIB_PATH}" = "x" ] && [ "x${USE_LIBPATH}" = xyes ] ; then |
218 | libs=${NATIVE_LIB_DIRS} | |
219 | if [ "x${NATIVE}" = "xyes" ] ; then | |
220 | case " ${libs} " in | |
221 | *" ${libdir} "*) ;; | |
222 | *) libs="${libdir} ${libs}" ;; | |
33423b7f MF |
223 | esac |
224 | fi | |
0f70b6b5 | 225 | append_to_lib_path ${libs} |
9c8ebd6a | 226 | fi |
252b5132 | 227 | |
0f70b6b5 AM |
228 | case :${lib_path1}:${lib_path2}: in |
229 | *:: | ::*) LIB_PATH=${lib_path1}${lib_path2} ;; | |
230 | *) LIB_PATH=${lib_path1}:${lib_path2} ;; | |
231 | esac | |
232 | ||
eb3d6bb8 | 233 | LIB_SEARCH_DIRS=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'` |
252b5132 | 234 | |
cdaeef2e | 235 | # We need it for testsuite. |
dc4f76f8 L |
236 | set $EMULATION_LIBPATH |
237 | if [ "x$1" = "x$EMULATION_NAME" ]; then | |
cdaeef2e | 238 | test -d tmpdir || mkdir tmpdir |
dc4f76f8 | 239 | rm -f tmpdir/libpath.exp |
cdaeef2e | 240 | echo "set libpath \"${LIB_PATH}\"" | sed -e 's/:/ /g' > tmpdir/libpath.exp |
dc4f76f8 | 241 | fi |
cdaeef2e | 242 | |
252b5132 RH |
243 | # Generate 5 or 6 script files from a master script template in |
244 | # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6 | |
245 | # script files is actually used depends on command line options given | |
246 | # to ld. (SCRIPT_NAME was set in the emulparams_file.) | |
247 | # | |
248 | # A .x script file is the default script. | |
249 | # A .xr script is for linking without relocation (-r flag). | |
250 | # A .xu script is like .xr, but *do* create constructors (-Ur flag). | |
251 | # A .xn script is for linking with -n flag (mix text and data on same page). | |
252 | # A .xbn script is for linking with -N flag (mix text and data on same page). | |
253 | # A .xs script is for generating a shared library with the --shared | |
254 | # flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the | |
255 | # emulation parameters. | |
db6751f2 JJ |
256 | # A .xc script is for linking with -z combreloc; it is only generated if |
257 | # $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or | |
258 | # $SCRIPT_NAME is "elf". | |
259 | # A .xsc script is for linking with --shared -z combreloc; it is generated | |
260 | # if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or | |
261 | # $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation | |
262 | # parameters too. | |
263 | ||
264 | if [ "x$SCRIPT_NAME" = "xelf" ]; then | |
265 | GENERATE_COMBRELOC_SCRIPT=yes | |
266 | fi | |
252b5132 | 267 | |
1ddd7b13 | 268 | SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}} |
252b5132 RH |
269 | |
270 | # Determine DATA_ALIGNMENT for the 5 variants, using | |
8fbdf3ab | 271 | # values specified in the emulparams/<script_to_run>.sh file or default. |
252b5132 RH |
272 | |
273 | DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}" | |
274 | DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}" | |
275 | DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}" | |
276 | DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}" | |
277 | DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}" | |
278 | ||
279 | LD_FLAG=r | |
280 | DATA_ALIGNMENT=${DATA_ALIGNMENT_r} | |
281 | DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})" | |
cedd6b0d | 282 | ( echo "/* Script for ld -r: link without relocation */" |
f50230ae | 283 | . ${CUSTOMIZER_SCRIPT} |
179c732c | 284 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
6c19b93b | 285 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xr |
252b5132 RH |
286 | |
287 | LD_FLAG=u | |
288 | DATA_ALIGNMENT=${DATA_ALIGNMENT_u} | |
289 | CONSTRUCTING=" " | |
cedd6b0d | 290 | ( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */" |
f50230ae | 291 | . ${CUSTOMIZER_SCRIPT} |
179c732c | 292 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
6c19b93b | 293 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu |
252b5132 | 294 | |
252b5132 RH |
295 | DATA_ALIGNMENT=${DATA_ALIGNMENT_} |
296 | RELOCATING=" " | |
47acac12 | 297 | LD_FLAG= |
cedd6b0d | 298 | ( echo "/* Default linker script, for normal executables */" |
f50230ae | 299 | . ${CUSTOMIZER_SCRIPT} |
179c732c | 300 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
6c19b93b | 301 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x |
252b5132 | 302 | |
47acac12 L |
303 | LD_FLAG=textonly |
304 | ( echo "/* Script for -z separate-code: generate normal executables with separate code segment */" | |
305 | . ${CUSTOMIZER_SCRIPT} | |
306 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | |
307 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xe | |
308 | ||
252b5132 RH |
309 | LD_FLAG=n |
310 | DATA_ALIGNMENT=${DATA_ALIGNMENT_n} | |
cedd6b0d | 311 | ( echo "/* Script for -n: mix text and data on same page */" |
f50230ae | 312 | . ${CUSTOMIZER_SCRIPT} |
179c732c | 313 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
6c19b93b | 314 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xn |
252b5132 RH |
315 | |
316 | LD_FLAG=N | |
317 | DATA_ALIGNMENT=${DATA_ALIGNMENT_N} | |
cedd6b0d | 318 | ( echo "/* Script for -N: mix text and data on same page; don't align data */" |
f50230ae | 319 | . ${CUSTOMIZER_SCRIPT} |
179c732c | 320 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
6c19b93b | 321 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xbn |
db6751f2 JJ |
322 | |
323 | if test -n "$GENERATE_COMBRELOC_SCRIPT"; then | |
324 | DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}} | |
325 | LD_FLAG=c | |
326 | COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp | |
e24d7c12 | 327 | ( echo "/* Script for -z combreloc: combine and sort reloc sections */" |
f50230ae | 328 | . ${CUSTOMIZER_SCRIPT} |
db6751f2 | 329 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
6c19b93b | 330 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc |
db6751f2 | 331 | rm -f ${COMBRELOC} |
47acac12 L |
332 | LD_FLAG=ctextonly |
333 | COMBRELOC=ldscripts/${EMULATION_NAME}.xce.tmp | |
334 | ( echo "/* Script for -z combreloc -z separate-code: combine and sort reloc sections with separate code segment */" | |
335 | . ${CUSTOMIZER_SCRIPT} | |
336 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | |
337 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xce | |
338 | rm -f ${COMBRELOC} | |
8c37241b | 339 | RELRO_NOW=" " |
47acac12 | 340 | LD_FLAG=w |
8c37241b JJ |
341 | COMBRELOC=ldscripts/${EMULATION_NAME}.xw.tmp |
342 | ( echo "/* Script for -z combreloc -z now -z relro: combine and sort reloc sections */" | |
f50230ae | 343 | . ${CUSTOMIZER_SCRIPT} |
8c37241b | 344 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
6c19b93b | 345 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xw |
8c37241b | 346 | rm -f ${COMBRELOC} |
47acac12 L |
347 | LD_FLAG=wtextonly |
348 | COMBRELOC=ldscripts/${EMULATION_NAME}.xwe.tmp | |
349 | ( echo "/* Script for -z combreloc -z now -z relro -z separate-code: combine and sort reloc sections with separate code segment */" | |
350 | . ${CUSTOMIZER_SCRIPT} | |
351 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | |
352 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xwe | |
353 | rm -f ${COMBRELOC} | |
db6751f2 | 354 | COMBRELOC= |
8c37241b | 355 | unset RELRO_NOW |
db6751f2 | 356 | fi |
252b5132 RH |
357 | |
358 | if test -n "$GENERATE_SHLIB_SCRIPT"; then | |
252b5132 RH |
359 | DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} |
360 | CREATE_SHLIB=" " | |
47acac12 | 361 | LD_FLAG=shared |
cedd6b0d JB |
362 | ( |
363 | echo "/* Script for ld --shared: link shared library */" | |
f50230ae | 364 | . ${CUSTOMIZER_SCRIPT} |
179c732c | 365 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
6c19b93b | 366 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs |
47acac12 L |
367 | LD_FLAG=sharedtextonly |
368 | ( | |
369 | echo "/* Script for ld --shared -z separate-code: link shared library with separate code segment */" | |
370 | . ${CUSTOMIZER_SCRIPT} | |
371 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | |
372 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xse | |
db6751f2 | 373 | if test -n "$GENERATE_COMBRELOC_SCRIPT"; then |
db6751f2 | 374 | DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}} |
47acac12 | 375 | LD_FLAG=cshared |
8c37241b | 376 | COMBRELOC=ldscripts/${EMULATION_NAME}.xsc.tmp |
cedd6b0d | 377 | ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */" |
f50230ae | 378 | . ${CUSTOMIZER_SCRIPT} |
db6751f2 | 379 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
6c19b93b | 380 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc |
db6751f2 | 381 | rm -f ${COMBRELOC} |
47acac12 L |
382 | LD_FLAG=csharedtextonly |
383 | COMBRELOC=ldscripts/${EMULATION_NAME}.xsce.tmp | |
384 | ( echo "/* Script for --shared -z combreloc -z separate-code: shared library, combine & sort relocs with separate code segment */" | |
385 | . ${CUSTOMIZER_SCRIPT} | |
386 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | |
387 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsce | |
388 | rm -f ${COMBRELOC} | |
8c37241b | 389 | RELRO_NOW=" " |
47acac12 | 390 | LD_FLAG=wshared |
8c37241b JJ |
391 | COMBRELOC=ldscripts/${EMULATION_NAME}.xsw.tmp |
392 | ( echo "/* Script for --shared -z combreloc -z now -z relro: shared library, combine & sort relocs */" | |
f50230ae | 393 | . ${CUSTOMIZER_SCRIPT} |
8c37241b | 394 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
6c19b93b | 395 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsw |
8c37241b | 396 | rm -f ${COMBRELOC} |
47acac12 L |
397 | LD_FLAG=wsharedtextonly |
398 | COMBRELOC=ldscripts/${EMULATION_NAME}.xswe.tmp | |
399 | ( echo "/* Script for --shared -z combreloc -z now -z relro -z separate-code: shared library, combine & sort relocs with separate code segment */" | |
400 | . ${CUSTOMIZER_SCRIPT} | |
401 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | |
402 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xswe | |
403 | rm -f ${COMBRELOC} | |
db6751f2 | 404 | COMBRELOC= |
8c37241b | 405 | unset RELRO_NOW |
db6751f2 | 406 | fi |
36af4a4e JJ |
407 | unset CREATE_SHLIB |
408 | fi | |
409 | ||
410 | if test -n "$GENERATE_PIE_SCRIPT"; then | |
36af4a4e JJ |
411 | DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} |
412 | CREATE_PIE=" " | |
47acac12 | 413 | LD_FLAG=pie |
36af4a4e JJ |
414 | ( |
415 | echo "/* Script for ld -pie: link position independent executable */" | |
f50230ae | 416 | . ${CUSTOMIZER_SCRIPT} |
36af4a4e | 417 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
6c19b93b | 418 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xd |
47acac12 L |
419 | LD_FLAG=pietextonly |
420 | ( | |
421 | echo "/* Script for ld -pie -z separate-code: link position independent executable with separate code segment */" | |
422 | . ${CUSTOMIZER_SCRIPT} | |
423 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | |
424 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xde | |
36af4a4e | 425 | if test -n "$GENERATE_COMBRELOC_SCRIPT"; then |
36af4a4e | 426 | DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}} |
8c37241b | 427 | COMBRELOC=ldscripts/${EMULATION_NAME}.xdc.tmp |
47acac12 | 428 | LD_FLAG=cpie |
36af4a4e | 429 | ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */" |
f50230ae | 430 | . ${CUSTOMIZER_SCRIPT} |
36af4a4e | 431 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
6c19b93b | 432 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdc |
36af4a4e | 433 | rm -f ${COMBRELOC} |
47acac12 L |
434 | LD_FLAG=cpietextonly |
435 | COMBRELOC=ldscripts/${EMULATION_NAME}.xdce.tmp | |
436 | ( echo "/* Script for -pie -z combreloc -z separate-code: position independent executable, combine & sort relocs with separate code segment */" | |
437 | . ${CUSTOMIZER_SCRIPT} | |
438 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | |
439 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdce | |
440 | rm -f ${COMBRELOC} | |
8c37241b | 441 | RELRO_NOW=" " |
47acac12 | 442 | LD_FLAG=wpie |
8c37241b JJ |
443 | COMBRELOC=ldscripts/${EMULATION_NAME}.xdw.tmp |
444 | ( echo "/* Script for -pie -z combreloc -z now -z relro: position independent executable, combine & sort relocs */" | |
f50230ae | 445 | . ${CUSTOMIZER_SCRIPT} |
8c37241b | 446 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
6c19b93b | 447 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdw |
8c37241b | 448 | rm -f ${COMBRELOC} |
47acac12 L |
449 | LD_FLAG=wpietextonly |
450 | COMBRELOC=ldscripts/${EMULATION_NAME}.xdwe.tmp | |
451 | ( echo "/* Script for -pie -z combreloc -z now -z relro -z separate-code: position independent executable, combine & sort relocs with separate code segment */" | |
452 | . ${CUSTOMIZER_SCRIPT} | |
453 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | |
454 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdwe | |
455 | rm -f ${COMBRELOC} | |
36af4a4e | 456 | COMBRELOC= |
8c37241b | 457 | unset RELRO_NOW |
36af4a4e JJ |
458 | fi |
459 | unset CREATE_PIE | |
252b5132 RH |
460 | fi |
461 | ||
e2a83dd0 NC |
462 | if test -n "$GENERATE_AUTO_IMPORT_SCRIPT"; then |
463 | LD_FLAG=auto_import | |
464 | DATA_ALIGNMENT=${DATA_ALIGNMENT_} | |
465 | ( | |
466 | echo "/* Script for ld --enable-auto-import: Like the default script except read only data is placed into .data */" | |
f50230ae | 467 | . ${CUSTOMIZER_SCRIPT} |
e2a83dd0 | 468 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
6c19b93b | 469 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xa |
e2a83dd0 NC |
470 | fi |
471 | ||
7225345d AM |
472 | case "$COMPILE_IN: $EMULATION_LIBPATH " in |
473 | :*" ${EMULATION_NAME} "*) COMPILE_IN=yes;; | |
eb3d6bb8 | 474 | esac |
252b5132 | 475 | |
6e73d595 NC |
476 | # PR ld/5652: |
477 | # Determine if the shell has support for the variable BASH_LINENO. | |
478 | # When it is the case, it is only available inside functions. | |
479 | has_lineno() | |
480 | { | |
481 | test "x$BASH_LINENO" != "x" | |
482 | } | |
483 | ||
484 | # Enable accruate error source in the compiler error messages, if possible. | |
485 | if has_lineno; then | |
c43cc9ff | 486 | . ${srcdir}/genscrba.sh |
92b93329 RM |
487 | else |
488 | source_em() | |
489 | { | |
490 | . $1 | |
491 | } | |
492 | fragment() | |
493 | { | |
494 | cat >> e${EMULATION_NAME}.c | |
495 | } | |
496 | fi | |
497 | ||
252b5132 | 498 | # Generate e${EMULATION_NAME}.c. |
92b93329 RM |
499 | # Start with an empty file, then the sourced .em script |
500 | # can use the "fragment" function to append. | |
501 | > e${EMULATION_NAME}.c | |
502 | source_em ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em |