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