ldemul.c revision 104834
14Srgrimes/* ldemul.c -- clearing house for ld emulation states
24Srgrimes   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 2000
34Srgrimes   Free Software Foundation, Inc.
44Srgrimes
54SrgrimesThis file is part of GLD, the Gnu Linker.
64Srgrimes
74SrgrimesGLD is free software; you can redistribute it and/or modify
84Srgrimesit under the terms of the GNU General Public License as published by
94Srgrimesthe Free Software Foundation; either version 2, or (at your option)
104Srgrimesany later version.
114Srgrimes
124SrgrimesGLD is distributed in the hope that it will be useful,
134Srgrimesbut WITHOUT ANY WARRANTY; without even the implied warranty of
144SrgrimesMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
154SrgrimesGNU General Public License for more details.
164Srgrimes
174SrgrimesYou should have received a copy of the GNU General Public License
184Srgrimesalong with GLD; see the file COPYING.  If not, write to the Free
194SrgrimesSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA
204Srgrimes02111-1307, USA.  */
214Srgrimes
224Srgrimes#include "bfd.h"
234Srgrimes#include "sysdep.h"
244Srgrimes
254Srgrimes#include "ld.h"
264Srgrimes#include "ldmisc.h"
274Srgrimes#include "ldexp.h"
284Srgrimes#include "ldlang.h"
294Srgrimes#include "ldfile.h"
304Srgrimes#include "ldemul.h"
314Srgrimes#include "ldmain.h"
324Srgrimes#include "ldemul-list.h"
334Srgrimes
344Srgrimesld_emulation_xfer_type *ld_emulation;
354Srgrimes
364Srgrimesvoid
374Srgrimesldemul_hll (name)
384Srgrimes     char *name;
394Srgrimes{
404Srgrimes  ld_emulation->hll (name);
414Srgrimes}
424Srgrimes
434Srgrimesvoid
444Srgrimesldemul_syslib (name)
454Srgrimes     char *name;
464Srgrimes{
474Srgrimes  ld_emulation->syslib (name);
484Srgrimes}
494Srgrimes
504Srgrimesvoid
514Srgrimesldemul_after_parse ()
524Srgrimes{
534Srgrimes  ld_emulation->after_parse ();
544Srgrimes}
554Srgrimes
564Srgrimesvoid
574Srgrimesldemul_before_parse ()
584Srgrimes{
594Srgrimes  ld_emulation->before_parse ();
60203Snate}
61203Snate
624Srgrimesvoid
63203Snateldemul_after_open ()
644Srgrimes{
654Srgrimes  ld_emulation->after_open ();
664Srgrimes}
674Srgrimes
684Srgrimesvoid
694Srgrimesldemul_after_allocation ()
704Srgrimes{
714Srgrimes  ld_emulation->after_allocation ();
724Srgrimes}
734Srgrimes
744Srgrimesvoid
754Srgrimesldemul_before_allocation ()
764Srgrimes{
774Srgrimes  if (ld_emulation->before_allocation)
784Srgrimes    ld_emulation->before_allocation ();
794Srgrimes}
804Srgrimes
814Srgrimesvoid
824Srgrimesldemul_set_output_arch ()
834Srgrimes{
844Srgrimes  ld_emulation->set_output_arch ();
854Srgrimes}
864Srgrimes
874Srgrimesvoid
884Srgrimesldemul_finish ()
894Srgrimes{
904Srgrimes  if (ld_emulation->finish)
914Srgrimes    ld_emulation->finish ();
924Srgrimes}
934Srgrimes
944Srgrimesvoid
954Srgrimesldemul_set_symbols ()
964Srgrimes{
974Srgrimes  if (ld_emulation->set_symbols)
984Srgrimes    ld_emulation->set_symbols ();
994Srgrimes}
1004Srgrimes
1014Srgrimesvoid
1024Srgrimesldemul_create_output_section_statements ()
1034Srgrimes{
1044Srgrimes  if (ld_emulation->create_output_section_statements)
1054Srgrimes    ld_emulation->create_output_section_statements ();
1064Srgrimes}
1074Srgrimes
1084Srgrimeschar *
1094Srgrimesldemul_get_script (isfile)
1104Srgrimes     int *isfile;
1114Srgrimes{
1124Srgrimes  return ld_emulation->get_script (isfile);
1134Srgrimes}
1144Srgrimes
1154Srgrimesboolean
1164Srgrimesldemul_open_dynamic_archive (arch, search, entry)
1174Srgrimes     const char *arch;
1184Srgrimes     search_dirs_type *search;
1194Srgrimes     lang_input_statement_type *entry;
1204Srgrimes{
1214Srgrimes  if (ld_emulation->open_dynamic_archive)
1224Srgrimes    return (*ld_emulation->open_dynamic_archive) (arch, search, entry);
1234Srgrimes  return false;
1244Srgrimes}
1254Srgrimes
1264Srgrimesboolean
1274Srgrimesldemul_place_orphan (file, s)
1284Srgrimes     lang_input_statement_type *file;
1294Srgrimes     asection *s;
1304Srgrimes{
1314Srgrimes  if (ld_emulation->place_orphan)
1324Srgrimes    return (*ld_emulation->place_orphan) (file, s);
1334Srgrimes  return false;
1344Srgrimes}
1354Srgrimes
1364Srgrimesint
1374Srgrimesldemul_parse_args (argc, argv)
1384Srgrimes     int argc;
1394Srgrimes     char **argv;
1404Srgrimes{
1414Srgrimes  /* Try and use the emulation parser if there is one.  */
1424Srgrimes  if (ld_emulation->parse_args)
1434Srgrimes    {
1444Srgrimes      return ld_emulation->parse_args (argc, argv);
1454Srgrimes    }
1464Srgrimes  return 0;
1474Srgrimes}
1484Srgrimes
1494Srgrimes/* Let the emulation code handle an unrecognized file.  */
1504Srgrimes
1514Srgrimesboolean
1524Srgrimesldemul_unrecognized_file (entry)
1534Srgrimes     lang_input_statement_type *entry;
1544Srgrimes{
1554Srgrimes  if (ld_emulation->unrecognized_file)
1564Srgrimes    return (*ld_emulation->unrecognized_file) (entry);
1574Srgrimes  return false;
1584Srgrimes}
1594Srgrimes
1604Srgrimes/* Let the emulation code handle a recognized file.  */
1614Srgrimes
1624Srgrimesboolean
1634Srgrimesldemul_recognized_file (entry)
1644Srgrimes     lang_input_statement_type *entry;
1654Srgrimes{
1664Srgrimes  if (ld_emulation->recognized_file)
167    return (*ld_emulation->recognized_file) (entry);
168  return false;
169}
170
171char *
172ldemul_choose_target (argc, argv)
173     int argc;
174     char **argv;
175{
176  return ld_emulation->choose_target (argc, argv);
177}
178
179
180/* The default choose_target function.  */
181
182char *
183ldemul_default_target (argc, argv)
184     int argc ATTRIBUTE_UNUSED;
185     char **argv ATTRIBUTE_UNUSED;
186{
187  char *from_outside = getenv (TARGET_ENVIRON);
188  if (from_outside != (char *) NULL)
189    return from_outside;
190  return ld_emulation->target_name;
191}
192
193void
194after_parse_default ()
195{
196}
197
198void
199after_open_default ()
200{
201}
202
203void
204after_allocation_default ()
205{
206}
207
208void
209before_allocation_default ()
210{
211}
212
213void
214set_output_arch_default ()
215{
216  /* Set the output architecture and machine if possible.  */
217  bfd_set_arch_mach (output_bfd,
218		     ldfile_output_architecture, ldfile_output_machine);
219}
220
221void
222syslib_default (ignore)
223     char *ignore ATTRIBUTE_UNUSED;
224{
225  info_msg (_("%S SYSLIB ignored\n"));
226}
227
228void
229hll_default (ignore)
230     char *ignore ATTRIBUTE_UNUSED;
231{
232  info_msg (_("%S HLL ignored\n"));
233}
234
235ld_emulation_xfer_type *ld_emulations[] = { EMULATION_LIST };
236
237void
238ldemul_choose_mode (target)
239     char *target;
240{
241  ld_emulation_xfer_type **eptr = ld_emulations;
242  /* Ignore "gld" prefix.  */
243  if (target[0] == 'g' && target[1] == 'l' && target[2] == 'd')
244    target += 3;
245  for (; *eptr; eptr++)
246    {
247      if (strcmp (target, (*eptr)->emulation_name) == 0)
248	{
249	  ld_emulation = *eptr;
250	  return;
251	}
252    }
253  einfo (_("%P: unrecognised emulation mode: %s\n"), target);
254  einfo (_("Supported emulations: "));
255  ldemul_list_emulations (stderr);
256  einfo ("%F\n");
257}
258
259void
260ldemul_list_emulations (f)
261     FILE *f;
262{
263  ld_emulation_xfer_type **eptr = ld_emulations;
264  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
276void
277ldemul_list_emulation_options (f)
278     FILE *f;
279{
280  ld_emulation_xfer_type **eptr;
281  int options_found = 0;
282
283  for (eptr = ld_emulations; *eptr; eptr++)
284    {
285      ld_emulation_xfer_type *emul = *eptr;
286
287      if (emul->list_options)
288	{
289	  fprintf (f, "%s: \n", emul->emulation_name);
290
291	  emul->list_options (f);
292
293	  options_found = 1;
294	}
295    }
296
297  if (! options_found)
298    fprintf (f, _("  no emulation specific options.\n"));
299}
300
301int
302ldemul_find_potential_libraries (name, entry)
303     char *name;
304     lang_input_statement_type *entry;
305{
306  if (ld_emulation->find_potential_libraries)
307    return ld_emulation->find_potential_libraries (name, entry);
308
309  return 0;
310}
311
312struct bfd_elf_version_expr *
313ldemul_new_vers_pattern (entry)
314     struct bfd_elf_version_expr *entry;
315{
316  if (ld_emulation->new_vers_pattern)
317    entry = (*ld_emulation->new_vers_pattern) (entry);
318  return entry;
319}
320