aout-adobe.c

来自「基于4个mips核的noc设计」· C语言 代码 · 共 563 行 · 第 1/2 页

C
563
字号
static booleanaout_adobe_write_object_contents (abfd)     bfd *abfd;{  struct external_exec swapped_hdr;  static struct external_segdesc sentinel[1];	/* Initialized to zero.  */  asection *sect;  exec_hdr (abfd)->a_info = ZMAGIC;  /* Calculate text size as total of text sections, etc.  */  exec_hdr (abfd)->a_text = 0;  exec_hdr (abfd)->a_data = 0;  exec_hdr (abfd)->a_bss  = 0;  exec_hdr (abfd)->a_trsize = 0;  exec_hdr (abfd)->a_drsize = 0;  for (sect = abfd->sections; sect; sect = sect->next)    {      if (sect->flags & SEC_CODE)	{	  exec_hdr (abfd)->a_text += sect->_raw_size;	  exec_hdr (abfd)->a_trsize += sect->reloc_count *	    sizeof (struct reloc_std_external);	}      else if (sect->flags & SEC_DATA)	{	  exec_hdr (abfd)->a_data += sect->_raw_size;	  exec_hdr (abfd)->a_drsize += sect->reloc_count *	    sizeof (struct reloc_std_external);	}      else if (sect->flags & SEC_ALLOC && !(sect->flags & SEC_LOAD))	{	  exec_hdr (abfd)->a_bss += sect->_raw_size;	}    }  exec_hdr (abfd)->a_syms = bfd_get_symcount (abfd)    * sizeof (struct external_nlist);  exec_hdr (abfd)->a_entry = bfd_get_start_address (abfd);  aout_adobe_swap_exec_header_out (abfd, exec_hdr (abfd), &swapped_hdr);  if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0      || (bfd_write ((PTR) &swapped_hdr, 1, EXEC_BYTES_SIZE, abfd)	  != EXEC_BYTES_SIZE))    return false;  /* Now write out the section information.  Text first, data next, rest     afterward.  */  for (sect = abfd->sections; sect; sect = sect->next)    {      if (sect->flags & SEC_CODE)	{	  aout_adobe_write_section (abfd, sect);	}    }  for (sect = abfd->sections; sect; sect = sect->next)    {      if (sect->flags & SEC_DATA)	{	  aout_adobe_write_section (abfd, sect);	}    }  for (sect = abfd->sections; sect; sect = sect->next)    {      if (!(sect->flags & (SEC_CODE | SEC_DATA)))	{	  aout_adobe_write_section (abfd, sect);	}    }  /* Write final `sentinel` section header (with type of 0).  */  if (bfd_write ((PTR) sentinel, 1, sizeof (*sentinel), abfd)      != sizeof (*sentinel))    return false;  /* Now write out reloc info, followed by syms and strings.  */  if (bfd_get_symcount (abfd) != 0)    {      if (bfd_seek (abfd, (file_ptr) (N_SYMOFF (*exec_hdr (abfd))), SEEK_SET)	  != 0)	return false;      if (! aout_32_write_syms (abfd))	return false;      if (bfd_seek (abfd, (file_ptr) (N_TRELOFF (*exec_hdr (abfd))), SEEK_SET)	  != 0)	return false;      for (sect = abfd->sections; sect; sect = sect->next)	{	  if (sect->flags & SEC_CODE)	    {	      if (!aout_32_squirt_out_relocs (abfd, sect))		return false;	    }	}      if (bfd_seek (abfd, (file_ptr) (N_DRELOFF (*exec_hdr (abfd))), SEEK_SET)	  != 0)	return false;      for (sect = abfd->sections; sect; sect = sect->next)	{	  if (sect->flags & SEC_DATA)	    {	      if (!aout_32_squirt_out_relocs (abfd, sect))		return false;	    }	}    }  return true;}static voidaout_adobe_write_section (abfd, sect)     bfd *abfd ATTRIBUTE_UNUSED;     sec_ptr sect ATTRIBUTE_UNUSED;{  /* FIXME XXX */}static booleanaout_adobe_set_section_contents (abfd, section, location, offset, count)     bfd *abfd;     asection *section;     PTR location;     file_ptr offset;     bfd_size_type count;{  file_ptr section_start;  sec_ptr sect;  /* Set by bfd.c handler.  */  if (abfd->output_has_begun == false)    {      /* Assign file offsets to sections.  Text sections are first, and	 are contiguous.  Then data sections.  Everything else at the end.  */      section_start = N_TXTOFF (ignore<-->me);      for (sect = abfd->sections; sect; sect = sect->next)	{	  if (sect->flags & SEC_CODE)	    {	      sect->filepos = section_start;	      /* FIXME:  Round to alignment.  */	      section_start += sect->_raw_size;	    }	}      for (sect = abfd->sections; sect; sect = sect->next)	{	  if (sect->flags & SEC_DATA)	    {	      sect->filepos = section_start;	      /* FIXME:  Round to alignment.  */	      section_start += sect->_raw_size;	    }	}      for (sect = abfd->sections; sect; sect = sect->next)	{	  if (sect->flags & SEC_HAS_CONTENTS &&	      !(sect->flags & (SEC_CODE | SEC_DATA)))	    {	      sect->filepos = section_start;	      /* FIXME:  Round to alignment.  */	      section_start += sect->_raw_size;	    }	}    }  /* Regardless, once we know what we're doing, we might as well get     going.  */  if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0)    return false;  if (count != 0)    {      return (bfd_write ((PTR) location, 1, count, abfd) == count) ? true : false;    }  return true;}static booleanaout_adobe_set_arch_mach (abfd, arch, machine)     bfd *abfd;     enum bfd_architecture arch;     unsigned long machine;{  if (! bfd_default_set_arch_mach (abfd, arch, machine))    return false;  if (arch == bfd_arch_unknown      || arch == bfd_arch_m68k)    return true;  return false;}static intaout_adobe_sizeof_headers (ignore_abfd, ignore)     bfd *ignore_abfd ATTRIBUTE_UNUSED;     boolean ignore ATTRIBUTE_UNUSED;{  return sizeof (struct internal_exec);}/* Build the transfer vector for Adobe A.Out files.  */#define aout_32_close_and_cleanup aout_32_bfd_free_cached_info#define aout_32_bfd_make_debug_symbol \  ((asymbol *(*) PARAMS ((bfd *, void *, unsigned long))) bfd_nullvoidptr)#define aout_32_bfd_reloc_type_lookup \  ((reloc_howto_type *(*) \    PARAMS ((bfd *, bfd_reloc_code_real_type))) bfd_nullvoidptr)#define	aout_32_set_arch_mach		aout_adobe_set_arch_mach#define	aout_32_set_section_contents	aout_adobe_set_section_contents#define	aout_32_sizeof_headers		aout_adobe_sizeof_headers#define aout_32_bfd_get_relocated_section_contents \  bfd_generic_get_relocated_section_contents#define aout_32_get_section_contents_in_window _bfd_generic_get_section_contents_in_window#define aout_32_bfd_relax_section       bfd_generic_relax_section#define aout_32_bfd_gc_sections         bfd_generic_gc_sections#define aout_32_bfd_link_hash_table_create \  _bfd_generic_link_hash_table_create#define aout_32_bfd_link_add_symbols	_bfd_generic_link_add_symbols#define aout_32_bfd_final_link		_bfd_generic_final_link#define aout_32_bfd_link_split_section	_bfd_generic_link_split_sectionconst bfd_target a_out_adobe_vec = {  "a.out.adobe",		/* name */  bfd_target_aout_flavour,  BFD_ENDIAN_BIG,		/* data byte order is unknown (big assumed) */  BFD_ENDIAN_BIG,		/* hdr byte order is big */  (HAS_RELOC | EXEC_P |		/* object flags */   HAS_LINENO | HAS_DEBUG |   HAS_SYMS | HAS_LOCALS | WP_TEXT ),  /* section flags */  (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD | SEC_CODE | SEC_DATA | SEC_RELOC),  '_',				/*  symbol leading char */  ' ',				/* ar_pad_char */  16,				/* ar_max_namelen */  bfd_getb64, bfd_getb_signed_64, bfd_putb64,  bfd_getb32, bfd_getb_signed_32, bfd_putb32,  bfd_getb16, bfd_getb_signed_16, bfd_putb16,	/* data */  bfd_getb64, bfd_getb_signed_64, bfd_putb64,  bfd_getb32, bfd_getb_signed_32, bfd_putb32,  bfd_getb16, bfd_getb_signed_16, bfd_putb16,	/* hdrs */  {_bfd_dummy_target, aout_adobe_object_p,	/* bfd_check_format */   bfd_generic_archive_p, _bfd_dummy_target},  {bfd_false, aout_adobe_mkobject,	/* bfd_set_format */   _bfd_generic_mkarchive, bfd_false},  {bfd_false, aout_adobe_write_object_contents,	/* bfd_write_contents */   _bfd_write_archive_contents, bfd_false},  BFD_JUMP_TABLE_GENERIC (aout_32),  BFD_JUMP_TABLE_COPY (_bfd_generic),  BFD_JUMP_TABLE_CORE (_bfd_nocore),  BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd),  BFD_JUMP_TABLE_SYMBOLS (aout_32),  BFD_JUMP_TABLE_RELOCS (aout_32),  BFD_JUMP_TABLE_WRITE (aout_32),  BFD_JUMP_TABLE_LINK (aout_32),  BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),  NULL,  (PTR) 0};

⌨️ 快捷键说明

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