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