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

📄 aoutx.h

📁 早期freebsd实现
💻 H
📖 第 1 页 / 共 5 页
字号:
	  obj_bsssec(abfd)->vma = vma;	else	  vma = obj_bsssec(abfd)->vma;      }      execp->a_text = obj_textsec(abfd)->_raw_size;      execp->a_data = obj_datasec(abfd)->_raw_size;      execp->a_bss = obj_bsssec(abfd)->_raw_size;      N_SET_MAGIC (*execp, NMAGIC);      break;    default:      abort ();    }#ifdef BFD_AOUT_DEBUG  fprintf (stderr, "       text=<%x,%x,%x> data=<%x,%x,%x> bss=<%x,%x>\n",	   obj_textsec(abfd)->vma, obj_textsec(abfd)->_raw_size, obj_textsec(abfd)->filepos,	   obj_datasec(abfd)->vma, obj_datasec(abfd)->_raw_size, obj_datasec(abfd)->filepos,	   obj_bsssec(abfd)->vma, obj_bsssec(abfd)->_raw_size);#endif  return true;}/*FUNCTION	aout_<size>new_section_hook  DESCRIPTION	Called by the BFD in response to a @code{bfd_make_section}	request.EXAMPLE        boolean aout_<size>_new_section_hook,	   (bfd *abfd,	    asection *newsect));*/booleanDEFUN(NAME(aout,new_section_hook),(abfd, newsect),	bfd *abfd AND	asection *newsect){  /* align to double at least */  newsect->alignment_power = bfd_get_arch_info(abfd)->section_align_power;      if (bfd_get_format (abfd) == bfd_object)   {    if (obj_textsec(abfd) == NULL && !strcmp(newsect->name, ".text")) {	obj_textsec(abfd)= newsect;	newsect->target_index = N_TEXT | N_EXT;	return true;      }          if (obj_datasec(abfd) == NULL && !strcmp(newsect->name, ".data")) {	obj_datasec(abfd) = newsect;	newsect->target_index = N_DATA | N_EXT;	return true;      }          if (obj_bsssec(abfd) == NULL && !strcmp(newsect->name, ".bss")) {	obj_bsssec(abfd) = newsect;	newsect->target_index = N_BSS | N_EXT;	return true;      }  }      /* We allow more than three sections internally */  return true;}boolean  DEFUN(NAME(aout,set_section_contents),(abfd, section, location, offset, count),	bfd *abfd AND	sec_ptr section AND	PTR location AND	file_ptr offset AND	bfd_size_type count){  file_ptr text_end;  bfd_size_type text_size;  if (abfd->output_has_begun == false)      {				/* set by bfd.c handler */	switch (abfd->direction)	    {	    case read_direction:	    case no_direction:	      bfd_error = invalid_operation;	      return false;	    case write_direction:	      if (NAME(aout,adjust_sizes_and_vmas) (abfd,						    &text_size,						    &text_end) == false)		return false;	    case both_direction:	      break;	    }      }  /* regardless, once we know what we're doing, we might as well get going */  if (section != obj_bsssec(abfd))       {	bfd_seek (abfd, section->filepos + offset, SEEK_SET);    	if (count) {	  return (bfd_write ((PTR)location, 1, count, abfd) == count) ?	    true : false;	}	return true;      }  return true;}/* Classify stabs symbols */#define sym_in_text_section(sym) \  (((sym)->type  & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_TEXT)#define sym_in_data_section(sym) \  (((sym)->type  & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_DATA)#define sym_in_bss_section(sym) \  (((sym)->type  & (N_ABS | N_TEXT | N_DATA | N_BSS))== N_BSS)/* Symbol is undefined if type is N_UNDF|N_EXT and if it has  zero in the "value" field.  Nonzeroes there are fortrancommon  symbols.  */#define sym_is_undefined(sym) \  ((sym)->type == (N_UNDF | N_EXT) && (sym)->symbol.value == 0)/* Symbol is a global definition if N_EXT is on and if it has  a nonzero type field.  */#define sym_is_global_defn(sym) \  (((sym)->type & N_EXT) && (sym)->type & N_TYPE)/* Symbol is debugger info if any bits outside N_TYPE or N_EXT  are on.  */#define sym_is_debugger_info(sym) \  ((sym)->type & ~(N_EXT | N_TYPE))#define sym_is_fortrancommon(sym)       \  (((sym)->type == (N_EXT)) && (sym)->symbol.value != 0)/* Symbol is absolute if it has N_ABS set */#define sym_is_absolute(sym) \  (((sym)->type  & N_TYPE)== N_ABS)#define sym_is_indirect(sym) \  (((sym)->type & N_ABS)== N_ABS)/* Only in their own functions for ease of debugging; when sym flags have  stabilised these should be inlined into their (single) caller */  static voidDEFUN(translate_from_native_sym_flags,(sym_pointer, cache_ptr, abfd),      struct external_nlist *sym_pointer AND      aout_symbol_type *cache_ptr AND      bfd *abfd){  switch (cache_ptr->type & N_TYPE)   {  case N_SETA:  case N_SETT:  case N_SETD:  case N_SETB:  {    char *copy = bfd_alloc(abfd, strlen(cache_ptr->symbol.name)+1);    asection *section ;    asection *into_section;          arelent_chain *reloc = (arelent_chain *)bfd_alloc(abfd, sizeof(arelent_chain));    strcpy(copy, cache_ptr->symbol.name);    /* Make sure that this bfd has a section with the right contructor       name */    section = bfd_get_section_by_name (abfd, copy);    if (!section)     section = bfd_make_section(abfd,copy);    /* Build a relocation entry for the constructor */    switch ( (cache_ptr->type  & N_TYPE) )     {    case N_SETA:      into_section = &bfd_abs_section;      break;    case N_SETT:      into_section = (asection *)obj_textsec(abfd);      break;    case N_SETD:      into_section = (asection *)obj_datasec(abfd);      break;    case N_SETB:      into_section = (asection *)obj_bsssec(abfd);      break;    default:      abort();    }    /* Build a relocation pointing into the constuctor section       pointing at the symbol in the set vector specified */    reloc->relent.addend = cache_ptr->symbol.value;    cache_ptr->symbol.section =  into_section->symbol->section;    reloc->relent.sym_ptr_ptr  = into_section->symbol_ptr_ptr;	      /* We modify the symbol to belong to a section depending upon the       name of the symbol - probably __CTOR__ or __DTOR__ but we don't       really care, and add to the size of the section to contain a       pointer to the symbol. Build a reloc entry to relocate to this       symbol attached to this section.  */	      section->flags = SEC_CONSTRUCTOR;	      section->reloc_count++;    section->alignment_power = 2;    reloc->next = section->constructor_chain;    section->constructor_chain = reloc;    reloc->relent.address = section->_raw_size;    section->_raw_size += sizeof(int *);    reloc->relent.howto = howto_table_ext + CTOR_TABLE_RELOC_IDX;    cache_ptr->symbol.flags |=  BSF_DEBUGGING  | BSF_CONSTRUCTOR;  }    break;  default:    if (cache_ptr->type ==  N_WARNING)     {      /* This symbol is the text of a warning message, the next symbol	 is the symbol to associate the warning with */      cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_WARNING;      cache_ptr->symbol.value = (bfd_vma)((cache_ptr+1));      /* We furgle with the next symbol in place. We don't want it to be undefined, we'll trample the type */      (sym_pointer+1)->e_type[0] = 0xff;      break;    }    if ((cache_ptr->type | N_EXT) == (N_INDR | N_EXT)) {	/* Two symbols in a row for an INDR message. The first symbol	   contains the name we will match, the second symbol contains the	   name the first name is translated into. It is supplied to us	   undefined. This is good, since we want to pull in any files which	   define it */	cache_ptr->symbol.flags = BSF_DEBUGGING | BSF_INDIRECT;	cache_ptr->symbol.value = (bfd_vma)((cache_ptr+1));	cache_ptr->symbol.section = &bfd_und_section;	break;      }          if (sym_is_debugger_info (cache_ptr)) {	cache_ptr->symbol.flags = BSF_DEBUGGING ;	/* Work out the section correct for this symbol */	switch (cache_ptr->type & N_TYPE) 	{	case N_TEXT:	case N_FN:	  cache_ptr->symbol.section = obj_textsec (abfd);	  cache_ptr->symbol.value -= obj_textsec(abfd)->vma;	  break;	case N_DATA:	  cache_ptr->symbol.value  -= obj_datasec(abfd)->vma;	  cache_ptr->symbol.section = obj_datasec (abfd);	  break;	case N_BSS :	  cache_ptr->symbol.section = obj_bsssec (abfd);	  cache_ptr->symbol.value -= obj_bsssec(abfd)->vma;	  break;	default:	case N_ABS:	  cache_ptr->symbol.section = &bfd_abs_section;	  break;	}      }    else {	if (sym_is_fortrancommon (cache_ptr))	{	  cache_ptr->symbol.flags = 0;	  cache_ptr->symbol.section = &bfd_com_section;	}	else {	  }	  	/* In a.out, the value of a symbol is always relative to the 	 * start of the file, if this is a data symbol we'll subtract	 * the size of the text section to get the section relative	 * value. If this is a bss symbol (which would be strange)	 * we'll subtract the size of the previous two sections	 * to find the section relative address.	 */	  	if (sym_in_text_section (cache_ptr))   {	    cache_ptr->symbol.value -= obj_textsec(abfd)->vma;	    cache_ptr->symbol.section = obj_textsec (abfd);	  }	else if (sym_in_data_section (cache_ptr)){	    cache_ptr->symbol.value -= obj_datasec(abfd)->vma;	    cache_ptr->symbol.section = obj_datasec (abfd);	  }	else if (sym_in_bss_section(cache_ptr)) {	    cache_ptr->symbol.section = obj_bsssec (abfd);	    cache_ptr->symbol.value -= obj_bsssec(abfd)->vma;	  }	else  if (sym_is_undefined (cache_ptr)) {	    cache_ptr->symbol.flags = 0;	    cache_ptr->symbol.section = &bfd_und_section;	  }	else if (sym_is_absolute(cache_ptr))	{	  cache_ptr->symbol.section = &bfd_abs_section;	}	    	if (sym_is_global_defn (cache_ptr)) 	{	  cache_ptr->symbol.flags = BSF_GLOBAL | BSF_EXPORT;	} 	else 	{	  cache_ptr->symbol.flags = BSF_LOCAL;	}      }  }}static voidDEFUN(translate_to_native_sym_flags,(sym_pointer, cache_ptr, abfd),     struct external_nlist *sym_pointer AND     asymbol *cache_ptr AND     bfd *abfd){  bfd_vma value = cache_ptr->value;  /* mask out any existing type bits in case copying from one section     to another */  sym_pointer->e_type[0] &= ~N_TYPE;    if (bfd_get_output_section(cache_ptr) == obj_bsssec (abfd)) {      sym_pointer->e_type[0] |= N_BSS;    }  else if (bfd_get_output_section(cache_ptr) == obj_datasec (abfd)) {      sym_pointer->e_type[0] |= N_DATA;    }  else  if (bfd_get_output_section(cache_ptr) == obj_textsec (abfd)) {      sym_pointer->e_type[0] |= N_TEXT;    }  else if (bfd_get_output_section(cache_ptr) == &bfd_abs_section)   {    sym_pointer->e_type[0] |= N_ABS;  }  else if (bfd_get_output_section(cache_ptr) == &bfd_und_section)   {    sym_pointer->e_type[0] = (N_UNDF | N_EXT);  }  else if (bfd_get_output_section(cache_ptr) == &bfd_com_section) {      sym_pointer->e_type[0] = (N_UNDF | N_EXT);    }      else {          if (cache_ptr->section->output_section)       {		bfd_error_vector.nonrepresentable_section(abfd,						  bfd_get_output_section(cache_ptr)->name);      }      else       {	bfd_error_vector.nonrepresentable_section(abfd,						  cache_ptr->section->name);	      }          }  /* Turn the symbol from section relative to absolute again */      value +=  cache_ptr->section->output_section->vma  + cache_ptr->section->output_offset ;  if (cache_ptr->flags & (BSF_WARNING)) {      (sym_pointer+1)->e_type[0] = 1;    }        if (cache_ptr->flags & (BSF_GLOBAL | BSF_EXPORT)) {      sym_pointer->e_type[0] |= N_EXT;    }  if (cache_ptr->flags & BSF_DEBUGGING) {      sym_pointer->e_type [0]= ((aout_symbol_type *)cache_ptr)->type;    }  PUT_WORD(abfd, value, sym_pointer->e_value);}/* Native-level interface to symbols. *//* We read the symbols into a buffer, which is discarded when thisfunction exits.  We read the strings into a buffer large enough tohold them all plus all the cached symbol entries. */asymbol *DEFUN(NAME(aout,make_empty_symbol),(abfd),      bfd *abfd){  aout_symbol_type  *new =    (aout_symbol_type *)bfd_zalloc (abfd, sizeof (aout_symbol_type));  new->symbol.the_bfd = abfd;      return &new->symbol;}booleanDEFUN(NAME(aout,slurp_symbol_table),(abfd),      bfd *abfd){  bfd_size_type symbol_size;  bfd_size_type string_size;  unsigned char string_chars[BYTES_IN_WORD];  struct external_nlist *syms;  char *strings;  aout_symbol_type *cached;    

⌨️ 快捷键说明

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