1 /* ldemul.c -- clearing house for ld emulation states
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 Free Software Foundation, Inc.
6 This file is part of GLD, the Gnu Linker.
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)
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.
18 You should have received a copy of the GNU General Public License
19 along with GLD; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
36 #include "ldemul-list.h"
38 static ld_emulation_xfer_type *ld_emulation;
41 ldemul_hll (char *name)
43 ld_emulation->hll (name);
47 ldemul_syslib (char *name)
49 ld_emulation->syslib (name);
53 ldemul_after_parse (void)
55 ld_emulation->after_parse ();
59 ldemul_before_parse (void)
61 ld_emulation->before_parse ();
65 ldemul_after_open (void)
67 ld_emulation->after_open ();
71 ldemul_after_allocation (void)
73 ld_emulation->after_allocation ();
77 ldemul_before_allocation (void)
79 ld_emulation->before_allocation ();
83 ldemul_do_assignments (void)
85 ld_emulation->do_assignments ();
89 ldemul_set_output_arch (void)
91 ld_emulation->set_output_arch ();
97 if (ld_emulation->finish)
98 ld_emulation->finish ();
102 ldemul_set_symbols (void)
104 if (ld_emulation->set_symbols)
105 ld_emulation->set_symbols ();
109 ldemul_create_output_section_statements (void)
111 if (ld_emulation->create_output_section_statements)
112 ld_emulation->create_output_section_statements ();
116 ldemul_get_script (int *isfile)
118 return ld_emulation->get_script (isfile);
122 ldemul_open_dynamic_archive (const char *arch, search_dirs_type *search,
123 lang_input_statement_type *entry)
125 if (ld_emulation->open_dynamic_archive)
126 return (*ld_emulation->open_dynamic_archive) (arch, search, entry);
131 ldemul_place_orphan (lang_input_statement_type *file, asection *s)
133 if (ld_emulation->place_orphan)
134 return (*ld_emulation->place_orphan) (file, s);
139 ldemul_add_options (int ns, char **shortopts, int nl,
140 struct option **longopts, int nrl,
141 struct option **really_longopts)
143 if (ld_emulation->add_options)
144 (*ld_emulation->add_options) (ns, shortopts, nl, longopts,
145 nrl, really_longopts);
149 ldemul_handle_option (int optc)
151 if (ld_emulation->handle_option)
152 return (*ld_emulation->handle_option) (optc);
157 ldemul_parse_args (int argc, char **argv)
159 /* Try and use the emulation parser if there is one. */
160 if (ld_emulation->parse_args)
161 return (*ld_emulation->parse_args) (argc, argv);
165 /* Let the emulation code handle an unrecognized file. */
168 ldemul_unrecognized_file (lang_input_statement_type *entry)
170 if (ld_emulation->unrecognized_file)
171 return (*ld_emulation->unrecognized_file) (entry);
175 /* Let the emulation code handle a recognized file. */
178 ldemul_recognized_file (lang_input_statement_type *entry)
180 if (ld_emulation->recognized_file)
181 return (*ld_emulation->recognized_file) (entry);
186 ldemul_choose_target (int argc, char **argv)
188 return ld_emulation->choose_target (argc, argv);
192 /* The default choose_target function. */
195 ldemul_default_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
197 char *from_outside = getenv (TARGET_ENVIRON);
198 if (from_outside != (char *) NULL)
200 return ld_emulation->target_name;
204 after_parse_default (void)
209 after_open_default (void)
214 after_allocation_default (void)
219 before_allocation_default (void)
221 if (!link_info.relocatable)
222 strip_excluded_output_sections ();
226 do_assignments_default (void)
231 set_output_arch_default (void)
233 /* Set the output architecture and machine if possible. */
234 bfd_set_arch_mach (output_bfd,
235 ldfile_output_architecture, ldfile_output_machine);
239 syslib_default (char *ignore ATTRIBUTE_UNUSED)
241 info_msg (_("%S SYSLIB ignored\n"));
245 hll_default (char *ignore ATTRIBUTE_UNUSED)
247 info_msg (_("%S HLL ignored\n"));
250 ld_emulation_xfer_type *ld_emulations[] = { EMULATION_LIST };
253 ldemul_choose_mode (char *target)
255 ld_emulation_xfer_type **eptr = ld_emulations;
256 /* Ignore "gld" prefix. */
257 if (target[0] == 'g' && target[1] == 'l' && target[2] == 'd')
259 for (; *eptr; eptr++)
261 if (strcmp (target, (*eptr)->emulation_name) == 0)
263 ld_emulation = *eptr;
267 einfo (_("%P: unrecognised emulation mode: %s\n"), target);
268 einfo (_("Supported emulations: "));
269 ldemul_list_emulations (stderr);
274 ldemul_list_emulations (FILE *f)
276 ld_emulation_xfer_type **eptr = ld_emulations;
277 bfd_boolean first = TRUE;
279 for (; *eptr; eptr++)
285 fprintf (f, "%s", (*eptr)->emulation_name);
290 ldemul_list_emulation_options (FILE *f)
292 ld_emulation_xfer_type **eptr;
293 int options_found = 0;
295 for (eptr = ld_emulations; *eptr; eptr++)
297 ld_emulation_xfer_type *emul = *eptr;
299 if (emul->list_options)
301 fprintf (f, "%s: \n", emul->emulation_name);
303 emul->list_options (f);
310 fprintf (f, _(" no emulation specific options.\n"));
314 ldemul_find_potential_libraries (char *name, lang_input_statement_type *entry)
316 if (ld_emulation->find_potential_libraries)
317 return ld_emulation->find_potential_libraries (name, entry);
322 struct bfd_elf_version_expr *
323 ldemul_new_vers_pattern (struct bfd_elf_version_expr *entry)
325 if (ld_emulation->new_vers_pattern)
326 entry = (*ld_emulation->new_vers_pattern) (entry);