]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/ldemul.c
19990502 sourceware import
[thirdparty/binutils-gdb.git] / ld / ldemul.c
1 /* ldemul.c -- clearing house for ld emulation states
2 Copyright (C) 1991, 92, 93, 94, 95, 96, 1997, 1998 Free Software Foundation, Inc.
3
4 This file is part of GLD, the Gnu Linker.
5
6 GLD is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GLD is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GLD; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20 #include "bfd.h"
21 #include "sysdep.h"
22
23 #include "ld.h"
24 #include "ldemul.h"
25 #include "ldmisc.h"
26 #include "ldexp.h"
27 #include "ldlang.h"
28 #include "ldfile.h"
29 #include "ldmain.h"
30 #include "ldemul-list.h"
31
32 ld_emulation_xfer_type *ld_emulation;
33
34 void
35 ldemul_hll(name)
36 char *name;
37 {
38 ld_emulation->hll(name);
39 }
40
41
42 void ldemul_syslib(name)
43 char *name;
44 {
45 ld_emulation->syslib(name);
46 }
47
48 void
49 ldemul_after_parse()
50 {
51 ld_emulation->after_parse();
52 }
53
54 void
55 ldemul_before_parse()
56 {
57 ld_emulation->before_parse();
58 }
59
60 void
61 ldemul_after_open ()
62 {
63 ld_emulation->after_open ();
64 }
65
66 void
67 ldemul_after_allocation()
68 {
69 ld_emulation->after_allocation();
70 }
71
72 void
73 ldemul_before_allocation()
74 {
75 if (ld_emulation->before_allocation)
76 ld_emulation->before_allocation();
77 }
78
79
80 void
81 ldemul_set_output_arch()
82 {
83 ld_emulation->set_output_arch();
84 }
85
86 void
87 ldemul_finish()
88 {
89 if (ld_emulation->finish)
90 ld_emulation->finish();
91 }
92
93 void
94 ldemul_set_symbols()
95 {
96 if (ld_emulation->set_symbols)
97 ld_emulation->set_symbols();
98 }
99
100 void
101 ldemul_create_output_section_statements()
102 {
103 if (ld_emulation->create_output_section_statements)
104 ld_emulation->create_output_section_statements();
105 }
106
107 char *
108 ldemul_get_script(isfile)
109 int *isfile;
110 {
111 return ld_emulation->get_script(isfile);
112 }
113
114 boolean
115 ldemul_open_dynamic_archive (arch, search, entry)
116 const char *arch;
117 search_dirs_type *search;
118 lang_input_statement_type *entry;
119 {
120 if (ld_emulation->open_dynamic_archive)
121 return (*ld_emulation->open_dynamic_archive) (arch, search, entry);
122 return false;
123 }
124
125 boolean
126 ldemul_place_orphan (file, s)
127 lang_input_statement_type *file;
128 asection *s;
129 {
130 if (ld_emulation->place_orphan)
131 return (*ld_emulation->place_orphan) (file, s);
132 return false;
133 }
134
135 int
136 ldemul_parse_args (argc, argv)
137 int argc;
138 char **argv;
139 {
140 /* Try and use the emulation parser if there is one. */
141 if (ld_emulation->parse_args)
142 {
143 return ld_emulation->parse_args (argc, argv);
144 }
145 return 0;
146 }
147
148 /* Let the emulation code handle an unrecognized file. */
149
150 boolean
151 ldemul_unrecognized_file (entry)
152 lang_input_statement_type *entry;
153 {
154 if (ld_emulation->unrecognized_file)
155 return (*ld_emulation->unrecognized_file) (entry);
156 return false;
157 }
158
159 /* Let the emulation code handle a recognized file. */
160
161 boolean
162 ldemul_recognized_file (entry)
163 lang_input_statement_type *entry;
164 {
165 if (ld_emulation->recognized_file)
166 return (*ld_emulation->recognized_file) (entry);
167 return false;
168 }
169
170 char *
171 ldemul_choose_target()
172 {
173 return ld_emulation->choose_target();
174 }
175
176 /* The default choose_target function. */
177
178 char *
179 ldemul_default_target()
180 {
181 char *from_outside = getenv (TARGET_ENVIRON);
182 if (from_outside != (char *)NULL)
183 return from_outside;
184 return ld_emulation->target_name;
185 }
186
187 void
188 after_parse_default()
189 {
190
191 }
192
193 void
194 after_open_default ()
195 {
196 }
197
198 void
199 after_allocation_default()
200 {
201
202 }
203
204 void
205 before_allocation_default()
206 {
207
208 }
209
210 void
211 set_output_arch_default()
212 {
213 /* Set the output architecture and machine if possible */
214 bfd_set_arch_mach(output_bfd,
215 ldfile_output_architecture, ldfile_output_machine);
216 }
217
218 /*ARGSUSED*/
219 void
220 syslib_default(ignore)
221 char *ignore;
222 {
223 info_msg (_("%S SYSLIB ignored\n"));
224 }
225
226 /*ARGSUSED*/
227 void
228 hll_default(ignore)
229 char *ignore;
230 {
231 info_msg (_("%S HLL ignored\n"));
232 }
233
234 ld_emulation_xfer_type *ld_emulations[] = { EMULATION_LIST };
235
236 void
237 ldemul_choose_mode(target)
238 char *target;
239 {
240 ld_emulation_xfer_type **eptr = ld_emulations;
241 /* Ignore "gld" prefix. */
242 if (target[0] == 'g' && target[1] == 'l' && target[2] == 'd')
243 target += 3;
244 for (; *eptr; eptr++)
245 {
246 if (strcmp(target, (*eptr)->emulation_name) == 0)
247 {
248 ld_emulation = *eptr;
249 return;
250 }
251 }
252 einfo (_("%P: unrecognised emulation mode: %s\n"), target);
253 einfo (_("Supported emulations: "));
254 ldemul_list_emulations (stderr);
255 einfo ("%F\n");
256 }
257
258 void
259 ldemul_list_emulations (f)
260 FILE *f;
261 {
262 ld_emulation_xfer_type **eptr = ld_emulations;
263 boolean first = true;
264
265 for (; *eptr; eptr++)
266 {
267 if (first)
268 first = false;
269 else
270 fprintf (f, " ");
271 fprintf (f, "%s", (*eptr)->emulation_name);
272 }
273 }
274
275 void
276 ldemul_list_emulation_options (f)
277 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 }