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