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