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