daily update
[binutils.git] / ld / ldemul.c
blobd1891270f9ee186c1b60c39634ad5aa9755975bb
1 /* ldemul.c -- clearing house for ld emulation states
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000, 2002, 2003
3 Free Software Foundation, Inc.
5 This file is part of GLD, the Gnu Linker.
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.
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.
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 the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
22 #include "bfd.h"
23 #include "sysdep.h"
24 #include "getopt.h"
26 #include "ld.h"
27 #include "ldmisc.h"
28 #include "ldexp.h"
29 #include "ldlang.h"
30 #include "ldfile.h"
31 #include "ldemul.h"
32 #include "ldmain.h"
33 #include "ldemul-list.h"
35 ld_emulation_xfer_type *ld_emulation;
37 void
38 ldemul_hll (name)
39 char *name;
41 ld_emulation->hll (name);
44 void
45 ldemul_syslib (name)
46 char *name;
48 ld_emulation->syslib (name);
51 void
52 ldemul_after_parse ()
54 ld_emulation->after_parse ();
57 void
58 ldemul_before_parse ()
60 ld_emulation->before_parse ();
63 void
64 ldemul_after_open ()
66 ld_emulation->after_open ();
69 void
70 ldemul_after_allocation ()
72 ld_emulation->after_allocation ();
75 void
76 ldemul_before_allocation ()
78 if (ld_emulation->before_allocation)
79 ld_emulation->before_allocation ();
82 void
83 ldemul_set_output_arch ()
85 ld_emulation->set_output_arch ();
88 void
89 ldemul_finish ()
91 if (ld_emulation->finish)
92 ld_emulation->finish ();
95 void
96 ldemul_set_symbols ()
98 if (ld_emulation->set_symbols)
99 ld_emulation->set_symbols ();
102 void
103 ldemul_create_output_section_statements ()
105 if (ld_emulation->create_output_section_statements)
106 ld_emulation->create_output_section_statements ();
109 char *
110 ldemul_get_script (isfile)
111 int *isfile;
113 return ld_emulation->get_script (isfile);
116 bfd_boolean
117 ldemul_open_dynamic_archive (arch, search, entry)
118 const char *arch;
119 search_dirs_type *search;
120 lang_input_statement_type *entry;
122 if (ld_emulation->open_dynamic_archive)
123 return (*ld_emulation->open_dynamic_archive) (arch, search, entry);
124 return FALSE;
127 bfd_boolean
128 ldemul_place_orphan (file, s)
129 lang_input_statement_type *file;
130 asection *s;
132 if (ld_emulation->place_orphan)
133 return (*ld_emulation->place_orphan) (file, s);
134 return FALSE;
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;
146 if (ld_emulation->add_options)
147 (*ld_emulation->add_options) (ns, shortopts, nl, longopts,
148 nrl, really_longopts);
151 bfd_boolean
152 ldemul_handle_option (optc)
153 int optc;
155 if (ld_emulation->handle_option)
156 return (*ld_emulation->handle_option) (optc);
157 return FALSE;
160 bfd_boolean
161 ldemul_parse_args (argc, argv)
162 int argc;
163 char **argv;
165 /* Try and use the emulation parser if there is one. */
166 if (ld_emulation->parse_args)
167 return (*ld_emulation->parse_args) (argc, argv);
168 return FALSE;
171 /* Let the emulation code handle an unrecognized file. */
173 bfd_boolean
174 ldemul_unrecognized_file (entry)
175 lang_input_statement_type *entry;
177 if (ld_emulation->unrecognized_file)
178 return (*ld_emulation->unrecognized_file) (entry);
179 return FALSE;
182 /* Let the emulation code handle a recognized file. */
184 bfd_boolean
185 ldemul_recognized_file (entry)
186 lang_input_statement_type *entry;
188 if (ld_emulation->recognized_file)
189 return (*ld_emulation->recognized_file) (entry);
190 return FALSE;
193 char *
194 ldemul_choose_target (argc, argv)
195 int argc;
196 char **argv;
198 return ld_emulation->choose_target (argc, argv);
202 /* The default choose_target function. */
204 char *
205 ldemul_default_target (argc, argv)
206 int argc ATTRIBUTE_UNUSED;
207 char **argv ATTRIBUTE_UNUSED;
209 char *from_outside = getenv (TARGET_ENVIRON);
210 if (from_outside != (char *) NULL)
211 return from_outside;
212 return ld_emulation->target_name;
215 void
216 after_parse_default ()
220 void
221 after_open_default ()
225 void
226 after_allocation_default ()
230 void
231 before_allocation_default ()
235 void
236 set_output_arch_default ()
238 /* Set the output architecture and machine if possible. */
239 bfd_set_arch_mach (output_bfd,
240 ldfile_output_architecture, ldfile_output_machine);
243 void
244 syslib_default (ignore)
245 char *ignore ATTRIBUTE_UNUSED;
247 info_msg (_("%S SYSLIB ignored\n"));
250 void
251 hll_default (ignore)
252 char *ignore ATTRIBUTE_UNUSED;
254 info_msg (_("%S HLL ignored\n"));
257 ld_emulation_xfer_type *ld_emulations[] = { EMULATION_LIST };
259 void
260 ldemul_choose_mode (target)
261 char *target;
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++)
269 if (strcmp (target, (*eptr)->emulation_name) == 0)
271 ld_emulation = *eptr;
272 return;
275 einfo (_("%P: unrecognised emulation mode: %s\n"), target);
276 einfo (_("Supported emulations: "));
277 ldemul_list_emulations (stderr);
278 einfo ("%F\n");
281 void
282 ldemul_list_emulations (f)
283 FILE *f;
285 ld_emulation_xfer_type **eptr = ld_emulations;
286 bfd_boolean first = TRUE;
288 for (; *eptr; eptr++)
290 if (first)
291 first = FALSE;
292 else
293 fprintf (f, " ");
294 fprintf (f, "%s", (*eptr)->emulation_name);
298 void
299 ldemul_list_emulation_options (f)
300 FILE *f;
302 ld_emulation_xfer_type **eptr;
303 int options_found = 0;
305 for (eptr = ld_emulations; *eptr; eptr++)
307 ld_emulation_xfer_type *emul = *eptr;
309 if (emul->list_options)
311 fprintf (f, "%s: \n", emul->emulation_name);
313 emul->list_options (f);
315 options_found = 1;
319 if (! options_found)
320 fprintf (f, _(" no emulation specific options.\n"));
324 ldemul_find_potential_libraries (name, entry)
325 char *name;
326 lang_input_statement_type *entry;
328 if (ld_emulation->find_potential_libraries)
329 return ld_emulation->find_potential_libraries (name, entry);
331 return 0;
334 struct bfd_elf_version_expr *
335 ldemul_new_vers_pattern (entry)
336 struct bfd_elf_version_expr *entry;
338 if (ld_emulation->new_vers_pattern)
339 entry = (*ld_emulation->new_vers_pattern) (entry);
340 return entry;