[PATCH 5/57][Arm][GAS] Add support for MVE instructions: vmull{b,t}
[binutils-gdb.git] / ld / ldemul.c
blob16ddb6dcf5430837890a790ebe49ba698630d590
1 /* ldemul.c -- clearing house for ld emulation states
2 Copyright (C) 1991-2019 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_check_relocs (void)
70 ld_emulation->after_check_relocs ();
73 void
74 ldemul_after_allocation (void)
76 ld_emulation->after_allocation ();
79 void
80 ldemul_before_allocation (void)
82 ld_emulation->before_allocation ();
85 void
86 ldemul_set_output_arch (void)
88 ld_emulation->set_output_arch ();
91 void
92 ldemul_finish (void)
94 ld_emulation->finish ();
97 void
98 ldemul_set_symbols (void)
100 if (ld_emulation->set_symbols)
101 ld_emulation->set_symbols ();
104 void
105 ldemul_create_output_section_statements (void)
107 if (ld_emulation->create_output_section_statements)
108 ld_emulation->create_output_section_statements ();
111 char *
112 ldemul_get_script (int *isfile)
114 return ld_emulation->get_script (isfile);
117 bfd_boolean
118 ldemul_open_dynamic_archive (const char *arch, search_dirs_type *search,
119 lang_input_statement_type *entry)
121 if (ld_emulation->open_dynamic_archive)
122 return (*ld_emulation->open_dynamic_archive) (arch, search, entry);
123 return FALSE;
126 lang_output_section_statement_type *
127 ldemul_place_orphan (asection *s, const char *name, int constraint)
129 if (ld_emulation->place_orphan)
130 return (*ld_emulation->place_orphan) (s, name, constraint);
131 return NULL;
134 void
135 ldemul_add_options (int ns, char **shortopts, int nl,
136 struct option **longopts, int nrl,
137 struct option **really_longopts)
139 if (ld_emulation->add_options)
140 (*ld_emulation->add_options) (ns, shortopts, nl, longopts,
141 nrl, really_longopts);
144 bfd_boolean
145 ldemul_handle_option (int optc)
147 if (ld_emulation->handle_option)
148 return (*ld_emulation->handle_option) (optc);
149 return FALSE;
152 bfd_boolean
153 ldemul_parse_args (int argc, char **argv)
155 /* Try and use the emulation parser if there is one. */
156 if (ld_emulation->parse_args)
157 return (*ld_emulation->parse_args) (argc, argv);
158 return FALSE;
161 /* Let the emulation code handle an unrecognized file. */
163 bfd_boolean
164 ldemul_unrecognized_file (lang_input_statement_type *entry)
166 if (ld_emulation->unrecognized_file)
167 return (*ld_emulation->unrecognized_file) (entry);
168 return FALSE;
171 /* Let the emulation code handle a recognized file. */
173 bfd_boolean
174 ldemul_recognized_file (lang_input_statement_type *entry)
176 if (ld_emulation->recognized_file)
177 return (*ld_emulation->recognized_file) (entry);
178 return FALSE;
181 char *
182 ldemul_choose_target (int argc, char **argv)
184 return ld_emulation->choose_target (argc, argv);
188 /* The default choose_target function. */
190 char *
191 ldemul_default_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
193 char *from_outside = getenv (TARGET_ENVIRON);
194 if (from_outside != (char *) NULL)
195 return from_outside;
196 return ld_emulation->target_name;
199 /* If the entry point was not specified as an address, then add the
200 symbol as undefined. This will cause ld to extract an archive
201 element defining the entry if ld is linking against such an archive.
203 We don't do this when generating shared libraries unless given -e
204 on the command line, because most shared libs are not designed to
205 be run as an executable. However, some are, eg. glibc ld.so and
206 may rely on the default linker script supplying ENTRY. So we can't
207 remove the ENTRY from the script, but would rather not insert
208 undefined _start syms. */
210 void
211 after_parse_default (void)
213 if (entry_symbol.name != NULL
214 && (bfd_link_executable (&link_info) || entry_from_cmdline))
216 bfd_boolean is_vma = FALSE;
218 if (entry_from_cmdline)
220 const char *send;
222 bfd_scan_vma (entry_symbol.name, &send, 0);
223 is_vma = *send == '\0';
225 if (!is_vma)
226 ldlang_add_undef (entry_symbol.name, entry_from_cmdline);
228 if (config.maxpagesize == 0)
229 config.maxpagesize = bfd_emul_get_maxpagesize (default_target);
230 if (config.commonpagesize == 0)
231 config.commonpagesize = bfd_emul_get_commonpagesize (default_target,
232 link_info.relro);
235 void
236 after_open_default (void)
240 void
241 after_check_relocs_default (void)
245 void
246 after_allocation_default (void)
248 lang_relax_sections (FALSE);
251 void
252 before_allocation_default (void)
254 if (!bfd_link_relocatable (&link_info))
255 strip_excluded_output_sections ();
258 void
259 finish_default (void)
261 if (!bfd_link_relocatable (&link_info))
262 _bfd_fix_excluded_sec_syms (link_info.output_bfd, &link_info);
265 void
266 set_output_arch_default (void)
268 /* Set the output architecture and machine if possible. */
269 bfd_set_arch_mach (link_info.output_bfd,
270 ldfile_output_architecture, ldfile_output_machine);
272 bfd_emul_set_maxpagesize (output_target, config.maxpagesize);
273 bfd_emul_set_commonpagesize (output_target, config.commonpagesize);
276 void
277 syslib_default (char *ignore ATTRIBUTE_UNUSED)
279 info_msg (_("%pS SYSLIB ignored\n"), NULL);
282 void
283 hll_default (char *ignore ATTRIBUTE_UNUSED)
285 info_msg (_("%pS HLL ignored\n"), NULL);
288 ld_emulation_xfer_type *ld_emulations[] = { EMULATION_LIST };
290 void
291 ldemul_choose_mode (char *target)
293 ld_emulation_xfer_type **eptr = ld_emulations;
294 /* Ignore "gld" prefix. */
295 if (target[0] == 'g' && target[1] == 'l' && target[2] == 'd')
296 target += 3;
297 for (; *eptr; eptr++)
299 if (strcmp (target, (*eptr)->emulation_name) == 0)
301 ld_emulation = *eptr;
302 return;
305 einfo (_("%P: unrecognised emulation mode: %s\n"), target);
306 einfo (_("Supported emulations: "));
307 ldemul_list_emulations (stderr);
308 einfo ("%F\n");
311 void
312 ldemul_list_emulations (FILE *f)
314 ld_emulation_xfer_type **eptr = ld_emulations;
315 bfd_boolean first = TRUE;
317 for (; *eptr; eptr++)
319 if (first)
320 first = FALSE;
321 else
322 fprintf (f, " ");
323 fprintf (f, "%s", (*eptr)->emulation_name);
327 void
328 ldemul_list_emulation_options (FILE *f)
330 ld_emulation_xfer_type **eptr;
331 int options_found = 0;
333 for (eptr = ld_emulations; *eptr; eptr++)
335 ld_emulation_xfer_type *emul = *eptr;
337 if (emul->list_options)
339 fprintf (f, "%s: \n", emul->emulation_name);
341 emul->list_options (f);
343 options_found = 1;
347 if (!options_found)
348 fprintf (f, _(" no emulation specific options.\n"));
352 ldemul_find_potential_libraries (char *name, lang_input_statement_type *entry)
354 if (ld_emulation->find_potential_libraries)
355 return ld_emulation->find_potential_libraries (name, entry);
357 return 0;
360 struct bfd_elf_version_expr *
361 ldemul_new_vers_pattern (struct bfd_elf_version_expr *entry)
363 if (ld_emulation->new_vers_pattern)
364 entry = (*ld_emulation->new_vers_pattern) (entry);
365 return entry;
368 void
369 ldemul_extra_map_file_text (bfd *abfd, struct bfd_link_info *info, FILE *mapf)
371 if (ld_emulation->extra_map_file_text)
372 ld_emulation->extra_map_file_text (abfd, info, mapf);