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