targets.c revision 38889
133965Sjdp/* Generic target-file-type support for the BFD library.
238889Sjdp   Copyright 1990, 91, 92, 93, 94, 95, 96, 97, 1998
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,
15533965Sjdp.  bfd_target_evax_flavour
15633965Sjdp.};
15733965Sjdp.
15833965Sjdp.enum bfd_endian { BFD_ENDIAN_BIG, BFD_ENDIAN_LITTLE, BFD_ENDIAN_UNKNOWN };
15933965Sjdp.
16033965Sjdp.{* Forward declaration.  *}
16133965Sjdp.typedef struct bfd_link_info _bfd_link_info;
16233965Sjdp.
16333965Sjdp.typedef struct bfd_target
16433965Sjdp.{
16533965Sjdp
16633965SjdpIdentifies the kind of target, e.g., SunOS4, Ultrix, etc.
16733965Sjdp
16833965Sjdp.  char *name;
16933965Sjdp
17033965SjdpThe "flavour" of a back end is a general indication about the contents
17133965Sjdpof a file.
17233965Sjdp
17333965Sjdp.  enum bfd_flavour flavour;
17433965Sjdp
17533965SjdpThe order of bytes within the data area of a file.
17633965Sjdp
17733965Sjdp.  enum bfd_endian byteorder;
17833965Sjdp
17933965SjdpThe order of bytes within the header parts of a file.
18033965Sjdp
18133965Sjdp.  enum bfd_endian header_byteorder;
18233965Sjdp
18333965SjdpA mask of all the flags which an executable may have set -
18433965Sjdpfrom the set <<BFD_NO_FLAGS>>, <<HAS_RELOC>>, ...<<D_PAGED>>.
18533965Sjdp
18633965Sjdp.  flagword object_flags;
18733965Sjdp
18833965SjdpA mask of all the flags which a section may have set - from
18933965Sjdpthe set <<SEC_NO_FLAGS>>, <<SEC_ALLOC>>, ...<<SET_NEVER_LOAD>>.
19033965Sjdp
19133965Sjdp.  flagword section_flags;
19233965Sjdp
19333965SjdpThe character normally found at the front of a symbol
19433965Sjdp(if any), perhaps `_'.
19533965Sjdp
19633965Sjdp.  char symbol_leading_char;
19733965Sjdp
19833965SjdpThe pad character for file names within an archive header.
19933965Sjdp
20033965Sjdp.  char ar_pad_char;
20133965Sjdp
20233965SjdpThe maximum number of characters in an archive header.
20333965Sjdp
20433965Sjdp.  unsigned short ar_max_namelen;
20533965Sjdp
20633965SjdpEntries for byte swapping for data. These are different from the other
20733965Sjdpentry points, since they don't take a BFD asthe first argument.
20833965SjdpCertain other handlers could do the same.
20933965Sjdp
21033965Sjdp.  bfd_vma      (*bfd_getx64) PARAMS ((const bfd_byte *));
21133965Sjdp.  bfd_signed_vma (*bfd_getx_signed_64) PARAMS ((const bfd_byte *));
21233965Sjdp.  void         (*bfd_putx64) PARAMS ((bfd_vma, bfd_byte *));
21333965Sjdp.  bfd_vma      (*bfd_getx32) PARAMS ((const bfd_byte *));
21433965Sjdp.  bfd_signed_vma (*bfd_getx_signed_32) PARAMS ((const bfd_byte *));
21533965Sjdp.  void         (*bfd_putx32) PARAMS ((bfd_vma, bfd_byte *));
21633965Sjdp.  bfd_vma      (*bfd_getx16) PARAMS ((const bfd_byte *));
21733965Sjdp.  bfd_signed_vma (*bfd_getx_signed_16) PARAMS ((const bfd_byte *));
21833965Sjdp.  void         (*bfd_putx16) PARAMS ((bfd_vma, bfd_byte *));
21933965Sjdp
22033965SjdpByte swapping for the headers
22133965Sjdp
22233965Sjdp.  bfd_vma      (*bfd_h_getx64) PARAMS ((const bfd_byte *));
22333965Sjdp.  bfd_signed_vma (*bfd_h_getx_signed_64) PARAMS ((const bfd_byte *));
22433965Sjdp.  void         (*bfd_h_putx64) PARAMS ((bfd_vma, bfd_byte *));
22533965Sjdp.  bfd_vma      (*bfd_h_getx32) PARAMS ((const bfd_byte *));
22633965Sjdp.  bfd_signed_vma (*bfd_h_getx_signed_32) PARAMS ((const bfd_byte *));
22733965Sjdp.  void         (*bfd_h_putx32) PARAMS ((bfd_vma, bfd_byte *));
22833965Sjdp.  bfd_vma      (*bfd_h_getx16) PARAMS ((const bfd_byte *));
22933965Sjdp.  bfd_signed_vma (*bfd_h_getx_signed_16) PARAMS ((const bfd_byte *));
23033965Sjdp.  void         (*bfd_h_putx16) PARAMS ((bfd_vma, bfd_byte *));
23133965Sjdp
23233965SjdpFormat dependent routines: these are vectors of entry points
23333965Sjdpwithin the target vector structure, one for each format to check.
23433965Sjdp
23533965SjdpCheck the format of a file being read.  Return a <<bfd_target *>> or zero.
23633965Sjdp
23733965Sjdp.  const struct bfd_target *(*_bfd_check_format[bfd_type_end]) PARAMS ((bfd *));
23833965Sjdp
23933965SjdpSet the format of a file being written.
24033965Sjdp
24133965Sjdp.  boolean             (*_bfd_set_format[bfd_type_end]) PARAMS ((bfd *));
24233965Sjdp
24333965SjdpWrite cached information into a file being written, at <<bfd_close>>.
24433965Sjdp
24533965Sjdp.  boolean             (*_bfd_write_contents[bfd_type_end]) PARAMS ((bfd *));
24633965Sjdp
24733965SjdpThe general target vector.
24833965Sjdp
24933965Sjdp.
25033965Sjdp.  {* Generic entry points.  *}
25133965Sjdp.#define BFD_JUMP_TABLE_GENERIC(NAME)\
25233965Sjdp.CAT(NAME,_close_and_cleanup),\
25333965Sjdp.CAT(NAME,_bfd_free_cached_info),\
25433965Sjdp.CAT(NAME,_new_section_hook),\
25533965Sjdp.CAT(NAME,_get_section_contents),\
25633965Sjdp.CAT(NAME,_get_section_contents_in_window)
25733965Sjdp.
25833965Sjdp.  {* Called when the BFD is being closed to do any necessary cleanup.  *}
25933965Sjdp.  boolean       (*_close_and_cleanup) PARAMS ((bfd *));
26033965Sjdp.  {* Ask the BFD to free all cached information.  *}
26133965Sjdp.  boolean (*_bfd_free_cached_info) PARAMS ((bfd *));
26233965Sjdp.  {* Called when a new section is created.  *}
26333965Sjdp.  boolean       (*_new_section_hook) PARAMS ((bfd *, sec_ptr));
26433965Sjdp.  {* Read the contents of a section.  *}
26533965Sjdp.  boolean       (*_bfd_get_section_contents) PARAMS ((bfd *, sec_ptr, PTR,
26633965Sjdp.                                            file_ptr, bfd_size_type));
26733965Sjdp.  boolean       (*_bfd_get_section_contents_in_window)
26833965Sjdp.                          PARAMS ((bfd *, sec_ptr, bfd_window *,
26933965Sjdp.                                   file_ptr, bfd_size_type));
27033965Sjdp.
27133965Sjdp.  {* Entry points to copy private data.  *}
27233965Sjdp.#define BFD_JUMP_TABLE_COPY(NAME)\
27333965Sjdp.CAT(NAME,_bfd_copy_private_bfd_data),\
27433965Sjdp.CAT(NAME,_bfd_merge_private_bfd_data),\
27533965Sjdp.CAT(NAME,_bfd_copy_private_section_data),\
27633965Sjdp.CAT(NAME,_bfd_copy_private_symbol_data),\
27733965Sjdp.CAT(NAME,_bfd_set_private_flags),\
27833965Sjdp.CAT(NAME,_bfd_print_private_bfd_data)\
27933965Sjdp.  {* Called to copy BFD general private data from one object file
28033965Sjdp.     to another.  *}
28133965Sjdp.  boolean	 (*_bfd_copy_private_bfd_data) PARAMS ((bfd *, bfd *));
28233965Sjdp.  {* Called to merge BFD general private data from one object file
28333965Sjdp.     to a common output file when linking.  *}
28433965Sjdp.  boolean	 (*_bfd_merge_private_bfd_data) PARAMS ((bfd *, bfd *));
28533965Sjdp.  {* Called to copy BFD private section data from one object file
28633965Sjdp.     to another.  *}
28733965Sjdp.  boolean       (*_bfd_copy_private_section_data) PARAMS ((bfd *, sec_ptr,
28833965Sjdp.                                                       bfd *, sec_ptr));
28933965Sjdp.  {* Called to copy BFD private symbol data from one symbol
29033965Sjdp.     to another.  *}
29133965Sjdp.  boolean       (*_bfd_copy_private_symbol_data) PARAMS ((bfd *, asymbol *,
29233965Sjdp.							   bfd *, asymbol *));
29333965Sjdp.  {* Called to set private backend flags *}
29433965Sjdp.  boolean	 (*_bfd_set_private_flags) PARAMS ((bfd *, flagword));
29533965Sjdp.
29633965Sjdp.  {* Called to print private BFD data *}
29733965Sjdp.  boolean       (*_bfd_print_private_bfd_data) PARAMS ((bfd *, PTR));
29833965Sjdp.
29933965Sjdp.  {* Core file entry points.  *}
30033965Sjdp.#define BFD_JUMP_TABLE_CORE(NAME)\
30133965Sjdp.CAT(NAME,_core_file_failing_command),\
30233965Sjdp.CAT(NAME,_core_file_failing_signal),\
30333965Sjdp.CAT(NAME,_core_file_matches_executable_p)
30433965Sjdp.  char *   (*_core_file_failing_command) PARAMS ((bfd *));
30533965Sjdp.  int      (*_core_file_failing_signal) PARAMS ((bfd *));
30633965Sjdp.  boolean  (*_core_file_matches_executable_p) PARAMS ((bfd *, bfd *));
30733965Sjdp.
30833965Sjdp.  {* Archive entry points.  *}
30933965Sjdp.#define BFD_JUMP_TABLE_ARCHIVE(NAME)\
31033965Sjdp.CAT(NAME,_slurp_armap),\
31133965Sjdp.CAT(NAME,_slurp_extended_name_table),\
31233965Sjdp.CAT(NAME,_construct_extended_name_table),\
31333965Sjdp.CAT(NAME,_truncate_arname),\
31433965Sjdp.CAT(NAME,_write_armap),\
31533965Sjdp.CAT(NAME,_read_ar_hdr),\
31633965Sjdp.CAT(NAME,_openr_next_archived_file),\
31733965Sjdp.CAT(NAME,_get_elt_at_index),\
31833965Sjdp.CAT(NAME,_generic_stat_arch_elt),\
31933965Sjdp.CAT(NAME,_update_armap_timestamp)
32033965Sjdp.  boolean  (*_bfd_slurp_armap) PARAMS ((bfd *));
32133965Sjdp.  boolean  (*_bfd_slurp_extended_name_table) PARAMS ((bfd *));
32233965Sjdp.  boolean  (*_bfd_construct_extended_name_table)
32333965Sjdp.             PARAMS ((bfd *, char **, bfd_size_type *, const char **));
32433965Sjdp.  void     (*_bfd_truncate_arname) PARAMS ((bfd *, CONST char *, char *));
32533965Sjdp.  boolean  (*write_armap) PARAMS ((bfd *arch,
32633965Sjdp.                              unsigned int elength,
32733965Sjdp.                              struct orl *map,
32833965Sjdp.                              unsigned int orl_count,
32933965Sjdp.                              int stridx));
33033965Sjdp.  PTR (*_bfd_read_ar_hdr_fn) PARAMS ((bfd *));
33133965Sjdp.  bfd *    (*openr_next_archived_file) PARAMS ((bfd *arch, bfd *prev));
33233965Sjdp.#define bfd_get_elt_at_index(b,i) BFD_SEND(b, _bfd_get_elt_at_index, (b,i))
33333965Sjdp.  bfd *    (*_bfd_get_elt_at_index) PARAMS ((bfd *, symindex));
33433965Sjdp.  int      (*_bfd_stat_arch_elt) PARAMS ((bfd *, struct stat *));
33533965Sjdp.  boolean  (*_bfd_update_armap_timestamp) PARAMS ((bfd *));
33633965Sjdp.
33733965Sjdp.  {* Entry points used for symbols.  *}
33833965Sjdp.#define BFD_JUMP_TABLE_SYMBOLS(NAME)\
33933965Sjdp.CAT(NAME,_get_symtab_upper_bound),\
34033965Sjdp.CAT(NAME,_get_symtab),\
34133965Sjdp.CAT(NAME,_make_empty_symbol),\
34233965Sjdp.CAT(NAME,_print_symbol),\
34333965Sjdp.CAT(NAME,_get_symbol_info),\
34433965Sjdp.CAT(NAME,_bfd_is_local_label_name),\
34533965Sjdp.CAT(NAME,_get_lineno),\
34633965Sjdp.CAT(NAME,_find_nearest_line),\
34733965Sjdp.CAT(NAME,_bfd_make_debug_symbol),\
34833965Sjdp.CAT(NAME,_read_minisymbols),\
34933965Sjdp.CAT(NAME,_minisymbol_to_symbol)
35033965Sjdp.  long  (*_bfd_get_symtab_upper_bound) PARAMS ((bfd *));
35133965Sjdp.  long  (*_bfd_canonicalize_symtab) PARAMS ((bfd *,
35233965Sjdp.                                             struct symbol_cache_entry **));
35333965Sjdp.  struct symbol_cache_entry  *
35433965Sjdp.                (*_bfd_make_empty_symbol) PARAMS ((bfd *));
35533965Sjdp.  void          (*_bfd_print_symbol) PARAMS ((bfd *, PTR,
35633965Sjdp.                                      struct symbol_cache_entry *,
35733965Sjdp.                                      bfd_print_symbol_type));
35833965Sjdp.#define bfd_print_symbol(b,p,s,e) BFD_SEND(b, _bfd_print_symbol, (b,p,s,e))
35933965Sjdp.  void          (*_bfd_get_symbol_info) PARAMS ((bfd *,
36033965Sjdp.                                      struct symbol_cache_entry *,
36133965Sjdp.                                      symbol_info *));
36233965Sjdp.#define bfd_get_symbol_info(b,p,e) BFD_SEND(b, _bfd_get_symbol_info, (b,p,e))
36333965Sjdp.  boolean	 (*_bfd_is_local_label_name) PARAMS ((bfd *, const char *));
36433965Sjdp.
36533965Sjdp.  alent *    (*_get_lineno) PARAMS ((bfd *, struct symbol_cache_entry *));
36633965Sjdp.  boolean    (*_bfd_find_nearest_line) PARAMS ((bfd *abfd,
36733965Sjdp.                    struct sec *section, struct symbol_cache_entry **symbols,
36833965Sjdp.                    bfd_vma offset, CONST char **file, CONST char **func,
36933965Sjdp.                    unsigned int *line));
37033965Sjdp. {* Back-door to allow format-aware applications to create debug symbols
37133965Sjdp.    while using BFD for everything else.  Currently used by the assembler
37233965Sjdp.    when creating COFF files.  *}
37333965Sjdp.  asymbol *  (*_bfd_make_debug_symbol) PARAMS ((
37433965Sjdp.       bfd *abfd,
37533965Sjdp.       void *ptr,
37633965Sjdp.       unsigned long size));
37733965Sjdp.#define bfd_read_minisymbols(b, d, m, s) \
37833965Sjdp.  BFD_SEND (b, _read_minisymbols, (b, d, m, s))
37933965Sjdp.  long  (*_read_minisymbols) PARAMS ((bfd *, boolean, PTR *,
38033965Sjdp.                                      unsigned int *));
38133965Sjdp.#define bfd_minisymbol_to_symbol(b, d, m, f) \
38233965Sjdp.  BFD_SEND (b, _minisymbol_to_symbol, (b, d, m, f))
38333965Sjdp.  asymbol *(*_minisymbol_to_symbol) PARAMS ((bfd *, boolean, const PTR,
38433965Sjdp.                                             asymbol *));
38533965Sjdp.
38633965Sjdp.  {* Routines for relocs.  *}
38733965Sjdp.#define BFD_JUMP_TABLE_RELOCS(NAME)\
38833965Sjdp.CAT(NAME,_get_reloc_upper_bound),\
38933965Sjdp.CAT(NAME,_canonicalize_reloc),\
39033965Sjdp.CAT(NAME,_bfd_reloc_type_lookup)
39133965Sjdp.  long  (*_get_reloc_upper_bound) PARAMS ((bfd *, sec_ptr));
39233965Sjdp.  long  (*_bfd_canonicalize_reloc) PARAMS ((bfd *, sec_ptr, arelent **,
39333965Sjdp.                                            struct symbol_cache_entry **));
39433965Sjdp.  {* See documentation on reloc types.  *}
39533965Sjdp.  reloc_howto_type *
39633965Sjdp.       (*reloc_type_lookup) PARAMS ((bfd *abfd,
39733965Sjdp.                                     bfd_reloc_code_real_type code));
39833965Sjdp.
39933965Sjdp.  {* Routines used when writing an object file.  *}
40033965Sjdp.#define BFD_JUMP_TABLE_WRITE(NAME)\
40133965Sjdp.CAT(NAME,_set_arch_mach),\
40233965Sjdp.CAT(NAME,_set_section_contents)
40333965Sjdp.  boolean    (*_bfd_set_arch_mach) PARAMS ((bfd *, enum bfd_architecture,
40433965Sjdp.                    unsigned long));
40533965Sjdp.  boolean       (*_bfd_set_section_contents) PARAMS ((bfd *, sec_ptr, PTR,
40633965Sjdp.                                            file_ptr, bfd_size_type));
40733965Sjdp.
40833965Sjdp.  {* Routines used by the linker.  *}
40933965Sjdp.#define BFD_JUMP_TABLE_LINK(NAME)\
41033965Sjdp.CAT(NAME,_sizeof_headers),\
41133965Sjdp.CAT(NAME,_bfd_get_relocated_section_contents),\
41233965Sjdp.CAT(NAME,_bfd_relax_section),\
41333965Sjdp.CAT(NAME,_bfd_link_hash_table_create),\
41433965Sjdp.CAT(NAME,_bfd_link_add_symbols),\
41533965Sjdp.CAT(NAME,_bfd_final_link),\
41633965Sjdp.CAT(NAME,_bfd_link_split_section)
41733965Sjdp.  int        (*_bfd_sizeof_headers) PARAMS ((bfd *, boolean));
41833965Sjdp.  bfd_byte * (*_bfd_get_relocated_section_contents) PARAMS ((bfd *,
41933965Sjdp.                    struct bfd_link_info *, struct bfd_link_order *,
42033965Sjdp.                    bfd_byte *data, boolean relocateable,
42133965Sjdp.                    struct symbol_cache_entry **));
42233965Sjdp.
42333965Sjdp.  boolean    (*_bfd_relax_section) PARAMS ((bfd *, struct sec *,
42433965Sjdp.                    struct bfd_link_info *, boolean *again));
42533965Sjdp.
42633965Sjdp.  {* Create a hash table for the linker.  Different backends store
42733965Sjdp.     different information in this table.  *}
42833965Sjdp.  struct bfd_link_hash_table *(*_bfd_link_hash_table_create) PARAMS ((bfd *));
42933965Sjdp.
43033965Sjdp.  {* Add symbols from this object file into the hash table.  *}
43133965Sjdp.  boolean (*_bfd_link_add_symbols) PARAMS ((bfd *, struct bfd_link_info *));
43233965Sjdp.
43333965Sjdp.  {* Do a link based on the link_order structures attached to each
43433965Sjdp.     section of the BFD.  *}
43533965Sjdp.  boolean (*_bfd_final_link) PARAMS ((bfd *, struct bfd_link_info *));
43633965Sjdp.
43733965Sjdp.  {* Should this section be split up into smaller pieces during linking.  *}
43833965Sjdp.  boolean (*_bfd_link_split_section) PARAMS ((bfd *, struct sec *));
43933965Sjdp.
44033965Sjdp. {* Routines to handle dynamic symbols and relocs.  *}
44133965Sjdp.#define BFD_JUMP_TABLE_DYNAMIC(NAME)\
44233965Sjdp.CAT(NAME,_get_dynamic_symtab_upper_bound),\
44333965Sjdp.CAT(NAME,_canonicalize_dynamic_symtab),\
44433965Sjdp.CAT(NAME,_get_dynamic_reloc_upper_bound),\
44533965Sjdp.CAT(NAME,_canonicalize_dynamic_reloc)
44633965Sjdp.  {* Get the amount of memory required to hold the dynamic symbols. *}
44733965Sjdp.  long  (*_bfd_get_dynamic_symtab_upper_bound) PARAMS ((bfd *));
44833965Sjdp.  {* Read in the dynamic symbols.  *}
44933965Sjdp.  long  (*_bfd_canonicalize_dynamic_symtab)
45033965Sjdp.    PARAMS ((bfd *, struct symbol_cache_entry **));
45133965Sjdp.  {* Get the amount of memory required to hold the dynamic relocs.  *}
45233965Sjdp.  long  (*_bfd_get_dynamic_reloc_upper_bound) PARAMS ((bfd *));
45333965Sjdp.  {* Read in the dynamic relocs.  *}
45433965Sjdp.  long  (*_bfd_canonicalize_dynamic_reloc)
45533965Sjdp.    PARAMS ((bfd *, arelent **, struct symbol_cache_entry **));
45633965Sjdp.
45733965Sjdp
45833965SjdpData for use by back-end routines, which isn't generic enough to belong
45933965Sjdpin this structure.
46033965Sjdp
46133965Sjdp. PTR backend_data;
46233965Sjdp.} bfd_target;
46333965Sjdp
46433965Sjdp*/
46533965Sjdp
46633965Sjdp/* All known xvecs (even those that don't compile on all systems).
46733965Sjdp   Alphabetized for easy reference.
46833965Sjdp   They are listed a second time below, since
46933965Sjdp   we can't intermix extern's and initializers.  */
47033965Sjdpextern const bfd_target a29kcoff_big_vec;
47133965Sjdpextern const bfd_target a_out_adobe_vec;
47233965Sjdpextern const bfd_target aout_arm_big_vec;
47333965Sjdpextern const bfd_target aout_arm_little_vec;
47433965Sjdpextern const bfd_target aout_mips_big_vec;
47533965Sjdpextern const bfd_target aout_mips_little_vec;
47633965Sjdpextern const bfd_target aout0_big_vec;
47733965Sjdpextern const bfd_target apollocoff_vec;
47833965Sjdpextern const bfd_target armcoff_little_vec;
47933965Sjdpextern const bfd_target armcoff_big_vec;
48033965Sjdpextern const bfd_target armpe_little_vec;
48133965Sjdpextern const bfd_target armpe_big_vec;
48233965Sjdpextern const bfd_target armpei_little_vec;
48333965Sjdpextern const bfd_target armpei_big_vec;
48433965Sjdpextern const bfd_target b_out_vec_big_host;
48533965Sjdpextern const bfd_target b_out_vec_little_host;
48633965Sjdpextern const bfd_target bfd_elf64_alpha_vec;
48738889Sjdpextern const bfd_target bfd_elf32_bigarc_vec;
48838889Sjdpextern const bfd_target bfd_elf32_littlearc_vec;
48933965Sjdpextern const bfd_target bfd_elf32_big_generic_vec;
49033965Sjdpextern const bfd_target bfd_elf32_bigmips_vec;
49133965Sjdpextern const bfd_target bfd_elf64_bigmips_vec;
49233965Sjdpextern const bfd_target bfd_elf32_d10v_vec;
49333965Sjdpextern const bfd_target bfd_elf32_hppa_vec;
49433965Sjdpextern const bfd_target bfd_elf32_i386_vec;
49533965Sjdpextern const bfd_target bfd_elf32_i860_vec;
49633965Sjdpextern const bfd_target bfd_elf32_little_generic_vec;
49733965Sjdpextern const bfd_target bfd_elf32_littlemips_vec;
49833965Sjdpextern const bfd_target bfd_elf64_littlemips_vec;
49933965Sjdpextern const bfd_target bfd_elf32_m32r_vec;
50033965Sjdpextern const bfd_target bfd_elf32_m68k_vec;
50133965Sjdpextern const bfd_target bfd_elf32_m88k_vec;
50233965Sjdpextern const bfd_target bfd_elf32_mn10200_vec;
50333965Sjdpextern const bfd_target bfd_elf32_mn10300_vec;
50433965Sjdpextern const bfd_target bfd_elf32_powerpc_vec;
50533965Sjdpextern const bfd_target bfd_elf32_powerpcle_vec;
50633965Sjdpextern const bfd_target bfd_elf32_sh_vec;
50733965Sjdpextern const bfd_target bfd_elf32_shl_vec;
50833965Sjdpextern const bfd_target bfd_elf32_sparc_vec;
50938889Sjdpextern const bfd_target bfd_elf32_v850_vec;
51033965Sjdpextern const bfd_target bfd_elf64_big_generic_vec;
51133965Sjdpextern const bfd_target bfd_elf64_little_generic_vec;
51233965Sjdpextern const bfd_target bfd_elf64_sparc_vec;
51333965Sjdpextern const bfd_target demo_64_vec;
51433965Sjdpextern const bfd_target ecoff_big_vec;
51533965Sjdpextern const bfd_target ecoff_little_vec;
51633965Sjdpextern const bfd_target ecoff_biglittle_vec;
51733965Sjdpextern const bfd_target ecoffalpha_little_vec;
51833965Sjdpextern const bfd_target evax_alpha_vec;
51933965Sjdpextern const bfd_target h8300coff_vec;
52033965Sjdpextern const bfd_target h8500coff_vec;
52133965Sjdpextern const bfd_target host_aout_vec;
52233965Sjdpextern const bfd_target hp300bsd_vec;
52333965Sjdpextern const bfd_target hp300hpux_vec;
52433965Sjdpextern const bfd_target som_vec;
52533965Sjdpextern const bfd_target i386aout_vec;
52633965Sjdpextern const bfd_target i386bsd_vec;
52733965Sjdpextern const bfd_target i386dynix_vec;
52833965Sjdpextern const bfd_target i386freebsd_vec;
52933965Sjdpextern const bfd_target i386os9k_vec;
53033965Sjdpextern const bfd_target i386coff_vec;
53133965Sjdpextern const bfd_target bfd_powerpc_pe_vec;
53233965Sjdpextern const bfd_target bfd_powerpcle_pe_vec;
53333965Sjdpextern const bfd_target bfd_powerpc_pei_vec;
53433965Sjdpextern const bfd_target bfd_powerpcle_pei_vec;
53533965Sjdpextern const bfd_target i386pe_vec;
53633965Sjdpextern const bfd_target i386pei_vec;
53733965Sjdpextern const bfd_target go32coff_vec;
53838889Sjdpextern const bfd_target go32stubbedcoff_vec;
53933965Sjdpextern const bfd_target i386linux_vec;
54033965Sjdpextern const bfd_target i386lynx_aout_vec;
54133965Sjdpextern const bfd_target i386lynx_coff_vec;
54233965Sjdpextern const bfd_target i386mach3_vec;
54333965Sjdpextern const bfd_target i386msdos_vec;
54433965Sjdpextern const bfd_target i386netbsd_vec;
54533965Sjdpextern const bfd_target i860coff_vec;
54633965Sjdpextern const bfd_target icoff_big_vec;
54733965Sjdpextern const bfd_target icoff_little_vec;
54833965Sjdpextern const bfd_target ieee_vec;
54933965Sjdpextern const bfd_target m68kaux_coff_vec;
55033965Sjdpextern const bfd_target m68kcoff_vec;
55133965Sjdpextern const bfd_target m68kcoffun_vec;
55233965Sjdpextern const bfd_target m68klinux_vec;
55333965Sjdpextern const bfd_target m68klynx_aout_vec;
55433965Sjdpextern const bfd_target m68klynx_coff_vec;
55533965Sjdpextern const bfd_target m68knetbsd_vec;
55633965Sjdpextern const bfd_target m68ksysvcoff_vec;
55733965Sjdpextern const bfd_target m68k4knetbsd_vec;
55833965Sjdpextern const bfd_target m88kbcs_vec;
55933965Sjdpextern const bfd_target m88kmach3_vec;
56033965Sjdpextern const bfd_target newsos3_vec;
56133965Sjdpextern const bfd_target nlm32_i386_vec;
56233965Sjdpextern const bfd_target nlm32_sparc_vec;
56333965Sjdpextern const bfd_target nlm32_alpha_vec;
56433965Sjdpextern const bfd_target nlm32_powerpc_vec;
56533965Sjdpextern const bfd_target pc532netbsd_vec;
56633965Sjdpextern const bfd_target oasys_vec;
56733965Sjdpextern const bfd_target pc532machaout_vec;
56833965Sjdpextern const bfd_target ppcboot_vec;
56933965Sjdpextern const bfd_target riscix_vec;
57033965Sjdpextern const bfd_target pmac_xcoff_vec;
57133965Sjdpextern const bfd_target rs6000coff_vec;
57233965Sjdpextern const bfd_target shcoff_vec;
57333965Sjdpextern const bfd_target shlcoff_vec;
57438889Sjdpextern const bfd_target shcoff_small_vec;
57538889Sjdpextern const bfd_target shlcoff_small_vec;
57633965Sjdpextern const bfd_target sparcle_aout_vec;
57733965Sjdpextern const bfd_target sparclinux_vec;
57833965Sjdpextern const bfd_target sparclynx_aout_vec;
57933965Sjdpextern const bfd_target sparclynx_coff_vec;
58033965Sjdpextern const bfd_target sparcnetbsd_vec;
58133965Sjdpextern const bfd_target sparccoff_vec;
58233965Sjdpextern const bfd_target sunos_big_vec;
58333965Sjdpextern const bfd_target tekhex_vec;
58438889Sjdpextern const bfd_target tic30_aout_vec;
58538889Sjdpextern const bfd_target tic30_coff_vec;
58638889Sjdpextern const bfd_target vaxnetbsd_vec;
58733965Sjdpextern const bfd_target versados_vec;
58833965Sjdpextern const bfd_target we32kcoff_vec;
58933965Sjdpextern const bfd_target w65_vec;
59033965Sjdpextern const bfd_target z8kcoff_vec;
59133965Sjdp
59233965Sjdp/* srec is always included.  */
59333965Sjdpextern const bfd_target srec_vec;
59433965Sjdpextern const bfd_target symbolsrec_vec;
59533965Sjdp
59633965Sjdp/* binary is always included.  */
59733965Sjdpextern const bfd_target binary_vec;
59833965Sjdp
59933965Sjdp/* ihex is always included.  */
60033965Sjdpextern const bfd_target ihex_vec;
60133965Sjdp
60233965Sjdp/* All of the xvecs for core files.  */
60333965Sjdpextern const bfd_target aix386_core_vec;
60433965Sjdpextern const bfd_target cisco_core_vec;
60533965Sjdpextern const bfd_target hpux_core_vec;
60633965Sjdpextern const bfd_target hppabsd_core_vec;
60733965Sjdpextern const bfd_target irix_core_vec;
60833965Sjdpextern const bfd_target netbsd_core_vec;
60933965Sjdpextern const bfd_target osf_core_vec;
61033965Sjdpextern const bfd_target sco_core_vec;
61133965Sjdpextern const bfd_target trad_core_vec;
61233965Sjdpextern const bfd_target ptrace_core_vec;
61333965Sjdp
61433965Sjdpconst bfd_target * const bfd_target_vector[] = {
61533965Sjdp
61633965Sjdp#ifdef SELECT_VECS
61733965Sjdp
61833965Sjdp	SELECT_VECS,
61933965Sjdp
62033965Sjdp#else /* not SELECT_VECS */
62133965Sjdp
62233965Sjdp#ifdef DEFAULT_VECTOR
62333965Sjdp	&DEFAULT_VECTOR,
62433965Sjdp#endif
62533965Sjdp	/* This list is alphabetized to make it easy to compare
62633965Sjdp	   with other vector lists -- the decls above and
62733965Sjdp	   the case statement in configure.in.
62833965Sjdp	   Vectors that don't compile on all systems, or aren't finished,
62933965Sjdp	   should have an entry here with #if 0 around it, to show that
63033965Sjdp	   it wasn't omitted by mistake.  */
63133965Sjdp	&a29kcoff_big_vec,
63233965Sjdp	&a_out_adobe_vec,
63333965Sjdp#if 0				/* No one seems to use this.  */
63433965Sjdp	&aout_mips_big_vec,
63533965Sjdp#endif
63633965Sjdp	&aout_mips_little_vec,
63733965Sjdp	&b_out_vec_big_host,
63833965Sjdp	&b_out_vec_little_host,
63933965Sjdp
64033965Sjdp	/* This, and other vectors, may not be used in any *.mt configuration.
64133965Sjdp	   But that does not mean they are unnecessary.  If configured with
64233965Sjdp	   --enable-targets=all, objdump or gdb should be able to examine
64333965Sjdp	   the file even if we don't recognize the machine type.  */
64433965Sjdp	&bfd_elf32_big_generic_vec,
64533965Sjdp#ifdef BFD64
64633965Sjdp	&bfd_elf64_alpha_vec,
64733965Sjdp#endif
64838889Sjdp	&bfd_elf32_bigarc_vec,
64933965Sjdp	&bfd_elf32_bigmips_vec,
65033965Sjdp#ifdef BFD64
65133965Sjdp	&bfd_elf64_bigmips_vec,
65233965Sjdp#endif
65333965Sjdp	&bfd_elf32_d10v_vec,
65433965Sjdp	&bfd_elf32_hppa_vec,
65533965Sjdp	&bfd_elf32_i386_vec,
65633965Sjdp	&bfd_elf32_i860_vec,
65733965Sjdp	&bfd_elf32_little_generic_vec,
65838889Sjdp	&bfd_elf32_littlearc_vec,
65933965Sjdp	&bfd_elf32_littlemips_vec,
66033965Sjdp#ifdef BFD64
66133965Sjdp	&bfd_elf64_littlemips_vec,
66233965Sjdp#endif
66333965Sjdp	&bfd_elf32_m32r_vec,
66433965Sjdp	&bfd_elf32_mn10200_vec,
66533965Sjdp	&bfd_elf32_mn10300_vec,
66633965Sjdp	&bfd_elf32_m68k_vec,
66733965Sjdp	&bfd_elf32_m88k_vec,
66833965Sjdp	&bfd_elf32_sparc_vec,
66933965Sjdp	&bfd_elf32_powerpc_vec,
67038889Sjdp	&bfd_elf32_powerpcle_vec,
67138889Sjdp	&bfd_elf32_v850_vec,
67233965Sjdp#ifdef BFD64			/* No one seems to use this.  */
67333965Sjdp	&bfd_elf64_big_generic_vec,
67433965Sjdp	&bfd_elf64_little_generic_vec,
67533965Sjdp#endif
67633965Sjdp#if 0
67733965Sjdp	&bfd_elf64_sparc_vec,
67833965Sjdp#endif
67933965Sjdp	/* We don't include cisco_core_vec.  Although it has a magic number,
68033965Sjdp	   the magic number isn't at the beginning of the file, and thus
68133965Sjdp	   might spuriously match other kinds of files.  */
68233965Sjdp#ifdef BFD64
68333965Sjdp	&demo_64_vec,	/* Only compiled if host has long-long support */
68433965Sjdp#endif
68533965Sjdp	&ecoff_big_vec,
68633965Sjdp	&ecoff_little_vec,
68733965Sjdp	&ecoff_biglittle_vec,
68833965Sjdp#ifdef BFD64
68933965Sjdp	&ecoffalpha_little_vec,
69033965Sjdp	&evax_alpha_vec,
69133965Sjdp#endif
69233965Sjdp	&h8300coff_vec,
69333965Sjdp	&h8500coff_vec,
69433965Sjdp#if 0
69533965Sjdp	/* Since a.out files lack decent magic numbers, no way to recognize
69633965Sjdp	   which kind of a.out file it is.  */
69733965Sjdp	&host_aout_vec,
69833965Sjdp#endif
69933965Sjdp#if 0				/* Clashes with sunos_big_vec magic no.  */
70033965Sjdp	&hp300bsd_vec,
70133965Sjdp#endif
70233965Sjdp	&hp300hpux_vec,
70333965Sjdp#if defined (HOST_HPPAHPUX) || defined (HOST_HPPABSD) || defined (HOST_HPPAOSF)
70433965Sjdp        &som_vec,
70533965Sjdp#endif
70633965Sjdp	&i386aout_vec,
70733965Sjdp	&i386bsd_vec,
70833965Sjdp	&i386coff_vec,
70933965Sjdp	&i386freebsd_vec,
71033965Sjdp	&i860coff_vec,
71133965Sjdp	&bfd_powerpc_pe_vec,
71233965Sjdp	&bfd_powerpcle_pe_vec,
71333965Sjdp	&bfd_powerpc_pei_vec,
71433965Sjdp	&bfd_powerpcle_pei_vec,
71533965Sjdp	&go32coff_vec,
71638889Sjdp	&go32stubbedcoff_vec,
71733965Sjdp#if 0
71833965Sjdp	/* Since a.out files lack decent magic numbers, no way to recognize
71933965Sjdp	   which kind of a.out file it is.  */
72033965Sjdp	&i386linux_vec,
72133965Sjdp#endif
72233965Sjdp	&i386lynx_aout_vec,
72333965Sjdp	&i386lynx_coff_vec,
72433965Sjdp#if 0
72533965Sjdp	/* No distinguishing features for Mach 3 executables.  */
72633965Sjdp	&i386mach3_vec,
72733965Sjdp#endif
72833965Sjdp	&i386msdos_vec,
72933965Sjdp	&i386netbsd_vec,
73033965Sjdp	&i386os9k_vec,
73133965Sjdp	&i386pe_vec,
73233965Sjdp	&i386pei_vec,
73333965Sjdp	&armcoff_little_vec,
73433965Sjdp	&armcoff_big_vec,
73533965Sjdp	&armpe_little_vec,
73633965Sjdp	&armpe_big_vec,
73733965Sjdp	&armpei_little_vec,
73833965Sjdp	&armpei_big_vec,
73933965Sjdp	&icoff_big_vec,
74033965Sjdp	&icoff_little_vec,
74133965Sjdp	&ieee_vec,
74233965Sjdp	&m68kcoff_vec,
74333965Sjdp	&m68kcoffun_vec,
74433965Sjdp#if 0
74533965Sjdp	/* Since a.out files lack decent magic numbers, no way to recognize
74633965Sjdp	   which kind of a.out file it is.  */
74733965Sjdp	&m68klinux_vec,
74833965Sjdp#endif
74933965Sjdp	&m68klynx_aout_vec,
75033965Sjdp	&m68klynx_coff_vec,
75133965Sjdp	&m68knetbsd_vec,
75233965Sjdp	&m68ksysvcoff_vec,
75333965Sjdp	&m88kbcs_vec,
75433965Sjdp	&m88kmach3_vec,
75533965Sjdp	&newsos3_vec,
75633965Sjdp	&nlm32_i386_vec,
75733965Sjdp	&nlm32_sparc_vec,
75833965Sjdp#ifdef BFD64
75933965Sjdp	&nlm32_alpha_vec,
76033965Sjdp#endif
76133965Sjdp	&pc532netbsd_vec,
76233965Sjdp#if 0
76333965Sjdp	/* We have no oasys tools anymore, so we can't test any of this
76433965Sjdp	   anymore. If you want to test the stuff yourself, go ahead...
76533965Sjdp	   steve@cygnus.com
76633965Sjdp	   Worse, since there is no magic number for archives, there
76733965Sjdp	   can be annoying target mis-matches.  */
76833965Sjdp	&oasys_vec,
76933965Sjdp#endif
77033965Sjdp	&pc532machaout_vec,
77133965Sjdp#if 0
77233965Sjdp	/* We have no way of distinguishing these from other a.out variants */
77333965Sjdp	&aout_arm_big_vec,
77433965Sjdp	&aout_arm_little_vec,
77533965Sjdp	&riscix_vec,
77633965Sjdp#endif
77733965Sjdp#if 0
77833965Sjdp	/* This has the same magic number as RS/6000. */
77933965Sjdp	&pmac_xcoff_vec,
78033965Sjdp#endif
78133965Sjdp	&rs6000coff_vec,
78233965Sjdp	&ppcboot_vec,
78333965Sjdp	&shcoff_vec,
78433965Sjdp	&shlcoff_vec,
78538889Sjdp	&shcoff_small_vec,
78638889Sjdp	&shlcoff_small_vec,
78733965Sjdp	&sparcle_aout_vec,
78833965Sjdp	&sparclinux_vec,
78933965Sjdp	&sparclynx_aout_vec,
79033965Sjdp	&sparclynx_coff_vec,
79133965Sjdp	&sparcnetbsd_vec,
79233965Sjdp	&sunos_big_vec,
79333965Sjdp	&aout0_big_vec,
79433965Sjdp	&tekhex_vec,
79538889Sjdp	&tic30_aout_vec,
79638889Sjdp	&tic30_coff_vec,
79738889Sjdp	&vaxnetbsd_vec,
79838889Sjdp	&versados_vec,
79933965Sjdp	&we32kcoff_vec,
80033965Sjdp	&z8kcoff_vec,
80133965Sjdp
80233965Sjdp#endif /* not SELECT_VECS */
80333965Sjdp
80433965Sjdp/* Always support S-records, for convenience.  */
80533965Sjdp	&srec_vec,
80633965Sjdp	&symbolsrec_vec,
80733965Sjdp/* And tekhex */
80833965Sjdp	&tekhex_vec,
80933965Sjdp/* Likewise for binary output.  */
81033965Sjdp	&binary_vec,
81133965Sjdp/* Likewise for ihex.  */
81233965Sjdp	&ihex_vec,
81333965Sjdp
81433965Sjdp/* Add any required traditional-core-file-handler.  */
81533965Sjdp
81633965Sjdp#ifdef AIX386_CORE
81733965Sjdp	&aix386_core_vec,
81833965Sjdp#endif
81933965Sjdp#ifdef HPUX_CORE
82033965Sjdp	&hpux_core_vec,
82133965Sjdp#endif
82233965Sjdp#ifdef HPPABSD_CORE
82333965Sjdp	&hppabsd_core_vec,
82433965Sjdp#endif
82533965Sjdp#ifdef IRIX_CORE
82633965Sjdp	&irix_core_vec,
82733965Sjdp#endif
82838889Sjdp#ifdef NETBSD_CORE
82938889Sjdp	&netbsd_core_vec,
83038889Sjdp#endif
83133965Sjdp#ifdef OSF_CORE
83233965Sjdp	&osf_core_vec,
83333965Sjdp#endif
83433965Sjdp#ifdef	TRAD_CORE
83533965Sjdp	&trad_core_vec,
83633965Sjdp#endif
83733965Sjdp
83833965Sjdp#ifdef	PTRACE_CORE
83933965Sjdp	&ptrace_core_vec,
84033965Sjdp#endif
84133965Sjdp
84233965Sjdp	NULL /* end of list marker */
84333965Sjdp};
84433965Sjdp
84533965Sjdp/* bfd_default_vector[0] contains either the address of the default vector,
84633965Sjdp   if there is one, or zero if there isn't.  */
84733965Sjdp
84833965Sjdpconst bfd_target *bfd_default_vector[] = {
84933965Sjdp#ifdef DEFAULT_VECTOR
85033965Sjdp	&DEFAULT_VECTOR,
85133965Sjdp#endif
85233965Sjdp	NULL
85333965Sjdp};
85433965Sjdp
85533965Sjdp/* When there is an ambiguous match, bfd_check_format_matches puts the
85633965Sjdp   names of the matching targets in an array.  This variable is the maximum
85733965Sjdp   number of entries that the array could possibly need.  */
85833965Sjdpconst size_t _bfd_target_vector_entries = sizeof(bfd_target_vector)/sizeof(*bfd_target_vector);
85933965Sjdp
86033965Sjdp/* This array maps configuration triplets onto BFD vectors.  */
86133965Sjdp
86233965Sjdpstruct targmatch
86333965Sjdp{
86433965Sjdp  /* The configuration triplet.  */
86533965Sjdp  const char *triplet;
86633965Sjdp  /* The BFD vector.  If this is NULL, then the vector is found by
86733965Sjdp     searching forward for the next structure with a non NULL vector
86833965Sjdp     field.  */
86933965Sjdp  const bfd_target *vector;
87033965Sjdp};
87133965Sjdp
87233965Sjdp/* targmatch.h is built by Makefile out of config.bfd.  */
87333965Sjdpstatic const struct targmatch bfd_target_match[] = {
87433965Sjdp#include "targmatch.h"
87533965Sjdp  { NULL, NULL }
87633965Sjdp};
87733965Sjdp
87833965Sjdpstatic const bfd_target *find_target PARAMS ((const char *));
87933965Sjdp
88033965Sjdp/* Find a target vector, given a name or configuration triplet.  */
88133965Sjdp
88233965Sjdpstatic const bfd_target *
88333965Sjdpfind_target (name)
88433965Sjdp     const char *name;
88533965Sjdp{
88633965Sjdp  const bfd_target * const *target;
88733965Sjdp  const struct targmatch *match;
88833965Sjdp
88933965Sjdp  for (target = &bfd_target_vector[0]; *target != NULL; target++)
89033965Sjdp    if (strcmp (name, (*target)->name) == 0)
89133965Sjdp      return *target;
89233965Sjdp
89333965Sjdp  /* If we couldn't match on the exact name, try matching on the
89433965Sjdp     configuration triplet.  FIXME: We should run the triplet through
89533965Sjdp     config.sub first, but that is hard.  */
89633965Sjdp  for (match = &bfd_target_match[0]; match->triplet != NULL; match++)
89733965Sjdp    {
89833965Sjdp      if (fnmatch (match->triplet, name, 0) == 0)
89933965Sjdp	{
90033965Sjdp	  while (match->vector == NULL)
90133965Sjdp	    ++match;
90233965Sjdp	  return match->vector;
90333965Sjdp	  break;
90433965Sjdp	}
90533965Sjdp    }
90633965Sjdp
90733965Sjdp  bfd_set_error (bfd_error_invalid_target);
90833965Sjdp  return NULL;
90933965Sjdp}
91033965Sjdp
91133965Sjdp/*
91233965SjdpFUNCTION
91333965Sjdp	bfd_set_default_target
91433965Sjdp
91533965SjdpSYNOPSIS
91633965Sjdp	boolean bfd_set_default_target (const char *name);
91733965Sjdp
91833965SjdpDESCRIPTION
91933965Sjdp	Set the default target vector to use when recognizing a BFD.
92033965Sjdp	This takes the name of the target, which may be a BFD target
92133965Sjdp	name or a configuration triplet.
92233965Sjdp*/
92333965Sjdp
92433965Sjdpboolean
92533965Sjdpbfd_set_default_target (name)
92633965Sjdp     const char *name;
92733965Sjdp{
92833965Sjdp  const bfd_target *target;
92933965Sjdp
93033965Sjdp  if (bfd_default_vector[0] != NULL
93133965Sjdp      && strcmp (name, bfd_default_vector[0]->name) == 0)
93233965Sjdp    return true;
93333965Sjdp
93433965Sjdp  target = find_target (name);
93533965Sjdp  if (target == NULL)
93633965Sjdp    return false;
93733965Sjdp
93833965Sjdp  bfd_default_vector[0] = target;
93933965Sjdp  return true;
94033965Sjdp}
94133965Sjdp
94233965Sjdp/*
94333965SjdpFUNCTION
94433965Sjdp	bfd_find_target
94533965Sjdp
94633965SjdpSYNOPSIS
94733965Sjdp	const bfd_target *bfd_find_target(CONST char *target_name, bfd *abfd);
94833965Sjdp
94933965SjdpDESCRIPTION
95033965Sjdp	Return a pointer to the transfer vector for the object target
95133965Sjdp	named @var{target_name}.  If @var{target_name} is <<NULL>>, choose the
95233965Sjdp	one in the environment variable <<GNUTARGET>>; if that is null or not
95333965Sjdp	defined, then choose the first entry in the target list.
95433965Sjdp	Passing in the string "default" or setting the environment
95533965Sjdp	variable to "default" will cause the first entry in the target
95633965Sjdp	list to be returned, and "target_defaulted" will be set in the
95733965Sjdp	BFD.  This causes <<bfd_check_format>> to loop over all the
95833965Sjdp	targets to find the one that matches the file being read.
95933965Sjdp*/
96033965Sjdp
96133965Sjdpconst bfd_target *
96233965Sjdpbfd_find_target (target_name, abfd)
96333965Sjdp     const char *target_name;
96433965Sjdp     bfd *abfd;
96533965Sjdp{
96633965Sjdp  const char *targname;
96733965Sjdp  const bfd_target *target;
96833965Sjdp
96933965Sjdp  if (target_name != NULL)
97033965Sjdp    targname = target_name;
97133965Sjdp  else
97233965Sjdp    targname = getenv ("GNUTARGET");
97333965Sjdp
97433965Sjdp  /* This is safe; the vector cannot be null */
97533965Sjdp  if (targname == NULL || strcmp (targname, "default") == 0)
97633965Sjdp    {
97733965Sjdp      abfd->target_defaulted = true;
97833965Sjdp      if (bfd_default_vector[0] != NULL)
97933965Sjdp	abfd->xvec = bfd_default_vector[0];
98033965Sjdp      else
98133965Sjdp	abfd->xvec = bfd_target_vector[0];
98233965Sjdp      return abfd->xvec;
98333965Sjdp    }
98433965Sjdp
98533965Sjdp  abfd->target_defaulted = false;
98633965Sjdp
98733965Sjdp  target = find_target (targname);
98833965Sjdp  if (target == NULL)
98933965Sjdp    return NULL;
99033965Sjdp
99133965Sjdp  abfd->xvec = target;
99233965Sjdp  return target;
99333965Sjdp}
99433965Sjdp
99533965Sjdp/*
99633965SjdpFUNCTION
99733965Sjdp	bfd_target_list
99833965Sjdp
99933965SjdpSYNOPSIS
100033965Sjdp	const char **bfd_target_list(void);
100133965Sjdp
100233965SjdpDESCRIPTION
100333965Sjdp	Return a freshly malloced NULL-terminated
100433965Sjdp	vector of the names of all the valid BFD targets. Do not
100533965Sjdp	modify the names.
100633965Sjdp
100733965Sjdp*/
100833965Sjdp
100933965Sjdpconst char **
101033965Sjdpbfd_target_list ()
101133965Sjdp{
101233965Sjdp  int vec_length= 0;
101333965Sjdp#if defined (HOST_HPPAHPUX) && ! defined (__STDC__)
101433965Sjdp  /* The native compiler on the HP9000/700 has a bug which causes it
101533965Sjdp     to loop endlessly when compiling this file.  This avoids it.  */
101633965Sjdp  volatile
101733965Sjdp#endif
101833965Sjdp    const bfd_target * const *target;
101933965Sjdp  CONST  char **name_list, **name_ptr;
102033965Sjdp
102133965Sjdp  for (target = &bfd_target_vector[0]; *target != NULL; target++)
102233965Sjdp    vec_length++;
102333965Sjdp
102433965Sjdp  name_ptr = name_list = (CONST char **)
102533965Sjdp    bfd_zmalloc ((vec_length + 1) * sizeof (char **));
102633965Sjdp
102733965Sjdp  if (name_list == NULL)
102833965Sjdp    return NULL;
102933965Sjdp
103033965Sjdp  for (target = &bfd_target_vector[0]; *target != NULL; target++)
103133965Sjdp    *(name_ptr++) = (*target)->name;
103233965Sjdp
103333965Sjdp  return name_list;
103433965Sjdp}
1035