]>
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 | |
3bcf5557 | 5 | Copyright 1991, 1992, 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2003 |
b71e2778 | 6 | Free Software Foundation, Inc. |
252b5132 RH |
7 | Written by Steve Chamberlain [email protected] |
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 | ||
50 | ||
51 | static void | |
0c7a8e5a | 52 | append (lib_list_type ***list, char *name) |
252b5132 | 53 | { |
b34976b6 | 54 | lib_list_type *element = (lib_list_type *) xmalloc (sizeof (lib_list_type)); |
252b5132 RH |
55 | |
56 | element->name = name; | |
b34976b6 | 57 | element->next = (lib_list_type *) NULL; |
252b5132 RH |
58 | **list = element; |
59 | *list = &element->next; | |
60 | ||
61 | } | |
62 | ||
b34976b6 AM |
63 | static bfd_boolean had_hll = FALSE; |
64 | static bfd_boolean had_hll_name = FALSE; | |
252b5132 RH |
65 | |
66 | static void | |
0c7a8e5a | 67 | lnk960_hll (char *name) |
252b5132 | 68 | { |
b34976b6 AM |
69 | had_hll = TRUE; |
70 | if (name != (char *) NULL) | |
71 | { | |
72 | had_hll_name = TRUE; | |
73 | append (&hll_list_tail, name); | |
74 | } | |
252b5132 RH |
75 | } |
76 | ||
0c7a8e5a AM |
77 | static void |
78 | lnk960_syslib (char *name) | |
252b5132 | 79 | { |
b34976b6 | 80 | append (&syslib_list_tail, name); |
252b5132 RH |
81 | } |
82 | ||
83 | ||
84 | #ifdef GNU960 | |
85 | ||
0c7a8e5a AM |
86 | static void |
87 | lnk960_before_parse (void) | |
252b5132 RH |
88 | { |
89 | static char *env_variables[] = { "G960LIB", "G960BASE", 0 }; | |
90 | char **p; | |
91 | char *env ; | |
92 | ||
b34976b6 AM |
93 | for (p = env_variables; *p; p++) |
94 | { | |
95 | env = (char *) getenv (*p); | |
96 | if (env) | |
97 | ldfile_add_library_path (concat (env, "/lib/libcoff", ""), FALSE); | |
252b5132 | 98 | } |
252b5132 | 99 | |
b34976b6 AM |
100 | env = (char *) getenv ("I960BASE"); |
101 | if (env) | |
102 | ldfile_add_library_path(concat (env, "/lib", ""), FALSE); | |
252b5132 RH |
103 | |
104 | ldfile_output_architecture = bfd_arch_i960; | |
105 | ldfile_output_machine = bfd_mach_i960_core; | |
106 | } | |
107 | ||
108 | #else /* not GNU960 */ | |
109 | ||
0c7a8e5a AM |
110 | static void |
111 | lnk960_before_parse (void) | |
252b5132 | 112 | { |
b34976b6 | 113 | char *name = getenv ("I960BASE"); |
252b5132 | 114 | |
b34976b6 AM |
115 | if (name == (char *) NULL) |
116 | { | |
117 | name = getenv("G960BASE"); | |
118 | if (name == (char *) NULL) | |
119 | einfo ("%P%F I960BASE and G960BASE not set\n"); | |
252b5132 | 120 | } |
252b5132 RH |
121 | |
122 | ||
b34976b6 | 123 | ldfile_add_library_path (concat (name, "/lib", ""), FALSE); |
252b5132 RH |
124 | ldfile_output_architecture = bfd_arch_i960; |
125 | ldfile_output_machine = bfd_mach_i960_core; | |
126 | } | |
127 | ||
128 | #endif /* GNU960 */ | |
129 | ||
130 | ||
131 | static void | |
0c7a8e5a | 132 | add_on (lib_list_type *list, lang_input_file_enum_type search) |
252b5132 | 133 | { |
b34976b6 AM |
134 | while (list) |
135 | { | |
136 | lang_add_input_file (list->name, search, (char *) NULL); | |
137 | list = list->next; | |
138 | } | |
252b5132 | 139 | } |
0c7a8e5a | 140 | |
252b5132 | 141 | static void |
0c7a8e5a | 142 | lnk960_after_parse (void) |
252b5132 RH |
143 | { |
144 | /* If there has been no arch, default to -KB */ | |
b34976b6 AM |
145 | if (ldfile_output_machine_name[0] == 0) |
146 | ldfile_add_arch ("KB"); | |
252b5132 RH |
147 | |
148 | /* if there has been no hll list then add our own */ | |
0c7a8e5a | 149 | |
b34976b6 AM |
150 | if (had_hll && !had_hll_name) |
151 | { | |
152 | append (&hll_list_tail, "cg"); | |
153 | if (ldfile_output_machine == bfd_mach_i960_ka_sa | |
154 | || ldfile_output_machine == bfd_mach_i960_ca) | |
155 | append (&hll_list_tail, "fpg"); | |
252b5132 | 156 | } |
0c7a8e5a | 157 | |
b34976b6 AM |
158 | add_on (hll_list, lang_input_file_is_l_enum); |
159 | add_on (syslib_list, lang_input_file_is_search_file_enum); | |
252b5132 RH |
160 | } |
161 | ||
162 | static void | |
0c7a8e5a | 163 | lnk960_before_allocation (void) |
252b5132 RH |
164 | { |
165 | } | |
166 | ||
167 | static void | |
0c7a8e5a | 168 | lnk960_after_allocation (void) |
252b5132 | 169 | { |
1049f94e | 170 | if (!link_info.relocatable) |
b34976b6 AM |
171 | { |
172 | lang_abs_symbol_at_end_of (".text", "_etext"); | |
173 | lang_abs_symbol_at_end_of (".data", "_edata"); | |
174 | lang_abs_symbol_at_beginning_of (".bss", "_bss_start"); | |
175 | lang_abs_symbol_at_end_of (".bss", "_end"); | |
176 | } | |
252b5132 RH |
177 | } |
178 | ||
179 | ||
180 | static struct | |
181 | { | |
182 | unsigned long number; | |
0c7a8e5a | 183 | char *name; |
252b5132 RH |
184 | } |
185 | machine_table[] = | |
186 | { | |
187 | { bfd_mach_i960_core ,"CORE" }, | |
188 | { bfd_mach_i960_kb_sb ,"KB" }, | |
189 | { bfd_mach_i960_kb_sb ,"SB" }, | |
190 | { bfd_mach_i960_mc ,"MC" }, | |
191 | { bfd_mach_i960_xa ,"XA" }, | |
192 | { bfd_mach_i960_ca ,"CA" }, | |
193 | { bfd_mach_i960_ka_sa ,"KA" }, | |
194 | { bfd_mach_i960_ka_sa ,"SA" }, | |
195 | { bfd_mach_i960_jx ,"JX" }, | |
196 | { bfd_mach_i960_hx ,"HX" }, | |
197 | ||
198 | { bfd_mach_i960_core ,"core" }, | |
199 | { bfd_mach_i960_kb_sb ,"kb" }, | |
200 | { bfd_mach_i960_kb_sb ,"sb" }, | |
201 | { bfd_mach_i960_mc ,"mc" }, | |
202 | { bfd_mach_i960_xa ,"xa" }, | |
203 | { bfd_mach_i960_ca ,"ca" }, | |
204 | { bfd_mach_i960_ka_sa ,"ka" }, | |
205 | { bfd_mach_i960_ka_sa ,"sa" }, | |
206 | { bfd_mach_i960_jx ,"jx" }, | |
207 | { bfd_mach_i960_hx ,"hx" }, | |
208 | ||
209 | { 0, (char *) NULL } | |
210 | }; | |
211 | ||
212 | static void | |
0c7a8e5a | 213 | lnk960_set_output_arch (void) |
252b5132 RH |
214 | { |
215 | /* Set the output architecture and machine if possible */ | |
216 | unsigned int i; | |
217 | ldfile_output_machine = bfd_mach_i960_core; | |
b34976b6 AM |
218 | for (i= 0; machine_table[i].name != (char*) NULL; i++) |
219 | { | |
220 | if (strcmp (ldfile_output_machine_name, machine_table[i].name) == 0) | |
221 | { | |
222 | ldfile_output_machine = machine_table[i].number; | |
223 | break; | |
224 | } | |
252b5132 | 225 | } |
b34976b6 AM |
226 | bfd_set_arch_mach (output_bfd, ldfile_output_architecture, |
227 | ldfile_output_machine); | |
252b5132 RH |
228 | } |
229 | ||
230 | static char * | |
0c7a8e5a | 231 | lnk960_choose_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) |
252b5132 RH |
232 | { |
233 | #ifdef GNU960 | |
234 | ||
b34976b6 | 235 | return bfd_make_targ_name (BFD_COFF_FORMAT, 0); |
252b5132 RH |
236 | |
237 | #else | |
238 | ||
b34976b6 AM |
239 | char *from_outside = getenv (TARGET_ENVIRON); |
240 | if (from_outside != (char *) NULL) | |
252b5132 RH |
241 | return from_outside; |
242 | #ifdef LNK960_LITTLE | |
243 | return "coff-Intel-little"; | |
244 | #else | |
245 | return "coff-Intel-big"; | |
246 | #endif | |
247 | #endif | |
248 | ||
249 | } | |
250 | ||
251 | static char * | |
0c7a8e5a | 252 | lnk960_get_script (int *isfile) |
252b5132 RH |
253 | EOF |
254 | ||
255 | if test -n "$COMPILE_IN" | |
256 | then | |
257 | # Scripts compiled in. | |
258 | ||
259 | # sed commands to quote an ld script as a C string. | |
597e2591 | 260 | sc="-f stringify.sed" |
252b5132 RH |
261 | |
262 | cat >>e${EMULATION_NAME}.c <<EOF | |
0c7a8e5a | 263 | { |
252b5132 RH |
264 | *isfile = 0; |
265 | ||
1049f94e | 266 | if (link_info.relocatable && config.build_constructors) |
597e2591 | 267 | return |
252b5132 | 268 | EOF |
b34976b6 | 269 | sed $sc ldscripts/${EMULATION_NAME}.xu >> e${EMULATION_NAME}.c |
1049f94e | 270 | echo ' ; else if (link_info.relocatable) return' >> e${EMULATION_NAME}.c |
b34976b6 AM |
271 | sed $sc ldscripts/${EMULATION_NAME}.xr >> e${EMULATION_NAME}.c |
272 | echo ' ; else if (!config.text_read_only) return' >> e${EMULATION_NAME}.c | |
273 | sed $sc ldscripts/${EMULATION_NAME}.xbn >> e${EMULATION_NAME}.c | |
274 | echo ' ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c | |
275 | sed $sc ldscripts/${EMULATION_NAME}.xn >> e${EMULATION_NAME}.c | |
276 | echo ' ; else return' >> e${EMULATION_NAME}.c | |
277 | sed $sc ldscripts/${EMULATION_NAME}.x >> e${EMULATION_NAME}.c | |
278 | echo '; }' >> e${EMULATION_NAME}.c | |
252b5132 RH |
279 | |
280 | else | |
281 | # Scripts read from the filesystem. | |
282 | ||
283 | cat >>e${EMULATION_NAME}.c <<EOF | |
0c7a8e5a | 284 | { |
252b5132 RH |
285 | *isfile = 1; |
286 | ||
1049f94e | 287 | if (link_info.relocatable && config.build_constructors) |
252b5132 | 288 | return "ldscripts/${EMULATION_NAME}.xu"; |
1049f94e | 289 | else if (link_info.relocatable) |
252b5132 RH |
290 | return "ldscripts/${EMULATION_NAME}.xr"; |
291 | else if (!config.text_read_only) | |
292 | return "ldscripts/${EMULATION_NAME}.xbn"; | |
293 | else if (!config.magic_demand_paged) | |
294 | return "ldscripts/${EMULATION_NAME}.xn"; | |
295 | else | |
296 | return "ldscripts/${EMULATION_NAME}.x"; | |
297 | } | |
298 | EOF | |
299 | ||
300 | fi | |
301 | ||
302 | cat >>e${EMULATION_NAME}.c <<EOF | |
303 | ||
0c7a8e5a | 304 | struct ld_emulation_xfer_struct ld_lnk960_emulation = |
252b5132 RH |
305 | { |
306 | lnk960_before_parse, | |
307 | lnk960_syslib, | |
308 | lnk960_hll, | |
309 | lnk960_after_parse, | |
310 | NULL, /* after_open */ | |
311 | lnk960_after_allocation, | |
312 | lnk960_set_output_arch, | |
313 | lnk960_choose_target, | |
314 | lnk960_before_allocation, | |
315 | lnk960_get_script, | |
316 | "lnk960", | |
e1c47aa4 AM |
317 | "", |
318 | NULL, /* finish */ | |
319 | NULL, /* create output section statements */ | |
320 | NULL, /* open dynamic archive */ | |
321 | NULL, /* place orphan */ | |
322 | NULL, /* set symbols */ | |
323 | NULL, /* parse args */ | |
3bcf5557 AM |
324 | NULL, /* add_options */ |
325 | NULL, /* handle_option */ | |
e1c47aa4 AM |
326 | NULL, /* unrecognized file */ |
327 | NULL, /* list options */ | |
40d109bf | 328 | NULL, /* recognized file */ |
fac1652d AM |
329 | NULL, /* find_potential_libraries */ |
330 | NULL /* new_vers_pattern */ | |
252b5132 RH |
331 | }; |
332 | EOF |