kernel - support dummy reallocblks in devfs
[dragonfly.git] / contrib / binutils-2.27 / ld / ldemul.c
blobe0c8ba3f1ee42bfec1dfa409356a069f8fb71b79
1 /* ldemul.c -- clearing house for ld emulation states
2 Copyright (C) 1991-2016 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. */
21 #include "sysdep.h"
22 #include "bfd.h"
23 #include "getopt.h"
24 #include "bfdlink.h"
26 #include "ld.h"
27 #include "ldmisc.h"
28 #include "ldexp.h"
29 #include "ldlang.h"
30 #include "ldfile.h"
31 #include "ldemul.h"
32 #include "ldmain.h"
33 #include "ldemul-list.h"
35 static ld_emulation_xfer_type *ld_emulation;
37 void
38 ldemul_hll (char *name)
40 ld_emulation->hll (name);
43 void
44 ldemul_syslib (char *name)
46 ld_emulation->syslib (name);
49 void
50 ldemul_after_parse (void)
52 ld_emulation->after_parse ();
55 void
56 ldemul_before_parse (void)
58 ld_emulation->before_parse ();
61 void
62 ldemul_after_open (void)
64 ld_emulation->after_open ();
67 void
68 ldemul_after_allocation (void)
70 ld_emulation->after_allocation ();
73 void
74 ldemul_before_allocation (void)
76 ld_emulation->before_allocation ();
79 void
80 ldemul_set_output_arch (void)
82 ld_emulation->set_output_arch ();
85 void
86 ldemul_finish (void)
88 ld_emulation->finish ();
91 void
92 ldemul_set_symbols (void)
94 if (ld_emulation->set_symbols)
95 ld_emulation->set_symbols ();
98 void
99 ldemul_create_output_section_statements (void)
101 if (ld_emulation->create_output_section_statements)
102 ld_emulation->create_output_section_statements ();
105 char *
106 ldemul_get_script (int *isfile)
108 return ld_emulation->get_script (isfile);
111 bfd_boolean
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);
117 return FALSE;
120 lang_output_section_statement_type *
121 ldemul_place_orphan (asection *s, const char *name, int constraint)
123 if (ld_emulation->place_orphan)
124 return (*ld_emulation->place_orphan) (s, name, constraint);
125 return NULL;
128 void
129 ldemul_add_options (int ns, char **shortopts, int nl,
130 struct option **longopts, int nrl,
131 struct option **really_longopts)
133 if (ld_emulation->add_options)
134 (*ld_emulation->add_options) (ns, shortopts, nl, longopts,
135 nrl, really_longopts);
138 bfd_boolean
139 ldemul_handle_option (int optc)
141 if (ld_emulation->handle_option)
142 return (*ld_emulation->handle_option) (optc);
143 return FALSE;
146 bfd_boolean
147 ldemul_parse_args (int argc, char **argv)
149 /* Try and use the emulation parser if there is one. */
150 if (ld_emulation->parse_args)
151 return (*ld_emulation->parse_args) (argc, argv);
152 return FALSE;
155 /* Let the emulation code handle an unrecognized file. */
157 bfd_boolean
158 ldemul_unrecognized_file (lang_input_statement_type *entry)
160 if (ld_emulation->unrecognized_file)
161 return (*ld_emulation->unrecognized_file) (entry);
162 return FALSE;
165 /* Let the emulation code handle a recognized file. */
167 bfd_boolean
168 ldemul_recognized_file (lang_input_statement_type *entry)
170 if (ld_emulation->recognized_file)
171 return (*ld_emulation->recognized_file) (entry);
172 return FALSE;
175 char *
176 ldemul_choose_target (int argc, char **argv)
178 return ld_emulation->choose_target (argc, argv);
182 /* The default choose_target function. */
184 char *
185 ldemul_default_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
187 char *from_outside = getenv (TARGET_ENVIRON);
188 if (from_outside != (char *) NULL)
189 return from_outside;
190 return ld_emulation->target_name;
193 /* If the entry point was not specified as an address, then add the
194 symbol as undefined. This will cause ld to extract an archive
195 element defining the entry if ld is linking against such an archive.
197 We don't do this when generating shared libraries unless given -e
198 on the command line, because most shared libs are not designed to
199 be run as an executable. However, some are, eg. glibc ld.so and
200 may rely on the default linker script supplying ENTRY. So we can't
201 remove the ENTRY from the script, but would rather not insert
202 undefined _start syms. */
204 void
205 after_parse_default (void)
207 if (entry_symbol.name != NULL
208 && (bfd_link_executable (&link_info) || entry_from_cmdline))
210 bfd_boolean is_vma = FALSE;
212 if (entry_from_cmdline)
214 const char *send;
216 bfd_scan_vma (entry_symbol.name, &send, 0);
217 is_vma = *send == '\0';
219 if (!is_vma)
220 ldlang_add_undef (entry_symbol.name, entry_from_cmdline);
224 void
225 after_open_default (void)
229 void
230 after_allocation_default (void)
232 lang_relax_sections (FALSE);
235 void
236 before_allocation_default (void)
238 if (!bfd_link_relocatable (&link_info))
239 strip_excluded_output_sections ();
242 void
243 finish_default (void)
245 if (!bfd_link_relocatable (&link_info))
246 _bfd_fix_excluded_sec_syms (link_info.output_bfd, &link_info);
249 void
250 set_output_arch_default (void)
252 /* Set the output architecture and machine if possible. */
253 bfd_set_arch_mach (link_info.output_bfd,
254 ldfile_output_architecture, ldfile_output_machine);
256 bfd_emul_set_maxpagesize (output_target, config.maxpagesize);
257 bfd_emul_set_commonpagesize (output_target, config.commonpagesize);
260 void
261 syslib_default (char *ignore ATTRIBUTE_UNUSED)
263 info_msg (_("%S SYSLIB ignored\n"), NULL);
266 void
267 hll_default (char *ignore ATTRIBUTE_UNUSED)
269 info_msg (_("%S HLL ignored\n"), NULL);
272 ld_emulation_xfer_type *ld_emulations[] = { EMULATION_LIST };
274 void
275 ldemul_choose_mode (char *target)
277 ld_emulation_xfer_type **eptr = ld_emulations;
278 /* Ignore "gld" prefix. */
279 if (target[0] == 'g' && target[1] == 'l' && target[2] == 'd')
280 target += 3;
281 for (; *eptr; eptr++)
283 if (strcmp (target, (*eptr)->emulation_name) == 0)
285 ld_emulation = *eptr;
286 return;
289 einfo (_("%P: unrecognised emulation mode: %s\n"), target);
290 einfo (_("Supported emulations: "));
291 ldemul_list_emulations (stderr);
292 einfo ("%F\n");
295 void
296 ldemul_list_emulations (FILE *f)
298 ld_emulation_xfer_type **eptr = ld_emulations;
299 bfd_boolean first = TRUE;
301 for (; *eptr; eptr++)
303 if (first)
304 first = FALSE;
305 else
306 fprintf (f, " ");
307 fprintf (f, "%s", (*eptr)->emulation_name);
311 void
312 ldemul_list_emulation_options (FILE *f)
314 ld_emulation_xfer_type **eptr;
315 int options_found = 0;
317 for (eptr = ld_emulations; *eptr; eptr++)
319 ld_emulation_xfer_type *emul = *eptr;
321 if (emul->list_options)
323 fprintf (f, "%s: \n", emul->emulation_name);
325 emul->list_options (f);
327 options_found = 1;
331 if (!options_found)
332 fprintf (f, _(" no emulation specific options.\n"));
336 ldemul_find_potential_libraries (char *name, lang_input_statement_type *entry)
338 if (ld_emulation->find_potential_libraries)
339 return ld_emulation->find_potential_libraries (name, entry);
341 return 0;
344 struct bfd_elf_version_expr *
345 ldemul_new_vers_pattern (struct bfd_elf_version_expr *entry)
347 if (ld_emulation->new_vers_pattern)
348 entry = (*ld_emulation->new_vers_pattern) (entry);
349 return entry;
352 void
353 ldemul_extra_map_file_text (bfd *abfd, struct bfd_link_info *info, FILE *mapf)
355 if (ld_emulation->extra_map_file_text)
356 ld_emulation->extra_map_file_text (abfd, info, mapf);