* elf32-ppc.c (ppc_elf_relax_section): Ignore non-code sections.
[deliverable/binutils-gdb.git] / ld / ldemul.c
CommitLineData
252b5132 1/* ldemul.c -- clearing house for ld emulation states
aef6203b 2 Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
f13a99db 3 2001, 2002, 2003, 2005, 2007, 2008
87f2a346 4 Free Software Foundation, Inc.
252b5132 5
f96b4a7b
NC
6 This file is part of the GNU Binutils.
7
8 This program 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 3 of the License, or
11 (at your option) any later version.
12
13 This program 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.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
252b5132 22
252b5132 23#include "sysdep.h"
3db64b00 24#include "bfd.h"
fcf65871 25#include "getopt.h"
8423293d 26#include "bfdlink.h"
252b5132
RH
27
28#include "ld.h"
252b5132
RH
29#include "ldmisc.h"
30#include "ldexp.h"
31#include "ldlang.h"
32#include "ldfile.h"
b71e2778 33#include "ldemul.h"
252b5132
RH
34#include "ldmain.h"
35#include "ldemul-list.h"
36
279e75dc 37static ld_emulation_xfer_type *ld_emulation;
252b5132
RH
38
39void
62b635b6 40ldemul_hll (char *name)
252b5132 41{
4de2d33d 42 ld_emulation->hll (name);
252b5132
RH
43}
44
4de2d33d 45void
62b635b6 46ldemul_syslib (char *name)
252b5132 47{
4de2d33d 48 ld_emulation->syslib (name);
252b5132
RH
49}
50
51void
62b635b6 52ldemul_after_parse (void)
252b5132 53{
4de2d33d 54 ld_emulation->after_parse ();
252b5132
RH
55}
56
57void
62b635b6 58ldemul_before_parse (void)
252b5132 59{
4de2d33d 60 ld_emulation->before_parse ();
252b5132
RH
61}
62
63void
62b635b6 64ldemul_after_open (void)
252b5132
RH
65{
66 ld_emulation->after_open ();
67}
68
4de2d33d 69void
62b635b6 70ldemul_after_allocation (void)
252b5132 71{
4de2d33d 72 ld_emulation->after_allocation ();
252b5132
RH
73}
74
4de2d33d 75void
62b635b6 76ldemul_before_allocation (void)
252b5132 77{
8423293d 78 ld_emulation->before_allocation ();
252b5132
RH
79}
80
252b5132 81void
62b635b6 82ldemul_set_output_arch (void)
252b5132 83{
4de2d33d 84 ld_emulation->set_output_arch ();
252b5132
RH
85}
86
87void
62b635b6 88ldemul_finish (void)
252b5132 89{
1e035701 90 ld_emulation->finish ();
252b5132
RH
91}
92
93void
62b635b6 94ldemul_set_symbols (void)
252b5132
RH
95{
96 if (ld_emulation->set_symbols)
4de2d33d 97 ld_emulation->set_symbols ();
252b5132
RH
98}
99
100void
62b635b6 101ldemul_create_output_section_statements (void)
252b5132
RH
102{
103 if (ld_emulation->create_output_section_statements)
4de2d33d 104 ld_emulation->create_output_section_statements ();
252b5132
RH
105}
106
107char *
62b635b6 108ldemul_get_script (int *isfile)
252b5132 109{
4de2d33d 110 return ld_emulation->get_script (isfile);
252b5132
RH
111}
112
b34976b6 113bfd_boolean
62b635b6
KH
114ldemul_open_dynamic_archive (const char *arch, search_dirs_type *search,
115 lang_input_statement_type *entry)
252b5132
RH
116{
117 if (ld_emulation->open_dynamic_archive)
118 return (*ld_emulation->open_dynamic_archive) (arch, search, entry);
b34976b6 119 return FALSE;
252b5132
RH
120}
121
c2edb4b8 122lang_output_section_statement_type *
8a99a385 123ldemul_place_orphan (asection *s, const char *name, int constraint)
252b5132
RH
124{
125 if (ld_emulation->place_orphan)
8a99a385 126 return (*ld_emulation->place_orphan) (s, name, constraint);
c2edb4b8 127 return NULL;
252b5132
RH
128}
129
3bcf5557 130void
62b635b6
KH
131ldemul_add_options (int ns, char **shortopts, int nl,
132 struct option **longopts, int nrl,
133 struct option **really_longopts)
3bcf5557
AM
134{
135 if (ld_emulation->add_options)
136 (*ld_emulation->add_options) (ns, shortopts, nl, longopts,
137 nrl, really_longopts);
138}
139
140bfd_boolean
62b635b6 141ldemul_handle_option (int optc)
3bcf5557
AM
142{
143 if (ld_emulation->handle_option)
144 return (*ld_emulation->handle_option) (optc);
145 return FALSE;
146}
147
148bfd_boolean
62b635b6 149ldemul_parse_args (int argc, char **argv)
252b5132 150{
4de2d33d 151 /* Try and use the emulation parser if there is one. */
252b5132 152 if (ld_emulation->parse_args)
3bcf5557 153 return (*ld_emulation->parse_args) (argc, argv);
3aa97c58 154 return FALSE;
252b5132
RH
155}
156
157/* Let the emulation code handle an unrecognized file. */
158
b34976b6 159bfd_boolean
62b635b6 160ldemul_unrecognized_file (lang_input_statement_type *entry)
252b5132
RH
161{
162 if (ld_emulation->unrecognized_file)
163 return (*ld_emulation->unrecognized_file) (entry);
b34976b6 164 return FALSE;
252b5132
RH
165}
166
167/* Let the emulation code handle a recognized file. */
168
b34976b6 169bfd_boolean
62b635b6 170ldemul_recognized_file (lang_input_statement_type *entry)
252b5132
RH
171{
172 if (ld_emulation->recognized_file)
173 return (*ld_emulation->recognized_file) (entry);
b34976b6 174 return FALSE;
252b5132
RH
175}
176
177char *
62b635b6 178ldemul_choose_target (int argc, char **argv)
252b5132 179{
742aeb63 180 return ld_emulation->choose_target (argc, argv);
252b5132
RH
181}
182
742aeb63 183
252b5132
RH
184/* The default choose_target function. */
185
186char *
62b635b6 187ldemul_default_target (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
252b5132
RH
188{
189 char *from_outside = getenv (TARGET_ENVIRON);
4de2d33d 190 if (from_outside != (char *) NULL)
252b5132
RH
191 return from_outside;
192 return ld_emulation->target_name;
193}
194
4de2d33d 195void
62b635b6 196after_parse_default (void)
252b5132 197{
252b5132
RH
198}
199
200void
62b635b6 201after_open_default (void)
252b5132
RH
202{
203}
204
205void
62b635b6 206after_allocation_default (void)
252b5132 207{
252b5132
RH
208}
209
210void
62b635b6 211before_allocation_default (void)
252b5132 212{
8423293d
AM
213 if (!link_info.relocatable)
214 strip_excluded_output_sections ();
252b5132
RH
215}
216
5e797c2c 217void
1e035701
AM
218finish_default (void)
219{
220 if (!link_info.relocatable)
f13a99db 221 _bfd_fix_excluded_sec_syms (link_info.output_bfd, &link_info);
1e035701
AM
222}
223
224void
62b635b6 225set_output_arch_default (void)
252b5132 226{
4de2d33d 227 /* Set the output architecture and machine if possible. */
f13a99db 228 bfd_set_arch_mach (link_info.output_bfd,
4de2d33d 229 ldfile_output_architecture, ldfile_output_machine);
252b5132
RH
230}
231
252b5132 232void
62b635b6 233syslib_default (char *ignore ATTRIBUTE_UNUSED)
252b5132
RH
234{
235 info_msg (_("%S SYSLIB ignored\n"));
236}
237
252b5132 238void
62b635b6 239hll_default (char *ignore ATTRIBUTE_UNUSED)
252b5132
RH
240{
241 info_msg (_("%S HLL ignored\n"));
242}
243
244ld_emulation_xfer_type *ld_emulations[] = { EMULATION_LIST };
245
246void
62b635b6 247ldemul_choose_mode (char *target)
252b5132 248{
4de2d33d
KH
249 ld_emulation_xfer_type **eptr = ld_emulations;
250 /* Ignore "gld" prefix. */
251 if (target[0] == 'g' && target[1] == 'l' && target[2] == 'd')
252 target += 3;
253 for (; *eptr; eptr++)
254 {
255 if (strcmp (target, (*eptr)->emulation_name) == 0)
256 {
257 ld_emulation = *eptr;
258 return;
259 }
260 }
261 einfo (_("%P: unrecognised emulation mode: %s\n"), target);
262 einfo (_("Supported emulations: "));
263 ldemul_list_emulations (stderr);
264 einfo ("%F\n");
252b5132
RH
265}
266
267void
62b635b6 268ldemul_list_emulations (FILE *f)
252b5132
RH
269{
270 ld_emulation_xfer_type **eptr = ld_emulations;
b34976b6 271 bfd_boolean first = TRUE;
252b5132
RH
272
273 for (; *eptr; eptr++)
274 {
275 if (first)
b34976b6 276 first = FALSE;
252b5132
RH
277 else
278 fprintf (f, " ");
279 fprintf (f, "%s", (*eptr)->emulation_name);
280 }
281}
282
283void
62b635b6 284ldemul_list_emulation_options (FILE *f)
252b5132 285{
4de2d33d 286 ld_emulation_xfer_type **eptr;
252b5132 287 int options_found = 0;
4de2d33d
KH
288
289 for (eptr = ld_emulations; *eptr; eptr++)
252b5132 290 {
4de2d33d
KH
291 ld_emulation_xfer_type *emul = *eptr;
292
252b5132
RH
293 if (emul->list_options)
294 {
295 fprintf (f, "%s: \n", emul->emulation_name);
4de2d33d 296
252b5132
RH
297 emul->list_options (f);
298
299 options_found = 1;
300 }
301 }
4de2d33d 302
252b5132
RH
303 if (! options_found)
304 fprintf (f, _(" no emulation specific options.\n"));
305}
344a211f
NC
306
307int
62b635b6 308ldemul_find_potential_libraries (char *name, lang_input_statement_type *entry)
344a211f
NC
309{
310 if (ld_emulation->find_potential_libraries)
311 return ld_emulation->find_potential_libraries (name, entry);
312
313 return 0;
314}
fac1652d
AM
315
316struct bfd_elf_version_expr *
62b635b6 317ldemul_new_vers_pattern (struct bfd_elf_version_expr *entry)
fac1652d
AM
318{
319 if (ld_emulation->new_vers_pattern)
320 entry = (*ld_emulation->new_vers_pattern) (entry);
321 return entry;
322}
This page took 0.425492 seconds and 4 git commands to generate.