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