1 /* ldemul.c -- clearing house for ld emulation states
2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
4 Free Software Foundation, Inc.
6 This file is part of GLD, the Gnu Linker.
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)
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.
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
36 #include "ldemul-list.h"
38 static ld_emulation_xfer_type
*ld_emulation
;
41 ldemul_hll (char *name
)
43 ld_emulation
->hll (name
);
47 ldemul_syslib (char *name
)
49 ld_emulation
->syslib (name
);
53 ldemul_after_parse (void)
55 ld_emulation
->after_parse ();
59 ldemul_before_parse (void)
61 ld_emulation
->before_parse ();
65 ldemul_after_open (void)
67 ld_emulation
->after_open ();
71 ldemul_after_allocation (void)
73 ld_emulation
->after_allocation ();
77 ldemul_before_allocation (void)
79 ld_emulation
->before_allocation ();
83 ldemul_set_output_arch (void)
85 ld_emulation
->set_output_arch ();
91 if (ld_emulation
->finish
)
92 ld_emulation
->finish ();
96 ldemul_set_symbols (void)
98 if (ld_emulation
->set_symbols
)
99 ld_emulation
->set_symbols ();
103 ldemul_create_output_section_statements (void)
105 if (ld_emulation
->create_output_section_statements
)
106 ld_emulation
->create_output_section_statements ();
110 ldemul_get_script (int *isfile
)
112 return ld_emulation
->get_script (isfile
);
116 ldemul_open_dynamic_archive (const char *arch
, search_dirs_type
*search
,
117 lang_input_statement_type
*entry
)
119 if (ld_emulation
->open_dynamic_archive
)
120 return (*ld_emulation
->open_dynamic_archive
) (arch
, search
, entry
);
125 ldemul_place_orphan (lang_input_statement_type
*file
, asection
*s
)
127 if (ld_emulation
->place_orphan
)
128 return (*ld_emulation
->place_orphan
) (file
, s
);
133 ldemul_add_options (int ns
, char **shortopts
, int nl
,
134 struct option
**longopts
, int nrl
,
135 struct option
**really_longopts
)
137 if (ld_emulation
->add_options
)
138 (*ld_emulation
->add_options
) (ns
, shortopts
, nl
, longopts
,
139 nrl
, really_longopts
);
143 ldemul_handle_option (int optc
)
145 if (ld_emulation
->handle_option
)
146 return (*ld_emulation
->handle_option
) (optc
);
151 ldemul_parse_args (int argc
, char **argv
)
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
);
159 /* Let the emulation code handle an unrecognized file. */
162 ldemul_unrecognized_file (lang_input_statement_type
*entry
)
164 if (ld_emulation
->unrecognized_file
)
165 return (*ld_emulation
->unrecognized_file
) (entry
);
169 /* Let the emulation code handle a recognized file. */
172 ldemul_recognized_file (lang_input_statement_type
*entry
)
174 if (ld_emulation
->recognized_file
)
175 return (*ld_emulation
->recognized_file
) (entry
);
180 ldemul_choose_target (int argc
, char **argv
)
182 return ld_emulation
->choose_target (argc
, argv
);
186 /* The default choose_target function. */
189 ldemul_default_target (int argc ATTRIBUTE_UNUSED
, char **argv ATTRIBUTE_UNUSED
)
191 char *from_outside
= getenv (TARGET_ENVIRON
);
192 if (from_outside
!= (char *) NULL
)
194 return ld_emulation
->target_name
;
198 after_parse_default (void)
203 after_open_default (void)
208 after_allocation_default (void)
213 before_allocation_default (void)
215 if (!link_info
.relocatable
)
216 strip_excluded_output_sections ();
220 set_output_arch_default (void)
222 /* Set the output architecture and machine if possible. */
223 bfd_set_arch_mach (output_bfd
,
224 ldfile_output_architecture
, ldfile_output_machine
);
228 syslib_default (char *ignore ATTRIBUTE_UNUSED
)
230 info_msg (_("%S SYSLIB ignored\n"));
234 hll_default (char *ignore ATTRIBUTE_UNUSED
)
236 info_msg (_("%S HLL ignored\n"));
239 ld_emulation_xfer_type
*ld_emulations
[] = { EMULATION_LIST
};
242 ldemul_choose_mode (char *target
)
244 ld_emulation_xfer_type
**eptr
= ld_emulations
;
245 /* Ignore "gld" prefix. */
246 if (target
[0] == 'g' && target
[1] == 'l' && target
[2] == 'd')
248 for (; *eptr
; eptr
++)
250 if (strcmp (target
, (*eptr
)->emulation_name
) == 0)
252 ld_emulation
= *eptr
;
256 einfo (_("%P: unrecognised emulation mode: %s\n"), target
);
257 einfo (_("Supported emulations: "));
258 ldemul_list_emulations (stderr
);
263 ldemul_list_emulations (FILE *f
)
265 ld_emulation_xfer_type
**eptr
= ld_emulations
;
266 bfd_boolean first
= TRUE
;
268 for (; *eptr
; eptr
++)
274 fprintf (f
, "%s", (*eptr
)->emulation_name
);
279 ldemul_list_emulation_options (FILE *f
)
281 ld_emulation_xfer_type
**eptr
;
282 int options_found
= 0;
284 for (eptr
= ld_emulations
; *eptr
; eptr
++)
286 ld_emulation_xfer_type
*emul
= *eptr
;
288 if (emul
->list_options
)
290 fprintf (f
, "%s: \n", emul
->emulation_name
);
292 emul
->list_options (f
);
299 fprintf (f
, _(" no emulation specific options.\n"));
303 ldemul_find_potential_libraries (char *name
, lang_input_statement_type
*entry
)
305 if (ld_emulation
->find_potential_libraries
)
306 return ld_emulation
->find_potential_libraries (name
, entry
);
311 struct bfd_elf_version_expr
*
312 ldemul_new_vers_pattern (struct bfd_elf_version_expr
*entry
)
314 if (ld_emulation
->new_vers_pattern
)
315 entry
= (*ld_emulation
->new_vers_pattern
) (entry
);