171867Smsmith@section Targets
267754Smsmith
367754Smsmith
467754Smsmith@strong{Description}@*
5138287SmarksEach port of BFD to a different machine requires the creation
667754Smsmithof a target back end. All the back end provides to the root
767754Smsmithpart of BFD is a structure containing pointers to functions
867754Smsmithwhich perform certain low level operations on files. BFD
967754Smsmithtranslates the applications's requests through a pointer into
1067754Smsmithcalls to the back end routines.
1167754Smsmith
1267754SmsmithWhen a file is opened with @code{bfd_openr}, its format and
13126372Snjltarget are unknown. BFD uses various mechanisms to determine
1470243Smsmithhow to interpret the file. The operations performed are:
1567754Smsmith
1667754Smsmith@itemize @bullet
1767754Smsmith
1867754Smsmith@item
1967754SmsmithCreate a BFD by calling the internal routine
2067754Smsmith@code{_bfd_new_bfd}, then call @code{bfd_find_target} with the
2167754Smsmithtarget string supplied to @code{bfd_openr} and the new BFD pointer.
2267754Smsmith
2367754Smsmith@item
2467754SmsmithIf a null target string was provided to @code{bfd_find_target},
2567754Smsmithlook up the environment variable @code{GNUTARGET} and use
2667754Smsmiththat as the target string.
2767754Smsmith
2867754Smsmith@item
2967754SmsmithIf the target string is still @code{NULL}, or the target string is
3067754Smsmith@code{default}, then use the first item in the target vector
3167754Smsmithas the target type, and set @code{target_defaulted} in the BFD to
3267754Smsmithcause @code{bfd_check_format} to loop through all the targets.
3367754Smsmith@xref{bfd_target}.  @xref{Formats}.
3467754Smsmith
3567754Smsmith@item
3667754SmsmithOtherwise, inspect the elements in the target vector
3767754Smsmithone by one, until a match on target name is found. When found,
3867754Smsmithuse it.
3967754Smsmith
4067754Smsmith@item
4167754SmsmithOtherwise return the error @code{bfd_error_invalid_target} to
4267754Smsmith@code{bfd_openr}.
4367754Smsmith
4467754Smsmith@item
4567754Smsmith@code{bfd_openr} attempts to open the file using
4667754Smsmith@code{bfd_open_file}, and returns the BFD.
4767754Smsmith@end itemize
4867754SmsmithOnce the BFD has been opened and the target selected, the file
4967754Smsmithformat may be determined. This is done by calling
5067754Smsmith@code{bfd_check_format} on the BFD with a suggested format.
5167754SmsmithIf @code{target_defaulted} has been set, each possible target
5267754Smsmithtype is tried to see if it recognizes the specified format.
5367754Smsmith@code{bfd_check_format} returns @code{TRUE} when the caller guesses right.
5467754Smsmith@menu
5567754Smsmith* bfd_target::
5667754Smsmith@end menu
5767754Smsmith
5867754Smsmith@node bfd_target,  , Targets, Targets
5967754Smsmith
6067754Smsmith@subsection bfd_target
6167754Smsmith
6267754Smsmith
6367754Smsmith@strong{Description}@*
6467754SmsmithThis structure contains everything that BFD knows about a
6567754Smsmithtarget. It includes things like its byte order, name, and which
6667754Smsmithroutines to call to do various operations.
6767754Smsmith
6867754SmsmithEvery BFD points to a target structure with its @code{xvec}
6967754Smsmithmember.
7067754Smsmith
7167754SmsmithThe macros below are used to dispatch to functions through the
7267754Smsmith@code{bfd_target} vector. They are used in a number of macros further
7367754Smsmithdown in @file{bfd.h}, and are also used when calling various
7467754Smsmithroutines by hand inside the BFD implementation.  The @var{arglist}
7567754Smsmithargument must be parenthesized; it contains all the arguments
7667754Smsmithto the called function.
7767754Smsmith
7867754SmsmithThey make the documentation (more) unpleasant to read, so if
7967754Smsmithsomeone wants to fix this and not break the above, please do.
8067754Smsmith@example
8167754Smsmith#define BFD_SEND(bfd, message, arglist) \
8267754Smsmith  ((*((bfd)->xvec->message)) arglist)
8367754Smsmith
8467754Smsmith#ifdef DEBUG_BFD_SEND
8567754Smsmith#undef BFD_SEND
8667754Smsmith#define BFD_SEND(bfd, message, arglist) \
8767754Smsmith  (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
8867754Smsmith    ((*((bfd)->xvec->message)) arglist) : \
8967754Smsmith    (bfd_assert (__FILE__,__LINE__), NULL))
9067754Smsmith#endif
9167754Smsmith@end example
9267754SmsmithFor operations which index on the BFD format:
9367754Smsmith@example
9467754Smsmith#define BFD_SEND_FMT(bfd, message, arglist) \
9567754Smsmith  (((bfd)->xvec->message[(int) ((bfd)->format)]) arglist)
9667754Smsmith
9767754Smsmith#ifdef DEBUG_BFD_SEND
9867754Smsmith#undef BFD_SEND_FMT
9967754Smsmith#define BFD_SEND_FMT(bfd, message, arglist) \
10067754Smsmith  (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \
10167754Smsmith   (((bfd)->xvec->message[(int) ((bfd)->format)]) arglist) : \
10267754Smsmith   (bfd_assert (__FILE__,__LINE__), NULL))
10367754Smsmith#endif
10467754Smsmith
10567754Smsmith/* Defined to TRUE if unused section symbol should be kept.  */
10667754Smsmith#ifndef TARGET_KEEP_UNUSED_SECTION_SYMBOLS
10767754Smsmith#define TARGET_KEEP_UNUSED_SECTION_SYMBOLS true
10867754Smsmith#endif
10967754Smsmith
11067754Smsmith@end example
11167754SmsmithThis is the structure which defines the type of BFD this is.  The
11267754Smsmith@code{xvec} member of the struct @code{bfd} itself points here.  Each
11367754Smsmithmodule that implements access to a different target under BFD,
11467754Smsmithdefines one of these.
11567754Smsmith
11667754SmsmithFIXME, these names should be rationalised with the names of
11767754Smsmiththe entry points which call them. Too bad we can't have one
11867754Smsmithmacro to define them both!
11967754Smsmith@example
12067754Smsmithenum bfd_flavour
12177424Smsmith@{
12291116Smsmith  /* N.B. Update bfd_flavour_name if you change this.  */
12367754Smsmith  bfd_target_unknown_flavour,
12467754Smsmith  bfd_target_aout_flavour,
12567754Smsmith  bfd_target_coff_flavour,
12667754Smsmith  bfd_target_ecoff_flavour,
127129684Snjl  bfd_target_xcoff_flavour,
12867754Smsmith  bfd_target_elf_flavour,
129128212Snjl  bfd_target_tekhex_flavour,
13067754Smsmith  bfd_target_srec_flavour,
131128212Snjl  bfd_target_verilog_flavour,
13267754Smsmith  bfd_target_ihex_flavour,
133138287Smarks  bfd_target_som_flavour,
134138287Smarks  bfd_target_os9k_flavour,
135129684Snjl  bfd_target_versados_flavour,
13667754Smsmith  bfd_target_msdos_flavour,
13767754Smsmith  bfd_target_ovax_flavour,
13867754Smsmith  bfd_target_evax_flavour,
13999679Siwasaki  bfd_target_mmo_flavour,
140129684Snjl  bfd_target_mach_o_flavour,
141114237Snjl  bfd_target_pef_flavour,
14267754Smsmith  bfd_target_pef_xlib_flavour,
143114237Snjl  bfd_target_sym_flavour
14499679Siwasaki@};
14567754Smsmith
14683174Smsmithenum bfd_endian @{ BFD_ENDIAN_BIG, BFD_ENDIAN_LITTLE, BFD_ENDIAN_UNKNOWN @};
14791116Smsmith
14883174Smsmith/* Forward declaration.  */
14983174Smsmithtypedef struct bfd_link_info _bfd_link_info;
150114237Snjl
15167754Smsmith/* Forward declaration.  */
152114237Snjltypedef struct flag_info flag_info;
153114237Snjl
154114237Snjltypedef void (*bfd_cleanup) (bfd *);
155129684Snjl
156114237Snjltypedef struct bfd_target
15767754Smsmith@{
158129684Snjl  /* Identifies the kind of target, e.g., SunOS4, Ultrix, etc.  */
15984491Smsmith  const char *name;
160129684Snjl
161117521Snjl /* The "flavour" of a back end is a general indication about
16299679Siwasaki    the contents of a file.  */
163129684Snjl  enum bfd_flavour flavour;
16467754Smsmith
16567754Smsmith  /* The order of bytes within the data area of a file.  */
16691116Smsmith  enum bfd_endian byteorder;
16784491Smsmith
16884491Smsmith /* The order of bytes within the header parts of a file.  */
16967754Smsmith  enum bfd_endian header_byteorder;
17067754Smsmith
171128212Snjl  /* A mask of all the flags which an executable may have set -
17267754Smsmith     from the set @code{BFD_NO_FLAGS}, @code{HAS_RELOC}, ...@code{D_PAGED}.  */
173138287Smarks  flagword object_flags;
17467754Smsmith
175128212Snjl /* A mask of all the flags which a section may have set - from
17667754Smsmith    the set @code{SEC_NO_FLAGS}, @code{SEC_ALLOC}, ...@code{SET_NEVER_LOAD}.  */
17767754Smsmith  flagword section_flags;
17867754Smsmith
17999679Siwasaki /* The character normally found at the front of a symbol.
18067754Smsmith    (if any), perhaps `_'.  */
181114237Snjl  char symbol_leading_char;
18267754Smsmith
18399679Siwasaki /* The pad character for file names within an archive header.  */
18467754Smsmith  char ar_pad_char;
18580062Smsmith
18691116Smsmith  /* The maximum number of characters in an archive header.  */
18783174Smsmith  unsigned char ar_max_namelen;
18883174Smsmith
18967754Smsmith  /* How well this target matches, used to select between various
19067754Smsmith     possible targets when more than one target matches.  */
19167754Smsmith  unsigned char match_priority;
19267754Smsmith
193129684Snjl /* TRUE if unused section symbols should be kept.  */
194117521Snjl  bool keep_unused_section_symbols;
19599679Siwasaki
19699679Siwasaki  /* Entries for byte swapping for data. These are different from the
19767754Smsmith     other entry points, since they don't take a BFD as the first argument.
19867754Smsmith     Certain other handlers could do the same.  */
19967754Smsmith  uint64_t       (*bfd_getx64) (const void *);
20067754Smsmith  int64_t        (*bfd_getx_signed_64) (const void *);
20167754Smsmith  void           (*bfd_putx64) (uint64_t, void *);
20267754Smsmith  bfd_vma        (*bfd_getx32) (const void *);
20367754Smsmith  bfd_signed_vma (*bfd_getx_signed_32) (const void *);
204128212Snjl  void           (*bfd_putx32) (bfd_vma, void *);
205128212Snjl  bfd_vma        (*bfd_getx16) (const void *);
20667754Smsmith  bfd_signed_vma (*bfd_getx_signed_16) (const void *);
207128212Snjl  void           (*bfd_putx16) (bfd_vma, void *);
20867754Smsmith
20967754Smsmith  /* Byte swapping for the headers.  */
21067754Smsmith  uint64_t       (*bfd_h_getx64) (const void *);
21167754Smsmith  int64_t        (*bfd_h_getx_signed_64) (const void *);
21267754Smsmith  void           (*bfd_h_putx64) (uint64_t, void *);
21399679Siwasaki  bfd_vma        (*bfd_h_getx32) (const void *);
21467754Smsmith  bfd_signed_vma (*bfd_h_getx_signed_32) (const void *);
215117521Snjl  void           (*bfd_h_putx32) (bfd_vma, void *);
21667754Smsmith  bfd_vma        (*bfd_h_getx16) (const void *);
21767754Smsmith  bfd_signed_vma (*bfd_h_getx_signed_16) (const void *);
218114237Snjl  void           (*bfd_h_putx16) (bfd_vma, void *);
219129684Snjl
22091116Smsmith  /* Format dependent routines: these are vectors of entry points
22199679Siwasaki     within the target vector structure, one for each format to check.  */
222114237Snjl
22367754Smsmith  /* Check the format of a file being read.  Return a @code{bfd_cleanup} on
22480062Smsmith     success or zero on failure.  */
22591116Smsmith  bfd_cleanup (*_bfd_check_format[bfd_type_end]) (bfd *);
22683174Smsmith
22783174Smsmith  /* Set the format of a file being written.  */
22867754Smsmith  bool (*_bfd_set_format[bfd_type_end]) (bfd *);
22967754Smsmith
23099679Siwasaki  /* Write cached information into a file being written, at @code{bfd_close}.  */
23167754Smsmith  bool (*_bfd_write_contents[bfd_type_end]) (bfd *);
23267754Smsmith
233114237Snjl@end example
23467754SmsmithThe general target vector.  These vectors are initialized using the
235114237SnjlBFD_JUMP_TABLE macros.
23667754Smsmith@example
23791116Smsmith
23891116Smsmith  /* Generic entry points.  */
239129684Snjl#define BFD_JUMP_TABLE_GENERIC(NAME) \
24091116Smsmith  NAME##_close_and_cleanup, \
241129684Snjl  NAME##_bfd_free_cached_info, \
24291116Smsmith  NAME##_new_section_hook, \
243129684Snjl  NAME##_get_section_contents, \
24499679Siwasaki  NAME##_get_section_contents_in_window
245114237Snjl
24667754Smsmith  /* Called when the BFD is being closed to do any necessary cleanup.  */
24767754Smsmith  bool (*_close_and_cleanup) (bfd *);
248129684Snjl  /* Ask the BFD to free all cached information.  */
24991116Smsmith  bool (*_bfd_free_cached_info) (bfd *);
250129684Snjl  /* Called when a new section is created.  */
25184491Smsmith  bool (*_new_section_hook) (bfd *, sec_ptr);
252114237Snjl  /* Read the contents of a section.  */
25384491Smsmith  bool (*_bfd_get_section_contents) (bfd *, sec_ptr, void *, file_ptr,
25484491Smsmith                                     bfd_size_type);
255129684Snjl  bool (*_bfd_get_section_contents_in_window) (bfd *, sec_ptr, bfd_window *,
25691116Smsmith                                               file_ptr, bfd_size_type);
257117521Snjl
25899679Siwasaki  /* Entry points to copy private data.  */
25999679Siwasaki#define BFD_JUMP_TABLE_COPY(NAME) \
260117521Snjl  NAME##_bfd_copy_private_bfd_data, \
26199679Siwasaki  NAME##_bfd_merge_private_bfd_data, \
26299679Siwasaki  _bfd_generic_init_private_section_data, \
263129684Snjl  NAME##_bfd_copy_private_section_data, \
26467754Smsmith  NAME##_bfd_copy_private_symbol_data, \
265114237Snjl  NAME##_bfd_copy_private_header_data, \
26667754Smsmith  NAME##_bfd_set_private_flags, \
267114237Snjl  NAME##_bfd_print_private_bfd_data
268114237Snjl
269114237Snjl  /* Called to copy BFD general private data from one object file
270114237Snjl     to another.  */
271117521Snjl  bool (*_bfd_copy_private_bfd_data) (bfd *, bfd *);
272117521Snjl  /* Called to merge BFD general private data from one object file
273117521Snjl     to a common output file when linking.  */
274117521Snjl  bool (*_bfd_merge_private_bfd_data) (bfd *, struct bfd_link_info *);
275117521Snjl  /* Called to initialize BFD private section data from one object file
276117521Snjl     to another.  */
277117521Snjl#define bfd_init_private_section_data(ibfd, isec, obfd, osec, link_info) \
278117521Snjl       BFD_SEND (obfd, _bfd_init_private_section_data, \
279117521Snjl                 (ibfd, isec, obfd, osec, link_info))
280117521Snjl  bool (*_bfd_init_private_section_data) (bfd *, sec_ptr, bfd *, sec_ptr,
281117521Snjl                                          struct bfd_link_info *);
282117521Snjl  /* Called to copy BFD private section data from one object file
283117521Snjl     to another.  */
284117521Snjl  bool (*_bfd_copy_private_section_data) (bfd *, sec_ptr, bfd *, sec_ptr);
285117521Snjl  /* Called to copy BFD private symbol data from one symbol
286117521Snjl     to another.  */
287117521Snjl  bool (*_bfd_copy_private_symbol_data) (bfd *, asymbol *,
288117521Snjl                                         bfd *, asymbol *);
289117521Snjl  /* Called to copy BFD private header data from one object file
290117521Snjl     to another.  */
291117521Snjl  bool (*_bfd_copy_private_header_data) (bfd *, bfd *);
292117521Snjl  /* Called to set private backend flags.  */
293117521Snjl  bool (*_bfd_set_private_flags) (bfd *, flagword);
294117521Snjl
295117521Snjl  /* Called to print private BFD data.  */
296117521Snjl  bool (*_bfd_print_private_bfd_data) (bfd *, void *);
297117521Snjl
298117521Snjl  /* Core file entry points.  */
299117521Snjl#define BFD_JUMP_TABLE_CORE(NAME) \
300117521Snjl  NAME##_core_file_failing_command, \
301117521Snjl  NAME##_core_file_failing_signal, \
302117521Snjl  NAME##_core_file_matches_executable_p, \
303117521Snjl  NAME##_core_file_pid
304126372Snjl
305126372Snjl  char *(*_core_file_failing_command) (bfd *);
306117521Snjl  int   (*_core_file_failing_signal) (bfd *);
307117521Snjl  bool  (*_core_file_matches_executable_p) (bfd *, bfd *);
308117521Snjl  int   (*_core_file_pid) (bfd *);
309117521Snjl
310117521Snjl  /* Archive entry points.  */
311117521Snjl#define BFD_JUMP_TABLE_ARCHIVE(NAME) \
312117521Snjl  NAME##_slurp_armap, \
313117521Snjl  NAME##_slurp_extended_name_table, \
31499679Siwasaki  NAME##_construct_extended_name_table, \
31567754Smsmith  NAME##_truncate_arname, \
31684491Smsmith  NAME##_write_armap, \
31791116Smsmith  NAME##_read_ar_hdr, \
31884491Smsmith  NAME##_write_ar_hdr, \
31984491Smsmith  NAME##_openr_next_archived_file, \
320117521Snjl  NAME##_get_elt_at_index, \
321117521Snjl  NAME##_generic_stat_arch_elt, \
322117521Snjl  NAME##_update_armap_timestamp
323117521Snjl
324117521Snjl  bool (*_bfd_slurp_armap) (bfd *);
325117521Snjl  bool (*_bfd_slurp_extended_name_table) (bfd *);
326117521Snjl  bool (*_bfd_construct_extended_name_table) (bfd *, char **,
327128212Snjl                                              bfd_size_type *,
328117521Snjl                                              const char **);
329117521Snjl  void (*_bfd_truncate_arname) (bfd *, const char *, char *);
330117521Snjl  bool (*write_armap) (bfd *, unsigned, struct orl *, unsigned, int);
331117521Snjl  void *(*_bfd_read_ar_hdr_fn) (bfd *);
332117521Snjl  bool (*_bfd_write_ar_hdr_fn) (bfd *, bfd *);
333117521Snjl  bfd *(*openr_next_archived_file) (bfd *, bfd *);
334117521Snjl#define bfd_get_elt_at_index(b,i) \
335117521Snjl       BFD_SEND (b, _bfd_get_elt_at_index, (b,i))
336117521Snjl  bfd *(*_bfd_get_elt_at_index) (bfd *, symindex);
337117521Snjl  int  (*_bfd_stat_arch_elt) (bfd *, struct stat *);
338117521Snjl  bool (*_bfd_update_armap_timestamp) (bfd *);
339117521Snjl
340117521Snjl  /* Entry points used for symbols.  */
341117521Snjl#define BFD_JUMP_TABLE_SYMBOLS(NAME) \
342117521Snjl  NAME##_get_symtab_upper_bound, \
343117521Snjl  NAME##_canonicalize_symtab, \
344128212Snjl  NAME##_make_empty_symbol, \
345126372Snjl  NAME##_print_symbol, \
346117521Snjl  NAME##_get_symbol_info, \
347117521Snjl  NAME##_get_symbol_version_string, \
348117521Snjl  NAME##_bfd_is_local_label_name, \
349117521Snjl  NAME##_bfd_is_target_special_symbol, \
350117521Snjl  NAME##_get_lineno, \
351117521Snjl  NAME##_find_nearest_line, \
352117521Snjl  NAME##_find_line, \
353117521Snjl  NAME##_find_inliner_info, \
354117521Snjl  NAME##_bfd_make_debug_symbol, \
355117521Snjl  NAME##_read_minisymbols, \
356117521Snjl  NAME##_minisymbol_to_symbol
357117521Snjl
358117521Snjl  long (*_bfd_get_symtab_upper_bound) (bfd *);
359117521Snjl  long (*_bfd_canonicalize_symtab) (bfd *, struct bfd_symbol **);
360129684Snjl  struct bfd_symbol *
361117521Snjl       (*_bfd_make_empty_symbol) (bfd *);
362117521Snjl  void (*_bfd_print_symbol) (bfd *, void *, struct bfd_symbol *,
363117521Snjl                             bfd_print_symbol_type);
364117521Snjl#define bfd_print_symbol(b,p,s,e) \
365117521Snjl       BFD_SEND (b, _bfd_print_symbol, (b,p,s,e))
366117521Snjl  void  (*_bfd_get_symbol_info) (bfd *, struct bfd_symbol *, symbol_info *);
367129684Snjl#define bfd_get_symbol_info(b,p,e) \
368129684Snjl       BFD_SEND (b, _bfd_get_symbol_info, (b,p,e))
369117521Snjl  const char *
370117521Snjl       (*_bfd_get_symbol_version_string) (bfd *, struct bfd_symbol *,
371117521Snjl                                          bool, bool *);
372129684Snjl#define bfd_get_symbol_version_string(b,s,p,h) \
373129684Snjl       BFD_SEND (b, _bfd_get_symbol_version_string, (b,s,p,h))
374117521Snjl  bool (*_bfd_is_local_label_name) (bfd *, const char *);
375117521Snjl  bool (*_bfd_is_target_special_symbol) (bfd *, asymbol *);
376117521Snjl  alent *
377117521Snjl       (*_get_lineno) (bfd *, struct bfd_symbol *);
378117521Snjl  bool (*_bfd_find_nearest_line) (bfd *, struct bfd_symbol **,
379117521Snjl                                  struct bfd_section *, bfd_vma,
380117521Snjl                                  const char **, const char **,
381129684Snjl                                  unsigned int *, unsigned int *);
382117521Snjl  bool (*_bfd_find_line) (bfd *, struct bfd_symbol **,
383117521Snjl                          struct bfd_symbol *, const char **,
384117521Snjl                          unsigned int *);
385117521Snjl  bool (*_bfd_find_inliner_info)
386117521Snjl    (bfd *, const char **, const char **, unsigned int *);
387129684Snjl /* Back-door to allow format-aware applications to create debug symbols
388117521Snjl    while using BFD for everything else.  Currently used by the assembler
389129684Snjl    when creating COFF files.  */
390117521Snjl  asymbol *
391117521Snjl       (*_bfd_make_debug_symbol) (bfd *, void *, unsigned long size);
392129684Snjl#define bfd_read_minisymbols(b, d, m, s) \
393117521Snjl       BFD_SEND (b, _read_minisymbols, (b, d, m, s))
394129684Snjl  long (*_read_minisymbols) (bfd *, bool, void **, unsigned int *);
395129684Snjl#define bfd_minisymbol_to_symbol(b, d, m, f) \
396117521Snjl       BFD_SEND (b, _minisymbol_to_symbol, (b, d, m, f))
397117521Snjl  asymbol *
398117521Snjl       (*_minisymbol_to_symbol) (bfd *, bool, const void *, asymbol *);
399117521Snjl
400117521Snjl  /* Routines for relocs.  */
401117521Snjl#define BFD_JUMP_TABLE_RELOCS(NAME) \
402117521Snjl  NAME##_get_reloc_upper_bound, \
403117521Snjl  NAME##_canonicalize_reloc, \
404117521Snjl  NAME##_set_reloc, \
405117521Snjl  NAME##_bfd_reloc_type_lookup, \
406117521Snjl  NAME##_bfd_reloc_name_lookup
407117521Snjl
408129684Snjl  long (*_get_reloc_upper_bound) (bfd *, sec_ptr);
40984491Smsmith  long (*_bfd_canonicalize_reloc) (bfd *, sec_ptr, arelent **,
410129684Snjl                                   struct bfd_symbol **);
411129684Snjl  void (*_bfd_set_reloc) (bfd *, sec_ptr, arelent **, unsigned int);
41284491Smsmith  /* See documentation on reloc types.  */
413128212Snjl  reloc_howto_type *
41484491Smsmith       (*reloc_type_lookup) (bfd *, bfd_reloc_code_real_type);
415129684Snjl  reloc_howto_type *
416129684Snjl       (*reloc_name_lookup) (bfd *, const char *);
41784491Smsmith
41884491Smsmith  /* Routines used when writing an object file.  */
41984491Smsmith#define BFD_JUMP_TABLE_WRITE(NAME) \
42099679Siwasaki  NAME##_set_arch_mach, \
421129684Snjl  NAME##_set_section_contents
422129684Snjl
423129684Snjl  bool (*_bfd_set_arch_mach) (bfd *, enum bfd_architecture,
42484491Smsmith                                     unsigned long);
425129684Snjl  bool (*_bfd_set_section_contents) (bfd *, sec_ptr, const void *,
42699679Siwasaki                                     file_ptr, bfd_size_type);
42784491Smsmith
42884491Smsmith  /* Routines used by the linker.  */
429129684Snjl#define BFD_JUMP_TABLE_LINK(NAME) \
43091116Smsmith  NAME##_sizeof_headers, \
431129684Snjl  NAME##_bfd_get_relocated_section_contents, \
432129684Snjl  NAME##_bfd_relax_section, \
433129684Snjl  NAME##_bfd_link_hash_table_create, \
434129684Snjl  NAME##_bfd_link_add_symbols, \
435129684Snjl  NAME##_bfd_link_just_syms, \
436129684Snjl  NAME##_bfd_copy_link_hash_symbol_type, \
43791116Smsmith  NAME##_bfd_final_link, \
438129684Snjl  NAME##_bfd_link_split_section, \
439129684Snjl  NAME##_bfd_link_check_relocs, \
440129684Snjl  NAME##_bfd_gc_sections, \
441129684Snjl  NAME##_bfd_lookup_section_flags, \
442129684Snjl  NAME##_bfd_merge_sections, \
443129684Snjl  NAME##_bfd_is_group_section, \
444129684Snjl  NAME##_bfd_group_name, \
445129684Snjl  NAME##_bfd_discard_group, \
446129684Snjl  NAME##_section_already_linked, \
447129684Snjl  NAME##_bfd_define_common_symbol, \
448129684Snjl  NAME##_bfd_link_hide_symbol, \
449117521Snjl  NAME##_bfd_define_start_stop
45084491Smsmith
45199679Siwasaki  int  (*_bfd_sizeof_headers) (bfd *, struct bfd_link_info *);
452117521Snjl  bfd_byte *
453117521Snjl       (*_bfd_get_relocated_section_contents) (bfd *,
454129684Snjl                                               struct bfd_link_info *,
455117521Snjl                                               struct bfd_link_order *,
456138287Smarks                                               bfd_byte *, bool,
457117521Snjl                                               struct bfd_symbol **);
458117521Snjl
459117521Snjl  bool (*_bfd_relax_section) (bfd *, struct bfd_section *,
460129684Snjl                              struct bfd_link_info *, bool *);
461117521Snjl
462117521Snjl  /* Create a hash table for the linker.  Different backends store
463114237Snjl     different information in this table.  */
464129684Snjl  struct bfd_link_hash_table *
465129684Snjl       (*_bfd_link_hash_table_create) (bfd *);
466138287Smarks
467117521Snjl  /* Add symbols from this object file into the hash table.  */
468117521Snjl  bool (*_bfd_link_add_symbols) (bfd *, struct bfd_link_info *);
469114237Snjl
470117521Snjl  /* Indicate that we are only retrieving symbol values from this section.  */
471129684Snjl  void (*_bfd_link_just_syms) (asection *, struct bfd_link_info *);
472117521Snjl
473117521Snjl  /* Copy the symbol type and other attributes for a linker script
474138287Smarks     assignment of one symbol to another.  */
475138287Smarks#define bfd_copy_link_hash_symbol_type(b, t, f) \
476129684Snjl       BFD_SEND (b, _bfd_copy_link_hash_symbol_type, (b, t, f))
477129684Snjl  void (*_bfd_copy_link_hash_symbol_type) (bfd *,
478117521Snjl                                           struct bfd_link_hash_entry *,
479117521Snjl                                           struct bfd_link_hash_entry *);
480129684Snjl
481129684Snjl  /* Do a link based on the link_order structures attached to each
482129684Snjl     section of the BFD.  */
483129684Snjl  bool (*_bfd_final_link) (bfd *, struct bfd_link_info *);
484138287Smarks
485129684Snjl  /* Should this section be split up into smaller pieces during linking.  */
486129684Snjl  bool (*_bfd_link_split_section) (bfd *, struct bfd_section *);
487129684Snjl
488129684Snjl  /* Check the relocations in the bfd for validity.  */
489129684Snjl  bool (* _bfd_link_check_relocs)(bfd *, struct bfd_link_info *);
490129684Snjl
491126372Snjl  /* Remove sections that are not referenced from the output.  */
492129684Snjl  bool (*_bfd_gc_sections) (bfd *, struct bfd_link_info *);
493129684Snjl
494138287Smarks  /* Sets the bitmask of allowed and disallowed section flags.  */
495129684Snjl  bool (*_bfd_lookup_section_flags) (struct bfd_link_info *,
496129684Snjl                                     struct flag_info *, asection *);
497126372Snjl
498114237Snjl  /* Attempt to merge SEC_MERGE sections.  */
499129684Snjl  bool (*_bfd_merge_sections) (bfd *, struct bfd_link_info *);
500128212Snjl
501114237Snjl  /* Is this section a member of a group?  */
502138287Smarks  bool (*_bfd_is_group_section) (bfd *, const struct bfd_section *);
503129684Snjl
50484491Smsmith  /* The group name, if section is a member of a group.  */
50584491Smsmith  const char *(*_bfd_group_name) (bfd *, const struct bfd_section *);
50691116Smsmith
50784491Smsmith  /* Discard members of a group.  */
50884491Smsmith  bool (*_bfd_discard_group) (bfd *, struct bfd_section *);
509129684Snjl
51084491Smsmith  /* Check if SEC has been already linked during a reloceatable or
511138287Smarks     final link.  */
51284491Smsmith  bool (*_section_already_linked) (bfd *, asection *,
513128212Snjl                                   struct bfd_link_info *);
51484491Smsmith
515129684Snjl  /* Define a common symbol.  */
51684491Smsmith  bool (*_bfd_define_common_symbol) (bfd *, struct bfd_link_info *,
51784491Smsmith                                     struct bfd_link_hash_entry *);
51884491Smsmith
51999679Siwasaki  /* Hide a symbol.  */
520129684Snjl  void (*_bfd_link_hide_symbol) (bfd *, struct bfd_link_info *,
521138287Smarks                                 struct bfd_link_hash_entry *);
52284491Smsmith
52399679Siwasaki  /* Define a __start, __stop, .startof. or .sizeof. symbol.  */
52484491Smsmith  struct bfd_link_hash_entry *
52584491Smsmith       (*_bfd_define_start_stop) (struct bfd_link_info *, const char *,
526129684Snjl                                  asection *);
52791116Smsmith
52891116Smsmith  /* Routines to handle dynamic symbols and relocs.  */
529138287Smarks#define BFD_JUMP_TABLE_DYNAMIC(NAME) \
530129684Snjl  NAME##_get_dynamic_symtab_upper_bound, \
53184491Smsmith  NAME##_canonicalize_dynamic_symtab, \
532129684Snjl  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