1 /* ldemul.c -- clearing house for ld emulation states
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2005, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of the GNU Binutils.
8 This program 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 3 of the License, or
11 (at your option) any later version.
13 This program 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 this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
35 #include "ldemul-list.h"
37 static ld_emulation_xfer_type *ld_emulation;
40 ldemul_hll (char *name)
42 ld_emulation->hll (name);
46 ldemul_syslib (char *name)
48 ld_emulation->syslib (name);
52 ldemul_after_parse (void)
54 ld_emulation->after_parse ();
58 ldemul_before_parse (void)
60 ld_emulation->before_parse ();
64 ldemul_after_open (void)
66 ld_emulation->after_open ();
70 ldemul_after_allocation (void)
72 ld_emulation->after_allocation ();
76 ldemul_before_allocation (void)
78 ld_emulation->before_allocation ();
82 ldemul_set_output_arch (void)
84 ld_emulation->set_output_arch ();
90 ld_emulation->finish ();
94 ldemul_set_symbols (void)
96 if (ld_emulation->set_symbols)
97 ld_emulation->set_symbols ();
101 ldemul_create_output_section_statements (void)
103 if (ld_emulation->create_output_section_statements)
104 ld_emulation->create_output_section_statements ();
108 ldemul_get_script (int *isfile)
110 return ld_emulation->get_script (isfile);
114 ldemul_open_dynamic_archive (const char *arch, search_dirs_type *search,
115 lang_input_statement_type *entry)
117 if (ld_emulation->open_dynamic_archive)
118 return (*ld_emulation->open_dynamic_archive) (arch, search, entry);
122 lang_output_section_statement_type *
123 ldemul_place_orphan (asection *s, const char *name, int constraint)
125 if (ld_emulation->place_orphan)
126 return (*ld_emulation->place_orphan) (s, name, constraint);
131 ldemul_add_options (int ns, char **shortopts, int nl,
132 struct option **longopts, int nrl,
133 struct option **really_longopts)
135 if (ld_emulation->add_options)
136 (*ld_emulation->add_options) (ns, shortopts, nl, longopts,
137 nrl, really_longopts);
141 ldemul_handle_option (int optc)
143 if (ld_emulation->handle_option)
144 return (*ld_emulation->handle_option) (optc);
149 ldemul_parse_args (int argc, char **argv)
151 /* Try and use the emulation parser if there is one. */
152 if (ld_emulation->parse_args)
153 return (*ld_emulation->parse_args) (argc, argv);
157 /* Let the emulation code handle an unrecognized file. */
160 ldemul_unrecognized_file (lang_input_statement_type *entry)
162 if (ld_emulation->unrecognized_file)
163 return (*ld_emulation->unrecognized_file) (entry);
167 /* Let the emulation code handle a recognized file. */
170 ldemul_recognized_file (lang_input_statement_type *entry)
172 if (ld_emulation->recognized_file)
173 return (*ld_emulation->recognized_file) (entry);
178 ldemul_choose_target (int argc, char **argv)
180 return ld_emulation->choose_target (argc, argv);
184 /* The default choose_target function. */
187 ldemul_default_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
189 char *from_outside = getenv (TARGET_ENVIRON);
190 if (from_outside != (char *) NULL)
192 return ld_emulation->target_name;
196 after_parse_default (void)
201 after_open_default (void)
206 after_allocation_default (void)
208 lang_relax_sections (FALSE);
212 before_allocation_default (void)
214 if (!link_info.relocatable)
215 strip_excluded_output_sections ();
219 finish_default (void)
221 if (!link_info.relocatable)
222 _bfd_fix_excluded_sec_syms (link_info.output_bfd, &link_info);
226 set_output_arch_default (void)
228 /* Set the output architecture and machine if possible. */
229 bfd_set_arch_mach (link_info.output_bfd,
230 ldfile_output_architecture, ldfile_output_machine);
232 bfd_emul_set_maxpagesize (output_target, config.maxpagesize);
233 bfd_emul_set_commonpagesize (output_target, config.commonpagesize);
237 syslib_default (char *ignore ATTRIBUTE_UNUSED)
239 info_msg (_("%S SYSLIB ignored\n"));
243 hll_default (char *ignore ATTRIBUTE_UNUSED)
245 info_msg (_("%S HLL ignored\n"));
248 ld_emulation_xfer_type *ld_emulations[] = { EMULATION_LIST };
251 ldemul_choose_mode (char *target)
253 ld_emulation_xfer_type **eptr = ld_emulations;
254 /* Ignore "gld" prefix. */
255 if (target[0] == 'g' && target[1] == 'l' && target[2] == 'd')
257 for (; *eptr; eptr++)
259 if (strcmp (target, (*eptr)->emulation_name) == 0)
261 ld_emulation = *eptr;
265 einfo (_("%P: unrecognised emulation mode: %s\n"), target);
266 einfo (_("Supported emulations: "));
267 ldemul_list_emulations (stderr);
272 ldemul_list_emulations (FILE *f)
274 ld_emulation_xfer_type **eptr = ld_emulations;
275 bfd_boolean first = TRUE;
277 for (; *eptr; eptr++)
283 fprintf (f, "%s", (*eptr)->emulation_name);
288 ldemul_list_emulation_options (FILE *f)
290 ld_emulation_xfer_type **eptr;
291 int options_found = 0;
293 for (eptr = ld_emulations; *eptr; eptr++)
295 ld_emulation_xfer_type *emul = *eptr;
297 if (emul->list_options)
299 fprintf (f, "%s: \n", emul->emulation_name);
301 emul->list_options (f);
308 fprintf (f, _(" no emulation specific options.\n"));
312 ldemul_find_potential_libraries (char *name, lang_input_statement_type *entry)
314 if (ld_emulation->find_potential_libraries)
315 return ld_emulation->find_potential_libraries (name, entry);
320 struct bfd_elf_version_expr *
321 ldemul_new_vers_pattern (struct bfd_elf_version_expr *entry)
323 if (ld_emulation->new_vers_pattern)
324 entry = (*ld_emulation->new_vers_pattern) (entry);