1 /* ldemul.c -- clearing house for ld emulation states
2 Copyright (C) 1991-2015 Free Software Foundation, Inc.
4 This file is part of the GNU Binutils.
6 This program 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 3 of the License, or
9 (at your option) any later version.
11 This program 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.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 MA 02110-1301, USA. */
33 #include "ldemul-list.h"
35 static ld_emulation_xfer_type
*ld_emulation
;
38 ldemul_hll (char *name
)
40 ld_emulation
->hll (name
);
44 ldemul_syslib (char *name
)
46 ld_emulation
->syslib (name
);
50 ldemul_after_parse (void)
52 ld_emulation
->after_parse ();
56 ldemul_before_parse (void)
58 ld_emulation
->before_parse ();
62 ldemul_after_open (void)
64 ld_emulation
->after_open ();
68 ldemul_after_allocation (void)
70 ld_emulation
->after_allocation ();
74 ldemul_before_allocation (void)
76 ld_emulation
->before_allocation ();
80 ldemul_set_output_arch (void)
82 ld_emulation
->set_output_arch ();
88 ld_emulation
->finish ();
92 ldemul_set_symbols (void)
94 if (ld_emulation
->set_symbols
)
95 ld_emulation
->set_symbols ();
99 ldemul_create_output_section_statements (void)
101 if (ld_emulation
->create_output_section_statements
)
102 ld_emulation
->create_output_section_statements ();
106 ldemul_get_script (int *isfile
)
108 return ld_emulation
->get_script (isfile
);
112 ldemul_open_dynamic_archive (const char *arch
, search_dirs_type
*search
,
113 lang_input_statement_type
*entry
)
115 if (ld_emulation
->open_dynamic_archive
)
116 return (*ld_emulation
->open_dynamic_archive
) (arch
, search
, entry
);
120 lang_output_section_statement_type
*
121 ldemul_place_orphan (asection
*s
, const char *name
, int constraint
)
123 if (config
.warn_orphan
)
124 einfo (_("%P: Warning: input section '%s' from file '%B' is not mentioned in linker script\n"),
127 if (ld_emulation
->place_orphan
)
128 return (*ld_emulation
->place_orphan
) (s
, name
, constraint
);
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
;
197 /* If the entry point was not specified as an address, then add the
198 symbol as undefined. This will cause ld to extract an archive
199 element defining the entry if ld is linking against such an archive.
201 We don't do this when generating shared libraries unless given -e
202 on the command line, because most shared libs are not designed to
203 be run as an executable. However, some are, eg. glibc ld.so and
204 may rely on the default linker script supplying ENTRY. So we can't
205 remove the ENTRY from the script, but would rather not insert
206 undefined _start syms. */
209 after_parse_default (void)
211 if (entry_symbol
.name
!= NULL
212 && (bfd_link_executable (&link_info
) || entry_from_cmdline
))
214 bfd_boolean is_vma
= FALSE
;
216 if (entry_from_cmdline
)
220 bfd_scan_vma (entry_symbol
.name
, &send
, 0);
221 is_vma
= *send
== '\0';
224 ldlang_add_undef (entry_symbol
.name
, entry_from_cmdline
);
229 after_open_default (void)
234 after_allocation_default (void)
236 lang_relax_sections (FALSE
);
240 before_allocation_default (void)
242 if (!bfd_link_relocatable (&link_info
))
243 strip_excluded_output_sections ();
247 finish_default (void)
249 if (!bfd_link_relocatable (&link_info
))
250 _bfd_fix_excluded_sec_syms (link_info
.output_bfd
, &link_info
);
254 set_output_arch_default (void)
256 /* Set the output architecture and machine if possible. */
257 bfd_set_arch_mach (link_info
.output_bfd
,
258 ldfile_output_architecture
, ldfile_output_machine
);
260 bfd_emul_set_maxpagesize (output_target
, config
.maxpagesize
);
261 bfd_emul_set_commonpagesize (output_target
, config
.commonpagesize
);
265 syslib_default (char *ignore ATTRIBUTE_UNUSED
)
267 info_msg (_("%S SYSLIB ignored\n"), NULL
);
271 hll_default (char *ignore ATTRIBUTE_UNUSED
)
273 info_msg (_("%S HLL ignored\n"), NULL
);
276 ld_emulation_xfer_type
*ld_emulations
[] = { EMULATION_LIST
};
279 ldemul_choose_mode (char *target
)
281 ld_emulation_xfer_type
**eptr
= ld_emulations
;
282 /* Ignore "gld" prefix. */
283 if (target
[0] == 'g' && target
[1] == 'l' && target
[2] == 'd')
285 for (; *eptr
; eptr
++)
287 if (strcmp (target
, (*eptr
)->emulation_name
) == 0)
289 ld_emulation
= *eptr
;
293 einfo (_("%P: unrecognised emulation mode: %s\n"), target
);
294 einfo (_("Supported emulations: "));
295 ldemul_list_emulations (stderr
);
300 ldemul_list_emulations (FILE *f
)
302 ld_emulation_xfer_type
**eptr
= ld_emulations
;
303 bfd_boolean first
= TRUE
;
305 for (; *eptr
; eptr
++)
311 fprintf (f
, "%s", (*eptr
)->emulation_name
);
316 ldemul_list_emulation_options (FILE *f
)
318 ld_emulation_xfer_type
**eptr
;
319 int options_found
= 0;
321 for (eptr
= ld_emulations
; *eptr
; eptr
++)
323 ld_emulation_xfer_type
*emul
= *eptr
;
325 if (emul
->list_options
)
327 fprintf (f
, "%s: \n", emul
->emulation_name
);
329 emul
->list_options (f
);
336 fprintf (f
, _(" no emulation specific options.\n"));
340 ldemul_find_potential_libraries (char *name
, lang_input_statement_type
*entry
)
342 if (ld_emulation
->find_potential_libraries
)
343 return ld_emulation
->find_potential_libraries (name
, entry
);
348 struct bfd_elf_version_expr
*
349 ldemul_new_vers_pattern (struct bfd_elf_version_expr
*entry
)
351 if (ld_emulation
->new_vers_pattern
)
352 entry
= (*ld_emulation
->new_vers_pattern
) (entry
);
357 ldemul_extra_map_file_text (bfd
*abfd
, struct bfd_link_info
*info
, FILE *mapf
)
359 if (ld_emulation
->extra_map_file_text
)
360 ld_emulation
->extra_map_file_text (abfd
, info
, mapf
);