1@section Targets
2
3
4@strong{Description}@*
5Each port of BFD to a different machine requires the creation
6of a target back end. All the back end provides to the root
7part of BFD is a structure containing pointers to functions
8which perform certain low level operations on files. BFD
9translates the applications's requests through a pointer into
10calls to the back end routines.
11
12When a file is opened with @code{bfd_openr}, its format and
13target are unknown. BFD uses various mechanisms to determine
14how to interpret the file. The operations performed are:
15
16@itemize @bullet
17
18@item
19Create a BFD by calling the internal routine
20@code{_bfd_new_bfd}, then call @code{bfd_find_target} with the
21target string supplied to @code{bfd_openr} and the new BFD pointer.
22
23@item
24If a null target string was provided to @code{bfd_find_target},
25look up the environment variable @code{GNUTARGET} and use
26that as the target string.
27
28@item
29If the target string is still @code{NULL}, or the target string is
30@code{default}, then use the first item in the target vector
31as the target type, and set @code{target_defaulted} in the BFD to
32cause @code{bfd_check_format} to loop through all the targets.
33@xref{bfd_target}.  @xref{Formats}.
34
35@item
36Otherwise, inspect the elements in the target vector
37one by one, until a match on target name is found. When found,
38use it.
39
40@item
41Otherwise return the error @code{bfd_error_invalid_target} to
42@code{bfd_openr}.
43
44@item
45@code{bfd_openr} attempts to open the file using
46@code{bfd_open_file}, and returns the BFD.
47@end itemize
48Once the BFD has been opened and the target selected, the file
49format may be determined. This is done by calling
50@code{bfd_check_format} on the BFD with a suggested format.
51If @code{target_defaulted} has been set, each possible target
52type is tried to see if it recognizes the specified format.
53@code{bfd_check_format} returns @code{TRUE} when the caller guesses right.
54@menu
55* bfd_target::
56@end menu
57
58@node bfd_target,  , Targets, Targets
59
60@subsection bfd_target
61
62
63@strong{Description}@*
64This structure contains everything that BFD knows about a
65target. It includes things like its byte order, name, and which
66routines to call to do various operations.
67
68Every BFD points to a target structure with its @code{xvec}
69member.
70
71The macros below are used to dispatch to functions through the
72@code{bfd_target} vector. They are used in a number of macros further
73down in @file{bfd.h}, and are also used when calling various
74routines by hand inside the BFD implementation.  The @var{arglist}
75argument must be parenthesized; it contains all the arguments
76to the called function.
77
78They make the documentation (more) unpleasant to read, so if
79someone wants to fix this and not break the above, please do.
80@example
81#define BFD_SEND(bfd, message, arglist) \
82  ((*((bfd)->xvec->message)) arglist)
83
84#ifdef DEBUG_BFD_SEND
85#undef BFD_SEND
86#define BFD_SEND(bfd, message, arglist) \
87  (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
88    ((*((bfd)->xvec->message)) arglist) : \
89    (bfd_assert (__FILE__,__LINE__), NULL))
90#endif
91@end example
92For operations which index on the BFD format:
93@example
94#define BFD_SEND_FMT(bfd, message, arglist) \
95  (((bfd)->xvec->message[(int) ((bfd)->format)]) arglist)
96
97#ifdef DEBUG_BFD_SEND
98#undef BFD_SEND_FMT
99#define BFD_SEND_FMT(bfd, message, arglist) \
100  (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
101   (((bfd)->xvec->message[(int) ((bfd)->format)]) arglist) : \
102   (bfd_assert (__FILE__,__LINE__), NULL))
103#endif
104
105/* Defined to TRUE if unused section symbol should be kept.  */
106#ifndef TARGET_KEEP_UNUSED_SECTION_SYMBOLS
107#define TARGET_KEEP_UNUSED_SECTION_SYMBOLS true
108#endif
109
110@end example
111This is the structure which defines the type of BFD this is.  The
112@code{xvec} member of the struct @code{bfd} itself points here.  Each
113module that implements access to a different target under BFD,
114defines one of these.
115
116FIXME, these names should be rationalised with the names of
117the entry points which call them. Too bad we can't have one
118macro to define them both!
119@example
120enum bfd_flavour
121@{
122  /* N.B. Update bfd_flavour_name if you change this.  */
123  bfd_target_unknown_flavour,
124  bfd_target_aout_flavour,
125  bfd_target_coff_flavour,
126  bfd_target_ecoff_flavour,
127  bfd_target_xcoff_flavour,
128  bfd_target_elf_flavour,
129  bfd_target_tekhex_flavour,
130  bfd_target_srec_flavour,
131  bfd_target_verilog_flavour,
132  bfd_target_ihex_flavour,
133  bfd_target_som_flavour,
134  bfd_target_os9k_flavour,
135  bfd_target_versados_flavour,
136  bfd_target_msdos_flavour,
137  bfd_target_ovax_flavour,
138  bfd_target_evax_flavour,
139  bfd_target_mmo_flavour,
140  bfd_target_mach_o_flavour,
141  bfd_target_pef_flavour,
142  bfd_target_pef_xlib_flavour,
143  bfd_target_sym_flavour
144@};
145
146enum bfd_endian @{ BFD_ENDIAN_BIG, BFD_ENDIAN_LITTLE, BFD_ENDIAN_UNKNOWN @};
147
148/* Forward declaration.  */
149typedef struct bfd_link_info _bfd_link_info;
150
151/* Forward declaration.  */
152typedef struct flag_info flag_info;
153
154typedef void (*bfd_cleanup) (bfd *);
155
156typedef struct bfd_target
157@{
158  /* Identifies the kind of target, e.g., SunOS4, Ultrix, etc.  */
159  const char *name;
160
161 /* The "flavour" of a back end is a general indication about
162    the contents of a file.  */
163  enum bfd_flavour flavour;
164
165  /* The order of bytes within the data area of a file.  */
166  enum bfd_endian byteorder;
167
168 /* The order of bytes within the header parts of a file.  */
169  enum bfd_endian header_byteorder;
170
171  /* A mask of all the flags which an executable may have set -
172     from the set @code{BFD_NO_FLAGS}, @code{HAS_RELOC}, ...@code{D_PAGED}.  */
173  flagword object_flags;
174
175 /* A mask of all the flags which a section may have set - from
176    the set @code{SEC_NO_FLAGS}, @code{SEC_ALLOC}, ...@code{SET_NEVER_LOAD}.  */
177  flagword section_flags;
178
179 /* The character normally found at the front of a symbol.
180    (if any), perhaps `_'.  */
181  char symbol_leading_char;
182
183 /* The pad character for file names within an archive header.  */
184  char ar_pad_char;
185
186  /* The maximum number of characters in an archive header.  */
187  unsigned char ar_max_namelen;
188
189  /* How well this target matches, used to select between various
190     possible targets when more than one target matches.  */
191  unsigned char match_priority;
192
193 /* TRUE if unused section symbols should be kept.  */
194  bool keep_unused_section_symbols;
195
196  /* Entries for byte swapping for data. These are different from the
197     other entry points, since they don't take a BFD as the first argument.
198     Certain other handlers could do the same.  */
199  uint64_t       (*bfd_getx64) (const void *);
200  int64_t        (*bfd_getx_signed_64) (const void *);
201  void           (*bfd_putx64) (uint64_t, void *);
202  bfd_vma        (*bfd_getx32) (const void *);
203  bfd_signed_vma (*bfd_getx_signed_32) (const void *);
204  void           (*bfd_putx32) (bfd_vma, void *);
205  bfd_vma        (*bfd_getx16) (const void *);
206  bfd_signed_vma (*bfd_getx_signed_16) (const void *);
207  void           (*bfd_putx16) (bfd_vma, void *);
208
209  /* Byte swapping for the headers.  */
210  uint64_t       (*bfd_h_getx64) (const void *);
211  int64_t        (*bfd_h_getx_signed_64) (const void *);
212  void           (*bfd_h_putx64) (uint64_t, void *);
213  bfd_vma        (*bfd_h_getx32) (const void *);
214  bfd_signed_vma (*bfd_h_getx_signed_32) (const void *);
215  void           (*bfd_h_putx32) (bfd_vma, void *);
216  bfd_vma        (*bfd_h_getx16) (const void *);
217  bfd_signed_vma (*bfd_h_getx_signed_16) (const void *);
218  void           (*bfd_h_putx16) (bfd_vma, void *);
219
220  /* Format dependent routines: these are vectors of entry points
221     within the target vector structure, one for each format to check.  */
222
223  /* Check the format of a file being read.  Return a @code{bfd_cleanup} on
224     success or zero on failure.  */
225  bfd_cleanup (*_bfd_check_format[bfd_type_end]) (bfd *);
226
227  /* Set the format of a file being written.  */
228  bool (*_bfd_set_format[bfd_type_end]) (bfd *);
229
230  /* Write cached information into a file being written, at @code{bfd_close}.  */
231  bool (*_bfd_write_contents[bfd_type_end]) (bfd *);
232
233@end example
234The general target vector.  These vectors are initialized using the
235BFD_JUMP_TABLE macros.
236@example
237
238  /* Generic entry points.  */
239#define BFD_JUMP_TABLE_GENERIC(NAME) \
240  NAME##_close_and_cleanup, \
241  NAME##_bfd_free_cached_info, \
242  NAME##_new_section_hook, \
243  NAME##_get_section_contents, \
244  NAME##_get_section_contents_in_window
245
246  /* Called when the BFD is being closed to do any necessary cleanup.  */
247  bool (*_close_and_cleanup) (bfd *);
248  /* Ask the BFD to free all cached information.  */
249  bool (*_bfd_free_cached_info) (bfd *);
250  /* Called when a new section is created.  */
251  bool (*_new_section_hook) (bfd *, sec_ptr);
252  /* Read the contents of a section.  */
253  bool (*_bfd_get_section_contents) (bfd *, sec_ptr, void *, file_ptr,
254                                     bfd_size_type);
255  bool (*_bfd_get_section_contents_in_window) (bfd *, sec_ptr, bfd_window *,
256                                               file_ptr, bfd_size_type);
257
258  /* Entry points to copy private data.  */
259#define BFD_JUMP_TABLE_COPY(NAME) \
260  NAME##_bfd_copy_private_bfd_data, \
261  NAME##_bfd_merge_private_bfd_data, \
262  _bfd_generic_init_private_section_data, \
263  NAME##_bfd_copy_private_section_data, \
264  NAME##_bfd_copy_private_symbol_data, \
265  NAME##_bfd_copy_private_header_data, \
266  NAME##_bfd_set_private_flags, \
267  NAME##_bfd_print_private_bfd_data
268
269  /* Called to copy BFD general private data from one object file
270     to another.  */
271  bool (*_bfd_copy_private_bfd_data) (bfd *, bfd *);
272  /* Called to merge BFD general private data from one object file
273     to a common output file when linking.  */
274  bool (*_bfd_merge_private_bfd_data) (bfd *, struct bfd_link_info *);
275  /* Called to initialize BFD private section data from one object file
276     to another.  */
277#define bfd_init_private_section_data(ibfd, isec, obfd, osec, link_info) \
278       BFD_SEND (obfd, _bfd_init_private_section_data, \
279                 (ibfd, isec, obfd, osec, link_info))
280  bool (*_bfd_init_private_section_data) (bfd *, sec_ptr, bfd *, sec_ptr,
281                                          struct bfd_link_info *);
282  /* Called to copy BFD private section data from one object file
283     to another.  */
284  bool (*_bfd_copy_private_section_data) (bfd *, sec_ptr, bfd *, sec_ptr);
285  /* Called to copy BFD private symbol data from one symbol
286     to another.  */
287  bool (*_bfd_copy_private_symbol_data) (bfd *, asymbol *,
288                                         bfd *, asymbol *);
289  /* Called to copy BFD private header data from one object file
290     to another.  */
291  bool (*_bfd_copy_private_header_data) (bfd *, bfd *);
292  /* Called to set private backend flags.  */
293  bool (*_bfd_set_private_flags) (bfd *, flagword);
294
295  /* Called to print private BFD data.  */
296  bool (*_bfd_print_private_bfd_data) (bfd *, void *);
297
298  /* Core file entry points.  */
299#define BFD_JUMP_TABLE_CORE(NAME) \
300  NAME##_core_file_failing_command, \
301  NAME##_core_file_failing_signal, \
302  NAME##_core_file_matches_executable_p, \
303  NAME##_core_file_pid
304
305  char *(*_core_file_failing_command) (bfd *);
306  int   (*_core_file_failing_signal) (bfd *);
307  bool  (*_core_file_matches_executable_p) (bfd *, bfd *);
308  int   (*_core_file_pid) (bfd *);
309
310  /* Archive entry points.  */
311#define BFD_JUMP_TABLE_ARCHIVE(NAME) \
312  NAME##_slurp_armap, \
313  NAME##_slurp_extended_name_table, \
314  NAME##_construct_extended_name_table, \
315  NAME##_truncate_arname, \
316  NAME##_write_armap, \
317  NAME##_read_ar_hdr, \
318  NAME##_write_ar_hdr, \
319  NAME##_openr_next_archived_file, \
320  NAME##_get_elt_at_index, \
321  NAME##_generic_stat_arch_elt, \
322  NAME##_update_armap_timestamp
323
324  bool (*_bfd_slurp_armap) (bfd *);
325  bool (*_bfd_slurp_extended_name_table) (bfd *);
326  bool (*_bfd_construct_extended_name_table) (bfd *, char **,
327                                              bfd_size_type *,
328                                              const char **);
329  void (*_bfd_truncate_arname) (bfd *, const char *, char *);
330  bool (*write_armap) (bfd *, unsigned, struct orl *, unsigned, int);
331  void *(*_bfd_read_ar_hdr_fn) (bfd *);
332  bool (*_bfd_write_ar_hdr_fn) (bfd *, bfd *);
333  bfd *(*openr_next_archived_file) (bfd *, bfd *);
334#define bfd_get_elt_at_index(b,i) \
335       BFD_SEND (b, _bfd_get_elt_at_index, (b,i))
336  bfd *(*_bfd_get_elt_at_index) (bfd *, symindex);
337  int  (*_bfd_stat_arch_elt) (bfd *, struct stat *);
338  bool (*_bfd_update_armap_timestamp) (bfd *);
339
340  /* Entry points used for symbols.  */
341#define BFD_JUMP_TABLE_SYMBOLS(NAME) \
342  NAME##_get_symtab_upper_bound, \
343  NAME##_canonicalize_symtab, \
344  NAME##_make_empty_symbol, \
345  NAME##_print_symbol, \
346  NAME##_get_symbol_info, \
347  NAME##_get_symbol_version_string, \
348  NAME##_bfd_is_local_label_name, \
349  NAME##_bfd_is_target_special_symbol, \
350  NAME##_get_lineno, \
351  NAME##_find_nearest_line, \
352  NAME##_find_line, \
353  NAME##_find_inliner_info, \
354  NAME##_bfd_make_debug_symbol, \
355  NAME##_read_minisymbols, \
356  NAME##_minisymbol_to_symbol
357
358  long (*_bfd_get_symtab_upper_bound) (bfd *);
359  long (*_bfd_canonicalize_symtab) (bfd *, struct bfd_symbol **);
360  struct bfd_symbol *
361       (*_bfd_make_empty_symbol) (bfd *);
362  void (*_bfd_print_symbol) (bfd *, void *, struct bfd_symbol *,
363                             bfd_print_symbol_type);
364#define bfd_print_symbol(b,p,s,e) \
365       BFD_SEND (b, _bfd_print_symbol, (b,p,s,e))
366  void  (*_bfd_get_symbol_info) (bfd *, struct bfd_symbol *, symbol_info *);
367#define bfd_get_symbol_info(b,p,e) \
368       BFD_SEND (b, _bfd_get_symbol_info, (b,p,e))
369  const char *
370       (*_bfd_get_symbol_version_string) (bfd *, struct bfd_symbol *,
371                                          bool, bool *);
372#define bfd_get_symbol_version_string(b,s,p,h) \
373       BFD_SEND (b, _bfd_get_symbol_version_string, (b,s,p,h))
374  bool (*_bfd_is_local_label_name) (bfd *, const char *);
375  bool (*_bfd_is_target_special_symbol) (bfd *, asymbol *);
376  alent *
377       (*_get_lineno) (bfd *, struct bfd_symbol *);
378  bool (*_bfd_find_nearest_line) (bfd *, struct bfd_symbol **,
379                                  struct bfd_section *, bfd_vma,
380                                  const char **, const char **,
381                                  unsigned int *, unsigned int *);
382  bool (*_bfd_find_line) (bfd *, struct bfd_symbol **,
383                          struct bfd_symbol *, const char **,
384                          unsigned int *);
385  bool (*_bfd_find_inliner_info)
386    (bfd *, const char **, const char **, unsigned int *);
387 /* Back-door to allow format-aware applications to create debug symbols
388    while using BFD for everything else.  Currently used by the assembler
389    when creating COFF files.  */
390  asymbol *
391       (*_bfd_make_debug_symbol) (bfd *, void *, unsigned long size);
392#define bfd_read_minisymbols(b, d, m, s) \
393       BFD_SEND (b, _read_minisymbols, (b, d, m, s))
394  long (*_read_minisymbols) (bfd *, bool, void **, unsigned int *);
395#define bfd_minisymbol_to_symbol(b, d, m, f) \
396       BFD_SEND (b, _minisymbol_to_symbol, (b, d, m, f))
397  asymbol *
398       (*_minisymbol_to_symbol) (bfd *, bool, const void *, asymbol *);
399
400  /* Routines for relocs.  */
401#define BFD_JUMP_TABLE_RELOCS(NAME) \
402  NAME##_get_reloc_upper_bound, \
403  NAME##_canonicalize_reloc, \
404  NAME##_set_reloc, \
405  NAME##_bfd_reloc_type_lookup, \
406  NAME##_bfd_reloc_name_lookup
407
408  long (*_get_reloc_upper_bound) (bfd *, sec_ptr);
409  long (*_bfd_canonicalize_reloc) (bfd *, sec_ptr, arelent **,
410                                   struct bfd_symbol **);
411  void (*_bfd_set_reloc) (bfd *, sec_ptr, arelent **, unsigned int);
412  /* See documentation on reloc types.  */
413  reloc_howto_type *
414       (*reloc_type_lookup) (bfd *, bfd_reloc_code_real_type);
415  reloc_howto_type *
416       (*reloc_name_lookup) (bfd *, const char *);
417
418  /* Routines used when writing an object file.  */
419#define BFD_JUMP_TABLE_WRITE(NAME) \
420  NAME##_set_arch_mach, \
421  NAME##_set_section_contents
422
423  bool (*_bfd_set_arch_mach) (bfd *, enum bfd_architecture,
424                                     unsigned long);
425  bool (*_bfd_set_section_contents) (bfd *, sec_ptr, const void *,
426                                     file_ptr, bfd_size_type);
427
428  /* Routines used by the linker.  */
429#define BFD_JUMP_TABLE_LINK(NAME) \
430  NAME##_sizeof_headers, \
431  NAME##_bfd_get_relocated_section_contents, \
432  NAME##_bfd_relax_section, \
433  NAME##_bfd_link_hash_table_create, \
434  NAME##_bfd_link_add_symbols, \
435  NAME##_bfd_link_just_syms, \
436  NAME##_bfd_copy_link_hash_symbol_type, \
437  NAME##_bfd_final_link, \
438  NAME##_bfd_link_split_section, \
439  NAME##_bfd_link_check_relocs, \
440  NAME##_bfd_gc_sections, \
441  NAME##_bfd_lookup_section_flags, \
442  NAME##_bfd_merge_sections, \
443  NAME##_bfd_is_group_section, \
444  NAME##_bfd_group_name, \
445  NAME##_bfd_discard_group, \
446  NAME##_section_already_linked, \
447  NAME##_bfd_define_common_symbol, \
448  NAME##_bfd_link_hide_symbol, \
449  NAME##_bfd_define_start_stop
450
451  int  (*_bfd_sizeof_headers) (bfd *, struct bfd_link_info *);
452  bfd_byte *
453       (*_bfd_get_relocated_section_contents) (bfd *,
454                                               struct bfd_link_info *,
455                                               struct bfd_link_order *,
456                                               bfd_byte *, bool,
457                                               struct bfd_symbol **);
458
459  bool (*_bfd_relax_section) (bfd *, struct bfd_section *,
460                              struct bfd_link_info *, bool *);
461
462  /* Create a hash table for the linker.  Different backends store
463     different information in this table.  */
464  struct bfd_link_hash_table *
465       (*_bfd_link_hash_table_create) (bfd *);
466
467  /* Add symbols from this object file into the hash table.  */
468  bool (*_bfd_link_add_symbols) (bfd *, struct bfd_link_info *);
469
470  /* Indicate that we are only retrieving symbol values from this section.  */
471  void (*_bfd_link_just_syms) (asection *, struct bfd_link_info *);
472
473  /* Copy the symbol type and other attributes for a linker script
474     assignment of one symbol to another.  */
475#define bfd_copy_link_hash_symbol_type(b, t, f) \
476       BFD_SEND (b, _bfd_copy_link_hash_symbol_type, (b, t, f))
477  void (*_bfd_copy_link_hash_symbol_type) (bfd *,
478                                           struct bfd_link_hash_entry *,
479                                           struct bfd_link_hash_entry *);
480
481  /* Do a link based on the link_order structures attached to each
482     section of the BFD.  */
483  bool (*_bfd_final_link) (bfd *, struct bfd_link_info *);
484
485  /* Should this section be split up into smaller pieces during linking.  */
486  bool (*_bfd_link_split_section) (bfd *, struct bfd_section *);
487
488  /* Check the relocations in the bfd for validity.  */
489  bool (* _bfd_link_check_relocs)(bfd *, struct bfd_link_info *);
490
491  /* Remove sections that are not referenced from the output.  */
492  bool (*_bfd_gc_sections) (bfd *, struct bfd_link_info *);
493
494  /* Sets the bitmask of allowed and disallowed section flags.  */
495  bool (*_bfd_lookup_section_flags) (struct bfd_link_info *,
496                                     struct flag_info *, asection *);
497
498  /* Attempt to merge SEC_MERGE sections.  */
499  bool (*_bfd_merge_sections) (bfd *, struct bfd_link_info *);
500
501  /* Is this section a member of a group?  */
502  bool (*_bfd_is_group_section) (bfd *, const struct bfd_section *);
503
504  /* The group name, if section is a member of a group.  */
505  const char *(*_bfd_group_name) (bfd *, const struct bfd_section *);
506
507  /* Discard members of a group.  */
508  bool (*_bfd_discard_group) (bfd *, struct bfd_section *);
509
510  /* Check if SEC has been already linked during a reloceatable or
511     final link.  */
512  bool (*_section_already_linked) (bfd *, asection *,
513                                   struct bfd_link_info *);
514
515  /* Define a common symbol.  */
516  bool (*_bfd_define_common_symbol) (bfd *, struct bfd_link_info *,
517                                     struct bfd_link_hash_entry *);
518
519  /* Hide a symbol.  */
520  void (*_bfd_link_hide_symbol) (bfd *, struct bfd_link_info *,
521                                 struct bfd_link_hash_entry *);
522
523  /* Define a __start, __stop, .startof. or .sizeof. symbol.  */
524  struct bfd_link_hash_entry *
525       (*_bfd_define_start_stop) (struct bfd_link_info *, const char *,
526                                  asection *);
527
528  /* Routines to handle dynamic symbols and relocs.  */
529#define BFD_JUMP_TABLE_DYNAMIC(NAME) \
530  NAME##_get_dynamic_symtab_upper_bound, \
531  NAME##_canonicalize_dynamic_symtab, \
532  NAME##_get_synthetic_symtab, \
533  NAME##_get_dynamic_reloc_upper_bound, \
534  NAME##_canonicalize_dynamic_reloc
535
536  /* Get the amount of memory required to hold the dynamic symbols.  */
537  long (*_bfd_get_dynamic_symtab_upper_bound) (bfd *);
538  /* Read in the dynamic symbols.  */
539  long (*_bfd_canonicalize_dynamic_symtab) (bfd *, struct bfd_symbol **);
540  /* Create synthetized symbols.  */
541  long (*_bfd_get_synthetic_symtab) (bfd *, long, struct bfd_symbol **,
542                                     long, struct bfd_symbol **,
543                                     struct bfd_symbol **);
544  /* Get the amount of memory required to hold the dynamic relocs.  */
545  long (*_bfd_get_dynamic_reloc_upper_bound) (bfd *);
546  /* Read in the dynamic relocs.  */
547  long (*_bfd_canonicalize_dynamic_reloc) (bfd *, arelent **,
548                                           struct bfd_symbol **);
549
550@end example
551A pointer to an alternative bfd_target in case the current one is not
552satisfactory.  This can happen when the target cpu supports both big
553and little endian code, and target chosen by the linker has the wrong
554endianness.  The function open_output() in ld/ldlang.c uses this field
555to find an alternative output format that is suitable.
556@example
557  /* Opposite endian version of this target.  */
558  const struct bfd_target *alternative_target;
559
560  /* Data for use by back-end routines, which isn't
561     generic enough to belong in this structure.  */
562  const void *backend_data;
563
564@} bfd_target;
565
566static inline const char *
567bfd_get_target (const bfd *abfd)
568@{
569  return abfd->xvec->name;
570@}
571
572static inline enum bfd_flavour
573bfd_get_flavour (const bfd *abfd)
574@{
575  return abfd->xvec->flavour;
576@}
577
578static inline flagword
579bfd_applicable_file_flags (const bfd *abfd)
580@{
581  return abfd->xvec->object_flags;
582@}
583
584static inline bool
585bfd_family_coff (const bfd *abfd)
586@{
587  return (bfd_get_flavour (abfd) == bfd_target_coff_flavour
588          || bfd_get_flavour (abfd) == bfd_target_xcoff_flavour);
589@}
590
591static inline bool
592bfd_big_endian (const bfd *abfd)
593@{
594  return abfd->xvec->byteorder == BFD_ENDIAN_BIG;
595@}
596static inline bool
597bfd_little_endian (const bfd *abfd)
598@{
599  return abfd->xvec->byteorder == BFD_ENDIAN_LITTLE;
600@}
601
602static inline bool
603bfd_header_big_endian (const bfd *abfd)
604@{
605  return abfd->xvec->header_byteorder == BFD_ENDIAN_BIG;
606@}
607
608static inline bool
609bfd_header_little_endian (const bfd *abfd)
610@{
611  return abfd->xvec->header_byteorder == BFD_ENDIAN_LITTLE;
612@}
613
614static inline flagword
615bfd_applicable_section_flags (const bfd *abfd)
616@{
617  return abfd->xvec->section_flags;
618@}
619
620static inline char
621bfd_get_symbol_leading_char (const bfd *abfd)
622@{
623  return abfd->xvec->symbol_leading_char;
624@}
625
626static inline enum bfd_flavour
627bfd_asymbol_flavour (const asymbol *sy)
628@{
629  if ((sy->flags & BSF_SYNTHETIC) != 0)
630    return bfd_target_unknown_flavour;
631  return sy->the_bfd->xvec->flavour;
632@}
633
634static inline bool
635bfd_keep_unused_section_symbols (const bfd *abfd)
636@{
637  return abfd->xvec->keep_unused_section_symbols;
638@}
639
640@end example
641
642@findex bfd_set_default_target
643@subsubsection @code{bfd_set_default_target}
644@strong{Synopsis}
645@example
646bool bfd_set_default_target (const char *name);
647@end example
648@strong{Description}@*
649Set the default target vector to use when recognizing a BFD.
650This takes the name of the target, which may be a BFD target
651name or a configuration triplet.
652
653@findex bfd_find_target
654@subsubsection @code{bfd_find_target}
655@strong{Synopsis}
656@example
657const bfd_target *bfd_find_target (const char *target_name, bfd *abfd);
658@end example
659@strong{Description}@*
660Return a pointer to the transfer vector for the object target
661named @var{target_name}.  If @var{target_name} is @code{NULL},
662choose the one in the environment variable @code{GNUTARGET}; if
663that is null or not defined, then choose the first entry in the
664target list.  Passing in the string "default" or setting the
665environment variable to "default" will cause the first entry in
666the target list to be returned, and "target_defaulted" will be
667set in the BFD if @var{abfd} isn't @code{NULL}.  This causes
668@code{bfd_check_format} to loop over all the targets to find the
669one that matches the file being read.
670
671@findex bfd_get_target_info
672@subsubsection @code{bfd_get_target_info}
673@strong{Synopsis}
674@example
675const bfd_target *bfd_get_target_info (const char *target_name,
676    bfd *abfd,
677    bool *is_bigendian,
678    int *underscoring,
679    const char **def_target_arch);
680@end example
681@strong{Description}@*
682Return a pointer to the transfer vector for the object target
683named @var{target_name}.  If @var{target_name} is @code{NULL},
684choose the one in the environment variable @code{GNUTARGET}; if
685that is null or not defined, then choose the first entry in the
686target list.  Passing in the string "default" or setting the
687environment variable to "default" will cause the first entry in
688the target list to be returned, and "target_defaulted" will be
689set in the BFD if @var{abfd} isn't @code{NULL}.  This causes
690@code{bfd_check_format} to loop over all the targets to find the
691one that matches the file being read.
692If @var{is_bigendian} is not @code{NULL}, then set this value to target's
693endian mode. True for big-endian, FALSE for little-endian or for
694invalid target.
695If @var{underscoring} is not @code{NULL}, then set this value to target's
696underscoring mode. Zero for none-underscoring, -1 for invalid target,
697else the value of target vector's symbol underscoring.
698If @var{def_target_arch} is not @code{NULL}, then set it to the architecture
699string specified by the target_name.
700
701@findex bfd_target_list
702@subsubsection @code{bfd_target_list}
703@strong{Synopsis}
704@example
705const char ** bfd_target_list (void);
706@end example
707@strong{Description}@*
708Return a freshly malloced NULL-terminated
709vector of the names of all the valid BFD targets. Do not
710modify the names.
711
712@findex bfd_iterate_over_targets
713@subsubsection @code{bfd_iterate_over_targets}
714@strong{Synopsis}
715@example
716const bfd_target *bfd_iterate_over_targets
717   (int (*func) (const bfd_target *, void *),
718    void *data);
719@end example
720@strong{Description}@*
721Call @var{func} for each target in the list of BFD target
722vectors, passing @var{data} to @var{func}.  Stop iterating if
723@var{func} returns a non-zero result, and return that target
724vector.  Return NULL if @var{func} always returns zero.
725
726@findex bfd_flavour_name
727@subsubsection @code{bfd_flavour_name}
728@strong{Synopsis}
729@example
730const char *bfd_flavour_name (enum bfd_flavour flavour);
731@end example
732@strong{Description}@*
733Return the string form of @var{flavour}.
734
735