Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | #!/bin/sh |
2 | # genscripts.sh - generate the ld-emulation-target specific files | |
3 | # | |
d9fc3714 AM |
4 | # Usage: genscripts.sh srcdir libdir exec_prefix \ |
5 | # host target target_alias default_emulation \ | |
9c8ebd6a | 6 | # native_lib_dirs use_sysroot this_emulation tool_dir |
252b5132 RH |
7 | # |
8 | # Sample usage: | |
d9fc3714 AM |
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 \ | |
9c8ebd6a | 11 | # "" no sun3 sparc-sun-sunos4.1.3 |
252b5132 RH |
12 | # produces sun3.x sun3.xbn sun3.xn sun3.xr sun3.xu em_sun3.c |
13 | ||
14 | srcdir=$1 | |
15 | libdir=$2 | |
d9fc3714 AM |
16 | exec_prefix=$3 |
17 | host=$4 | |
18 | target=$5 | |
19 | target_alias=$6 | |
20 | EMULATION_LIBPATH=$7 | |
21 | NATIVE_LIB_DIRS=$8 | |
9c8ebd6a | 22 | use_sysroot=$9 |
d9fc3714 | 23 | shift 9 |
9c8ebd6a DJ |
24 | EMULATION_NAME=$1 |
25 | shift | |
d9fc3714 AM |
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 | |
29 | else | |
30 | tool_lib=${exec_prefix}/$1/lib | |
31 | fi | |
252b5132 RH |
32 | |
33 | # Include the emulation-specific parameters: | |
34 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
35 | ||
36 | if test -d ldscripts; then | |
37 | true | |
38 | else | |
39 | mkdir ldscripts | |
40 | fi | |
41 | ||
9c8ebd6a DJ |
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). | |
47 | ||
48 | case " $EMULATION_LIBPATH " in | |
49 | *" ${EMULATION_NAME} "*) | |
50 | if [ "x${host}" = "x${target}" ] ; then | |
51 | NATIVE=yes | |
52 | USE_LIBPATH=yes | |
53 | elif [ "x${use_sysroot}" = "xyes" ] ; then | |
54 | USE_LIBPATH=yes | |
55 | fi | |
56 | ;; | |
57 | esac | |
58 | ||
59 | # If the emulparams file sets NATIVE, make sure USE_LIBPATH is set also. | |
60 | if test "x$NATIVE" = "xyes" ; then | |
61 | USE_LIBPATH=yes | |
62 | fi | |
63 | ||
252b5132 RH |
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. | |
67 | # | |
68 | # The format is the usual list of colon-separated directories. | |
69 | # To force a logically empty LIB_PATH, do LIBPATH=":". | |
9c8ebd6a DJ |
70 | # |
71 | # If we are using a sysroot, prefix library paths with "=" to indicate this. | |
72 | # | |
73 | # If the emulparams file set LIBPATH_SUFFIX, prepend an extra copy of | |
74 | # the library path with the suffix applied. | |
252b5132 | 75 | |
9c8ebd6a | 76 | if [ "x${LIB_PATH}" = "x" ] && [ "x${USE_LIBPATH}" = xyes ] ; then |
f22f5fcd | 77 | LIB_PATH2= |
9c8ebd6a | 78 | if [ x"$use_sysroot" != xyes ] ; then |
f22f5fcd | 79 | LIB_PATH2=${libdir} |
9c8ebd6a DJ |
80 | fi |
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 | |
84 | lib="=${lib}" | |
85 | fi | |
d460ab58 JJ |
86 | addsuffix= |
87 | case "${LIBPATH_SUFFIX}:${lib}" in | |
88 | :*) ;; | |
89 | *:*${LIBPATH_SUFFIX}) ;; | |
90 | *) addsuffix=yes ;; | |
3336653a | 91 | esac |
d460ab58 JJ |
92 | if test -n "$addsuffix"; then |
93 | case :${LIB_PATH}: in | |
94 | *:${lib}${LIBPATH_SUFFIX}:*) ;; | |
95 | ::) LIB_PATH=${lib}${LIBPATH_SUFFIX} ;; | |
96 | *) LIB_PATH=${LIB_PATH}:${lib}${LIBPATH_SUFFIX} ;; | |
97 | esac | |
f22f5fcd | 98 | case :${LIB_PATH}:${LIB_PATH2}: in |
d460ab58 | 99 | *:${lib}:*) ;; |
f22f5fcd AM |
100 | *::) LIB_PATH2=${lib} ;; |
101 | *) LIB_PATH2=${LIB_PATH2}:${lib} ;; | |
d460ab58 JJ |
102 | esac |
103 | else | |
f22f5fcd AM |
104 | case :${LIB_PATH2}: in |
105 | *:${lib}:*) ;; | |
106 | ::) LIB_PATH2=${lib} ;; | |
107 | *) LIB_PATH2=${LIB_PATH2}:${lib} ;; | |
d460ab58 JJ |
108 | esac |
109 | fi | |
9c8ebd6a | 110 | done |
f22f5fcd AM |
111 | case :${LIB_PATH}:${LIB_PATH2}: in |
112 | *:: | ::*) LIB_PATH=${LIB_PATH}${LIB_PATH2} ;; | |
113 | *) LIB_PATH=${LIB_PATH}:${LIB_PATH2} ;; | |
114 | esac | |
252b5132 RH |
115 | fi |
116 | ||
9c8ebd6a DJ |
117 | |
118 | # Always search $(tooldir)/lib, aka /usr/local/TARGET/lib, except for | |
f22f5fcd | 119 | # sysrooted configurations and when LIBPATH=":". |
9c8ebd6a | 120 | if [ "x${use_sysroot}" != "xyes" ] ; then |
f22f5fcd AM |
121 | case :${LIB_PATH}: in |
122 | ::: | *:${tool_lib}:*) ;; | |
123 | ::) LIB_PATH=${tool_lib} ;; | |
124 | *) LIB_PATH=${tool_lib}:${LIB_PATH} ;; | |
125 | esac | |
9c8ebd6a | 126 | fi |
252b5132 | 127 | |
eb3d6bb8 | 128 | LIB_SEARCH_DIRS=`echo ${LIB_PATH} | sed -e 's/:/ /g' -e 's/\([^ ][^ ]*\)/SEARCH_DIR(\\"\1\\");/g'` |
252b5132 | 129 | |
cdaeef2e L |
130 | # We need it for testsuite. |
131 | case " $EMULATION_LIBPATH " in | |
132 | *" ${EMULATION_NAME} "*) | |
133 | test -d tmpdir || mkdir tmpdir | |
f22f5fcd | 134 | test -f tmpdir/libpath.exp || \ |
cdaeef2e L |
135 | echo "set libpath \"${LIB_PATH}\"" | sed -e 's/:/ /g' > tmpdir/libpath.exp |
136 | ;; | |
137 | esac | |
138 | ||
252b5132 RH |
139 | # Generate 5 or 6 script files from a master script template in |
140 | # ${srcdir}/scripttempl/${SCRIPT_NAME}.sh. Which one of the 5 or 6 | |
141 | # script files is actually used depends on command line options given | |
142 | # to ld. (SCRIPT_NAME was set in the emulparams_file.) | |
143 | # | |
144 | # A .x script file is the default script. | |
145 | # A .xr script is for linking without relocation (-r flag). | |
146 | # A .xu script is like .xr, but *do* create constructors (-Ur flag). | |
147 | # A .xn script is for linking with -n flag (mix text and data on same page). | |
148 | # A .xbn script is for linking with -N flag (mix text and data on same page). | |
149 | # A .xs script is for generating a shared library with the --shared | |
150 | # flag; it is only generated if $GENERATE_SHLIB_SCRIPT is set by the | |
151 | # emulation parameters. | |
db6751f2 JJ |
152 | # A .xc script is for linking with -z combreloc; it is only generated if |
153 | # $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or | |
154 | # $SCRIPT_NAME is "elf". | |
155 | # A .xsc script is for linking with --shared -z combreloc; it is generated | |
156 | # if $GENERATE_COMBRELOC_SCRIPT is set by the emulation parameters or | |
157 | # $SCRIPT_NAME is "elf" and $GENERATE_SHLIB_SCRIPT is set by the emulation | |
158 | # parameters too. | |
159 | ||
160 | if [ "x$SCRIPT_NAME" = "xelf" ]; then | |
161 | GENERATE_COMBRELOC_SCRIPT=yes | |
162 | fi | |
252b5132 | 163 | |
1ddd7b13 | 164 | SEGMENT_SIZE=${SEGMENT_SIZE-${MAXPAGESIZE-${TARGET_PAGE_SIZE}}} |
252b5132 RH |
165 | |
166 | # Determine DATA_ALIGNMENT for the 5 variants, using | |
167 | # values specified in the emulparams/<emulation>.sh file or default. | |
168 | ||
169 | DATA_ALIGNMENT_="${DATA_ALIGNMENT_-${DATA_ALIGNMENT-ALIGN(${SEGMENT_SIZE})}}" | |
170 | DATA_ALIGNMENT_n="${DATA_ALIGNMENT_n-${DATA_ALIGNMENT_}}" | |
171 | DATA_ALIGNMENT_N="${DATA_ALIGNMENT_N-${DATA_ALIGNMENT-.}}" | |
172 | DATA_ALIGNMENT_r="${DATA_ALIGNMENT_r-${DATA_ALIGNMENT-}}" | |
173 | DATA_ALIGNMENT_u="${DATA_ALIGNMENT_u-${DATA_ALIGNMENT_r}}" | |
174 | ||
175 | LD_FLAG=r | |
176 | DATA_ALIGNMENT=${DATA_ALIGNMENT_r} | |
177 | DEFAULT_DATA_ALIGNMENT="ALIGN(${SEGMENT_SIZE})" | |
cedd6b0d JB |
178 | ( echo "/* Script for ld -r: link without relocation */" |
179 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
179c732c | 180 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 | 181 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xr |
252b5132 RH |
182 | |
183 | LD_FLAG=u | |
184 | DATA_ALIGNMENT=${DATA_ALIGNMENT_u} | |
185 | CONSTRUCTING=" " | |
cedd6b0d JB |
186 | ( echo "/* Script for ld -Ur: link w/out relocation, do create constructors */" |
187 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
179c732c | 188 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 | 189 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xu |
252b5132 RH |
190 | |
191 | LD_FLAG= | |
192 | DATA_ALIGNMENT=${DATA_ALIGNMENT_} | |
193 | RELOCATING=" " | |
cedd6b0d JB |
194 | ( echo "/* Default linker script, for normal executables */" |
195 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
179c732c | 196 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 | 197 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.x |
252b5132 RH |
198 | |
199 | LD_FLAG=n | |
200 | DATA_ALIGNMENT=${DATA_ALIGNMENT_n} | |
201 | TEXT_START_ADDR=${NONPAGED_TEXT_START_ADDR-${TEXT_START_ADDR}} | |
cedd6b0d JB |
202 | ( echo "/* Script for -n: mix text and data on same page */" |
203 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
179c732c | 204 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 | 205 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xn |
252b5132 RH |
206 | |
207 | LD_FLAG=N | |
208 | DATA_ALIGNMENT=${DATA_ALIGNMENT_N} | |
cedd6b0d JB |
209 | ( echo "/* Script for -N: mix text and data on same page; don't align data */" |
210 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
179c732c | 211 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 JJ |
212 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xbn |
213 | ||
214 | if test -n "$GENERATE_COMBRELOC_SCRIPT"; then | |
215 | DATA_ALIGNMENT=${DATA_ALIGNMENT_c-${DATA_ALIGNMENT_}} | |
216 | LD_FLAG=c | |
217 | COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp | |
e24d7c12 | 218 | ( echo "/* Script for -z combreloc: combine and sort reloc sections */" |
cedd6b0d | 219 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh |
db6751f2 JJ |
220 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
221 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xc | |
222 | rm -f ${COMBRELOC} | |
223 | COMBRELOC= | |
224 | fi | |
252b5132 RH |
225 | |
226 | if test -n "$GENERATE_SHLIB_SCRIPT"; then | |
227 | LD_FLAG=shared | |
228 | DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} | |
229 | CREATE_SHLIB=" " | |
230 | # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR. | |
cedd6b0d JB |
231 | ( |
232 | echo "/* Script for ld --shared: link shared library */" | |
233 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
179c732c | 234 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
db6751f2 JJ |
235 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xs |
236 | if test -n "$GENERATE_COMBRELOC_SCRIPT"; then | |
237 | LD_FLAG=cshared | |
238 | DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}} | |
239 | COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp | |
cedd6b0d JB |
240 | ( echo "/* Script for --shared -z combreloc: shared library, combine & sort relocs */" |
241 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
db6751f2 JJ |
242 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc |
243 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xsc | |
244 | rm -f ${COMBRELOC} | |
245 | COMBRELOC= | |
246 | fi | |
36af4a4e JJ |
247 | unset CREATE_SHLIB |
248 | fi | |
249 | ||
250 | if test -n "$GENERATE_PIE_SCRIPT"; then | |
251 | LD_FLAG=pie | |
252 | DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}} | |
253 | CREATE_PIE=" " | |
254 | # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR. | |
255 | ( | |
256 | echo "/* Script for ld -pie: link position independent executable */" | |
257 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
258 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | |
259 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xd | |
260 | if test -n "$GENERATE_COMBRELOC_SCRIPT"; then | |
261 | LD_FLAG=cpie | |
262 | DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}} | |
263 | COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp | |
264 | ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */" | |
265 | . ${srcdir}/emulparams/${EMULATION_NAME}.sh | |
266 | . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc | |
267 | ) | sed -e '/^ *$/d;s/[ ]*$//' > ldscripts/${EMULATION_NAME}.xdc | |
268 | rm -f ${COMBRELOC} | |
269 | COMBRELOC= | |
270 | fi | |
271 | unset CREATE_PIE | |
252b5132 RH |
272 | fi |
273 | ||
eb3d6bb8 AM |
274 | case " $EMULATION_LIBPATH " in |
275 | *" ${EMULATION_NAME} "*) COMPILE_IN=true;; | |
276 | esac | |
252b5132 RH |
277 | |
278 | # Generate e${EMULATION_NAME}.c. | |
279 | . ${srcdir}/emultempl/${TEMPLATE_NAME-generic}.em |