Sun Feb 27 15:22:36 1994 Stan Shebs (shebs@andros.cygnus.com)
[deliverable/binutils-gdb.git] / bfd / targets.c
1 /* Generic target-file-type support for the BFD library.
2 Copyright 1990, 91, 92, 93, 1994 Free Software Foundation, Inc.
3 Written by Cygnus Support.
4
5 This file is part of BFD, the Binary File Descriptor library.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21 #include "bfd.h"
22 #include "sysdep.h"
23 #include "libbfd.h"
24
25 /*
26 SECTION
27 Targets
28
29 DESCRIPTION
30 Each port of BFD to a different machine requries the creation
31 of a target back end. All the back end provides to the root
32 part of BFD is a structure containing pointers to functions
33 which perform certain low level operations on files. BFD
34 translates the applications's requests through a pointer into
35 calls to the back end routines.
36
37 When a file is opened with <<bfd_openr>>, its format and
38 target are unknown. BFD uses various mechanisms to determine
39 how to interpret the file. The operations performed are:
40
41 o Create a BFD by calling the internal routine
42 <<_bfd_new_bfd>>, then call <<bfd_find_target>> with the
43 target string supplied to <<bfd_openr>> and the new BFD pointer.
44
45 o If a null target string was provided to <<bfd_find_target>>,
46 look up the environment variable <<GNUTARGET>> and use
47 that as the target string.
48
49 o If the target string is still <<NULL>>, or the target string is
50 <<default>>, then use the first item in the target vector
51 as the target type, and set <<target_defaulted>> in the BFD to
52 cause <<bfd_check_format>> to loop through all the targets.
53 @xref{bfd_target}. @xref{Formats}.
54
55 o Otherwise, inspect the elements in the target vector
56 one by one, until a match on target name is found. When found,
57 use it.
58
59 o Otherwise return the error <<bfd_error_invalid_target>> to
60 <<bfd_openr>>.
61
62 o <<bfd_openr>> attempts to open the file using
63 <<bfd_open_file>>, and returns the BFD.
64
65 Once the BFD has been opened and the target selected, the file
66 format may be determined. This is done by calling
67 <<bfd_check_format>> on the BFD with a suggested format.
68 If <<target_defaulted>> has been set, each possible target
69 type is tried to see if it recognizes the specified format.
70 <<bfd_check_format>> returns <<true>> when the caller guesses right.
71 @menu
72 @* bfd_target::
73 @end menu
74 */
75
76
77 /*
78
79 INODE
80 bfd_target, , Targets, Targets
81 DOCDD
82 SUBSECTION
83 bfd_target
84
85 DESCRIPTION
86 This structure contains everything that BFD knows about a
87 target. It includes things like its byte order, name, and which
88 routines to call to do various operations.
89
90 Every BFD points to a target structure with its <<xvec>>
91 member.
92
93 The macros below are used to dispatch to functions through the
94 <<bfd_target>> vector. They are used in a number of macros further
95 down in @file{bfd.h}, and are also used when calling various
96 routines by hand inside the BFD implementation. The @var{arglist}
97 argument must be parenthesized; it contains all the arguments
98 to the called function.
99
100 They make the documentation (more) unpleasant to read, so if
101 someone wants to fix this and not break the above, please do.
102
103 .#define BFD_SEND(bfd, message, arglist) \
104 . ((*((bfd)->xvec->message)) arglist)
105 .
106 .#ifdef DEBUG_BFD_SEND
107 .#undef BFD_SEND
108 .#define BFD_SEND(bfd, message, arglist) \
109 . (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
110 . ((*((bfd)->xvec->message)) arglist) : \
111 . (bfd_assert (__FILE__,__LINE__), NULL))
112 .#endif
113
114 For operations which index on the BFD format:
115
116 .#define BFD_SEND_FMT(bfd, message, arglist) \
117 . (((bfd)->xvec->message[(int)((bfd)->format)]) arglist)
118 .
119 .#ifdef DEBUG_BFD_SEND
120 .#undef BFD_SEND_FMT
121 .#define BFD_SEND_FMT(bfd, message, arglist) \
122 . (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
123 . (((bfd)->xvec->message[(int)((bfd)->format)]) arglist) : \
124 . (bfd_assert (__FILE__,__LINE__), NULL))
125 .#endif
126
127 This is the structure which defines the type of BFD this is. The
128 <<xvec>> member of the struct <<bfd>> itself points here. Each
129 module that implements access to a different target under BFD,
130 defines one of these.
131
132
133 FIXME, these names should be rationalised with the names of
134 the entry points which call them. Too bad we can't have one
135 macro to define them both!
136
137 .enum bfd_flavour {
138 . bfd_target_unknown_flavour,
139 . bfd_target_aout_flavour,
140 . bfd_target_coff_flavour,
141 . bfd_target_ecoff_flavour,
142 . bfd_target_elf_flavour,
143 . bfd_target_ieee_flavour,
144 . bfd_target_nlm_flavour,
145 . bfd_target_oasys_flavour,
146 . bfd_target_tekhex_flavour,
147 . bfd_target_srec_flavour,
148 . bfd_target_som_flavour};
149 .
150 .{* Forward declaration. *}
151 .typedef struct bfd_link_info _bfd_link_info;
152 .
153 .typedef struct bfd_target
154 .{
155
156 Identifies the kind of target, e.g., SunOS4, Ultrix, etc.
157
158 . char *name;
159
160 The "flavour" of a back end is a general indication about the contents
161 of a file.
162
163 . enum bfd_flavour flavour;
164
165 The order of bytes within the data area of a file.
166
167 . boolean byteorder_big_p;
168
169 The order of bytes within the header parts of a file.
170
171 . boolean header_byteorder_big_p;
172
173 A mask of all the flags which an executable may have set -
174 from the set <<NO_FLAGS>>, <<HAS_RELOC>>, ...<<D_PAGED>>.
175
176 . flagword object_flags;
177
178 A mask of all the flags which a section may have set - from
179 the set <<SEC_NO_FLAGS>>, <<SEC_ALLOC>>, ...<<SET_NEVER_LOAD>>.
180
181 . flagword section_flags;
182
183 The character normally found at the front of a symbol
184 (if any), perhaps `_'.
185
186 . char symbol_leading_char;
187
188 The pad character for file names within an archive header.
189
190 . char ar_pad_char;
191
192 The maximum number of characters in an archive header.
193
194 . unsigned short ar_max_namelen;
195
196 The minimum alignment restriction for any section.
197
198 . unsigned int align_power_min;
199
200 Entries for byte swapping for data. These are different from the other
201 entry points, since they don't take a BFD asthe first argument.
202 Certain other handlers could do the same.
203
204 . bfd_vma (*bfd_getx64) PARAMS ((const bfd_byte *));
205 . bfd_signed_vma (*bfd_getx_signed_64) PARAMS ((const bfd_byte *));
206 . void (*bfd_putx64) PARAMS ((bfd_vma, bfd_byte *));
207 . bfd_vma (*bfd_getx32) PARAMS ((const bfd_byte *));
208 . bfd_signed_vma (*bfd_getx_signed_32) PARAMS ((const bfd_byte *));
209 . void (*bfd_putx32) PARAMS ((bfd_vma, bfd_byte *));
210 . bfd_vma (*bfd_getx16) PARAMS ((const bfd_byte *));
211 . bfd_signed_vma (*bfd_getx_signed_16) PARAMS ((const bfd_byte *));
212 . void (*bfd_putx16) PARAMS ((bfd_vma, bfd_byte *));
213
214 Byte swapping for the headers
215
216 . bfd_vma (*bfd_h_getx64) PARAMS ((const bfd_byte *));
217 . bfd_signed_vma (*bfd_h_getx_signed_64) PARAMS ((const bfd_byte *));
218 . void (*bfd_h_putx64) PARAMS ((bfd_vma, bfd_byte *));
219 . bfd_vma (*bfd_h_getx32) PARAMS ((const bfd_byte *));
220 . bfd_signed_vma (*bfd_h_getx_signed_32) PARAMS ((const bfd_byte *));
221 . void (*bfd_h_putx32) PARAMS ((bfd_vma, bfd_byte *));
222 . bfd_vma (*bfd_h_getx16) PARAMS ((const bfd_byte *));
223 . bfd_signed_vma (*bfd_h_getx_signed_16) PARAMS ((const bfd_byte *));
224 . void (*bfd_h_putx16) PARAMS ((bfd_vma, bfd_byte *));
225
226 Format dependent routines: these are vectors of entry points
227 within the target vector structure, one for each format to check.
228
229 Check the format of a file being read. Return a <<bfd_target *>> or zero.
230
231 . struct bfd_target * (*_bfd_check_format[bfd_type_end]) PARAMS ((bfd *));
232
233 Set the format of a file being written.
234
235 . boolean (*_bfd_set_format[bfd_type_end]) PARAMS ((bfd *));
236
237 Write cached information into a file being written, at <<bfd_close>>.
238
239 . boolean (*_bfd_write_contents[bfd_type_end]) PARAMS ((bfd *));
240
241 The following functions are defined in <<JUMP_TABLE>>. The idea is
242 that the back end writer of <<foo>> names all the routines
243 <<foo_>>@var{entry_point}; <<JUMP_TABLE>> will build the entries
244 in this structure in the right order.
245
246 Core file entry points.
247
248 . char * (*_core_file_failing_command) PARAMS ((bfd *));
249 . int (*_core_file_failing_signal) PARAMS ((bfd *));
250 . boolean (*_core_file_matches_executable_p) PARAMS ((bfd *, bfd *));
251
252 Archive entry points.
253
254 . boolean (*_bfd_slurp_armap) PARAMS ((bfd *));
255 . boolean (*_bfd_slurp_extended_name_table) PARAMS ((bfd *));
256 . void (*_bfd_truncate_arname) PARAMS ((bfd *, CONST char *, char *));
257 . boolean (*write_armap) PARAMS ((bfd *arch,
258 . unsigned int elength,
259 . struct orl *map,
260 . unsigned int orl_count,
261 . int stridx));
262
263 Standard stuff.
264
265 . boolean (*_close_and_cleanup) PARAMS ((bfd *));
266 . boolean (*_bfd_set_section_contents) PARAMS ((bfd *, sec_ptr, PTR,
267 . file_ptr, bfd_size_type));
268 . boolean (*_bfd_get_section_contents) PARAMS ((bfd *, sec_ptr, PTR,
269 . file_ptr, bfd_size_type));
270 . boolean (*_new_section_hook) PARAMS ((bfd *, sec_ptr));
271
272 Symbols and relocations.
273
274 . unsigned int (*_get_symtab_upper_bound) PARAMS ((bfd *));
275 . unsigned int (*_bfd_canonicalize_symtab) PARAMS ((bfd *,
276 . struct symbol_cache_entry **));
277 . unsigned int (*_get_reloc_upper_bound) PARAMS ((bfd *, sec_ptr));
278 . unsigned int (*_bfd_canonicalize_reloc) PARAMS ((bfd *, sec_ptr, arelent **,
279 . struct symbol_cache_entry **));
280 . struct symbol_cache_entry *
281 . (*_bfd_make_empty_symbol) PARAMS ((bfd *));
282 . void (*_bfd_print_symbol) PARAMS ((bfd *, PTR,
283 . struct symbol_cache_entry *,
284 . bfd_print_symbol_type));
285 .#define bfd_print_symbol(b,p,s,e) BFD_SEND(b, _bfd_print_symbol, (b,p,s,e))
286 . void (*_bfd_get_symbol_info) PARAMS ((bfd *,
287 . struct symbol_cache_entry *,
288 . symbol_info *));
289 .#define bfd_get_symbol_info(b,p,e) BFD_SEND(b, _bfd_get_symbol_info, (b,p,e))
290
291 . alent * (*_get_lineno) PARAMS ((bfd *, struct symbol_cache_entry *));
292 .
293 . boolean (*_bfd_set_arch_mach) PARAMS ((bfd *, enum bfd_architecture,
294 . unsigned long));
295 .
296 . bfd * (*openr_next_archived_file) PARAMS ((bfd *arch, bfd *prev));
297 .
298 . boolean (*_bfd_find_nearest_line) PARAMS ((bfd *abfd,
299 . struct sec *section, struct symbol_cache_entry **symbols,
300 . bfd_vma offset, CONST char **file, CONST char **func,
301 . unsigned int *line));
302 .
303 . int (*_bfd_stat_arch_elt) PARAMS ((bfd *, struct stat *));
304 .
305 . int (*_bfd_sizeof_headers) PARAMS ((bfd *, boolean));
306 .
307 . void (*_bfd_debug_info_start) PARAMS ((bfd *));
308 . void (*_bfd_debug_info_end) PARAMS ((bfd *));
309 . void (*_bfd_debug_info_accumulate) PARAMS ((bfd *, struct sec *));
310 .
311 . bfd_byte * (*_bfd_get_relocated_section_contents) PARAMS ((bfd *,
312 . struct bfd_link_info *, struct bfd_link_order *,
313 . bfd_byte *data, boolean relocateable,
314 . struct symbol_cache_entry **));
315 .
316 . boolean (*_bfd_relax_section) PARAMS ((bfd *, struct sec *,
317 . struct bfd_link_info *, struct symbol_cache_entry **));
318 .
319 . {* See documentation on reloc types. *}
320 . CONST struct reloc_howto_struct *
321 . (*reloc_type_lookup) PARAMS ((bfd *abfd,
322 . bfd_reloc_code_real_type code));
323 .
324 . {* Back-door to allow format-aware applications to create debug symbols
325 . while using BFD for everything else. Currently used by the assembler
326 . when creating COFF files. *}
327 . asymbol * (*_bfd_make_debug_symbol) PARAMS ((
328 . bfd *abfd,
329 . void *ptr,
330 . unsigned long size));
331 .
332 . {* Create a hash table for the linker. Different backends store
333 . different information in this table. *}
334 . struct bfd_link_hash_table *(*_bfd_link_hash_table_create) PARAMS ((bfd *));
335 .
336 . {* Add symbols from this object file into the hash table. *}
337 . boolean (*_bfd_link_add_symbols) PARAMS ((bfd *, struct bfd_link_info *));
338 .
339 . {* Do a link based on the link_order structures attached to each
340 . section of the BFD. *}
341 . boolean (*_bfd_final_link) PARAMS ((bfd *, struct bfd_link_info *));
342 .
343
344 Data for use by back-end routines, which isn't generic enough to belong
345 in this structure.
346
347 . PTR backend_data;
348 .} bfd_target;
349
350 */
351
352 /* All known xvecs (even those that don't compile on all systems).
353 Alphabetized for easy reference.
354 They are listed a second time below, since
355 we can't intermix extern's and initializers. */
356 extern bfd_target a29kcoff_big_vec;
357 extern bfd_target a_out_adobe_vec;
358 extern bfd_target aout_mips_big_vec;
359 extern bfd_target aout_mips_little_vec;
360 extern bfd_target apollocoff_vec;
361 extern bfd_target b_out_vec_big_host;
362 extern bfd_target b_out_vec_little_host;
363 extern bfd_target bfd_elf32_big_generic_vec;
364 extern bfd_target bfd_elf32_bigmips_vec;
365 extern bfd_target bfd_elf32_hppa_vec;
366 extern bfd_target bfd_elf32_i386_vec;
367 extern bfd_target bfd_elf32_i860_vec;
368 extern bfd_target bfd_elf32_little_generic_vec;
369 extern bfd_target bfd_elf32_littlemips_vec;
370 extern bfd_target bfd_elf32_m68k_vec;
371 extern bfd_target bfd_elf32_m88k_vec;
372 extern bfd_target bfd_elf32_powerpc_vec;
373 extern bfd_target bfd_elf32_sparc_vec;
374 extern bfd_target bfd_elf64_big_generic_vec;
375 extern bfd_target bfd_elf64_little_generic_vec;
376 /* start-sanitize-v9 */
377 extern bfd_target bfd_elf64_sparc_vec;
378 /* end-sanitize-v9 */
379 extern bfd_target demo_64_vec;
380 extern bfd_target ecoff_big_vec;
381 extern bfd_target ecoff_little_vec;
382 extern bfd_target ecoffalpha_little_vec;
383 extern bfd_target h8300coff_vec;
384 extern bfd_target h8500coff_vec;
385 extern bfd_target host_aout_vec;
386 extern bfd_target hp300bsd_vec;
387 extern bfd_target hp300hpux_vec;
388 extern bfd_target som_vec;
389 extern bfd_target i386aout_vec;
390 extern bfd_target i386bsd_vec;
391 extern bfd_target netbsd386_vec;
392 extern bfd_target i386coff_vec;
393 extern bfd_target i386linux_vec;
394 extern bfd_target i386lynx_aout_vec;
395 extern bfd_target i386lynx_coff_vec;
396 extern bfd_target i386mach3_vec;
397 extern bfd_target icoff_big_vec;
398 extern bfd_target icoff_little_vec;
399 extern bfd_target ieee_vec;
400 extern bfd_target m68kcoff_vec;
401 extern bfd_target m68kcoffun_vec;
402 extern bfd_target m68klynx_aout_vec;
403 extern bfd_target m68klynx_coff_vec;
404 extern bfd_target m88kbcs_vec;
405 extern bfd_target newsos3_vec;
406 extern bfd_target nlm32_i386_vec;
407 extern bfd_target nlm32_sparc_vec;
408 extern bfd_target nlm32_alpha_vec;
409 /*start-sanitize-powerpc-netware*/
410 extern bfd_target nlm32_powerpc_vec;
411 /*end-sanitize-powerpc-netware*/
412 extern bfd_target oasys_vec;
413 extern bfd_target rs6000coff_vec;
414 extern bfd_target shcoff_vec;
415 extern bfd_target sparclynx_aout_vec;
416 extern bfd_target sparclynx_coff_vec;
417 extern bfd_target sparccoff_vec;
418 extern bfd_target sunos_big_vec;
419 extern bfd_target tekhex_vec;
420 extern bfd_target we32kcoff_vec;
421 extern bfd_target z8kcoff_vec;
422
423 /* srec is always included. */
424 extern bfd_target srec_vec;
425 extern bfd_target symbolsrec_vec;
426
427 /* All of the xvecs for core files. */
428 extern bfd_target aix386_core_vec;
429 extern bfd_target hpux_core_vec;
430 extern bfd_target hppabsd_core_vec;
431 extern bfd_target irix_core_vec;
432 extern bfd_target osf_core_vec;
433 extern bfd_target sco_core_vec;
434 extern bfd_target trad_core_vec;
435 extern bfd_target ptrace_core_vec;
436
437 bfd_target *bfd_target_vector[] = {
438
439 #ifdef SELECT_VECS
440
441 SELECT_VECS,
442
443 #else /* not SELECT_VECS */
444
445 #ifdef DEFAULT_VECTOR
446 &DEFAULT_VECTOR,
447 #endif
448 /* This list is alphabetized to make it easy to compare
449 with other vector lists -- the decls above and
450 the case statement in configure.in.
451 Vectors that don't compile on all systems, or aren't finished,
452 should have an entry here with #if 0 around it, to show that
453 it wasn't omitted by mistake. */
454 &a29kcoff_big_vec,
455 &a_out_adobe_vec,
456 #if 0 /* No one seems to use this. */
457 &aout_mips_big_vec,
458 #endif
459 &aout_mips_little_vec,
460 &b_out_vec_big_host,
461 &b_out_vec_little_host,
462
463 /* This, and other vectors, may not be used in any *.mt configuration.
464 But that does not mean they are unnecessary. If configured
465 --with-targets=all, objdump or gdb should be able to examine
466 the file even if we don't recognize the machine type. */
467 &bfd_elf32_big_generic_vec,
468 &bfd_elf32_bigmips_vec,
469 &bfd_elf32_hppa_vec,
470 &bfd_elf32_i386_vec,
471 &bfd_elf32_i860_vec,
472 &bfd_elf32_little_generic_vec,
473 &bfd_elf32_littlemips_vec,
474 &bfd_elf32_m68k_vec,
475 &bfd_elf32_m88k_vec,
476 &bfd_elf32_sparc_vec,
477 #ifdef BFD64 /* No one seems to use this. */
478 &bfd_elf64_big_generic_vec,
479 &bfd_elf64_little_generic_vec,
480 #endif
481 /* start-sanitize-v9 */
482 #if 0
483 &bfd_elf64_sparc_vec,
484 #endif
485 /* end-sanitize-v9 */
486 #ifdef BFD64
487 &demo_64_vec, /* Only compiled if host has long-long support */
488 #endif
489 &ecoff_big_vec,
490 &ecoff_little_vec,
491 #if 0
492 &ecoffalpha_little_vec,
493 #endif
494 &h8300coff_vec,
495 &h8500coff_vec,
496 #if 0
497 /* Since a.out files lack decent magic numbers, no way to recognize
498 which kind of a.out file it is. */
499 &host_aout_vec,
500 #endif
501 #if 0 /* Clashes with sunos_big_vec magic no. */
502 &hp300bsd_vec,
503 #endif
504 &hp300hpux_vec,
505 #if defined (HOST_HPPAHPUX) || defined (HOST_HPPABSD) || defined (HOST_HPPAOSF)
506 &som_vec,
507 #endif
508 &i386aout_vec,
509 &i386bsd_vec,
510 &netbsd386_vec,
511 &i386coff_vec,
512 #if 0
513 /* Since a.out files lack decent magic numbers, no way to recognize
514 which kind of a.out file it is. */
515 &i386linux_vec,
516 #endif
517 &i386lynx_aout_vec,
518 &i386lynx_coff_vec,
519 &icoff_big_vec,
520 &icoff_little_vec,
521 &ieee_vec,
522 &m68kcoff_vec,
523 &m68kcoffun_vec,
524 &m68klynx_aout_vec,
525 &m68klynx_coff_vec,
526 &m88kbcs_vec,
527 &newsos3_vec,
528 &nlm32_i386_vec,
529 &nlm32_sparc_vec,
530 #ifdef BFD64
531 &nlm32_alpha_vec,
532 #endif
533 #if 0
534 /* We have no oasys tools anymore, so we can't test any of this
535 anymore. If you want to test the stuff yourself, go ahead...
536 steve@cygnus.com
537 Worse, since there is no magic number for archives, there
538 can be annoying target mis-matches. */
539 &oasys_vec,
540 #endif
541 &rs6000coff_vec,
542 &shcoff_vec,
543 &sparclynx_aout_vec,
544 &sparclynx_coff_vec,
545 &sunos_big_vec,
546 #if 0
547 &tekhex_vec,
548 #endif
549 &we32kcoff_vec,
550 &z8kcoff_vec,
551
552 #endif /* not SELECT_VECS */
553
554 /* Always support S-records, for convenience. */
555 &srec_vec,
556 &symbolsrec_vec,
557
558 /* Add any required traditional-core-file-handler. */
559
560 #ifdef AIX386_CORE
561 &aix386_core_vec,
562 #endif
563 #ifdef HPUX_CORE
564 &hpux_core_vec,
565 #endif
566 #ifdef HPPABSD_CORE
567 &hppabsd_core_vec,
568 #endif
569 #ifdef IRIX_CORE
570 &irix_core_vec,
571 #endif
572 #ifdef OSF_CORE
573 &osf_core_vec,
574 #endif
575 #ifdef TRAD_CORE
576 &trad_core_vec,
577 #endif
578
579 #ifdef PTRACE_CORE
580 &ptrace_core_vec,
581 #endif
582
583 NULL /* end of list marker */
584 };
585
586 /* bfd_default_vector[0] contains either the address of the default vector,
587 if there is one, or zero if there isn't. */
588
589 bfd_target *bfd_default_vector[] = {
590 #ifdef DEFAULT_VECTOR
591 &DEFAULT_VECTOR,
592 #endif
593 NULL
594 };
595
596 /* When there is an ambiguous match, bfd_check_format_matches puts the
597 names of the matching targets in an array. This variable is the maximum
598 number of entries that the array could possibly need. */
599 CONST size_t _bfd_target_vector_entries = sizeof(bfd_target_vector)/sizeof(*bfd_target_vector);
600
601 /*
602 FUNCTION
603 bfd_find_target
604
605 SYNOPSIS
606 bfd_target *bfd_find_target(CONST char *target_name, bfd *abfd);
607
608 DESCRIPTION
609 Return a pointer to the transfer vector for the object target
610 named @var{target_name}. If @var{target_name} is <<NULL>>, choose the
611 one in the environment variable <<GNUTARGET>>; if that is null or not
612 defined, then choose the first entry in the target list.
613 Passing in the string "default" or setting the environment
614 variable to "default" will cause the first entry in the target
615 list to be returned, and "target_defaulted" will be set in the
616 BFD. This causes <<bfd_check_format>> to loop over all the
617 targets to find the one that matches the file being read.
618 */
619
620 bfd_target *
621 DEFUN(bfd_find_target,(target_name, abfd),
622 CONST char *target_name AND
623 bfd *abfd)
624 {
625 bfd_target **target;
626 extern char *getenv ();
627 CONST char *targname = (target_name ? target_name :
628 (CONST char *) getenv ("GNUTARGET"));
629
630 /* This is safe; the vector cannot be null */
631 if (targname == NULL || !strcmp (targname, "default")) {
632 abfd->target_defaulted = true;
633 return abfd->xvec = bfd_target_vector[0];
634 }
635
636 abfd->target_defaulted = false;
637
638 for (target = &bfd_target_vector[0]; *target != NULL; target++) {
639 if (!strcmp (targname, (*target)->name))
640 return abfd->xvec = *target;
641 }
642
643 bfd_set_error (bfd_error_invalid_target);
644 return NULL;
645 }
646
647
648 /*
649 FUNCTION
650 bfd_target_list
651
652 SYNOPSIS
653 CONST char **bfd_target_list(void);
654
655 DESCRIPTION
656 Return a freshly malloced NULL-terminated
657 vector of the names of all the valid BFD targets. Do not
658 modify the names.
659
660 */
661
662 CONST char **
663 DEFUN_VOID(bfd_target_list)
664 {
665 int vec_length= 0;
666 #ifdef NATIVE_HPPAHPUX_COMPILER
667 /* The native compiler on the HP9000/700 has a bug which causes it
668 to loop endlessly when compiling this file. This avoids it. */
669 volatile
670 #endif
671 bfd_target **target;
672 CONST char **name_list, **name_ptr;
673
674 for (target = &bfd_target_vector[0]; *target != NULL; target++)
675 vec_length++;
676
677 name_ptr = name_list = (CONST char **)
678 bfd_zmalloc ((vec_length + 1) * sizeof (char **));
679
680 if (name_list == NULL) {
681 bfd_set_error (bfd_error_no_memory);
682 return NULL;
683 }
684
685 for (target = &bfd_target_vector[0]; *target != NULL; target++)
686 *(name_ptr++) = (*target)->name;
687
688 return name_list;
689 }
This page took 0.046577 seconds and 5 git commands to generate.