Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* ldemul.c -- clearing house for ld emulation states |
b71e2778 | 2 | Copyright (C) 1991, 92, 93, 94, 95, 96, 97, 98, 99, 2000 |
87f2a346 | 3 | Free Software Foundation, Inc. |
252b5132 RH |
4 | |
5 | This file is part of GLD, the Gnu Linker. | |
6 | ||
7 | GLD 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 2, or (at your option) | |
10 | any later version. | |
11 | ||
12 | GLD 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 | |
19 | the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | #include "bfd.h" | |
22 | #include "sysdep.h" | |
23 | ||
24 | #include "ld.h" | |
252b5132 RH |
25 | #include "ldmisc.h" |
26 | #include "ldexp.h" | |
27 | #include "ldlang.h" | |
28 | #include "ldfile.h" | |
b71e2778 | 29 | #include "ldemul.h" |
252b5132 RH |
30 | #include "ldmain.h" |
31 | #include "ldemul-list.h" | |
32 | ||
33 | ld_emulation_xfer_type *ld_emulation; | |
34 | ||
35 | void | |
36 | ldemul_hll(name) | |
37 | char *name; | |
38 | { | |
39 | ld_emulation->hll(name); | |
40 | } | |
41 | ||
42 | ||
43 | void ldemul_syslib(name) | |
44 | char *name; | |
45 | { | |
46 | ld_emulation->syslib(name); | |
47 | } | |
48 | ||
49 | void | |
50 | ldemul_after_parse() | |
51 | { | |
52 | ld_emulation->after_parse(); | |
53 | } | |
54 | ||
55 | void | |
56 | ldemul_before_parse() | |
57 | { | |
58 | ld_emulation->before_parse(); | |
59 | } | |
60 | ||
61 | void | |
62 | ldemul_after_open () | |
63 | { | |
64 | ld_emulation->after_open (); | |
65 | } | |
66 | ||
67 | void | |
68 | ldemul_after_allocation() | |
69 | { | |
70 | ld_emulation->after_allocation(); | |
71 | } | |
72 | ||
73 | void | |
74 | ldemul_before_allocation() | |
75 | { | |
76 | if (ld_emulation->before_allocation) | |
77 | ld_emulation->before_allocation(); | |
78 | } | |
79 | ||
80 | ||
81 | void | |
82 | ldemul_set_output_arch() | |
83 | { | |
84 | ld_emulation->set_output_arch(); | |
85 | } | |
86 | ||
87 | void | |
88 | ldemul_finish() | |
89 | { | |
90 | if (ld_emulation->finish) | |
91 | ld_emulation->finish(); | |
92 | } | |
93 | ||
94 | void | |
95 | ldemul_set_symbols() | |
96 | { | |
97 | if (ld_emulation->set_symbols) | |
98 | ld_emulation->set_symbols(); | |
99 | } | |
100 | ||
101 | void | |
102 | ldemul_create_output_section_statements() | |
103 | { | |
104 | if (ld_emulation->create_output_section_statements) | |
105 | ld_emulation->create_output_section_statements(); | |
106 | } | |
107 | ||
108 | char * | |
109 | ldemul_get_script(isfile) | |
110 | int *isfile; | |
111 | { | |
112 | return ld_emulation->get_script(isfile); | |
113 | } | |
114 | ||
115 | boolean | |
116 | ldemul_open_dynamic_archive (arch, search, entry) | |
117 | const char *arch; | |
118 | search_dirs_type *search; | |
119 | lang_input_statement_type *entry; | |
120 | { | |
121 | if (ld_emulation->open_dynamic_archive) | |
122 | return (*ld_emulation->open_dynamic_archive) (arch, search, entry); | |
123 | return false; | |
124 | } | |
125 | ||
126 | boolean | |
127 | ldemul_place_orphan (file, s) | |
128 | lang_input_statement_type *file; | |
129 | asection *s; | |
130 | { | |
131 | if (ld_emulation->place_orphan) | |
132 | return (*ld_emulation->place_orphan) (file, s); | |
133 | return false; | |
134 | } | |
135 | ||
136 | int | |
137 | ldemul_parse_args (argc, argv) | |
138 | int argc; | |
139 | char **argv; | |
140 | { | |
141 | /* Try and use the emulation parser if there is one. */ | |
142 | if (ld_emulation->parse_args) | |
143 | { | |
144 | return ld_emulation->parse_args (argc, argv); | |
145 | } | |
146 | return 0; | |
147 | } | |
148 | ||
149 | /* Let the emulation code handle an unrecognized file. */ | |
150 | ||
151 | boolean | |
152 | ldemul_unrecognized_file (entry) | |
153 | lang_input_statement_type *entry; | |
154 | { | |
155 | if (ld_emulation->unrecognized_file) | |
156 | return (*ld_emulation->unrecognized_file) (entry); | |
157 | return false; | |
158 | } | |
159 | ||
160 | /* Let the emulation code handle a recognized file. */ | |
161 | ||
162 | boolean | |
163 | ldemul_recognized_file (entry) | |
164 | lang_input_statement_type *entry; | |
165 | { | |
166 | if (ld_emulation->recognized_file) | |
167 | return (*ld_emulation->recognized_file) (entry); | |
168 | return false; | |
169 | } | |
170 | ||
171 | char * | |
172 | ldemul_choose_target() | |
173 | { | |
174 | return ld_emulation->choose_target(); | |
175 | } | |
176 | ||
177 | /* The default choose_target function. */ | |
178 | ||
179 | char * | |
180 | ldemul_default_target() | |
181 | { | |
182 | char *from_outside = getenv (TARGET_ENVIRON); | |
183 | if (from_outside != (char *)NULL) | |
184 | return from_outside; | |
185 | return ld_emulation->target_name; | |
186 | } | |
187 | ||
188 | void | |
189 | after_parse_default() | |
190 | { | |
191 | ||
192 | } | |
193 | ||
194 | void | |
195 | after_open_default () | |
196 | { | |
197 | } | |
198 | ||
199 | void | |
200 | after_allocation_default() | |
201 | { | |
202 | ||
203 | } | |
204 | ||
205 | void | |
206 | before_allocation_default() | |
207 | { | |
208 | ||
209 | } | |
210 | ||
211 | void | |
212 | set_output_arch_default() | |
213 | { | |
214 | /* Set the output architecture and machine if possible */ | |
215 | bfd_set_arch_mach(output_bfd, | |
216 | ldfile_output_architecture, ldfile_output_machine); | |
217 | } | |
218 | ||
219 | /*ARGSUSED*/ | |
220 | void | |
221 | syslib_default(ignore) | |
87f2a346 | 222 | char *ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
223 | { |
224 | info_msg (_("%S SYSLIB ignored\n")); | |
225 | } | |
226 | ||
227 | /*ARGSUSED*/ | |
228 | void | |
229 | hll_default(ignore) | |
87f2a346 | 230 | char *ignore ATTRIBUTE_UNUSED; |
252b5132 RH |
231 | { |
232 | info_msg (_("%S HLL ignored\n")); | |
233 | } | |
234 | ||
235 | ld_emulation_xfer_type *ld_emulations[] = { EMULATION_LIST }; | |
236 | ||
237 | void | |
238 | ldemul_choose_mode(target) | |
239 | char *target; | |
240 | { | |
241 | ld_emulation_xfer_type **eptr = ld_emulations; | |
242 | /* Ignore "gld" prefix. */ | |
243 | if (target[0] == 'g' && target[1] == 'l' && target[2] == 'd') | |
244 | target += 3; | |
245 | for (; *eptr; eptr++) | |
246 | { | |
247 | if (strcmp(target, (*eptr)->emulation_name) == 0) | |
248 | { | |
249 | ld_emulation = *eptr; | |
250 | return; | |
251 | } | |
252 | } | |
253 | einfo (_("%P: unrecognised emulation mode: %s\n"), target); | |
254 | einfo (_("Supported emulations: ")); | |
255 | ldemul_list_emulations (stderr); | |
256 | einfo ("%F\n"); | |
257 | } | |
258 | ||
259 | void | |
260 | ldemul_list_emulations (f) | |
261 | FILE *f; | |
262 | { | |
263 | ld_emulation_xfer_type **eptr = ld_emulations; | |
264 | boolean first = true; | |
265 | ||
266 | for (; *eptr; eptr++) | |
267 | { | |
268 | if (first) | |
269 | first = false; | |
270 | else | |
271 | fprintf (f, " "); | |
272 | fprintf (f, "%s", (*eptr)->emulation_name); | |
273 | } | |
274 | } | |
275 | ||
276 | void | |
277 | ldemul_list_emulation_options (f) | |
278 | FILE * f; | |
279 | { | |
280 | ld_emulation_xfer_type ** eptr; | |
281 | int options_found = 0; | |
282 | ||
283 | for (eptr = ld_emulations; * eptr; eptr ++) | |
284 | { | |
285 | ld_emulation_xfer_type * emul = * eptr; | |
286 | ||
287 | if (emul->list_options) | |
288 | { | |
289 | fprintf (f, "%s: \n", emul->emulation_name); | |
290 | ||
291 | emul->list_options (f); | |
292 | ||
293 | options_found = 1; | |
294 | } | |
295 | } | |
296 | ||
297 | if (! options_found) | |
298 | fprintf (f, _(" no emulation specific options.\n")); | |
299 | } | |
344a211f NC |
300 | |
301 | int | |
302 | ldemul_find_potential_libraries (name, entry) | |
303 | char * name; | |
304 | lang_input_statement_type * entry; | |
305 | { | |
306 | if (ld_emulation->find_potential_libraries) | |
307 | return ld_emulation->find_potential_libraries (name, entry); | |
308 | ||
309 | return 0; | |
310 | } |