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