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