⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 aoutx.h

📁 早期freebsd实现
💻 H
📖 第 1 页 / 共 5 页
字号:
  /* If there's no work to be done, don't do any */  if (obj_aout_symbols (abfd) != (aout_symbol_type *)NULL) return true;  symbol_size = exec_hdr(abfd)->a_syms;  if (symbol_size == 0) {    bfd_error = no_symbols;    return false;  }      bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET);  if (bfd_read ((PTR)string_chars, BYTES_IN_WORD, 1, abfd) != BYTES_IN_WORD)    return false;  string_size = GET_WORD (abfd, string_chars);      strings =(char *) bfd_alloc(abfd, string_size + 1);  cached = (aout_symbol_type *)    bfd_zalloc(abfd, (bfd_size_type)(bfd_get_symcount (abfd) * sizeof(aout_symbol_type)));  /* malloc this, so we can free it if simply. The symbol caching     might want to allocate onto the bfd's obstack  */  syms = (struct external_nlist *) bfd_xmalloc(symbol_size);  bfd_seek (abfd, obj_sym_filepos (abfd), SEEK_SET);  if (bfd_read ((PTR)syms, 1, symbol_size, abfd) != symbol_size) {  bailout:    if (syms) 	free (syms);    if (cached)	bfd_release (abfd, cached);    if (strings)bfd_release (abfd, strings);    return false;  }      bfd_seek (abfd, obj_str_filepos (abfd), SEEK_SET);  if (bfd_read ((PTR)strings, 1, string_size, abfd) != string_size) {    goto bailout;  }      /* OK, now walk the new symtable, cacheing symbol properties */    {      register struct external_nlist *sym_pointer;      register struct external_nlist *sym_end = syms + bfd_get_symcount (abfd);      register aout_symbol_type *cache_ptr = cached;	      /* Run through table and copy values */      for (sym_pointer = syms, cache_ptr = cached;	   sym_pointer < sym_end; sym_pointer++, cache_ptr++) 	  {	    bfd_vma x = GET_WORD(abfd, sym_pointer->e_strx);	    cache_ptr->symbol.the_bfd = abfd;	    if (x)	      cache_ptr->symbol.name = x + strings;	    else	      cache_ptr->symbol.name = (char *)NULL;	      	    cache_ptr->symbol.value = GET_SWORD(abfd,  sym_pointer->e_value);	    cache_ptr->desc = bfd_h_get_16(abfd, sym_pointer->e_desc);	    cache_ptr->other = bfd_h_get_8(abfd, sym_pointer->e_other);	    cache_ptr->type = bfd_h_get_8(abfd,  sym_pointer->e_type);	    cache_ptr->symbol.udata = 0;	    translate_from_native_sym_flags (sym_pointer, cache_ptr, abfd);	  }    }      obj_aout_symbols (abfd) =  cached;  free((PTR)syms);      return true;}voidDEFUN(NAME(aout,write_syms),(abfd),      bfd *abfd)  {    unsigned int count ;    asymbol **generic = bfd_get_outsymbols (abfd);        bfd_size_type stindex = BYTES_IN_WORD; /* initial string length */        for (count = 0; count < bfd_get_symcount (abfd); count++) {      asymbol *g = generic[count];      struct external_nlist nsp;      if (g->name) {	unsigned int length = strlen(g->name) +1;	PUT_WORD  (abfd, stindex, (unsigned char *)nsp.e_strx);	stindex += length;      }      else       {	PUT_WORD  (abfd, 0, (unsigned char *)nsp.e_strx);      }            if (g->the_bfd->xvec->flavour == abfd->xvec->flavour) 	  {	    bfd_h_put_16(abfd, aout_symbol(g)->desc,  nsp.e_desc);	    bfd_h_put_8(abfd, aout_symbol(g)->other,  nsp.e_other);	    bfd_h_put_8(abfd, aout_symbol(g)->type,  nsp.e_type);	  }      else	  {	    bfd_h_put_16(abfd,0, nsp.e_desc);	    bfd_h_put_8(abfd, 0,  nsp.e_other);	    bfd_h_put_8(abfd, 0,  nsp.e_type);	  }      translate_to_native_sym_flags (&nsp, g, abfd);      bfd_write((PTR)&nsp,1,EXTERNAL_NLIST_SIZE, abfd);    }        /* Now output the strings.  Be sure to put string length into correct       byte ordering before writing it.  */      {	char buffer[BYTES_IN_WORD];	PUT_WORD  (abfd, stindex, (unsigned char *)buffer);    	bfd_write((PTR)buffer, 1, BYTES_IN_WORD, abfd);      }    generic = bfd_get_outsymbols(abfd);    for (count = 0; count < bfd_get_symcount(abfd); count++) 	{	  asymbol *g = *(generic++);	  	  if (g->name)	      {		size_t length = strlen(g->name)+1;		bfd_write((PTR)g->name, 1, length, abfd);	      }	    g->KEEPIT = (KEEPITTYPE) count;	}  }unsigned intDEFUN(NAME(aout,get_symtab),(abfd, location),      bfd *abfd AND      asymbol **location){    unsigned int counter = 0;    aout_symbol_type *symbase;    if (!NAME(aout,slurp_symbol_table)(abfd)) return 0;    for (symbase = obj_aout_symbols(abfd); counter++ < bfd_get_symcount (abfd);)      *(location++) = (asymbol *)( symbase++);    *location++ =0;    return bfd_get_symcount (abfd);}/* Standard reloc stuff *//* Output standard relocation information to a file in target byte order. */voidDEFUN(NAME(aout,swap_std_reloc_out),(abfd, g, natptr),      bfd *abfd AND      arelent *g AND      struct reloc_std_external *natptr){  int r_index;  asymbol *sym = *(g->sym_ptr_ptr);  int r_extern;  unsigned int r_length;  int r_pcrel;  int r_baserel, r_jmptable, r_relative;  unsigned int r_addend;  asection *output_section = sym->section->output_section;  PUT_WORD(abfd, g->address, natptr->r_address);  r_length = g->howto->size ;	/* Size as a power of two */  r_pcrel  = (int) g->howto->pc_relative; /* Relative to PC? */  /* r_baserel, r_jmptable, r_relative???  FIXME-soon */  r_baserel = 0;  r_jmptable = 0;  r_relative = 0;      r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma;      /* name was clobbered by aout_write_syms to be symbol index */  /* If this relocation is relative to a symbol then set the      r_index to the symbols index, and the r_extern bit.     Absolute symbols can come in in two ways, either as an offset     from the abs section, or as a symbol which has an abs value.     check for that here     */       if (output_section == &bfd_com_section       || output_section == &bfd_abs_section      || output_section == &bfd_und_section)     {      if (bfd_abs_section.symbol == sym)      {	/* Whoops, looked like an abs symbol, but is really an offset	   from the abs section */	r_index = 0;	r_extern = 0;       }      else       {	/* Fill in symbol */	r_extern = 1;	r_index =  stoi((*(g->sym_ptr_ptr))->KEEPIT);           }    }  else     {      /* Just an ordinary section */      r_extern = 0;      r_index  = output_section->target_index;          }  /* now the fun stuff */  if (abfd->xvec->header_byteorder_big_p != false) {      natptr->r_index[0] = r_index >> 16;      natptr->r_index[1] = r_index >> 8;      natptr->r_index[2] = r_index;      natptr->r_type[0] =       (r_extern?    RELOC_STD_BITS_EXTERN_BIG: 0)	| (r_pcrel?     RELOC_STD_BITS_PCREL_BIG: 0)	 | (r_baserel?   RELOC_STD_BITS_BASEREL_BIG: 0)	  | (r_jmptable?  RELOC_STD_BITS_JMPTABLE_BIG: 0)	   | (r_relative?  RELOC_STD_BITS_RELATIVE_BIG: 0)	    | (r_length <<  RELOC_STD_BITS_LENGTH_SH_BIG);    } else {	natptr->r_index[2] = r_index >> 16;	natptr->r_index[1] = r_index >> 8;	natptr->r_index[0] = r_index;	natptr->r_type[0] =	 (r_extern?    RELOC_STD_BITS_EXTERN_LITTLE: 0)	  | (r_pcrel?     RELOC_STD_BITS_PCREL_LITTLE: 0)	   | (r_baserel?   RELOC_STD_BITS_BASEREL_LITTLE: 0)	    | (r_jmptable?  RELOC_STD_BITS_JMPTABLE_LITTLE: 0)	     | (r_relative?  RELOC_STD_BITS_RELATIVE_LITTLE: 0)	      | (r_length <<  RELOC_STD_BITS_LENGTH_SH_LITTLE);      }}/* Extended stuff *//* Output extended relocation information to a file in target byte order. */voidDEFUN(NAME(aout,swap_ext_reloc_out),(abfd, g, natptr),      bfd *abfd AND      arelent *g AND      register struct reloc_ext_external *natptr){  int r_index;  int r_extern;  unsigned int r_type;  unsigned int r_addend;  asymbol *sym = *(g->sym_ptr_ptr);      asection *output_section = sym->section->output_section;    PUT_WORD (abfd, g->address, natptr->r_address);      r_type = (unsigned int) g->howto->type;      r_addend = g->addend + (*(g->sym_ptr_ptr))->section->output_section->vma;  /* If this relocation is relative to a symbol then set the      r_index to the symbols index, and the r_extern bit.     Absolute symbols can come in in two ways, either as an offset     from the abs section, or as a symbol which has an abs value.     check for that here     */       if (output_section == &bfd_com_section       || output_section == &bfd_abs_section      || output_section == &bfd_und_section)   {    if (bfd_abs_section.symbol == sym)    {      /* Whoops, looked like an abs symbol, but is really an offset	 from the abs section */      r_index = 0;      r_extern = 0;     }    else     {      r_extern = 1;      r_index =  stoi((*(g->sym_ptr_ptr))->KEEPIT);    }  }  else   {    /* Just an ordinary section */    r_extern = 0;    r_index  = output_section->target_index;        }	 	   /* now the fun stuff */  if (abfd->xvec->header_byteorder_big_p != false) {    natptr->r_index[0] = r_index >> 16;    natptr->r_index[1] = r_index >> 8;    natptr->r_index[2] = r_index;    natptr->r_type[0] =     (r_extern? RELOC_EXT_BITS_EXTERN_BIG: 0)      | (r_type << RELOC_EXT_BITS_TYPE_SH_BIG);  } else {    natptr->r_index[2] = r_index >> 16;    natptr->r_index[1] = r_index >> 8;    natptr->r_index[0] = r_index;    natptr->r_type[0] =     (r_extern? RELOC_EXT_BITS_EXTERN_LITTLE: 0)      | (r_type << RELOC_EXT_BITS_TYPE_SH_LITTLE);  }  PUT_WORD (abfd, r_addend, natptr->r_addend);}/* BFD deals internally with all things based from the section they're   in. so, something in 10 bytes into a text section  with a base of   50 would have a symbol (.text+10) and know .text vma was 50.    Aout keeps all it's symbols based from zero, so the symbol would   contain 60. This macro subs the base of each section from the value   to give the true offset from the section */#define MOVE_ADDRESS(ad)       						\  if (r_extern) {							\   /* undefined symbol */						\     cache_ptr->sym_ptr_ptr = symbols + r_index;			\     cache_ptr->addend = ad;						\     } else {								\    /* defined, section relative. replace symbol with pointer to    	\       symbol which points to section  */				\    switch (r_index) {							\    case N_TEXT:							\    case N_TEXT | N_EXT:						\      cache_ptr->sym_ptr_ptr  = obj_textsec(abfd)->symbol_ptr_ptr;	\      cache_ptr->addend = ad  - su->textsec->vma;			\      break;								\    case N_DATA:							\    case N_DATA | N_EXT:						\      cache_ptr->sym_ptr_ptr  = obj_datasec(abfd)->symbol_ptr_ptr;	\      cache_ptr->addend = ad - su->datasec->vma;			\      break;								\    case N_BSS:								\    case N_BSS | N_EXT:							\      cache_ptr->sym_ptr_ptr  = obj_bsssec(abfd)->symbol_ptr_ptr;	\      cache_ptr->addend = ad - su->bsssec->vma;				\      break;								\    default:								\    case N_ABS:								\    case N_ABS | N_EXT:							\     cache_ptr->sym_ptr_ptr = bfd_abs_section.symbol_ptr_ptr;	\      cache_ptr->addend = ad;						\      break;								\    }									\  }     								\voidDEFUN(NAME(aout,swap_ext_reloc_in), (abfd, bytes, cache_ptr, symbols),      bfd *abfd AND      struct reloc_ext_external *bytes AND      arelent *cache_ptr AND      asymbol **symbols){  int r_index;  int r_extern;  unsigned int r_type;  struct aoutdata *su = &(abfd->tdata.aout_data->a);  cache_ptr->address = (GET_SWORD (abfd, bytes->r_address));  /* now the fun stuff */  if (abfd->xvec->header_byteorder_big_p != false) {    r_index =  (bytes->r_index[0] << 16)	     | (bytes->r_index[1] << 8)	     |  bytes->r_index[2];    r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_BIG));    r_type   =       (bytes->r_type[0] & RELOC_EXT_BITS_TYPE_BIG)				      >> RELOC_EXT_BITS_TYPE_SH_BIG;  } else {    r_index =  (bytes->r_index[2] << 16)	     | (bytes->r_index[1] << 8)	     |  bytes->r_index[0];    r_extern = (0 != (bytes->r_type[0] & RELOC_EXT_BITS_EXTERN_LITTLE));    r_type   =       (bytes->r_type[0] & RELOC_EXT_BITS_TYPE_LITTLE)				      >> RELOC_EXT_BITS_TYPE_SH_LITTLE;  }  cache_ptr->howto =  howto_table_ext + r_type;  MOVE_ADDRESS(GET_SWORD(abfd, bytes->r_addend));}voidDEFUN(NAME(aout,swap_std_reloc_in), (abfd, bytes, cache_ptr, symbols),  bfd *abfd AND  struct reloc_std_external *bytes AND  arelent *cache_ptr AND  asymbol **symbols){  int r_index;  int r_extern;  unsigned int r_length;  int r_pcrel;  int r_baserel, r_jmptable, r_relative;  struct aoutdata  *su = &(abfd->tdata.aout_data->a);  cache_ptr->address = (int32_type)(bfd_h_get_32 (abfd, bytes->r_address));  /* now the fun stuff */  if (abfd->xvec->header_byteorder_big_p != false) {    r_index =  (bytes->r_index[0] << 16)      | (bytes->r_index[1] << 8)	|  bytes->r_index[2];    r_extern  = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_BIG));    r_pcrel   = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_BIG));    r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_BIG));    r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_BIG));    r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_BIG));    r_length  =       (bytes->r_type[0] & RELOC_STD_BITS_LENGTH_BIG)       			>> RELOC_STD_BITS_LENGTH_SH_BIG;  } else {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -