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

📄 aoutx.h

📁 早期freebsd实现
💻 H
📖 第 1 页 / 共 5 页
字号:
    r_index =  (bytes->r_index[2] << 16)      | (bytes->r_index[1] << 8)	|  bytes->r_index[0];    r_extern  = (0 != (bytes->r_type[0] & RELOC_STD_BITS_EXTERN_LITTLE));    r_pcrel   = (0 != (bytes->r_type[0] & RELOC_STD_BITS_PCREL_LITTLE));    r_baserel = (0 != (bytes->r_type[0] & RELOC_STD_BITS_BASEREL_LITTLE));    r_jmptable= (0 != (bytes->r_type[0] & RELOC_STD_BITS_JMPTABLE_LITTLE));    r_relative= (0 != (bytes->r_type[0] & RELOC_STD_BITS_RELATIVE_LITTLE));    r_length  =       (bytes->r_type[0] & RELOC_STD_BITS_LENGTH_LITTLE)       			>> RELOC_STD_BITS_LENGTH_SH_LITTLE;  }  cache_ptr->howto =  howto_table_std + r_length + 4 * r_pcrel;  /* FIXME-soon:  Roll baserel, jmptable, relative bits into howto setting */  MOVE_ADDRESS(0);}/* Reloc hackery */booleanDEFUN(NAME(aout,slurp_reloc_table),(abfd, asect, symbols),      bfd *abfd AND      sec_ptr asect AND      asymbol **symbols){  unsigned int count;  bfd_size_type reloc_size;  PTR relocs;  arelent *reloc_cache;  size_t each_size;  if (asect->relocation) return true;  if (asect->flags & SEC_CONSTRUCTOR) return true;  if (asect == obj_datasec (abfd)) {    reloc_size = exec_hdr(abfd)->a_drsize;    goto doit;  }  if (asect == obj_textsec (abfd)) {    reloc_size = exec_hdr(abfd)->a_trsize;    goto doit;  }  bfd_error = invalid_operation;  return false; doit:  bfd_seek (abfd, asect->rel_filepos, SEEK_SET);  each_size = obj_reloc_entry_size (abfd);  count = reloc_size / each_size;  reloc_cache = (arelent *) bfd_zalloc (abfd, (size_t)(count * sizeof						       (arelent)));  if (!reloc_cache) {nomem:    bfd_error = no_memory;    return false;  }  relocs = (PTR) bfd_alloc (abfd, reloc_size);  if (!relocs) {    bfd_release (abfd, reloc_cache);    goto nomem;  }  if (bfd_read (relocs, 1, reloc_size, abfd) != reloc_size) {    bfd_release (abfd, relocs);    bfd_release (abfd, reloc_cache);    bfd_error = system_call_error;    return false;  }  if (each_size == RELOC_EXT_SIZE) {    register struct reloc_ext_external *rptr = (struct reloc_ext_external *) relocs;    unsigned int counter = 0;    arelent *cache_ptr = reloc_cache;    for (; counter < count; counter++, rptr++, cache_ptr++) {      NAME(aout,swap_ext_reloc_in)(abfd, rptr, cache_ptr, symbols);    }  } else {    register struct reloc_std_external *rptr = (struct reloc_std_external*) relocs;    unsigned int counter = 0;    arelent *cache_ptr = reloc_cache;    for (; counter < count; counter++, rptr++, cache_ptr++) {	NAME(aout,swap_std_reloc_in)(abfd, rptr, cache_ptr, symbols);    }  }  bfd_release (abfd,relocs);  asect->relocation = reloc_cache;  asect->reloc_count = count;  return true;}/* Write out a relocation section into an object file.  */booleanDEFUN(NAME(aout,squirt_out_relocs),(abfd, section),      bfd *abfd AND      asection *section){  arelent **generic;  unsigned char *native, *natptr;  size_t each_size;  unsigned int count = section->reloc_count;  size_t natsize;  if (count == 0) return true;  each_size = obj_reloc_entry_size (abfd);  natsize = each_size * count;  native = (unsigned char *) bfd_zalloc (abfd, natsize);  if (!native) {    bfd_error = no_memory;    return false;  }  generic = section->orelocation;  if (each_size == RELOC_EXT_SIZE)     {      for (natptr = native;	   count != 0;	   --count, natptr += each_size, ++generic)	NAME(aout,swap_ext_reloc_out) (abfd, *generic, (struct reloc_ext_external *)natptr);    }  else     {      for (natptr = native;	   count != 0;	   --count, natptr += each_size, ++generic)	NAME(aout,swap_std_reloc_out)(abfd, *generic, (struct reloc_std_external *)natptr);    }  if ( bfd_write ((PTR) native, 1, natsize, abfd) != natsize) {    bfd_release(abfd, native);    return false;  }  bfd_release (abfd, native);  return true;}/* This is stupid.  This function should be a boolean predicate */unsigned intDEFUN(NAME(aout,canonicalize_reloc),(abfd, section, relptr, symbols),      bfd *abfd AND      sec_ptr section AND      arelent **relptr AND      asymbol **symbols){  arelent *tblptr = section->relocation;  unsigned int count;  if (!(tblptr || NAME(aout,slurp_reloc_table)(abfd, section, symbols)))    return 0;  if (section->flags & SEC_CONSTRUCTOR) {    arelent_chain *chain = section->constructor_chain;    for (count = 0; count < section->reloc_count; count ++) {      *relptr ++ = &chain->relent;      chain = chain->next;    }  }  else {    tblptr = section->relocation;    if (!tblptr) return 0;    for (count = 0; count++ < section->reloc_count;)       {	*relptr++ = tblptr++;      }  }  *relptr = 0;  return section->reloc_count;}unsigned intDEFUN(NAME(aout,get_reloc_upper_bound),(abfd, asect),     bfd *abfd AND     sec_ptr asect){  if (bfd_get_format (abfd) != bfd_object) {    bfd_error = invalid_operation;    return 0;  }  if (asect->flags & SEC_CONSTRUCTOR) {    return (sizeof (arelent *) * (asect->reloc_count+1));  }  if (asect == obj_datasec (abfd))    return (sizeof (arelent *) *            ((exec_hdr(abfd)->a_drsize / obj_reloc_entry_size (abfd))             +1));  if (asect == obj_textsec (abfd))    return (sizeof (arelent *) *            ((exec_hdr(abfd)->a_trsize / obj_reloc_entry_size (abfd))             +1));  bfd_error = invalid_operation;  return 0;} unsigned intDEFUN(NAME(aout,get_symtab_upper_bound),(abfd),     bfd *abfd){  if (!NAME(aout,slurp_symbol_table)(abfd)) return 0;  return (bfd_get_symcount (abfd)+1) * (sizeof (aout_symbol_type *));} alent *DEFUN(NAME(aout,get_lineno),(ignore_abfd, ignore_symbol),      bfd *ignore_abfd AND      asymbol *ignore_symbol){return (alent *)NULL;}void DEFUN(NAME(aout,print_symbol),(ignore_abfd, afile, symbol, how),      bfd *ignore_abfd AND      PTR afile AND      asymbol *symbol AND      bfd_print_symbol_type how){  FILE *file = (FILE *)afile;  switch (how) {  case bfd_print_symbol_name:    if (symbol->name)      fprintf(file,"%s", symbol->name);    break;  case bfd_print_symbol_more:    fprintf(file,"%4x %2x %2x",(unsigned)(aout_symbol(symbol)->desc & 0xffff),	    (unsigned)(aout_symbol(symbol)->other & 0xff),	    (unsigned)(aout_symbol(symbol)->type));    break;  case bfd_print_symbol_all:    {   CONST char *section_name = symbol->section->name;      bfd_print_symbol_vandf((PTR)file,symbol);      fprintf(file," %-5s %04x %02x %02x",	      section_name,	      (unsigned)(aout_symbol(symbol)->desc & 0xffff),	      (unsigned)(aout_symbol(symbol)->other & 0xff),	      (unsigned)(aout_symbol(symbol)->type  & 0xff));      if (symbol->name)        fprintf(file," %s", symbol->name);    }    break;  case bfd_print_symbol_nm:    {      int section_code = bfd_decode_symclass  (symbol);      if (section_code == 'U')	fprintf(file, "        ");      else	fprintf_vma(file, symbol->value+symbol->section->vma);      if (section_code == '?')	{	  int type_code = aout_symbol(symbol)->type  & 0xff;	  char *stab_name = aout_stab_name(type_code);	  char buf[10];	  if (stab_name == NULL)	    {	      sprintf(buf, "(%d)", type_code);	      stab_name = buf;	    }	  fprintf(file," - %02x %04x %5s",		  (unsigned)(aout_symbol(symbol)->other & 0xff),		  (unsigned)(aout_symbol(symbol)->desc & 0xffff),		  stab_name);        }      else	fprintf(file," %c", section_code);      if (symbol->name)        fprintf(file," %s", symbol->name);    }    break;  }}/*  provided a BFD, a section and an offset into the section, calculate and return the name of the source file and the line nearest to the wanted location.*/ booleanDEFUN(NAME(aout,find_nearest_line),(abfd,				     section,				     symbols,				     offset,				     filename_ptr,				     functionname_ptr,				     line_ptr),      bfd *abfd AND      asection *section AND      asymbol **symbols AND      bfd_vma offset AND      CONST char **filename_ptr AND      CONST char **functionname_ptr AND      unsigned int *line_ptr){  /* Run down the file looking for the filename, function and linenumber */  asymbol **p;  static  char buffer[100];  static  char filename_buffer[200];  CONST char *directory_name = NULL;  CONST char *main_file_name = NULL;  CONST char *current_file_name = NULL;  CONST char *line_file_name = NULL; /* Value of current_file_name at line number. */  bfd_vma high_line_vma = ~0;  bfd_vma low_func_vma = 0;  asymbol *func = 0;  *filename_ptr = abfd->filename;  *functionname_ptr = 0;  *line_ptr = 0;  if (symbols != (asymbol **)NULL) {    for (p = symbols; *p; p++) {      aout_symbol_type  *q = (aout_symbol_type *)(*p);    next:      switch (q->type){      case N_SO:	main_file_name = current_file_name = q->symbol.name;	/* Look ahead to next symbol to check if that too is an N_SO. */	p++;	if (*p == NULL)	  break;	q = (aout_symbol_type *)(*p);	if (q->type != (int)N_SO)	  goto next;	/* Found a second N_SO  First is directory; second is filename. */	directory_name = current_file_name;	main_file_name = current_file_name = q->symbol.name;	if (obj_textsec(abfd) != section)	  goto done;	break;      case N_SOL:	current_file_name = q->symbol.name;	break;      case N_SLINE:      case N_DSLINE:      case N_BSLINE:	/* We'll keep this if it resolves nearer than the one we have already */	if (q->symbol.value >= offset &&	    q->symbol.value < high_line_vma) {	  *line_ptr = q->desc;	  high_line_vma = q->symbol.value;	  line_file_name = current_file_name;	}	break;      case N_FUN:	{	  /* We'll keep this if it is nearer than the one we have already */	  if (q->symbol.value >= low_func_vma &&	      q->symbol.value <= offset) {	    low_func_vma = q->symbol.value;	    func = (asymbol *)q;	  }	  if (*line_ptr && func) {	    CONST char *function = func->name;	    char *p;	    strncpy(buffer, function, sizeof(buffer)-1);	    buffer[sizeof(buffer)-1] = 0;	    /* Have to remove : stuff */	    p = strchr(buffer,':');	    if (p != NULL) { *p = '\0'; }	    *functionname_ptr = buffer;	    goto done;	  }	}	break;      }    }  } done:  if (*line_ptr)    main_file_name = line_file_name;  if (main_file_name) {      if (main_file_name[0] == '/' || directory_name == NULL)	  *filename_ptr = main_file_name;      else {	  sprintf(filename_buffer, "%.140s%.50s",		  directory_name, main_file_name);	  *filename_ptr = filename_buffer;      }  }  return true;}int DEFUN(NAME(aout,sizeof_headers),(abfd, execable),      bfd *abfd AND      boolean execable){  return adata(abfd).exec_bytes_size;}

⌨️ 快捷键说明

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