aoutx.h
来自「基于4个mips核的noc设计」· C头文件 代码 · 共 2,130 行 · 第 1/5 页
H
2,130 行
/* BFD semi-generic back-end for a.out binaries. Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 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. *//*SECTION a.out backendsDESCRIPTION BFD supports a number of different flavours of a.out format, though the major differences are only the sizes of the structures on disk, and the shape of the relocation information. The support is split into a basic support file @file{aoutx.h} and other files which derive functions from the base. One derivation file is @file{aoutf1.h} (for a.out flavour 1), and adds to the basic a.out functions support for sun3, sun4, 386 and 29k a.out files, to create a target jump vector for a specific target. This information is further split out into more specific files for each machine, including @file{sunos.c} for sun3 and sun4, @file{newsos3.c} for the Sony NEWS, and @file{demo64.c} for a demonstration of a 64 bit a.out format. The base file @file{aoutx.h} defines general mechanisms for reading and writing records to and from disk and various other methods which BFD requires. It is included by @file{aout32.c} and @file{aout64.c} to form the names <<aout_32_swap_exec_header_in>>, <<aout_64_swap_exec_header_in>>, etc. As an example, this is what goes on to make the back end for a sun4, from @file{aout32.c}:| #define ARCH_SIZE 32| #include "aoutx.h" Which exports names:| ...| aout_32_canonicalize_reloc| aout_32_find_nearest_line| aout_32_get_lineno| aout_32_get_reloc_upper_bound| ... from @file{sunos.c}:| #define TARGET_NAME "a.out-sunos-big"| #define VECNAME sunos_big_vec| #include "aoutf1.h" requires all the names from @file{aout32.c}, and produces the jump vector| sunos_big_vec The file @file{host-aout.c} is a special case. It is for a large set of hosts that use ``more or less standard'' a.out files, and for which cross-debugging is not interesting. It uses the standard 32-bit a.out support routines, but determines the file offsets and addresses of the text, data, and BSS sections, the machine architecture and machine type, and the entry point address, in a host-dependent manner. Once these values have been determined, generic code is used to handle the object file. When porting it to run on a new system, you must supply:| HOST_PAGE_SIZE| HOST_SEGMENT_SIZE| HOST_MACHINE_ARCH (optional)| HOST_MACHINE_MACHINE (optional)| HOST_TEXT_START_ADDR| HOST_STACK_END_ADDR in the file @file{../include/sys/h-@var{XXX}.h} (for your host). These values, plus the structures and macros defined in @file{a.out.h} on your host system, will produce a BFD target that will access ordinary a.out files on your host. To configure a new machine to use @file{host-aout.c}, specify:| TDEFAULTS = -DDEFAULT_VECTOR=host_aout_big_vec| TDEPFILES= host-aout.o trad-core.o in the @file{config/@var{XXX}.mt} file, and modify @file{configure.in} to use the @file{@var{XXX}.mt} file (by setting "<<bfd_target=XXX>>") when your configuration is selected.*//* Some assumptions: * Any BFD with D_PAGED set is ZMAGIC, and vice versa. Doesn't matter what the setting of WP_TEXT is on output, but it'll get set on input. * Any BFD with D_PAGED clear and WP_TEXT set is NMAGIC. * Any BFD with both flags clear is OMAGIC. (Just want to make these explicit, so the conditions tested in this file make sense if you're more familiar with a.out than with BFD.) */#define KEEPIT udata.i#include <ctype.h>#include "bfd.h"#include "sysdep.h"#include "bfdlink.h"#include "libaout.h"#include "libbfd.h"#include "aout/aout64.h"#include "aout/stab_gnu.h"#include "aout/ar.h"static boolean aout_get_external_symbols PARAMS ((bfd *));static boolean translate_from_native_sym_flags PARAMS ((bfd *, aout_symbol_type *));static boolean translate_to_native_sym_flags PARAMS ((bfd *, asymbol *, struct external_nlist *));static void adjust_o_magic PARAMS ((bfd *, struct internal_exec *));static void adjust_z_magic PARAMS ((bfd *, struct internal_exec *));static void adjust_n_magic PARAMS ((bfd *, struct internal_exec *));/*SUBSECTION RelocationsDESCRIPTION The file @file{aoutx.h} provides for both the @emph{standard} and @emph{extended} forms of a.out relocation records. The standard records contain only an address, a symbol index, and a type field. The extended records (used on 29ks and sparcs) also have a full integer for an addend.*/#ifndef CTOR_TABLE_RELOC_HOWTO#define CTOR_TABLE_RELOC_IDX 2#define CTOR_TABLE_RELOC_HOWTO(BFD) ((obj_reloc_entry_size(BFD) == RELOC_EXT_SIZE \ ? howto_table_ext : howto_table_std) \ + CTOR_TABLE_RELOC_IDX)#endif#ifndef MY_swap_std_reloc_in#define MY_swap_std_reloc_in NAME(aout,swap_std_reloc_in)#endif#ifndef MY_swap_ext_reloc_in#define MY_swap_ext_reloc_in NAME(aout,swap_ext_reloc_in)#endif#ifndef MY_swap_std_reloc_out#define MY_swap_std_reloc_out NAME(aout,swap_std_reloc_out)#endif#ifndef MY_swap_ext_reloc_out#define MY_swap_ext_reloc_out NAME(aout,swap_ext_reloc_out)#endif#ifndef MY_final_link_relocate#define MY_final_link_relocate _bfd_final_link_relocate#endif#ifndef MY_relocate_contents#define MY_relocate_contents _bfd_relocate_contents#endif#define howto_table_ext NAME(aout,ext_howto_table)#define howto_table_std NAME(aout,std_howto_table)reloc_howto_type howto_table_ext[] ={ /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */ HOWTO(RELOC_8, 0, 0, 8, false, 0, complain_overflow_bitfield,0,"8", false, 0,0x000000ff, false), HOWTO(RELOC_16, 0, 1, 16, false, 0, complain_overflow_bitfield,0,"16", false, 0,0x0000ffff, false), HOWTO(RELOC_32, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"32", false, 0,0xffffffff, false), HOWTO(RELOC_DISP8, 0, 0, 8, true, 0, complain_overflow_signed,0,"DISP8", false, 0,0x000000ff, false), HOWTO(RELOC_DISP16, 0, 1, 16, true, 0, complain_overflow_signed,0,"DISP16", false, 0,0x0000ffff, false), HOWTO(RELOC_DISP32, 0, 2, 32, true, 0, complain_overflow_signed,0,"DISP32", false, 0,0xffffffff, false), HOWTO(RELOC_WDISP30,2, 2, 30, true, 0, complain_overflow_signed,0,"WDISP30", false, 0,0x3fffffff, false), HOWTO(RELOC_WDISP22,2, 2, 22, true, 0, complain_overflow_signed,0,"WDISP22", false, 0,0x003fffff, false), HOWTO(RELOC_HI22, 10, 2, 22, false, 0, complain_overflow_bitfield,0,"HI22", false, 0,0x003fffff, false), HOWTO(RELOC_22, 0, 2, 22, false, 0, complain_overflow_bitfield,0,"22", false, 0,0x003fffff, false), HOWTO(RELOC_13, 0, 2, 13, false, 0, complain_overflow_bitfield,0,"13", false, 0,0x00001fff, false), HOWTO(RELOC_LO10, 0, 2, 10, false, 0, complain_overflow_dont,0,"LO10", false, 0,0x000003ff, false), HOWTO(RELOC_SFA_BASE,0, 2, 32, false, 0, complain_overflow_bitfield,0,"SFA_BASE", false, 0,0xffffffff, false), HOWTO(RELOC_SFA_OFF13,0,2, 32, false, 0, complain_overflow_bitfield,0,"SFA_OFF13",false, 0,0xffffffff, false), HOWTO(RELOC_BASE10, 0, 2, 10, false, 0, complain_overflow_dont,0,"BASE10", false, 0,0x000003ff, false), HOWTO(RELOC_BASE13, 0, 2, 13, false, 0, complain_overflow_signed,0,"BASE13", false, 0,0x00001fff, false), HOWTO(RELOC_BASE22, 10, 2, 22, false, 0, complain_overflow_bitfield,0,"BASE22", false, 0,0x003fffff, false), HOWTO(RELOC_PC10, 0, 2, 10, true, 0, complain_overflow_dont,0,"PC10", false, 0,0x000003ff, true), HOWTO(RELOC_PC22, 10, 2, 22, true, 0, complain_overflow_signed,0,"PC22", false, 0,0x003fffff, true), HOWTO(RELOC_JMP_TBL,2, 2, 30, true, 0, complain_overflow_signed,0,"JMP_TBL", false, 0,0x3fffffff, false), HOWTO(RELOC_SEGOFF16,0, 2, 0, false, 0, complain_overflow_bitfield,0,"SEGOFF16", false, 0,0x00000000, false), HOWTO(RELOC_GLOB_DAT,0, 2, 0, false, 0, complain_overflow_bitfield,0,"GLOB_DAT", false, 0,0x00000000, false), HOWTO(RELOC_JMP_SLOT,0, 2, 0, false, 0, complain_overflow_bitfield,0,"JMP_SLOT", false, 0,0x00000000, false), HOWTO(RELOC_RELATIVE,0, 2, 0, false, 0, complain_overflow_bitfield,0,"RELATIVE", false, 0,0x00000000, false), HOWTO(0, 0, 0, 0, false, 0, complain_overflow_dont, 0, "R_SPARC_NONE", false,0,0x00000000,true), HOWTO(0, 0, 0, 0, false, 0, complain_overflow_dont, 0, "R_SPARC_NONE", false,0,0x00000000,true),#define RELOC_SPARC_REV32 RELOC_WDISP19 HOWTO(RELOC_SPARC_REV32, 0, 2, 32, false, 0, complain_overflow_dont,0,"R_SPARC_REV32", false, 0,0xffffffff, false),};/* Convert standard reloc records to "arelent" format (incl byte swap). */reloc_howto_type howto_table_std[] = { /* type rs size bsz pcrel bitpos ovrf sf name part_inpl readmask setmask pcdone */HOWTO( 0, 0, 0, 8, false, 0, complain_overflow_bitfield,0,"8", true, 0x000000ff,0x000000ff, false),HOWTO( 1, 0, 1, 16, false, 0, complain_overflow_bitfield,0,"16", true, 0x0000ffff,0x0000ffff, false),HOWTO( 2, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"32", true, 0xffffffff,0xffffffff, false),HOWTO( 3, 0, 4, 64, false, 0, complain_overflow_bitfield,0,"64", true, 0xdeaddead,0xdeaddead, false),HOWTO( 4, 0, 0, 8, true, 0, complain_overflow_signed, 0,"DISP8", true, 0x000000ff,0x000000ff, false),HOWTO( 5, 0, 1, 16, true, 0, complain_overflow_signed, 0,"DISP16", true, 0x0000ffff,0x0000ffff, false),HOWTO( 6, 0, 2, 32, true, 0, complain_overflow_signed, 0,"DISP32", true, 0xffffffff,0xffffffff, false),HOWTO( 7, 0, 4, 64, true, 0, complain_overflow_signed, 0,"DISP64", true, 0xfeedface,0xfeedface, false),HOWTO( 8, 0, 2, 0, false, 0, complain_overflow_bitfield,0,"GOT_REL", false, 0,0x00000000, false),HOWTO( 9, 0, 1, 16, false, 0, complain_overflow_bitfield,0,"BASE16", false,0xffffffff,0xffffffff, false),HOWTO(10, 0, 2, 32, false, 0, complain_overflow_bitfield,0,"BASE32", false,0xffffffff,0xffffffff, false),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1), HOWTO(16, 0, 2, 0, false, 0, complain_overflow_bitfield,0,"JMP_TABLE", false, 0,0x00000000, false),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1), HOWTO(32, 0, 2, 0, false, 0, complain_overflow_bitfield,0,"RELATIVE", false, 0,0x00000000, false),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1),EMPTY_HOWTO (-1), HOWTO(40, 0, 2, 0, false, 0, complain_overflow_bitfield,0,"BASEREL", false, 0,0x00000000, false),};#define TABLE_SIZE(TABLE) (sizeof (TABLE)/sizeof (TABLE[0]))reloc_howto_type *NAME(aout,reloc_type_lookup) (abfd,code) bfd *abfd; bfd_reloc_code_real_type code;{#define EXT(i,j) case i: return &howto_table_ext[j]#define STD(i,j) case i: return &howto_table_std[j] int ext = obj_reloc_entry_size (abfd) == RELOC_EXT_SIZE; if (code == BFD_RELOC_CTOR) switch (bfd_get_arch_info (abfd)->bits_per_address) { case 32: code = BFD_RELOC_32; break; case 64: code = BFD_RELOC_64; break; } if (ext) switch (code) { EXT (BFD_RELOC_8, 0); EXT (BFD_RELOC_16, 1); EXT (BFD_RELOC_32, 2); EXT (BFD_RELOC_HI22, 8); EXT (BFD_RELOC_LO10, 11); EXT (BFD_RELOC_32_PCREL_S2, 6); EXT (BFD_RELOC_SPARC_WDISP22, 7); EXT (BFD_RELOC_SPARC13, 10); EXT (BFD_RELOC_SPARC_GOT10, 14); EXT (BFD_RELOC_SPARC_BASE13, 15); EXT (BFD_RELOC_SPARC_GOT13, 15); EXT (BFD_RELOC_SPARC_GOT22, 16); EXT (BFD_RELOC_SPARC_PC10, 17); EXT (BFD_RELOC_SPARC_PC22, 18); EXT (BFD_RELOC_SPARC_WPLT30, 19); EXT (BFD_RELOC_SPARC_REV32, 26); default: return (reloc_howto_type *) NULL; } else /* std relocs */ switch (code) { STD (BFD_RELOC_16, 1); STD (BFD_RELOC_32, 2); STD (BFD_RELOC_8_PCREL, 4); STD (BFD_RELOC_16_PCREL, 5); STD (BFD_RELOC_32_PCREL, 6); STD (BFD_RELOC_16_BASEREL, 9); STD (BFD_RELOC_32_BASEREL, 10); default: return (reloc_howto_type *) NULL; }}/*SUBSECTION Internal entry pointsDESCRIPTION @file{aoutx.h} exports several routines for accessing the contents of an a.out file, which are gathered and exported in turn by various format specific files (eg sunos.c).*//*FUNCTION aout_@var{size}_swap_exec_header_inSYNOPSIS void aout_@var{size}_swap_exec_header_in, (bfd *abfd, struct external_exec *raw_bytes, struct internal_exec *execp);DESCRIPTION Swap the information in an executable header @var{raw_bytes} taken from a raw byte stream memory image into the internal exec header structure @var{execp}.*/#ifndef NAME_swap_exec_header_invoidNAME(aout,swap_exec_header_in) (abfd, raw_bytes, execp) bfd *abfd; struct external_exec *raw_bytes; struct internal_exec *execp;{ struct external_exec *bytes = (struct external_exec *)raw_bytes; /* The internal_exec structure has some fields that are unused in this configuration (IE for i960), so ensure that all such uninitialized fields are zero'd out. There are places where two of these structs are memcmp'd, and thus the contents do matter. */ memset ((PTR) execp, 0, sizeof (struct internal_exec)); /* Now fill in fields in the execp, from the bytes in the raw data. */ execp->a_info = bfd_h_get_32 (abfd, bytes->e_info); execp->a_text = GET_WORD (abfd, bytes->e_text); execp->a_data = GET_WORD (abfd, bytes->e_data); execp->a_bss = GET_WORD (abfd, bytes->e_bss); execp->a_syms = GET_WORD (abfd, bytes->e_syms); execp->a_entry = GET_WORD (abfd, bytes->e_entry); execp->a_trsize = GET_WORD (abfd, bytes->e_trsize); execp->a_drsize = GET_WORD (abfd, bytes->e_drsize);}#define NAME_swap_exec_header_in NAME(aout,swap_exec_header_in)#endif/*FUNCTION aout_@var{size}_swap_exec_header_outSYNOPSIS void aout_@var{size}_swap_exec_header_out (bfd *abfd, struct internal_exec *execp, struct external_exec *raw_bytes);DESCRIPTION Swap the information in an internal exec header structure @var{execp} into the buffer @var{raw_bytes} ready for writing to disk.*/voidNAME(aout,swap_exec_header_out) (abfd, execp, raw_bytes) bfd *abfd; struct internal_exec *execp; struct external_exec *raw_bytes;{ struct external_exec *bytes = (struct external_exec *)raw_bytes; /* Now fill in fields in the raw data, from the fields in the exec struct. */ bfd_h_put_32 (abfd, execp->a_info , bytes->e_info); PUT_WORD (abfd, execp->a_text , bytes->e_text); PUT_WORD (abfd, execp->a_data , bytes->e_data); PUT_WORD (abfd, execp->a_bss , bytes->e_bss); PUT_WORD (abfd, execp->a_syms , bytes->e_syms); PUT_WORD (abfd, execp->a_entry , bytes->e_entry); PUT_WORD (abfd, execp->a_trsize, bytes->e_trsize); PUT_WORD (abfd, execp->a_drsize, bytes->e_drsize);}/* Make all the section for an a.out file. */booleanNAME(aout,make_sections) (abfd) bfd *abfd;{ if (obj_textsec (abfd) == (asection *) NULL && bfd_make_section (abfd, ".text") == (asection *) NULL) return false; if (obj_datasec (abfd) == (asection *) NULL && bfd_make_section (abfd, ".data") == (asection *) NULL) return false; if (obj_bsssec (abfd) == (asection *) NULL
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?