Commit | Line | Data |
---|---|---|
252b5132 RH |
1 | # This shell script emits a C file. -*- C -*- |
2 | # It does some substitutions. | |
3 | cat >e${EMULATION_NAME}.c <<EOF | |
4 | /* intel coff loader emulation specific stuff | |
48f6162b | 5 | Copyright 1991, 1992, 1994, 1995, 1996, 1999, 2000, 2001 |
b71e2778 | 6 | Free Software Foundation, Inc. |
252b5132 RH |
7 | Written by Steve Chamberlain steve@cygnus.com |
8 | ||
9 | This file is part of GLD, the Gnu Linker. | |
10 | ||
11 | GLD is free software; you can redistribute it and/or modify | |
12 | it under the terms of the GNU General Public License as published by | |
13 | the Free Software Foundation; either version 2, or (at your option) | |
14 | any later version. | |
15 | ||
16 | GLD is distributed in the hope that it will be useful, | |
17 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | GNU General Public License for more details. | |
20 | ||
21 | You should have received a copy of the GNU General Public License | |
22 | along with GLD; see the file COPYING. If not, write to | |
23 | the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
24 | ||
25 | #include "libiberty.h" | |
26 | #include "bfd.h" | |
27 | #include "sysdep.h" | |
28 | #include "bfdlink.h" | |
29 | ||
30 | /*#include "archures.h"*/ | |
31 | #include "ld.h" | |
b71e2778 | 32 | #include "ldmain.h" |
252b5132 RH |
33 | #include "ldmisc.h" |
34 | #include "ldexp.h" | |
35 | #include "ldlang.h" | |
36 | #include "ldfile.h" | |
b71e2778 | 37 | #include "ldemul.h" |
252b5132 RH |
38 | |
39 | typedef struct lib_list { | |
40 | char *name; | |
41 | struct lib_list *next; | |
42 | } lib_list_type; | |
43 | ||
44 | static lib_list_type *hll_list; | |
45 | static lib_list_type **hll_list_tail = &hll_list; | |
46 | ||
47 | static lib_list_type *syslib_list; | |
48 | static lib_list_type **syslib_list_tail = &syslib_list; | |
49 | ||
48f6162b AJ |
50 | static void append PARAMS ((lib_list_type ***, char *)); |
51 | static void lnk960_hll PARAMS ((char *)); | |
52 | static void lnk960_syslib PARAMS ((char *)); | |
53 | static void lnk960_before_parse PARAMS ((void)); | |
54 | static void add_on PARAMS ((lib_list_type *, lang_input_file_enum_type)); | |
55 | static void lnk960_after_parse PARAMS ((void)); | |
56 | static void lnk960_before_allocation PARAMS ((void)); | |
57 | static void lnk960_after_allocation PARAMS ((void)); | |
58 | static void lnk960_set_output_arch PARAMS ((void)); | |
59 | static char *lnk960_choose_target PARAMS ((void)); | |
60 | static char *lnk960_get_script PARAMS ((int *)); | |
61 | ||
252b5132 RH |
62 | |
63 | static void | |
64 | append(list, name) | |
65 | lib_list_type ***list; | |
66 | char *name; | |
67 | { | |
68 | lib_list_type *element = | |
69 | (lib_list_type *)(xmalloc(sizeof(lib_list_type))); | |
70 | ||
71 | element->name = name; | |
72 | element->next = (lib_list_type *)NULL; | |
73 | **list = element; | |
74 | *list = &element->next; | |
75 | ||
76 | } | |
77 | ||
78 | static boolean had_hll = false; | |
79 | static boolean had_hll_name = false; | |
80 | ||
81 | static void | |
82 | lnk960_hll(name) | |
83 | char *name; | |
84 | { | |
85 | had_hll = true; | |
86 | if (name != (char *)NULL) { | |
87 | had_hll_name = true; | |
88 | append(&hll_list_tail, name); | |
89 | } | |
90 | } | |
91 | ||
92 | static void | |
93 | lnk960_syslib(name) | |
94 | char *name; | |
95 | { | |
96 | append(&syslib_list_tail,name); | |
97 | } | |
98 | ||
99 | ||
100 | #ifdef GNU960 | |
101 | ||
102 | static void | |
103 | lnk960_before_parse() | |
104 | { | |
105 | static char *env_variables[] = { "G960LIB", "G960BASE", 0 }; | |
106 | char **p; | |
107 | char *env ; | |
108 | ||
109 | for ( p = env_variables; *p; p++ ){ | |
110 | env = (char *) getenv(*p); | |
111 | if (env) { | |
112 | ldfile_add_library_path(concat(env,"/lib/libcoff",""), false); | |
113 | } | |
114 | } | |
115 | ||
116 | env= (char *) getenv("I960BASE"); | |
117 | if ( env ) { | |
118 | ldfile_add_library_path(concat(env,"/lib",""), false); | |
119 | } | |
120 | ||
121 | ldfile_output_architecture = bfd_arch_i960; | |
122 | ldfile_output_machine = bfd_mach_i960_core; | |
123 | } | |
124 | ||
125 | #else /* not GNU960 */ | |
126 | ||
127 | static void | |
128 | lnk960_before_parse() | |
129 | { | |
130 | char *name = getenv("I960BASE"); | |
131 | ||
132 | if (name == (char *)NULL) { | |
133 | name = getenv("G960BASE"); | |
134 | if (name == (char *)NULL) { | |
135 | einfo("%P%F I960BASE and G960BASE not set\n"); | |
136 | } | |
137 | } | |
138 | ||
139 | ||
140 | ldfile_add_library_path(concat(name,"/lib",""), false); | |
141 | ldfile_output_architecture = bfd_arch_i960; | |
142 | ldfile_output_machine = bfd_mach_i960_core; | |
143 | } | |
144 | ||
145 | #endif /* GNU960 */ | |
146 | ||
147 | ||
148 | static void | |
149 | add_on(list, search) | |
150 | lib_list_type *list; | |
151 | lang_input_file_enum_type search; | |
152 | { | |
153 | while (list) { | |
154 | lang_add_input_file(list->name, | |
155 | search, | |
156 | (char *)NULL); | |
157 | list = list->next; | |
158 | } | |
159 | } | |
160 | static void | |
161 | lnk960_after_parse() | |
162 | { | |
163 | /* If there has been no arch, default to -KB */ | |
164 | if (ldfile_output_machine_name[0] ==0) { | |
165 | ldfile_add_arch("KB"); | |
166 | } | |
167 | ||
168 | /* if there has been no hll list then add our own */ | |
169 | ||
170 | if(had_hll && !had_hll_name) { | |
171 | append(&hll_list_tail,"cg"); | |
172 | if (ldfile_output_machine == bfd_mach_i960_ka_sa || | |
173 | ldfile_output_machine == bfd_mach_i960_ca) { | |
174 | { | |
175 | append(&hll_list_tail,"fpg"); | |
176 | } | |
177 | } | |
178 | } | |
179 | ||
180 | add_on(hll_list, lang_input_file_is_l_enum); | |
181 | add_on(syslib_list, lang_input_file_is_search_file_enum); | |
182 | } | |
183 | ||
184 | static void | |
185 | lnk960_before_allocation() | |
186 | { | |
187 | } | |
188 | ||
189 | static void | |
190 | lnk960_after_allocation() | |
191 | { | |
192 | if (link_info.relocateable == false) { | |
193 | lang_abs_symbol_at_end_of(".text","_etext"); | |
194 | lang_abs_symbol_at_end_of(".data","_edata"); | |
195 | lang_abs_symbol_at_beginning_of(".bss","_bss_start"); | |
196 | lang_abs_symbol_at_end_of(".bss","_end"); | |
197 | } | |
198 | } | |
199 | ||
200 | ||
201 | static struct | |
202 | { | |
203 | unsigned long number; | |
204 | char *name; | |
205 | } | |
206 | machine_table[] = | |
207 | { | |
208 | { bfd_mach_i960_core ,"CORE" }, | |
209 | { bfd_mach_i960_kb_sb ,"KB" }, | |
210 | { bfd_mach_i960_kb_sb ,"SB" }, | |
211 | { bfd_mach_i960_mc ,"MC" }, | |
212 | { bfd_mach_i960_xa ,"XA" }, | |
213 | { bfd_mach_i960_ca ,"CA" }, | |
214 | { bfd_mach_i960_ka_sa ,"KA" }, | |
215 | { bfd_mach_i960_ka_sa ,"SA" }, | |
216 | { bfd_mach_i960_jx ,"JX" }, | |
217 | { bfd_mach_i960_hx ,"HX" }, | |
218 | ||
219 | { bfd_mach_i960_core ,"core" }, | |
220 | { bfd_mach_i960_kb_sb ,"kb" }, | |
221 | { bfd_mach_i960_kb_sb ,"sb" }, | |
222 | { bfd_mach_i960_mc ,"mc" }, | |
223 | { bfd_mach_i960_xa ,"xa" }, | |
224 | { bfd_mach_i960_ca ,"ca" }, | |
225 | { bfd_mach_i960_ka_sa ,"ka" }, | |
226 | { bfd_mach_i960_ka_sa ,"sa" }, | |
227 | { bfd_mach_i960_jx ,"jx" }, | |
228 | { bfd_mach_i960_hx ,"hx" }, | |
229 | ||
230 | { 0, (char *) NULL } | |
231 | }; | |
232 | ||
233 | static void | |
234 | lnk960_set_output_arch() | |
235 | { | |
236 | /* Set the output architecture and machine if possible */ | |
237 | unsigned int i; | |
238 | ldfile_output_machine = bfd_mach_i960_core; | |
239 | for (i= 0; machine_table[i].name != (char*)NULL; i++) { | |
240 | if (strcmp(ldfile_output_machine_name,machine_table[i].name)==0) { | |
241 | ldfile_output_machine = machine_table[i].number; | |
242 | break; | |
243 | } | |
244 | } | |
245 | bfd_set_arch_mach(output_bfd, ldfile_output_architecture, ldfile_output_machine); | |
246 | } | |
247 | ||
248 | static char * | |
249 | lnk960_choose_target() | |
250 | { | |
251 | #ifdef GNU960 | |
252 | ||
253 | return bfd_make_targ_name(BFD_COFF_FORMAT, 0); | |
254 | ||
255 | #else | |
256 | ||
257 | char *from_outside = getenv(TARGET_ENVIRON); | |
258 | if (from_outside != (char *)NULL) | |
259 | return from_outside; | |
260 | #ifdef LNK960_LITTLE | |
261 | return "coff-Intel-little"; | |
262 | #else | |
263 | return "coff-Intel-big"; | |
264 | #endif | |
265 | #endif | |
266 | ||
267 | } | |
268 | ||
269 | static char * | |
270 | lnk960_get_script(isfile) | |
271 | int *isfile; | |
272 | EOF | |
273 | ||
274 | if test -n "$COMPILE_IN" | |
275 | then | |
276 | # Scripts compiled in. | |
277 | ||
278 | # sed commands to quote an ld script as a C string. | |
597e2591 | 279 | sc="-f stringify.sed" |
252b5132 RH |
280 | |
281 | cat >>e${EMULATION_NAME}.c <<EOF | |
597e2591 | 282 | { |
252b5132 RH |
283 | *isfile = 0; |
284 | ||
285 | if (link_info.relocateable == true && config.build_constructors == true) | |
597e2591 | 286 | return |
252b5132 | 287 | EOF |
597e2591 ILT |
288 | sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c |
289 | echo ' ; else if (link_info.relocateable == true) return' >> e${EMULATION_NAME}.c | |
290 | sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c | |
291 | echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c | |
292 | sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c | |
293 | echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c | |
294 | sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c | |
295 | echo ' ; else return' >> e${EMULATION_NAME}.c | |
296 | sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c | |
297 | echo '; }' >> e${EMULATION_NAME}.c | |
252b5132 RH |
298 | |
299 | else | |
300 | # Scripts read from the filesystem. | |
301 | ||
302 | cat >>e${EMULATION_NAME}.c <<EOF | |
303 | { | |
304 | *isfile = 1; | |
305 | ||
306 | if (link_info.relocateable == true && config.build_constructors == true) | |
307 | return "ldscripts/${EMULATION_NAME}.xu"; | |
308 | else if (link_info.relocateable == true) | |
309 | return "ldscripts/${EMULATION_NAME}.xr"; | |
310 | else if (!config.text_read_only) | |
311 | return "ldscripts/${EMULATION_NAME}.xbn"; | |
312 | else if (!config.magic_demand_paged) | |
313 | return "ldscripts/${EMULATION_NAME}.xn"; | |
314 | else | |
315 | return "ldscripts/${EMULATION_NAME}.x"; | |
316 | } | |
317 | EOF | |
318 | ||
319 | fi | |
320 | ||
321 | cat >>e${EMULATION_NAME}.c <<EOF | |
322 | ||
323 | struct ld_emulation_xfer_struct ld_lnk960_emulation = | |
324 | { | |
325 | lnk960_before_parse, | |
326 | lnk960_syslib, | |
327 | lnk960_hll, | |
328 | lnk960_after_parse, | |
329 | NULL, /* after_open */ | |
330 | lnk960_after_allocation, | |
331 | lnk960_set_output_arch, | |
332 | lnk960_choose_target, | |
333 | lnk960_before_allocation, | |
334 | lnk960_get_script, | |
335 | "lnk960", | |
e1c47aa4 AM |
336 | "", |
337 | NULL, /* finish */ | |
338 | NULL, /* create output section statements */ | |
339 | NULL, /* open dynamic archive */ | |
340 | NULL, /* place orphan */ | |
341 | NULL, /* set symbols */ | |
342 | NULL, /* parse args */ | |
343 | NULL, /* unrecognized file */ | |
344 | NULL, /* list options */ | |
40d109bf AM |
345 | NULL, /* recognized file */ |
346 | NULL /* find_potential_libraries */ | |
252b5132 RH |
347 | }; |
348 | EOF |