targets.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 1,201 行 · 第 1/3 页
C
1,201 行
/* Generic target-file-type support for the BFD library. Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. Written by Cygnus Support.This file is part of BFD, the Binary File Descriptor library.This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include "bfd.h"#include "sysdep.h"#include "libbfd.h"#include "fnmatch.h"/*SECTION TargetsDESCRIPTION Each port of BFD to a different machine requries the creation of a target back end. All the back end provides to the root part of BFD is a structure containing pointers to functions which perform certain low level operations on files. BFD translates the applications's requests through a pointer into calls to the back end routines. When a file is opened with <<bfd_openr>>, its format and target are unknown. BFD uses various mechanisms to determine how to interpret the file. The operations performed are: o Create a BFD by calling the internal routine <<_bfd_new_bfd>>, then call <<bfd_find_target>> with the target string supplied to <<bfd_openr>> and the new BFD pointer. o If a null target string was provided to <<bfd_find_target>>, look up the environment variable <<GNUTARGET>> and use that as the target string. o If the target string is still <<NULL>>, or the target string is <<default>>, then use the first item in the target vector as the target type, and set <<target_defaulted>> in the BFD to cause <<bfd_check_format>> to loop through all the targets. @xref{bfd_target}. @xref{Formats}. o Otherwise, inspect the elements in the target vector one by one, until a match on target name is found. When found, use it. o Otherwise return the error <<bfd_error_invalid_target>> to <<bfd_openr>>. o <<bfd_openr>> attempts to open the file using <<bfd_open_file>>, and returns the BFD. Once the BFD has been opened and the target selected, the file format may be determined. This is done by calling <<bfd_check_format>> on the BFD with a suggested format. If <<target_defaulted>> has been set, each possible target type is tried to see if it recognizes the specified format. <<bfd_check_format>> returns <<true>> when the caller guesses right.@menu@* bfd_target::@end menu*//*INODE bfd_target, , Targets, TargetsDOCDDSUBSECTION bfd_targetDESCRIPTION This structure contains everything that BFD knows about a target. It includes things like its byte order, name, and which routines to call to do various operations. Every BFD points to a target structure with its <<xvec>> member. The macros below are used to dispatch to functions through the <<bfd_target>> vector. They are used in a number of macros further down in @file{bfd.h}, and are also used when calling various routines by hand inside the BFD implementation. The @var{arglist} argument must be parenthesized; it contains all the arguments to the called function. They make the documentation (more) unpleasant to read, so if someone wants to fix this and not break the above, please do..#define BFD_SEND(bfd, message, arglist) \. ((*((bfd)->xvec->message)) arglist)..#ifdef DEBUG_BFD_SEND.#undef BFD_SEND.#define BFD_SEND(bfd, message, arglist) \. (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \. ((*((bfd)->xvec->message)) arglist) : \. (bfd_assert (__FILE__,__LINE__), NULL)).#endif For operations which index on the BFD format:.#define BFD_SEND_FMT(bfd, message, arglist) \. (((bfd)->xvec->message[(int) ((bfd)->format)]) arglist)..#ifdef DEBUG_BFD_SEND.#undef BFD_SEND_FMT.#define BFD_SEND_FMT(bfd, message, arglist) \. (((bfd) && (bfd)->xvec && (bfd)->xvec->message) ? \. (((bfd)->xvec->message[(int) ((bfd)->format)]) arglist) : \. (bfd_assert (__FILE__,__LINE__), NULL)).#endif This is the structure which defines the type of BFD this is. The <<xvec>> member of the struct <<bfd>> itself points here. Each module that implements access to a different target under BFD, defines one of these. FIXME, these names should be rationalised with the names of the entry points which call them. Too bad we can't have one macro to define them both!.enum bfd_flavour {. bfd_target_unknown_flavour,. bfd_target_aout_flavour,. bfd_target_coff_flavour,. bfd_target_ecoff_flavour,. bfd_target_xcoff_flavour,. bfd_target_elf_flavour,. bfd_target_ieee_flavour,. bfd_target_nlm_flavour,. bfd_target_oasys_flavour,. bfd_target_tekhex_flavour,. bfd_target_srec_flavour,. bfd_target_ihex_flavour,. bfd_target_som_flavour,. bfd_target_os9k_flavour,. bfd_target_versados_flavour,. bfd_target_msdos_flavour,. bfd_target_ovax_flavour,. bfd_target_evax_flavour.};..enum bfd_endian { BFD_ENDIAN_BIG, BFD_ENDIAN_LITTLE, BFD_ENDIAN_UNKNOWN };..{* Forward declaration. *}.typedef struct bfd_link_info _bfd_link_info;..typedef struct bfd_target.{Identifies the kind of target, e.g., SunOS4, Ultrix, etc.. char *name;The "flavour" of a back end is a general indication about the contentsof a file.. enum bfd_flavour flavour;The order of bytes within the data area of a file.. enum bfd_endian byteorder;The order of bytes within the header parts of a file.. enum bfd_endian header_byteorder;A mask of all the flags which an executable may have set -from the set <<BFD_NO_FLAGS>>, <<HAS_RELOC>>, ...<<D_PAGED>>.. flagword object_flags;A mask of all the flags which a section may have set - fromthe set <<SEC_NO_FLAGS>>, <<SEC_ALLOC>>, ...<<SET_NEVER_LOAD>>.. flagword section_flags;The character normally found at the front of a symbol(if any), perhaps `_'.. char symbol_leading_char;The pad character for file names within an archive header.. char ar_pad_char;The maximum number of characters in an archive header.. unsigned short ar_max_namelen;Entries for byte swapping for data. These are different from the otherentry points, since they don't take a BFD asthe first argument.Certain other handlers could do the same.. bfd_vma (*bfd_getx64) PARAMS ((const bfd_byte *));. bfd_signed_vma (*bfd_getx_signed_64) PARAMS ((const bfd_byte *));. void (*bfd_putx64) PARAMS ((bfd_vma, bfd_byte *));. bfd_vma (*bfd_getx32) PARAMS ((const bfd_byte *));. bfd_signed_vma (*bfd_getx_signed_32) PARAMS ((const bfd_byte *));. void (*bfd_putx32) PARAMS ((bfd_vma, bfd_byte *));. bfd_vma (*bfd_getx16) PARAMS ((const bfd_byte *));. bfd_signed_vma (*bfd_getx_signed_16) PARAMS ((const bfd_byte *));. void (*bfd_putx16) PARAMS ((bfd_vma, bfd_byte *));Byte swapping for the headers. bfd_vma (*bfd_h_getx64) PARAMS ((const bfd_byte *));. bfd_signed_vma (*bfd_h_getx_signed_64) PARAMS ((const bfd_byte *));. void (*bfd_h_putx64) PARAMS ((bfd_vma, bfd_byte *));. bfd_vma (*bfd_h_getx32) PARAMS ((const bfd_byte *));. bfd_signed_vma (*bfd_h_getx_signed_32) PARAMS ((const bfd_byte *));. void (*bfd_h_putx32) PARAMS ((bfd_vma, bfd_byte *));. bfd_vma (*bfd_h_getx16) PARAMS ((const bfd_byte *));. bfd_signed_vma (*bfd_h_getx_signed_16) PARAMS ((const bfd_byte *));. void (*bfd_h_putx16) PARAMS ((bfd_vma, bfd_byte *));Format dependent routines: these are vectors of entry pointswithin the target vector structure, one for each format to check.Check the format of a file being read. Return a <<bfd_target *>> or zero.. const struct bfd_target *(*_bfd_check_format[bfd_type_end]) PARAMS ((bfd *));Set the format of a file being written.. boolean (*_bfd_set_format[bfd_type_end]) PARAMS ((bfd *));Write cached information into a file being written, at <<bfd_close>>.. boolean (*_bfd_write_contents[bfd_type_end]) PARAMS ((bfd *));The general target vector. These vectors are initialized using theBFD_JUMP_TABLE macros... {* Generic entry points. *}.#define BFD_JUMP_TABLE_GENERIC(NAME)\.CAT(NAME,_close_and_cleanup),\.CAT(NAME,_bfd_free_cached_info),\.CAT(NAME,_new_section_hook),\.CAT(NAME,_get_section_contents),\.CAT(NAME,_get_section_contents_in_window).. {* Called when the BFD is being closed to do any necessary cleanup. *}. boolean (*_close_and_cleanup) PARAMS ((bfd *));. {* Ask the BFD to free all cached information. *}. boolean (*_bfd_free_cached_info) PARAMS ((bfd *));. {* Called when a new section is created. *}. boolean (*_new_section_hook) PARAMS ((bfd *, sec_ptr));. {* Read the contents of a section. *}. boolean (*_bfd_get_section_contents) PARAMS ((bfd *, sec_ptr, PTR,. file_ptr, bfd_size_type));. boolean (*_bfd_get_section_contents_in_window). PARAMS ((bfd *, sec_ptr, bfd_window *,. file_ptr, bfd_size_type));.. {* Entry points to copy private data. *}.#define BFD_JUMP_TABLE_COPY(NAME)\.CAT(NAME,_bfd_copy_private_bfd_data),\.CAT(NAME,_bfd_merge_private_bfd_data),\.CAT(NAME,_bfd_copy_private_section_data),\.CAT(NAME,_bfd_copy_private_symbol_data),\.CAT(NAME,_bfd_set_private_flags),\.CAT(NAME,_bfd_print_private_bfd_data)\. {* Called to copy BFD general private data from one object file. to another. *}. boolean (*_bfd_copy_private_bfd_data) PARAMS ((bfd *, bfd *));. {* Called to merge BFD general private data from one object file. to a common output file when linking. *}. boolean (*_bfd_merge_private_bfd_data) PARAMS ((bfd *, bfd *));. {* Called to copy BFD private section data from one object file. to another. *}. boolean (*_bfd_copy_private_section_data) PARAMS ((bfd *, sec_ptr,. bfd *, sec_ptr));. {* Called to copy BFD private symbol data from one symbol. to another. *}. boolean (*_bfd_copy_private_symbol_data) PARAMS ((bfd *, asymbol *,. bfd *, asymbol *));. {* Called to set private backend flags *}. boolean (*_bfd_set_private_flags) PARAMS ((bfd *, flagword));.. {* Called to print private BFD data *}. boolean (*_bfd_print_private_bfd_data) PARAMS ((bfd *, PTR));.. {* Core file entry points. *}.#define BFD_JUMP_TABLE_CORE(NAME)\.CAT(NAME,_core_file_failing_command),\.CAT(NAME,_core_file_failing_signal),\.CAT(NAME,_core_file_matches_executable_p). char * (*_core_file_failing_command) PARAMS ((bfd *));. int (*_core_file_failing_signal) PARAMS ((bfd *));. boolean (*_core_file_matches_executable_p) PARAMS ((bfd *, bfd *));.. {* Archive entry points. *}.#define BFD_JUMP_TABLE_ARCHIVE(NAME)\.CAT(NAME,_slurp_armap),\.CAT(NAME,_slurp_extended_name_table),\.CAT(NAME,_construct_extended_name_table),\.CAT(NAME,_truncate_arname),\.CAT(NAME,_write_armap),\.CAT(NAME,_read_ar_hdr),\.CAT(NAME,_openr_next_archived_file),\.CAT(NAME,_get_elt_at_index),\.CAT(NAME,_generic_stat_arch_elt),\.CAT(NAME,_update_armap_timestamp). boolean (*_bfd_slurp_armap) PARAMS ((bfd *));. boolean (*_bfd_slurp_extended_name_table) PARAMS ((bfd *));. boolean (*_bfd_construct_extended_name_table). PARAMS ((bfd *, char **, bfd_size_type *, const char **));. void (*_bfd_truncate_arname) PARAMS ((bfd *, CONST char *, char *));. boolean (*write_armap) PARAMS ((bfd *arch,. unsigned int elength,. struct orl *map,. unsigned int orl_count,. int stridx));. PTR (*_bfd_read_ar_hdr_fn) PARAMS ((bfd *));. bfd * (*openr_next_archived_file) PARAMS ((bfd *arch, bfd *prev));.#define bfd_get_elt_at_index(b,i) BFD_SEND(b, _bfd_get_elt_at_index, (b,i)). bfd * (*_bfd_get_elt_at_index) PARAMS ((bfd *, symindex));. int (*_bfd_stat_arch_elt) PARAMS ((bfd *, struct stat *));. boolean (*_bfd_update_armap_timestamp) PARAMS ((bfd *));.. {* Entry points used for symbols. *}.#define BFD_JUMP_TABLE_SYMBOLS(NAME)\.CAT(NAME,_get_symtab_upper_bound),\.CAT(NAME,_get_symtab),\.CAT(NAME,_make_empty_symbol),\.CAT(NAME,_print_symbol),\.CAT(NAME,_get_symbol_info),\.CAT(NAME,_bfd_is_local_label_name),\.CAT(NAME,_get_lineno),\.CAT(NAME,_find_nearest_line),\.CAT(NAME,_bfd_make_debug_symbol),\.CAT(NAME,_read_minisymbols),\.CAT(NAME,_minisymbol_to_symbol). long (*_bfd_get_symtab_upper_bound) PARAMS ((bfd *));. long (*_bfd_canonicalize_symtab) PARAMS ((bfd *,. struct symbol_cache_entry **));. struct symbol_cache_entry *. (*_bfd_make_empty_symbol) PARAMS ((bfd *));. void (*_bfd_print_symbol) PARAMS ((bfd *, PTR,. struct symbol_cache_entry *,. bfd_print_symbol_type));.#define bfd_print_symbol(b,p,s,e) BFD_SEND(b, _bfd_print_symbol, (b,p,s,e)). void (*_bfd_get_symbol_info) PARAMS ((bfd *,. struct symbol_cache_entry *,. symbol_info *));.#define bfd_get_symbol_info(b,p,e) BFD_SEND(b, _bfd_get_symbol_info, (b,p,e)). boolean (*_bfd_is_local_label_name) PARAMS ((bfd *, const char *));.. alent * (*_get_lineno) PARAMS ((bfd *, struct symbol_cache_entry *));. boolean (*_bfd_find_nearest_line) PARAMS ((bfd *abfd,. struct sec *section, struct symbol_cache_entry **symbols,. bfd_vma offset, CONST char **file, CONST char **func,. unsigned int *line));. {* Back-door to allow format-aware applications to create debug symbols. while using BFD for everything else. Currently used by the assembler. when creating COFF files. *}. asymbol * (*_bfd_make_debug_symbol) PARAMS ((. bfd *abfd,. void *ptr,. unsigned long size));.#define bfd_read_minisymbols(b, d, m, s) \. BFD_SEND (b, _read_minisymbols, (b, d, m, s)). long (*_read_minisymbols) PARAMS ((bfd *, boolean, PTR *,. unsigned int *));.#define bfd_minisymbol_to_symbol(b, d, m, f) \. BFD_SEND (b, _minisymbol_to_symbol, (b, d, m, f)). asymbol *(*_minisymbol_to_symbol) PARAMS ((bfd *, boolean, const PTR,. asymbol *));.. {* Routines for relocs. *}.#define BFD_JUMP_TABLE_RELOCS(NAME)\.CAT(NAME,_get_reloc_upper_bound),\.CAT(NAME,_canonicalize_reloc),\.CAT(NAME,_bfd_reloc_type_lookup). long (*_get_reloc_upper_bound) PARAMS ((bfd *, sec_ptr));. long (*_bfd_canonicalize_reloc) PARAMS ((bfd *, sec_ptr, arelent **,. struct symbol_cache_entry **));. {* See documentation on reloc types. *}. reloc_howto_type *. (*reloc_type_lookup) PARAMS ((bfd *abfd,. bfd_reloc_code_real_type code));.. {* Routines used when writing an object file. *}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?