targets.c revision 60484
133965Sjdp/* Generic target-file-type support for the BFD library.
260484Sobrien   Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000
338889Sjdp   Free Software Foundation, Inc.
433965Sjdp   Written by Cygnus Support.
533965Sjdp
633965SjdpThis file is part of BFD, the Binary File Descriptor library.
733965Sjdp
833965SjdpThis program is free software; you can redistribute it and/or modify
933965Sjdpit under the terms of the GNU General Public License as published by
1033965Sjdpthe Free Software Foundation; either version 2 of the License, or
1133965Sjdp(at your option) any later version.
1233965Sjdp
1333965SjdpThis program is distributed in the hope that it will be useful,
1433965Sjdpbut WITHOUT ANY WARRANTY; without even the implied warranty of
1533965SjdpMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1633965SjdpGNU General Public License for more details.
1733965Sjdp
1833965SjdpYou should have received a copy of the GNU General Public License
1933965Sjdpalong with this program; if not, write to the Free Software
2033965SjdpFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
2133965Sjdp
2233965Sjdp#include "bfd.h"
2333965Sjdp#include "sysdep.h"
2433965Sjdp#include "libbfd.h"
2533965Sjdp#include "fnmatch.h"
2633965Sjdp
2733965Sjdp/*
2833965SjdpSECTION
2933965Sjdp	Targets
3033965Sjdp
3133965SjdpDESCRIPTION
3233965Sjdp	Each port of BFD to a different machine requries the creation
3333965Sjdp	of a target back end. All the back end provides to the root
3433965Sjdp	part of BFD is a structure containing pointers to functions
3533965Sjdp	which perform certain low level operations on files. BFD
3633965Sjdp	translates the applications's requests through a pointer into
3733965Sjdp	calls to the back end routines.
3833965Sjdp
3933965Sjdp	When a file is opened with <<bfd_openr>>, its format and
4033965Sjdp	target are unknown. BFD uses various mechanisms to determine
4133965Sjdp	how to interpret the file. The operations performed are:
4233965Sjdp
4333965Sjdp	o Create a BFD by calling the internal routine
4433965Sjdp	<<_bfd_new_bfd>>, then call <<bfd_find_target>> with the
4533965Sjdp	target string supplied to <<bfd_openr>> and the new BFD pointer.
4633965Sjdp
4733965Sjdp	o If a null target string was provided to <<bfd_find_target>>,
4833965Sjdp	look up the environment variable <<GNUTARGET>> and use
4933965Sjdp	that as the target string.
5033965Sjdp
5133965Sjdp	o If the target string is still <<NULL>>, or the target string is
5233965Sjdp	<<default>>, then use the first item in the target vector
5333965Sjdp	as the target type, and set <<target_defaulted>> in the BFD to
5433965Sjdp	cause <<bfd_check_format>> to loop through all the targets.
5533965Sjdp	@xref{bfd_target}.  @xref{Formats}.
5633965Sjdp
5733965Sjdp	o Otherwise, inspect the elements in the target vector
5833965Sjdp	one by one, until a match on target name is found. When found,
5933965Sjdp	use it.
6033965Sjdp
6133965Sjdp	o Otherwise return the error <<bfd_error_invalid_target>> to
6233965Sjdp	<<bfd_openr>>.
6333965Sjdp
6433965Sjdp	o <<bfd_openr>> attempts to open the file using
6533965Sjdp	<<bfd_open_file>>, and returns the BFD.
6633965Sjdp
6733965Sjdp	Once the BFD has been opened and the target selected, the file
6833965Sjdp	format may be determined. This is done by calling
6933965Sjdp	<<bfd_check_format>> on the BFD with a suggested format.
7033965Sjdp	If <<target_defaulted>> has been set, each possible target
7133965Sjdp	type is tried to see if it recognizes the specified format.
7233965Sjdp	<<bfd_check_format>> returns <<true>> when the caller guesses right.
7333965Sjdp@menu
7433965Sjdp@* bfd_target::
7533965Sjdp@end menu
7633965Sjdp*/
7733965Sjdp
7833965Sjdp
7933965Sjdp/*
8033965Sjdp
8133965SjdpINODE
8233965Sjdp	bfd_target,  , Targets, Targets
8333965SjdpDOCDD
8433965SjdpSUBSECTION
8533965Sjdp	bfd_target
8633965Sjdp
8733965SjdpDESCRIPTION
8833965Sjdp	This structure contains everything that BFD knows about a
8933965Sjdp	target. It includes things like its byte order, name, and which
9033965Sjdp	routines to call to do various operations.
9133965Sjdp
9233965Sjdp	Every BFD points to a target structure with its <<xvec>>
9333965Sjdp	member.
9433965Sjdp
9533965Sjdp	The macros below are used to dispatch to functions through the
9633965Sjdp	<<bfd_target>> vector. They are used in a number of macros further
9733965Sjdp	down in @file{bfd.h}, and are also used when calling various
9833965Sjdp	routines by hand inside the BFD implementation.  The @var{arglist}
9933965Sjdp	argument must be parenthesized; it contains all the arguments
10033965Sjdp	to the called function.
10133965Sjdp
10233965Sjdp	They make the documentation (more) unpleasant to read, so if
10333965Sjdp	someone wants to fix this and not break the above, please do.
10433965Sjdp
10533965Sjdp.#define BFD_SEND(bfd, message, arglist) \
10633965Sjdp.               ((*((bfd)->xvec->message)) arglist)
10733965Sjdp.
10833965Sjdp.#ifdef DEBUG_BFD_SEND
10933965Sjdp.#undef BFD_SEND
11033965Sjdp.#define BFD_SEND(bfd, message, arglist) \
11133965Sjdp.  (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
11233965Sjdp.    ((*((bfd)->xvec->message)) arglist) : \
11333965Sjdp.    (bfd_assert (__FILE__,__LINE__), NULL))
11433965Sjdp.#endif
11533965Sjdp
11633965Sjdp	For operations which index on the BFD format:
11733965Sjdp
11833965Sjdp.#define BFD_SEND_FMT(bfd, message, arglist) \
11933965Sjdp.            (((bfd)->xvec->message[(int)((bfd)->format)]) arglist)
12033965Sjdp.
12133965Sjdp.#ifdef DEBUG_BFD_SEND
12233965Sjdp.#undef BFD_SEND_FMT
12333965Sjdp.#define BFD_SEND_FMT(bfd, message, arglist) \
12433965Sjdp.  (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
12533965Sjdp.   (((bfd)->xvec->message[(int)((bfd)->format)]) arglist) : \
12633965Sjdp.   (bfd_assert (__FILE__,__LINE__), NULL))
12733965Sjdp.#endif
12833965Sjdp
12933965Sjdp	This is the structure which defines the type of BFD this is.  The
13033965Sjdp	<<xvec>> member of the struct <<bfd>> itself points here.  Each
13133965Sjdp	module that implements access to a different target under BFD,
13233965Sjdp	defines one of these.
13333965Sjdp
13433965Sjdp
13533965Sjdp	FIXME, these names should be rationalised with the names of
13633965Sjdp	the entry points which call them. Too bad we can't have one
13733965Sjdp	macro to define them both!
13833965Sjdp
13933965Sjdp.enum bfd_flavour {
14033965Sjdp.  bfd_target_unknown_flavour,
14133965Sjdp.  bfd_target_aout_flavour,
14233965Sjdp.  bfd_target_coff_flavour,
14333965Sjdp.  bfd_target_ecoff_flavour,
14433965Sjdp.  bfd_target_elf_flavour,
14533965Sjdp.  bfd_target_ieee_flavour,
14633965Sjdp.  bfd_target_nlm_flavour,
14733965Sjdp.  bfd_target_oasys_flavour,
14833965Sjdp.  bfd_target_tekhex_flavour,
14933965Sjdp.  bfd_target_srec_flavour,
15033965Sjdp.  bfd_target_ihex_flavour,
15133965Sjdp.  bfd_target_som_flavour,
15233965Sjdp.  bfd_target_os9k_flavour,
15333965Sjdp.  bfd_target_versados_flavour,
15433965Sjdp.  bfd_target_msdos_flavour,
15560484Sobrien.  bfd_target_ovax_flavour,
15633965Sjdp.  bfd_target_evax_flavour
15733965Sjdp.};
15833965Sjdp.
15933965Sjdp.enum bfd_endian { BFD_ENDIAN_BIG, BFD_ENDIAN_LITTLE, BFD_ENDIAN_UNKNOWN };
16033965Sjdp.
16133965Sjdp.{* Forward declaration.  *}
16233965Sjdp.typedef struct bfd_link_info _bfd_link_info;
16333965Sjdp.
16433965Sjdp.typedef struct bfd_target
16533965Sjdp.{
16633965Sjdp
16733965SjdpIdentifies the kind of target, e.g., SunOS4, Ultrix, etc.
16833965Sjdp
16933965Sjdp.  char *name;
17033965Sjdp
17133965SjdpThe "flavour" of a back end is a general indication about the contents
17233965Sjdpof a file.
17333965Sjdp
17433965Sjdp.  enum bfd_flavour flavour;
17533965Sjdp
17633965SjdpThe order of bytes within the data area of a file.
17733965Sjdp
17833965Sjdp.  enum bfd_endian byteorder;
17933965Sjdp
18033965SjdpThe order of bytes within the header parts of a file.
18133965Sjdp
18233965Sjdp.  enum bfd_endian header_byteorder;
18333965Sjdp
18433965SjdpA mask of all the flags which an executable may have set -
18533965Sjdpfrom the set <<BFD_NO_FLAGS>>, <<HAS_RELOC>>, ...<<D_PAGED>>.
18633965Sjdp
18733965Sjdp.  flagword object_flags;
18833965Sjdp
18933965SjdpA mask of all the flags which a section may have set - from
19033965Sjdpthe set <<SEC_NO_FLAGS>>, <<SEC_ALLOC>>, ...<<SET_NEVER_LOAD>>.
19133965Sjdp
19233965Sjdp.  flagword section_flags;
19333965Sjdp
19433965SjdpThe character normally found at the front of a symbol
19533965Sjdp(if any), perhaps `_'.
19633965Sjdp
19733965Sjdp.  char symbol_leading_char;
19833965Sjdp
19933965SjdpThe pad character for file names within an archive header.
20033965Sjdp
20133965Sjdp.  char ar_pad_char;
20233965Sjdp
20333965SjdpThe maximum number of characters in an archive header.
20433965Sjdp
20533965Sjdp.  unsigned short ar_max_namelen;
20633965Sjdp
20733965SjdpEntries for byte swapping for data. These are different from the other
20833965Sjdpentry points, since they don't take a BFD asthe first argument.
20933965SjdpCertain other handlers could do the same.
21033965Sjdp
21133965Sjdp.  bfd_vma      (*bfd_getx64) PARAMS ((const bfd_byte *));
21233965Sjdp.  bfd_signed_vma (*bfd_getx_signed_64) PARAMS ((const bfd_byte *));
21333965Sjdp.  void         (*bfd_putx64) PARAMS ((bfd_vma, bfd_byte *));
21433965Sjdp.  bfd_vma      (*bfd_getx32) PARAMS ((const bfd_byte *));
21533965Sjdp.  bfd_signed_vma (*bfd_getx_signed_32) PARAMS ((const bfd_byte *));
21633965Sjdp.  void         (*bfd_putx32) PARAMS ((bfd_vma, bfd_byte *));
21733965Sjdp.  bfd_vma      (*bfd_getx16) PARAMS ((const bfd_byte *));
21833965Sjdp.  bfd_signed_vma (*bfd_getx_signed_16) PARAMS ((const bfd_byte *));
21933965Sjdp.  void         (*bfd_putx16) PARAMS ((bfd_vma, bfd_byte *));
22033965Sjdp
22133965SjdpByte swapping for the headers
22233965Sjdp
22333965Sjdp.  bfd_vma      (*bfd_h_getx64) PARAMS ((const bfd_byte *));
22433965Sjdp.  bfd_signed_vma (*bfd_h_getx_signed_64) PARAMS ((const bfd_byte *));
22533965Sjdp.  void         (*bfd_h_putx64) PARAMS ((bfd_vma, bfd_byte *));
22633965Sjdp.  bfd_vma      (*bfd_h_getx32) PARAMS ((const bfd_byte *));
22733965Sjdp.  bfd_signed_vma (*bfd_h_getx_signed_32) PARAMS ((const bfd_byte *));
22833965Sjdp.  void         (*bfd_h_putx32) PARAMS ((bfd_vma, bfd_byte *));
22933965Sjdp.  bfd_vma      (*bfd_h_getx16) PARAMS ((const bfd_byte *));
23033965Sjdp.  bfd_signed_vma (*bfd_h_getx_signed_16) PARAMS ((const bfd_byte *));
23133965Sjdp.  void         (*bfd_h_putx16) PARAMS ((bfd_vma, bfd_byte *));
23233965Sjdp
23333965SjdpFormat dependent routines: these are vectors of entry points
23433965Sjdpwithin the target vector structure, one for each format to check.
23533965Sjdp
23633965SjdpCheck the format of a file being read.  Return a <<bfd_target *>> or zero.
23733965Sjdp
23833965Sjdp.  const struct bfd_target *(*_bfd_check_format[bfd_type_end]) PARAMS ((bfd *));
23933965Sjdp
24033965SjdpSet the format of a file being written.
24133965Sjdp
24233965Sjdp.  boolean             (*_bfd_set_format[bfd_type_end]) PARAMS ((bfd *));
24333965Sjdp
24433965SjdpWrite cached information into a file being written, at <<bfd_close>>.
24533965Sjdp
24633965Sjdp.  boolean             (*_bfd_write_contents[bfd_type_end]) PARAMS ((bfd *));
24733965Sjdp
24860484SobrienThe general target vector.  These vectors are initialized using the
24960484SobrienBFD_JUMP_TABLE macros.
25033965Sjdp
25133965Sjdp.
25233965Sjdp.  {* Generic entry points.  *}
25333965Sjdp.#define BFD_JUMP_TABLE_GENERIC(NAME)\
25433965Sjdp.CAT(NAME,_close_and_cleanup),\
25533965Sjdp.CAT(NAME,_bfd_free_cached_info),\
25633965Sjdp.CAT(NAME,_new_section_hook),\
25733965Sjdp.CAT(NAME,_get_section_contents),\
25833965Sjdp.CAT(NAME,_get_section_contents_in_window)
25933965Sjdp.
26033965Sjdp.  {* Called when the BFD is being closed to do any necessary cleanup.  *}
26133965Sjdp.  boolean       (*_close_and_cleanup) PARAMS ((bfd *));
26233965Sjdp.  {* Ask the BFD to free all cached information.  *}
26333965Sjdp.  boolean (*_bfd_free_cached_info) PARAMS ((bfd *));
26433965Sjdp.  {* Called when a new section is created.  *}
26533965Sjdp.  boolean       (*_new_section_hook) PARAMS ((bfd *, sec_ptr));
26633965Sjdp.  {* Read the contents of a section.  *}
26733965Sjdp.  boolean       (*_bfd_get_section_contents) PARAMS ((bfd *, sec_ptr, PTR,
26833965Sjdp.                                            file_ptr, bfd_size_type));
26933965Sjdp.  boolean       (*_bfd_get_section_contents_in_window)
27033965Sjdp.                          PARAMS ((bfd *, sec_ptr, bfd_window *,
27133965Sjdp.                                   file_ptr, bfd_size_type));
27233965Sjdp.
27333965Sjdp.  {* Entry points to copy private data.  *}
27433965Sjdp.#define BFD_JUMP_TABLE_COPY(NAME)\
27533965Sjdp.CAT(NAME,_bfd_copy_private_bfd_data),\
27633965Sjdp.CAT(NAME,_bfd_merge_private_bfd_data),\
27733965Sjdp.CAT(NAME,_bfd_copy_private_section_data),\
27833965Sjdp.CAT(NAME,_bfd_copy_private_symbol_data),\
27933965Sjdp.CAT(NAME,_bfd_set_private_flags),\
28033965Sjdp.CAT(NAME,_bfd_print_private_bfd_data)\
28133965Sjdp.  {* Called to copy BFD general private data from one object file
28233965Sjdp.     to another.  *}
28333965Sjdp.  boolean	 (*_bfd_copy_private_bfd_data) PARAMS ((bfd *, bfd *));
28433965Sjdp.  {* Called to merge BFD general private data from one object file
28533965Sjdp.     to a common output file when linking.  *}
28633965Sjdp.  boolean	 (*_bfd_merge_private_bfd_data) PARAMS ((bfd *, bfd *));
28733965Sjdp.  {* Called to copy BFD private section data from one object file
28833965Sjdp.     to another.  *}
28933965Sjdp.  boolean       (*_bfd_copy_private_section_data) PARAMS ((bfd *, sec_ptr,
29033965Sjdp.                                                       bfd *, sec_ptr));
29133965Sjdp.  {* Called to copy BFD private symbol data from one symbol
29233965Sjdp.     to another.  *}
29333965Sjdp.  boolean       (*_bfd_copy_private_symbol_data) PARAMS ((bfd *, asymbol *,
29433965Sjdp.							   bfd *, asymbol *));
29533965Sjdp.  {* Called to set private backend flags *}
29633965Sjdp.  boolean	 (*_bfd_set_private_flags) PARAMS ((bfd *, flagword));
29733965Sjdp.
29833965Sjdp.  {* Called to print private BFD data *}
29933965Sjdp.  boolean       (*_bfd_print_private_bfd_data) PARAMS ((bfd *, PTR));
30033965Sjdp.
30133965Sjdp.  {* Core file entry points.  *}
30233965Sjdp.#define BFD_JUMP_TABLE_CORE(NAME)\
30333965Sjdp.CAT(NAME,_core_file_failing_command),\
30433965Sjdp.CAT(NAME,_core_file_failing_signal),\
30533965Sjdp.CAT(NAME,_core_file_matches_executable_p)
30633965Sjdp.  char *   (*_core_file_failing_command) PARAMS ((bfd *));
30733965Sjdp.  int      (*_core_file_failing_signal) PARAMS ((bfd *));
30833965Sjdp.  boolean  (*_core_file_matches_executable_p) PARAMS ((bfd *, bfd *));
30933965Sjdp.
31033965Sjdp.  {* Archive entry points.  *}
31133965Sjdp.#define BFD_JUMP_TABLE_ARCHIVE(NAME)\
31233965Sjdp.CAT(NAME,_slurp_armap),\
31333965Sjdp.CAT(NAME,_slurp_extended_name_table),\
31433965Sjdp.CAT(NAME,_construct_extended_name_table),\
31533965Sjdp.CAT(NAME,_truncate_arname),\
31633965Sjdp.CAT(NAME,_write_armap),\
31733965Sjdp.CAT(NAME,_read_ar_hdr),\
31833965Sjdp.CAT(NAME,_openr_next_archived_file),\
31933965Sjdp.CAT(NAME,_get_elt_at_index),\
32033965Sjdp.CAT(NAME,_generic_stat_arch_elt),\
32133965Sjdp.CAT(NAME,_update_armap_timestamp)
32233965Sjdp.  boolean  (*_bfd_slurp_armap) PARAMS ((bfd *));
32333965Sjdp.  boolean  (*_bfd_slurp_extended_name_table) PARAMS ((bfd *));
32433965Sjdp.  boolean  (*_bfd_construct_extended_name_table)
32533965Sjdp.             PARAMS ((bfd *, char **, bfd_size_type *, const char **));
32633965Sjdp.  void     (*_bfd_truncate_arname) PARAMS ((bfd *, CONST char *, char *));
32733965Sjdp.  boolean  (*write_armap) PARAMS ((bfd *arch,
32833965Sjdp.                              unsigned int elength,
32933965Sjdp.                              struct orl *map,
33033965Sjdp.                              unsigned int orl_count,
33133965Sjdp.                              int stridx));
33233965Sjdp.  PTR (*_bfd_read_ar_hdr_fn) PARAMS ((bfd *));
33333965Sjdp.  bfd *    (*openr_next_archived_file) PARAMS ((bfd *arch, bfd *prev));
33433965Sjdp.#define bfd_get_elt_at_index(b,i) BFD_SEND(b, _bfd_get_elt_at_index, (b,i))
33533965Sjdp.  bfd *    (*_bfd_get_elt_at_index) PARAMS ((bfd *, symindex));
33633965Sjdp.  int      (*_bfd_stat_arch_elt) PARAMS ((bfd *, struct stat *));
33733965Sjdp.  boolean  (*_bfd_update_armap_timestamp) PARAMS ((bfd *));
33833965Sjdp.
33933965Sjdp.  {* Entry points used for symbols.  *}
34033965Sjdp.#define BFD_JUMP_TABLE_SYMBOLS(NAME)\
34133965Sjdp.CAT(NAME,_get_symtab_upper_bound),\
34233965Sjdp.CAT(NAME,_get_symtab),\
34333965Sjdp.CAT(NAME,_make_empty_symbol),\
34433965Sjdp.CAT(NAME,_print_symbol),\
34533965Sjdp.CAT(NAME,_get_symbol_info),\
34633965Sjdp.CAT(NAME,_bfd_is_local_label_name),\
34733965Sjdp.CAT(NAME,_get_lineno),\
34833965Sjdp.CAT(NAME,_find_nearest_line),\
34933965Sjdp.CAT(NAME,_bfd_make_debug_symbol),\
35033965Sjdp.CAT(NAME,_read_minisymbols),\
35133965Sjdp.CAT(NAME,_minisymbol_to_symbol)
35233965Sjdp.  long  (*_bfd_get_symtab_upper_bound) PARAMS ((bfd *));
35333965Sjdp.  long  (*_bfd_canonicalize_symtab) PARAMS ((bfd *,
35433965Sjdp.                                             struct symbol_cache_entry **));
35533965Sjdp.  struct symbol_cache_entry  *
35633965Sjdp.                (*_bfd_make_empty_symbol) PARAMS ((bfd *));
35733965Sjdp.  void          (*_bfd_print_symbol) PARAMS ((bfd *, PTR,
35833965Sjdp.                                      struct symbol_cache_entry *,
35933965Sjdp.                                      bfd_print_symbol_type));
36033965Sjdp.#define bfd_print_symbol(b,p,s,e) BFD_SEND(b, _bfd_print_symbol, (b,p,s,e))
36133965Sjdp.  void          (*_bfd_get_symbol_info) PARAMS ((bfd *,
36233965Sjdp.                                      struct symbol_cache_entry *,
36333965Sjdp.                                      symbol_info *));
36433965Sjdp.#define bfd_get_symbol_info(b,p,e) BFD_SEND(b, _bfd_get_symbol_info, (b,p,e))
36533965Sjdp.  boolean	 (*_bfd_is_local_label_name) PARAMS ((bfd *, const char *));
36633965Sjdp.
36733965Sjdp.  alent *    (*_get_lineno) PARAMS ((bfd *, struct symbol_cache_entry *));
36833965Sjdp.  boolean    (*_bfd_find_nearest_line) PARAMS ((bfd *abfd,
36933965Sjdp.                    struct sec *section, struct symbol_cache_entry **symbols,
37033965Sjdp.                    bfd_vma offset, CONST char **file, CONST char **func,
37133965Sjdp.                    unsigned int *line));
37233965Sjdp. {* Back-door to allow format-aware applications to create debug symbols
37333965Sjdp.    while using BFD for everything else.  Currently used by the assembler
37433965Sjdp.    when creating COFF files.  *}
37533965Sjdp.  asymbol *  (*_bfd_make_debug_symbol) PARAMS ((
37633965Sjdp.       bfd *abfd,
37733965Sjdp.       void *ptr,
37833965Sjdp.       unsigned long size));
37933965Sjdp.#define bfd_read_minisymbols(b, d, m, s) \
38033965Sjdp.  BFD_SEND (b, _read_minisymbols, (b, d, m, s))
38133965Sjdp.  long  (*_read_minisymbols) PARAMS ((bfd *, boolean, PTR *,
38233965Sjdp.                                      unsigned int *));
38333965Sjdp.#define bfd_minisymbol_to_symbol(b, d, m, f) \
38433965Sjdp.  BFD_SEND (b, _minisymbol_to_symbol, (b, d, m, f))
38533965Sjdp.  asymbol *(*_minisymbol_to_symbol) PARAMS ((bfd *, boolean, const PTR,
38633965Sjdp.                                             asymbol *));
38733965Sjdp.
38833965Sjdp.  {* Routines for relocs.  *}
38933965Sjdp.#define BFD_JUMP_TABLE_RELOCS(NAME)\
39033965Sjdp.CAT(NAME,_get_reloc_upper_bound),\
39133965Sjdp.CAT(NAME,_canonicalize_reloc),\
39233965Sjdp.CAT(NAME,_bfd_reloc_type_lookup)
39333965Sjdp.  long  (*_get_reloc_upper_bound) PARAMS ((bfd *, sec_ptr));
39433965Sjdp.  long  (*_bfd_canonicalize_reloc) PARAMS ((bfd *, sec_ptr, arelent **,
39533965Sjdp.                                            struct symbol_cache_entry **));
39633965Sjdp.  {* See documentation on reloc types.  *}
39733965Sjdp.  reloc_howto_type *
39833965Sjdp.       (*reloc_type_lookup) PARAMS ((bfd *abfd,
39933965Sjdp.                                     bfd_reloc_code_real_type code));
40033965Sjdp.
40133965Sjdp.  {* Routines used when writing an object file.  *}
40233965Sjdp.#define BFD_JUMP_TABLE_WRITE(NAME)\
40333965Sjdp.CAT(NAME,_set_arch_mach),\
40433965Sjdp.CAT(NAME,_set_section_contents)
40533965Sjdp.  boolean    (*_bfd_set_arch_mach) PARAMS ((bfd *, enum bfd_architecture,
40633965Sjdp.                    unsigned long));
40733965Sjdp.  boolean       (*_bfd_set_section_contents) PARAMS ((bfd *, sec_ptr, PTR,
40833965Sjdp.                                            file_ptr, bfd_size_type));
40933965Sjdp.
41033965Sjdp.  {* Routines used by the linker.  *}
41133965Sjdp.#define BFD_JUMP_TABLE_LINK(NAME)\
41233965Sjdp.CAT(NAME,_sizeof_headers),\
41333965Sjdp.CAT(NAME,_bfd_get_relocated_section_contents),\
41433965Sjdp.CAT(NAME,_bfd_relax_section),\
41533965Sjdp.CAT(NAME,_bfd_link_hash_table_create),\
41633965Sjdp.CAT(NAME,_bfd_link_add_symbols),\
41733965Sjdp.CAT(NAME,_bfd_final_link),\
41860484Sobrien.CAT(NAME,_bfd_link_split_section),\
41960484Sobrien.CAT(NAME,_bfd_gc_sections)
42033965Sjdp.  int        (*_bfd_sizeof_headers) PARAMS ((bfd *, boolean));
42133965Sjdp.  bfd_byte * (*_bfd_get_relocated_section_contents) PARAMS ((bfd *,
42233965Sjdp.                    struct bfd_link_info *, struct bfd_link_order *,
42333965Sjdp.                    bfd_byte *data, boolean relocateable,
42433965Sjdp.                    struct symbol_cache_entry **));
42533965Sjdp.
42633965Sjdp.  boolean    (*_bfd_relax_section) PARAMS ((bfd *, struct sec *,
42733965Sjdp.                    struct bfd_link_info *, boolean *again));
42833965Sjdp.
42933965Sjdp.  {* Create a hash table for the linker.  Different backends store
43033965Sjdp.     different information in this table.  *}
43133965Sjdp.  struct bfd_link_hash_table *(*_bfd_link_hash_table_create) PARAMS ((bfd *));
43233965Sjdp.
43333965Sjdp.  {* Add symbols from this object file into the hash table.  *}
43433965Sjdp.  boolean (*_bfd_link_add_symbols) PARAMS ((bfd *, struct bfd_link_info *));
43533965Sjdp.
43633965Sjdp.  {* Do a link based on the link_order structures attached to each
43733965Sjdp.     section of the BFD.  *}
43833965Sjdp.  boolean (*_bfd_final_link) PARAMS ((bfd *, struct bfd_link_info *));
43933965Sjdp.
44033965Sjdp.  {* Should this section be split up into smaller pieces during linking.  *}
44133965Sjdp.  boolean (*_bfd_link_split_section) PARAMS ((bfd *, struct sec *));
44233965Sjdp.
44360484Sobrien.  {* Remove sections that are not referenced from the output.  *}
44460484Sobrien.  boolean (*_bfd_gc_sections) PARAMS ((bfd *, struct bfd_link_info *));
44560484Sobrien.
44660484Sobrien.  {* Routines to handle dynamic symbols and relocs.  *}
44733965Sjdp.#define BFD_JUMP_TABLE_DYNAMIC(NAME)\
44833965Sjdp.CAT(NAME,_get_dynamic_symtab_upper_bound),\
44933965Sjdp.CAT(NAME,_canonicalize_dynamic_symtab),\
45033965Sjdp.CAT(NAME,_get_dynamic_reloc_upper_bound),\
45133965Sjdp.CAT(NAME,_canonicalize_dynamic_reloc)
45233965Sjdp.  {* Get the amount of memory required to hold the dynamic symbols. *}
45333965Sjdp.  long  (*_bfd_get_dynamic_symtab_upper_bound) PARAMS ((bfd *));
45433965Sjdp.  {* Read in the dynamic symbols.  *}
45533965Sjdp.  long  (*_bfd_canonicalize_dynamic_symtab)
45633965Sjdp.    PARAMS ((bfd *, struct symbol_cache_entry **));
45733965Sjdp.  {* Get the amount of memory required to hold the dynamic relocs.  *}
45833965Sjdp.  long  (*_bfd_get_dynamic_reloc_upper_bound) PARAMS ((bfd *));
45933965Sjdp.  {* Read in the dynamic relocs.  *}
46033965Sjdp.  long  (*_bfd_canonicalize_dynamic_reloc)
46133965Sjdp.    PARAMS ((bfd *, arelent **, struct symbol_cache_entry **));
46233965Sjdp.
46333965Sjdp
46460484SobrienA pointer to an alternative bfd_target in case the current one is not
46560484Sobriensatisfactory.  This can happen when the target cpu supports both big
46660484Sobrienand little endian code, and target chosen by the linker has the wrong
46760484Sobrienendianness.  The function open_output() in ld/ldlang.c uses this field
46860484Sobriento find an alternative output format that is suitable.
46960484Sobrien
47060484Sobrien. {* Opposite endian version of this target.  *}
47160484Sobrien. const struct bfd_target * alternative_target;
47260484Sobrien.
47360484Sobrien
47433965SjdpData for use by back-end routines, which isn't generic enough to belong
47533965Sjdpin this structure.
47633965Sjdp
47733965Sjdp. PTR backend_data;
47860484Sobrien.
47933965Sjdp.} bfd_target;
48033965Sjdp
48133965Sjdp*/
48233965Sjdp
48333965Sjdp/* All known xvecs (even those that don't compile on all systems).
48433965Sjdp   Alphabetized for easy reference.
48533965Sjdp   They are listed a second time below, since
48633965Sjdp   we can't intermix extern's and initializers.  */
48733965Sjdpextern const bfd_target a29kcoff_big_vec;
48833965Sjdpextern const bfd_target a_out_adobe_vec;
48933965Sjdpextern const bfd_target aout_arm_big_vec;
49033965Sjdpextern const bfd_target aout_arm_little_vec;
49133965Sjdpextern const bfd_target aout_mips_big_vec;
49233965Sjdpextern const bfd_target aout_mips_little_vec;
49333965Sjdpextern const bfd_target aout0_big_vec;
49433965Sjdpextern const bfd_target apollocoff_vec;
49533965Sjdpextern const bfd_target armcoff_little_vec;
49633965Sjdpextern const bfd_target armcoff_big_vec;
49760484Sobrienextern const bfd_target armnetbsd_vec;
49833965Sjdpextern const bfd_target armpe_little_vec;
49933965Sjdpextern const bfd_target armpe_big_vec;
50033965Sjdpextern const bfd_target armpei_little_vec;
50133965Sjdpextern const bfd_target armpei_big_vec;
50260484Sobrienextern const bfd_target arm_epoc_pe_little_vec;
50360484Sobrienextern const bfd_target arm_epoc_pe_big_vec;
50460484Sobrienextern const bfd_target arm_epoc_pei_little_vec;
50560484Sobrienextern const bfd_target arm_epoc_pei_big_vec;
50633965Sjdpextern const bfd_target b_out_vec_big_host;
50733965Sjdpextern const bfd_target b_out_vec_little_host;
50833965Sjdpextern const bfd_target bfd_elf64_alpha_vec;
50960484Sobrienextern const bfd_target bfd_elf32_avr_vec;
51038889Sjdpextern const bfd_target bfd_elf32_bigarc_vec;
51160484Sobrienextern const bfd_target bfd_elf32_bigarm_vec;
51260484Sobrienextern const bfd_target bfd_elf32_bigarm_oabi_vec;
51338889Sjdpextern const bfd_target bfd_elf32_littlearc_vec;
51460484Sobrienextern const bfd_target bfd_elf32_littlearm_vec;
51560484Sobrienextern const bfd_target bfd_elf32_littlearm_oabi_vec;
51633965Sjdpextern const bfd_target bfd_elf32_big_generic_vec;
51733965Sjdpextern const bfd_target bfd_elf32_bigmips_vec;
51833965Sjdpextern const bfd_target bfd_elf64_bigmips_vec;
51933965Sjdpextern const bfd_target bfd_elf32_d10v_vec;
52060484Sobrienextern const bfd_target bfd_elf32_d30v_vec;
52133965Sjdpextern const bfd_target bfd_elf32_hppa_vec;
52260484Sobrienextern const bfd_target bfd_elf32_i370_vec;
52333965Sjdpextern const bfd_target bfd_elf32_i386_vec;
52433965Sjdpextern const bfd_target bfd_elf32_i860_vec;
52560484Sobrienextern const bfd_target bfd_elf32_i960_vec;
52633965Sjdpextern const bfd_target bfd_elf32_little_generic_vec;
52733965Sjdpextern const bfd_target bfd_elf32_littlemips_vec;
52833965Sjdpextern const bfd_target bfd_elf64_littlemips_vec;
52933965Sjdpextern const bfd_target bfd_elf32_m32r_vec;
53033965Sjdpextern const bfd_target bfd_elf32_m68k_vec;
53133965Sjdpextern const bfd_target bfd_elf32_m88k_vec;
53233965Sjdpextern const bfd_target bfd_elf32_mn10200_vec;
53333965Sjdpextern const bfd_target bfd_elf32_mn10300_vec;
53460484Sobrienextern const bfd_target bfd_elf32_pj_vec;
53560484Sobrienextern const bfd_target bfd_elf32_pjl_vec;
53633965Sjdpextern const bfd_target bfd_elf32_powerpc_vec;
53733965Sjdpextern const bfd_target bfd_elf32_powerpcle_vec;
53833965Sjdpextern const bfd_target bfd_elf32_sh_vec;
53933965Sjdpextern const bfd_target bfd_elf32_shl_vec;
54033965Sjdpextern const bfd_target bfd_elf32_sparc_vec;
54138889Sjdpextern const bfd_target bfd_elf32_v850_vec;
54260484Sobrienextern const bfd_target bfd_elf32_fr30_vec;
54360484Sobrienextern const bfd_target bfd_elf32_mcore_big_vec;
54460484Sobrienextern const bfd_target bfd_elf32_mcore_little_vec;
54533965Sjdpextern const bfd_target bfd_elf64_big_generic_vec;
54633965Sjdpextern const bfd_target bfd_elf64_little_generic_vec;
54733965Sjdpextern const bfd_target bfd_elf64_sparc_vec;
54833965Sjdpextern const bfd_target demo_64_vec;
54933965Sjdpextern const bfd_target ecoff_big_vec;
55033965Sjdpextern const bfd_target ecoff_little_vec;
55133965Sjdpextern const bfd_target ecoff_biglittle_vec;
55233965Sjdpextern const bfd_target ecoffalpha_little_vec;
55333965Sjdpextern const bfd_target h8300coff_vec;
55433965Sjdpextern const bfd_target h8500coff_vec;
55533965Sjdpextern const bfd_target host_aout_vec;
55633965Sjdpextern const bfd_target hp300bsd_vec;
55733965Sjdpextern const bfd_target hp300hpux_vec;
55833965Sjdpextern const bfd_target som_vec;
55933965Sjdpextern const bfd_target i386aout_vec;
56033965Sjdpextern const bfd_target i386bsd_vec;
56133965Sjdpextern const bfd_target i386dynix_vec;
56233965Sjdpextern const bfd_target i386freebsd_vec;
56333965Sjdpextern const bfd_target i386os9k_vec;
56433965Sjdpextern const bfd_target i386coff_vec;
56533965Sjdpextern const bfd_target bfd_powerpc_pe_vec;
56633965Sjdpextern const bfd_target bfd_powerpcle_pe_vec;
56733965Sjdpextern const bfd_target bfd_powerpc_pei_vec;
56833965Sjdpextern const bfd_target bfd_powerpcle_pei_vec;
56933965Sjdpextern const bfd_target i386pe_vec;
57033965Sjdpextern const bfd_target i386pei_vec;
57133965Sjdpextern const bfd_target go32coff_vec;
57238889Sjdpextern const bfd_target go32stubbedcoff_vec;
57333965Sjdpextern const bfd_target i386linux_vec;
57433965Sjdpextern const bfd_target i386lynx_aout_vec;
57533965Sjdpextern const bfd_target i386lynx_coff_vec;
57633965Sjdpextern const bfd_target i386mach3_vec;
57733965Sjdpextern const bfd_target i386msdos_vec;
57833965Sjdpextern const bfd_target i386netbsd_vec;
57933965Sjdpextern const bfd_target i860coff_vec;
58033965Sjdpextern const bfd_target icoff_big_vec;
58133965Sjdpextern const bfd_target icoff_little_vec;
58233965Sjdpextern const bfd_target ieee_vec;
58333965Sjdpextern const bfd_target m68kaux_coff_vec;
58433965Sjdpextern const bfd_target m68kcoff_vec;
58533965Sjdpextern const bfd_target m68kcoffun_vec;
58633965Sjdpextern const bfd_target m68klinux_vec;
58733965Sjdpextern const bfd_target m68klynx_aout_vec;
58833965Sjdpextern const bfd_target m68klynx_coff_vec;
58933965Sjdpextern const bfd_target m68knetbsd_vec;
59033965Sjdpextern const bfd_target m68ksysvcoff_vec;
59133965Sjdpextern const bfd_target m68k4knetbsd_vec;
59233965Sjdpextern const bfd_target m88kbcs_vec;
59333965Sjdpextern const bfd_target m88kmach3_vec;
59460484Sobrienextern const bfd_target mipslpe_vec;
59560484Sobrienextern const bfd_target mipslpei_vec;
59660484Sobrienextern const bfd_target mcore_pe_big_vec;
59760484Sobrienextern const bfd_target mcore_pe_little_vec;
59860484Sobrienextern const bfd_target mcore_pei_big_vec;
59960484Sobrienextern const bfd_target mcore_pei_little_vec;
60033965Sjdpextern const bfd_target newsos3_vec;
60133965Sjdpextern const bfd_target nlm32_i386_vec;
60233965Sjdpextern const bfd_target nlm32_sparc_vec;
60333965Sjdpextern const bfd_target nlm32_alpha_vec;
60433965Sjdpextern const bfd_target nlm32_powerpc_vec;
60533965Sjdpextern const bfd_target pc532netbsd_vec;
60633965Sjdpextern const bfd_target oasys_vec;
60733965Sjdpextern const bfd_target pc532machaout_vec;
60833965Sjdpextern const bfd_target ppcboot_vec;
60933965Sjdpextern const bfd_target riscix_vec;
61033965Sjdpextern const bfd_target pmac_xcoff_vec;
61133965Sjdpextern const bfd_target rs6000coff_vec;
61233965Sjdpextern const bfd_target shcoff_vec;
61333965Sjdpextern const bfd_target shlcoff_vec;
61438889Sjdpextern const bfd_target shcoff_small_vec;
61538889Sjdpextern const bfd_target shlcoff_small_vec;
61660484Sobrienextern const bfd_target shlpe_vec;
61760484Sobrienextern const bfd_target shlpei_vec;
61833965Sjdpextern const bfd_target sparcle_aout_vec;
61933965Sjdpextern const bfd_target sparclinux_vec;
62033965Sjdpextern const bfd_target sparclynx_aout_vec;
62133965Sjdpextern const bfd_target sparclynx_coff_vec;
62233965Sjdpextern const bfd_target sparcnetbsd_vec;
62333965Sjdpextern const bfd_target sparccoff_vec;
62433965Sjdpextern const bfd_target sunos_big_vec;
62533965Sjdpextern const bfd_target tekhex_vec;
62638889Sjdpextern const bfd_target tic30_aout_vec;
62738889Sjdpextern const bfd_target tic30_coff_vec;
62860484Sobrienextern const bfd_target tic80coff_vec;
62938889Sjdpextern const bfd_target vaxnetbsd_vec;
63033965Sjdpextern const bfd_target versados_vec;
63160484Sobrienextern const bfd_target vms_alpha_vec;
63260484Sobrienextern const bfd_target vms_vax_vec;
63333965Sjdpextern const bfd_target we32kcoff_vec;
63433965Sjdpextern const bfd_target w65_vec;
63533965Sjdpextern const bfd_target z8kcoff_vec;
63633965Sjdp
63733965Sjdp/* srec is always included.  */
63833965Sjdpextern const bfd_target srec_vec;
63933965Sjdpextern const bfd_target symbolsrec_vec;
64033965Sjdp
64133965Sjdp/* binary is always included.  */
64233965Sjdpextern const bfd_target binary_vec;
64333965Sjdp
64433965Sjdp/* ihex is always included.  */
64533965Sjdpextern const bfd_target ihex_vec;
64633965Sjdp
64733965Sjdp/* All of the xvecs for core files.  */
64833965Sjdpextern const bfd_target aix386_core_vec;
64960484Sobrienextern const bfd_target cisco_core_big_vec;
65060484Sobrienextern const bfd_target cisco_core_little_vec;
65133965Sjdpextern const bfd_target hpux_core_vec;
65233965Sjdpextern const bfd_target hppabsd_core_vec;
65333965Sjdpextern const bfd_target irix_core_vec;
65433965Sjdpextern const bfd_target netbsd_core_vec;
65533965Sjdpextern const bfd_target osf_core_vec;
65660484Sobrienextern const bfd_target sco5_core_vec;
65733965Sjdpextern const bfd_target trad_core_vec;
65833965Sjdpextern const bfd_target ptrace_core_vec;
65933965Sjdp
66033965Sjdpconst bfd_target * const bfd_target_vector[] = {
66133965Sjdp
66233965Sjdp#ifdef SELECT_VECS
66333965Sjdp
66433965Sjdp	SELECT_VECS,
66533965Sjdp
66633965Sjdp#else /* not SELECT_VECS */
66733965Sjdp
66833965Sjdp#ifdef DEFAULT_VECTOR
66933965Sjdp	&DEFAULT_VECTOR,
67033965Sjdp#endif
67133965Sjdp	/* This list is alphabetized to make it easy to compare
67233965Sjdp	   with other vector lists -- the decls above and
67333965Sjdp	   the case statement in configure.in.
67433965Sjdp	   Vectors that don't compile on all systems, or aren't finished,
67533965Sjdp	   should have an entry here with #if 0 around it, to show that
67633965Sjdp	   it wasn't omitted by mistake.  */
67733965Sjdp	&a29kcoff_big_vec,
67833965Sjdp	&a_out_adobe_vec,
67933965Sjdp#if 0				/* No one seems to use this.  */
68033965Sjdp	&aout_mips_big_vec,
68133965Sjdp#endif
68233965Sjdp	&aout_mips_little_vec,
68333965Sjdp	&b_out_vec_big_host,
68433965Sjdp	&b_out_vec_little_host,
68533965Sjdp
68633965Sjdp	/* This, and other vectors, may not be used in any *.mt configuration.
68733965Sjdp	   But that does not mean they are unnecessary.  If configured with
68833965Sjdp	   --enable-targets=all, objdump or gdb should be able to examine
68933965Sjdp	   the file even if we don't recognize the machine type.  */
69033965Sjdp	&bfd_elf32_big_generic_vec,
69133965Sjdp#ifdef BFD64
69233965Sjdp	&bfd_elf64_alpha_vec,
69333965Sjdp#endif
69460484Sobrien	&bfd_elf32_avr_vec,
69538889Sjdp	&bfd_elf32_bigarc_vec,
69660484Sobrien        &bfd_elf32_bigarm_vec,
69760484Sobrien        &bfd_elf32_bigarm_oabi_vec,
69833965Sjdp	&bfd_elf32_bigmips_vec,
69933965Sjdp#ifdef BFD64
70033965Sjdp	&bfd_elf64_bigmips_vec,
70133965Sjdp#endif
70233965Sjdp	&bfd_elf32_d10v_vec,
70360484Sobrien	&bfd_elf32_d30v_vec,
70460484Sobrien#if 0
70533965Sjdp	&bfd_elf32_hppa_vec,
70660484Sobrien#endif
70760484Sobrien	&bfd_elf32_i370_vec,
70833965Sjdp	&bfd_elf32_i386_vec,
70933965Sjdp	&bfd_elf32_i860_vec,
71060484Sobrien	&bfd_elf32_i960_vec,
71133965Sjdp	&bfd_elf32_little_generic_vec,
71238889Sjdp	&bfd_elf32_littlearc_vec,
71360484Sobrien        &bfd_elf32_littlearm_vec,
71460484Sobrien        &bfd_elf32_littlearm_oabi_vec,
71533965Sjdp	&bfd_elf32_littlemips_vec,
71633965Sjdp#ifdef BFD64
71733965Sjdp	&bfd_elf64_littlemips_vec,
71833965Sjdp#endif
71933965Sjdp	&bfd_elf32_m32r_vec,
72033965Sjdp	&bfd_elf32_mn10200_vec,
72133965Sjdp	&bfd_elf32_mn10300_vec,
72233965Sjdp	&bfd_elf32_m68k_vec,
72333965Sjdp	&bfd_elf32_m88k_vec,
72433965Sjdp	&bfd_elf32_sparc_vec,
72560484Sobrien	&bfd_elf32_pj_vec,
72660484Sobrien	&bfd_elf32_pjl_vec,
72733965Sjdp	&bfd_elf32_powerpc_vec,
72838889Sjdp	&bfd_elf32_powerpcle_vec,
72938889Sjdp	&bfd_elf32_v850_vec,
73060484Sobrien	&bfd_elf32_fr30_vec,
73160484Sobrien	&bfd_elf32_mcore_big_vec,
73260484Sobrien	&bfd_elf32_mcore_little_vec,
73333965Sjdp#ifdef BFD64			/* No one seems to use this.  */
73433965Sjdp	&bfd_elf64_big_generic_vec,
73533965Sjdp	&bfd_elf64_little_generic_vec,
73633965Sjdp#endif
73733965Sjdp#if 0
73833965Sjdp	&bfd_elf64_sparc_vec,
73933965Sjdp#endif
74060484Sobrien	/* We don't include cisco_core_*_vec.  Although it has a magic number,
74133965Sjdp	   the magic number isn't at the beginning of the file, and thus
74233965Sjdp	   might spuriously match other kinds of files.  */
74333965Sjdp#ifdef BFD64
74433965Sjdp	&demo_64_vec,	/* Only compiled if host has long-long support */
74533965Sjdp#endif
74633965Sjdp	&ecoff_big_vec,
74733965Sjdp	&ecoff_little_vec,
74833965Sjdp	&ecoff_biglittle_vec,
74933965Sjdp#ifdef BFD64
75033965Sjdp	&ecoffalpha_little_vec,
75133965Sjdp#endif
75233965Sjdp	&h8300coff_vec,
75333965Sjdp	&h8500coff_vec,
75433965Sjdp#if 0
75533965Sjdp	/* Since a.out files lack decent magic numbers, no way to recognize
75633965Sjdp	   which kind of a.out file it is.  */
75733965Sjdp	&host_aout_vec,
75833965Sjdp#endif
75933965Sjdp#if 0				/* Clashes with sunos_big_vec magic no.  */
76033965Sjdp	&hp300bsd_vec,
76133965Sjdp#endif
76233965Sjdp	&hp300hpux_vec,
76333965Sjdp#if defined (HOST_HPPAHPUX) || defined (HOST_HPPABSD) || defined (HOST_HPPAOSF)
76433965Sjdp        &som_vec,
76533965Sjdp#endif
76633965Sjdp	&i386aout_vec,
76733965Sjdp	&i386bsd_vec,
76833965Sjdp	&i386coff_vec,
76933965Sjdp	&i386freebsd_vec,
77033965Sjdp	&i860coff_vec,
77133965Sjdp	&bfd_powerpc_pe_vec,
77233965Sjdp	&bfd_powerpcle_pe_vec,
77333965Sjdp	&bfd_powerpc_pei_vec,
77433965Sjdp	&bfd_powerpcle_pei_vec,
77533965Sjdp	&go32coff_vec,
77638889Sjdp	&go32stubbedcoff_vec,
77733965Sjdp#if 0
77833965Sjdp	/* Since a.out files lack decent magic numbers, no way to recognize
77933965Sjdp	   which kind of a.out file it is.  */
78033965Sjdp	&i386linux_vec,
78133965Sjdp#endif
78233965Sjdp	&i386lynx_aout_vec,
78333965Sjdp	&i386lynx_coff_vec,
78433965Sjdp#if 0
78533965Sjdp	/* No distinguishing features for Mach 3 executables.  */
78633965Sjdp	&i386mach3_vec,
78733965Sjdp#endif
78833965Sjdp	&i386msdos_vec,
78933965Sjdp	&i386netbsd_vec,
79033965Sjdp	&i386os9k_vec,
79133965Sjdp	&i386pe_vec,
79233965Sjdp	&i386pei_vec,
79333965Sjdp	&armcoff_little_vec,
79433965Sjdp	&armcoff_big_vec,
79560484Sobrien	&armnetbsd_vec,
79633965Sjdp	&armpe_little_vec,
79733965Sjdp	&armpe_big_vec,
79833965Sjdp	&armpei_little_vec,
79933965Sjdp	&armpei_big_vec,
80060484Sobrien	&arm_epoc_pe_little_vec,
80160484Sobrien	&arm_epoc_pe_big_vec,
80260484Sobrien	&arm_epoc_pei_little_vec,
80360484Sobrien	&arm_epoc_pei_big_vec,
80433965Sjdp	&icoff_big_vec,
80533965Sjdp	&icoff_little_vec,
80633965Sjdp	&ieee_vec,
80733965Sjdp	&m68kcoff_vec,
80833965Sjdp	&m68kcoffun_vec,
80933965Sjdp#if 0
81033965Sjdp	/* Since a.out files lack decent magic numbers, no way to recognize
81133965Sjdp	   which kind of a.out file it is.  */
81233965Sjdp	&m68klinux_vec,
81333965Sjdp#endif
81433965Sjdp	&m68klynx_aout_vec,
81533965Sjdp	&m68klynx_coff_vec,
81633965Sjdp	&m68knetbsd_vec,
81733965Sjdp	&m68ksysvcoff_vec,
81833965Sjdp	&m88kbcs_vec,
81933965Sjdp	&m88kmach3_vec,
82060484Sobrien	&mcore_pe_big_vec,
82160484Sobrien	&mcore_pe_little_vec,
82260484Sobrien	&mcore_pei_big_vec,
82360484Sobrien	&mcore_pei_little_vec,
82433965Sjdp	&newsos3_vec,
82533965Sjdp	&nlm32_i386_vec,
82633965Sjdp	&nlm32_sparc_vec,
82733965Sjdp#ifdef BFD64
82833965Sjdp	&nlm32_alpha_vec,
82933965Sjdp#endif
83033965Sjdp	&pc532netbsd_vec,
83133965Sjdp#if 0
83233965Sjdp	/* We have no oasys tools anymore, so we can't test any of this
83333965Sjdp	   anymore. If you want to test the stuff yourself, go ahead...
83433965Sjdp	   steve@cygnus.com
83533965Sjdp	   Worse, since there is no magic number for archives, there
83633965Sjdp	   can be annoying target mis-matches.  */
83733965Sjdp	&oasys_vec,
83833965Sjdp#endif
83933965Sjdp	&pc532machaout_vec,
84033965Sjdp#if 0
84133965Sjdp	/* We have no way of distinguishing these from other a.out variants */
84233965Sjdp	&aout_arm_big_vec,
84333965Sjdp	&aout_arm_little_vec,
84433965Sjdp	&riscix_vec,
84533965Sjdp#endif
84633965Sjdp#if 0
84733965Sjdp	/* This has the same magic number as RS/6000. */
84833965Sjdp	&pmac_xcoff_vec,
84933965Sjdp#endif
85033965Sjdp	&rs6000coff_vec,
85133965Sjdp	&ppcboot_vec,
85233965Sjdp	&shcoff_vec,
85333965Sjdp	&shlcoff_vec,
85438889Sjdp	&shcoff_small_vec,
85538889Sjdp	&shlcoff_small_vec,
85633965Sjdp	&sparcle_aout_vec,
85733965Sjdp	&sparclinux_vec,
85833965Sjdp	&sparclynx_aout_vec,
85933965Sjdp	&sparclynx_coff_vec,
86033965Sjdp	&sparcnetbsd_vec,
86133965Sjdp	&sunos_big_vec,
86233965Sjdp	&aout0_big_vec,
86338889Sjdp	&tic30_aout_vec,
86438889Sjdp	&tic30_coff_vec,
86560484Sobrien	&tic80coff_vec,
86638889Sjdp	&vaxnetbsd_vec,
86738889Sjdp	&versados_vec,
86860484Sobrien#ifdef BFD64
86960484Sobrien	&vms_alpha_vec,
87060484Sobrien#endif
87160484Sobrien	&vms_vax_vec,
87233965Sjdp	&we32kcoff_vec,
87333965Sjdp	&z8kcoff_vec,
87433965Sjdp
87533965Sjdp#endif /* not SELECT_VECS */
87633965Sjdp
87733965Sjdp/* Always support S-records, for convenience.  */
87833965Sjdp	&srec_vec,
87933965Sjdp	&symbolsrec_vec,
88033965Sjdp/* And tekhex */
88133965Sjdp	&tekhex_vec,
88233965Sjdp/* Likewise for binary output.  */
88333965Sjdp	&binary_vec,
88433965Sjdp/* Likewise for ihex.  */
88533965Sjdp	&ihex_vec,
88633965Sjdp
88733965Sjdp/* Add any required traditional-core-file-handler.  */
88833965Sjdp
88933965Sjdp#ifdef AIX386_CORE
89033965Sjdp	&aix386_core_vec,
89133965Sjdp#endif
89233965Sjdp#ifdef HPUX_CORE
89333965Sjdp	&hpux_core_vec,
89433965Sjdp#endif
89533965Sjdp#ifdef HPPABSD_CORE
89633965Sjdp	&hppabsd_core_vec,
89733965Sjdp#endif
89833965Sjdp#ifdef IRIX_CORE
89933965Sjdp	&irix_core_vec,
90033965Sjdp#endif
90138889Sjdp#ifdef NETBSD_CORE
90238889Sjdp	&netbsd_core_vec,
90338889Sjdp#endif
90433965Sjdp#ifdef OSF_CORE
90533965Sjdp	&osf_core_vec,
90633965Sjdp#endif
90760484Sobrien#ifdef SCO5_CORE
90860484Sobrien	&sco5_core_vec,
90960484Sobrien#endif
91033965Sjdp#ifdef	TRAD_CORE
91133965Sjdp	&trad_core_vec,
91233965Sjdp#endif
91333965Sjdp
91433965Sjdp#ifdef	PTRACE_CORE
91533965Sjdp	&ptrace_core_vec,
91633965Sjdp#endif
91733965Sjdp
91833965Sjdp	NULL /* end of list marker */
91933965Sjdp};
92033965Sjdp
92133965Sjdp/* bfd_default_vector[0] contains either the address of the default vector,
92233965Sjdp   if there is one, or zero if there isn't.  */
92333965Sjdp
92433965Sjdpconst bfd_target *bfd_default_vector[] = {
92533965Sjdp#ifdef DEFAULT_VECTOR
92633965Sjdp	&DEFAULT_VECTOR,
92733965Sjdp#endif
92833965Sjdp	NULL
92933965Sjdp};
93033965Sjdp
93133965Sjdp/* When there is an ambiguous match, bfd_check_format_matches puts the
93233965Sjdp   names of the matching targets in an array.  This variable is the maximum
93333965Sjdp   number of entries that the array could possibly need.  */
93433965Sjdpconst size_t _bfd_target_vector_entries = sizeof(bfd_target_vector)/sizeof(*bfd_target_vector);
93533965Sjdp
93633965Sjdp/* This array maps configuration triplets onto BFD vectors.  */
93733965Sjdp
93833965Sjdpstruct targmatch
93933965Sjdp{
94033965Sjdp  /* The configuration triplet.  */
94133965Sjdp  const char *triplet;
94233965Sjdp  /* The BFD vector.  If this is NULL, then the vector is found by
94333965Sjdp     searching forward for the next structure with a non NULL vector
94433965Sjdp     field.  */
94533965Sjdp  const bfd_target *vector;
94633965Sjdp};
94733965Sjdp
94833965Sjdp/* targmatch.h is built by Makefile out of config.bfd.  */
94933965Sjdpstatic const struct targmatch bfd_target_match[] = {
95033965Sjdp#include "targmatch.h"
95133965Sjdp  { NULL, NULL }
95233965Sjdp};
95333965Sjdp
95433965Sjdpstatic const bfd_target *find_target PARAMS ((const char *));
95533965Sjdp
95633965Sjdp/* Find a target vector, given a name or configuration triplet.  */
95733965Sjdp
95833965Sjdpstatic const bfd_target *
95933965Sjdpfind_target (name)
96033965Sjdp     const char *name;
96133965Sjdp{
96233965Sjdp  const bfd_target * const *target;
96333965Sjdp  const struct targmatch *match;
96433965Sjdp
96533965Sjdp  for (target = &bfd_target_vector[0]; *target != NULL; target++)
96633965Sjdp    if (strcmp (name, (*target)->name) == 0)
96733965Sjdp      return *target;
96833965Sjdp
96933965Sjdp  /* If we couldn't match on the exact name, try matching on the
97033965Sjdp     configuration triplet.  FIXME: We should run the triplet through
97133965Sjdp     config.sub first, but that is hard.  */
97233965Sjdp  for (match = &bfd_target_match[0]; match->triplet != NULL; match++)
97333965Sjdp    {
97433965Sjdp      if (fnmatch (match->triplet, name, 0) == 0)
97533965Sjdp	{
97633965Sjdp	  while (match->vector == NULL)
97733965Sjdp	    ++match;
97833965Sjdp	  return match->vector;
97933965Sjdp	  break;
98033965Sjdp	}
98133965Sjdp    }
98233965Sjdp
98333965Sjdp  bfd_set_error (bfd_error_invalid_target);
98433965Sjdp  return NULL;
98533965Sjdp}
98633965Sjdp
98733965Sjdp/*
98833965SjdpFUNCTION
98933965Sjdp	bfd_set_default_target
99033965Sjdp
99133965SjdpSYNOPSIS
99233965Sjdp	boolean bfd_set_default_target (const char *name);
99333965Sjdp
99433965SjdpDESCRIPTION
99533965Sjdp	Set the default target vector to use when recognizing a BFD.
99633965Sjdp	This takes the name of the target, which may be a BFD target
99733965Sjdp	name or a configuration triplet.
99833965Sjdp*/
99933965Sjdp
100033965Sjdpboolean
100133965Sjdpbfd_set_default_target (name)
100233965Sjdp     const char *name;
100333965Sjdp{
100433965Sjdp  const bfd_target *target;
100533965Sjdp
100633965Sjdp  if (bfd_default_vector[0] != NULL
100733965Sjdp      && strcmp (name, bfd_default_vector[0]->name) == 0)
100833965Sjdp    return true;
100933965Sjdp
101033965Sjdp  target = find_target (name);
101133965Sjdp  if (target == NULL)
101233965Sjdp    return false;
101333965Sjdp
101433965Sjdp  bfd_default_vector[0] = target;
101533965Sjdp  return true;
101633965Sjdp}
101733965Sjdp
101833965Sjdp/*
101933965SjdpFUNCTION
102033965Sjdp	bfd_find_target
102133965Sjdp
102233965SjdpSYNOPSIS
102333965Sjdp	const bfd_target *bfd_find_target(CONST char *target_name, bfd *abfd);
102433965Sjdp
102533965SjdpDESCRIPTION
102633965Sjdp	Return a pointer to the transfer vector for the object target
102733965Sjdp	named @var{target_name}.  If @var{target_name} is <<NULL>>, choose the
102833965Sjdp	one in the environment variable <<GNUTARGET>>; if that is null or not
102933965Sjdp	defined, then choose the first entry in the target list.
103033965Sjdp	Passing in the string "default" or setting the environment
103133965Sjdp	variable to "default" will cause the first entry in the target
103233965Sjdp	list to be returned, and "target_defaulted" will be set in the
103333965Sjdp	BFD.  This causes <<bfd_check_format>> to loop over all the
103433965Sjdp	targets to find the one that matches the file being read.
103533965Sjdp*/
103633965Sjdp
103733965Sjdpconst bfd_target *
103833965Sjdpbfd_find_target (target_name, abfd)
103933965Sjdp     const char *target_name;
104033965Sjdp     bfd *abfd;
104133965Sjdp{
104233965Sjdp  const char *targname;
104333965Sjdp  const bfd_target *target;
104433965Sjdp
104533965Sjdp  if (target_name != NULL)
104633965Sjdp    targname = target_name;
104733965Sjdp  else
104833965Sjdp    targname = getenv ("GNUTARGET");
104933965Sjdp
105033965Sjdp  /* This is safe; the vector cannot be null */
105133965Sjdp  if (targname == NULL || strcmp (targname, "default") == 0)
105233965Sjdp    {
105333965Sjdp      abfd->target_defaulted = true;
105433965Sjdp      if (bfd_default_vector[0] != NULL)
105533965Sjdp	abfd->xvec = bfd_default_vector[0];
105633965Sjdp      else
105733965Sjdp	abfd->xvec = bfd_target_vector[0];
105833965Sjdp      return abfd->xvec;
105933965Sjdp    }
106033965Sjdp
106133965Sjdp  abfd->target_defaulted = false;
106233965Sjdp
106333965Sjdp  target = find_target (targname);
106433965Sjdp  if (target == NULL)
106533965Sjdp    return NULL;
106633965Sjdp
106733965Sjdp  abfd->xvec = target;
106833965Sjdp  return target;
106933965Sjdp}
107033965Sjdp
107133965Sjdp/*
107233965SjdpFUNCTION
107333965Sjdp	bfd_target_list
107433965Sjdp
107533965SjdpSYNOPSIS
107633965Sjdp	const char **bfd_target_list(void);
107733965Sjdp
107833965SjdpDESCRIPTION
107933965Sjdp	Return a freshly malloced NULL-terminated
108033965Sjdp	vector of the names of all the valid BFD targets. Do not
108133965Sjdp	modify the names.
108233965Sjdp
108333965Sjdp*/
108433965Sjdp
108533965Sjdpconst char **
108633965Sjdpbfd_target_list ()
108733965Sjdp{
108833965Sjdp  int vec_length= 0;
108933965Sjdp#if defined (HOST_HPPAHPUX) && ! defined (__STDC__)
109033965Sjdp  /* The native compiler on the HP9000/700 has a bug which causes it
109133965Sjdp     to loop endlessly when compiling this file.  This avoids it.  */
109233965Sjdp  volatile
109333965Sjdp#endif
109433965Sjdp    const bfd_target * const *target;
109533965Sjdp  CONST  char **name_list, **name_ptr;
109633965Sjdp
109733965Sjdp  for (target = &bfd_target_vector[0]; *target != NULL; target++)
109833965Sjdp    vec_length++;
109933965Sjdp
110033965Sjdp  name_ptr = name_list = (CONST char **)
110133965Sjdp    bfd_zmalloc ((vec_length + 1) * sizeof (char **));
110233965Sjdp
110333965Sjdp  if (name_list == NULL)
110433965Sjdp    return NULL;
110533965Sjdp
110633965Sjdp  for (target = &bfd_target_vector[0]; *target != NULL; target++)
110733965Sjdp    *(name_ptr++) = (*target)->name;
110833965Sjdp
110933965Sjdp  return name_list;
111033965Sjdp}
111160484Sobrien
111260484Sobrien/*
111360484SobrienFUNCTION
111460484Sobrien	bfd_seach_for_target
111560484Sobrien
111660484SobrienSYNOPSIS
111760484Sobrien	const bfd_target * bfd_search_for_target (int (* search_func)(const bfd_target *, void *), void *);
111860484Sobrien
111960484SobrienDESCRIPTION
112060484Sobrien	Return a pointer to the first transfer vector in the list of
112160484Sobrien	transfer vectors maintained by BFD that produces a non-zero
112260484Sobrien	result when passed to the function @var{search_func}.  The
112360484Sobrien	parameter @var{data} is passed, unexamined, to the search
112460484Sobrien	function.
112560484Sobrien*/
112660484Sobrien
112760484Sobrienconst bfd_target *
112860484Sobrienbfd_search_for_target (search_func, data)
112960484Sobrien     int (* search_func) PARAMS ((const bfd_target * target, void * data));
113060484Sobrien     void * data;
113160484Sobrien{
113260484Sobrien  const bfd_target * const * target;
113360484Sobrien
113460484Sobrien  for (target = bfd_target_vector; * target != NULL; target ++)
113560484Sobrien    if (search_func (* target, data))
113660484Sobrien      return * target;
113760484Sobrien
113860484Sobrien  return NULL;
113960484Sobrien}
1140