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

📄 elf32-m32r.c

📁 基于4个mips核的noc设计
💻 C
📖 第 1 页 / 共 5 页
字号:
      /* Get the new reloc address.  */      if ((irel->r_offset > addr	   && irel->r_offset < toaddr))	irel->r_offset -= count;    }  /* Adjust the local symbols defined in this section.  */  esym = extsyms;  esymend = esym + symtab_hdr->sh_info;  for (; esym < esymend; esym++)    {      Elf_Internal_Sym isym;      bfd_elf32_swap_symbol_in (abfd, esym, &isym);      if (isym.st_shndx == shndx	  && isym.st_value > addr	  && isym.st_value < toaddr)	{	  isym.st_value -= count;	  bfd_elf32_swap_symbol_out (abfd, &isym, esym);	}    }  /* Now adjust the global symbols defined in this section.  */  esym = extsyms + symtab_hdr->sh_info;  esymend = extsyms + (symtab_hdr->sh_size / sizeof (Elf32_External_Sym));  for (index = 0; esym < esymend; esym++, index++)    {      Elf_Internal_Sym isym;      bfd_elf32_swap_symbol_in (abfd, esym, &isym);      sym_hash = elf_sym_hashes (abfd)[index];      if (isym.st_shndx == shndx	  && ((sym_hash)->root.type == bfd_link_hash_defined	      || (sym_hash)->root.type == bfd_link_hash_defweak)	  && (sym_hash)->root.u.def.section == sec	  && (sym_hash)->root.u.def.value > addr	  && (sym_hash)->root.u.def.value < toaddr)	{	  (sym_hash)->root.u.def.value -= count;	}    }  return true;}/* This is a version of bfd_generic_get_relocated_section_contents   which uses m32r_elf_relocate_section.  */static bfd_byte *m32r_elf_get_relocated_section_contents (output_bfd, link_info, link_order,					 data, relocateable, symbols)     bfd *output_bfd;     struct bfd_link_info *link_info;     struct bfd_link_order *link_order;     bfd_byte *data;     boolean relocateable;     asymbol **symbols;{  Elf_Internal_Shdr *symtab_hdr;  asection *input_section = link_order->u.indirect.section;  bfd *input_bfd = input_section->owner;  asection **sections = NULL;  Elf_Internal_Rela *internal_relocs = NULL;  Elf32_External_Sym *external_syms = NULL;  Elf_Internal_Sym *internal_syms = NULL;  /* We only need to handle the case of relaxing, or of having a     particular set of section contents, specially.  */  if (relocateable      || elf_section_data (input_section)->this_hdr.contents == NULL)    return bfd_generic_get_relocated_section_contents (output_bfd, link_info,						       link_order, data,						       relocateable,						       symbols);  symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;  memcpy (data, elf_section_data (input_section)->this_hdr.contents,	  input_section->_raw_size);  if ((input_section->flags & SEC_RELOC) != 0      && input_section->reloc_count > 0)    {      Elf_Internal_Sym *isymp;      asection **secpp;      Elf32_External_Sym *esym, *esymend;      if (symtab_hdr->contents != NULL)	external_syms = (Elf32_External_Sym *) symtab_hdr->contents;      else	{	  external_syms = ((Elf32_External_Sym *)			   bfd_malloc (symtab_hdr->sh_info				       * sizeof (Elf32_External_Sym)));	  if (external_syms == NULL && symtab_hdr->sh_info > 0)	    goto error_return;	  if (bfd_seek (input_bfd, symtab_hdr->sh_offset, SEEK_SET) != 0	      || (bfd_read (external_syms, sizeof (Elf32_External_Sym),			    symtab_hdr->sh_info, input_bfd)		  != (symtab_hdr->sh_info * sizeof (Elf32_External_Sym))))	    goto error_return;	}      internal_relocs = (_bfd_elf32_link_read_relocs			 (input_bfd, input_section, (PTR) NULL,			  (Elf_Internal_Rela *) NULL, false));      if (internal_relocs == NULL)	goto error_return;      internal_syms = ((Elf_Internal_Sym *)		       bfd_malloc (symtab_hdr->sh_info				   * sizeof (Elf_Internal_Sym)));      if (internal_syms == NULL && symtab_hdr->sh_info > 0)	goto error_return;      sections = (asection **) bfd_malloc (symtab_hdr->sh_info					   * sizeof (asection *));      if (sections == NULL && symtab_hdr->sh_info > 0)	goto error_return;      isymp = internal_syms;      secpp = sections;      esym = external_syms;      esymend = esym + symtab_hdr->sh_info;      for (; esym < esymend; ++esym, ++isymp, ++secpp)	{	  asection *isec;	  bfd_elf32_swap_symbol_in (input_bfd, esym, isymp);	  if (isymp->st_shndx == SHN_UNDEF)	    isec = bfd_und_section_ptr;	  else if (isymp->st_shndx > 0 && isymp->st_shndx < SHN_LORESERVE)	    isec = bfd_section_from_elf_index (input_bfd, isymp->st_shndx);	  else if (isymp->st_shndx == SHN_ABS)	    isec = bfd_abs_section_ptr;	  else if (isymp->st_shndx == SHN_COMMON)	    isec = bfd_com_section_ptr;	  else if (isymp->st_shndx == SHN_M32R_SCOMMON)	    isec = &m32r_elf_scom_section;	  else	    {	      /* Who knows?  */	      isec = NULL;	    }	  *secpp = isec;	}      if (! m32r_elf_relocate_section (output_bfd, link_info, input_bfd,				       input_section, data, internal_relocs,				       internal_syms, sections))	goto error_return;      if (sections != NULL)	free (sections);      sections = NULL;      if (internal_syms != NULL)	free (internal_syms);      internal_syms = NULL;      if (external_syms != NULL && symtab_hdr->contents == NULL)	free (external_syms);      external_syms = NULL;      if (internal_relocs != elf_section_data (input_section)->relocs)	free (internal_relocs);      internal_relocs = NULL;    }  return data; error_return:  if (internal_relocs != NULL      && internal_relocs != elf_section_data (input_section)->relocs)    free (internal_relocs);  if (external_syms != NULL && symtab_hdr->contents == NULL)    free (external_syms);  if (internal_syms != NULL)    free (internal_syms);  if (sections != NULL)    free (sections);  return NULL;}#endif /* #if 0 *//* Set the right machine number.  */static booleanm32r_elf_object_p (abfd)     bfd *abfd;{  switch (elf_elfheader (abfd)->e_flags & EF_M32R_ARCH)    {    default:    case E_M32R_ARCH:   (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32r);  break;    case E_M32RX_ARCH:  (void) bfd_default_set_arch_mach (abfd, bfd_arch_m32r, bfd_mach_m32rx); break;    }  return true;}/* Store the machine number in the flags field.  */static voidm32r_elf_final_write_processing (abfd, linker)     bfd *   abfd;     boolean linker ATTRIBUTE_UNUSED;{  unsigned long val;  switch (bfd_get_mach (abfd))    {    default:    case bfd_mach_m32r:  val = E_M32R_ARCH; break;    case bfd_mach_m32rx: val = E_M32RX_ARCH; break;    }  elf_elfheader (abfd)->e_flags &=~ EF_M32R_ARCH;  elf_elfheader (abfd)->e_flags |= val;}/* Function to keep M32R specific file flags.  */static booleanm32r_elf_set_private_flags (abfd, flags)     bfd *    abfd;     flagword flags;{  BFD_ASSERT (!elf_flags_init (abfd)	      || elf_elfheader (abfd)->e_flags == flags);  elf_elfheader (abfd)->e_flags = flags;  elf_flags_init (abfd) = true;  return true;}/* Copy backend specific data from one object module to another */static booleanm32r_elf_copy_private_bfd_data (ibfd, obfd)     bfd * ibfd;     bfd * obfd;{  if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)    return true;  BFD_ASSERT (!elf_flags_init (obfd)	      || (elf_elfheader (obfd)->e_flags		  == elf_elfheader (ibfd)->e_flags));  elf_gp (obfd) = elf_gp (ibfd);  elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags;  elf_flags_init (obfd) = true;  return true;}/* Merge backend specific data from an object file to the output   object file when linking.  */static booleanm32r_elf_merge_private_bfd_data (ibfd, obfd)     bfd * ibfd;     bfd * obfd;{  flagword out_flags;  flagword in_flags;  if (   bfd_get_flavour (ibfd) != bfd_target_elf_flavour      || bfd_get_flavour (obfd) != bfd_target_elf_flavour)    return true;  in_flags  = elf_elfheader (ibfd)->e_flags;  out_flags = elf_elfheader (obfd)->e_flags;  if (! elf_flags_init (obfd))    {      /* If the input is the default architecture then do not	 bother setting the flags for the output architecture,	 instead allow future merges to do this.  If no future	 merges ever set these flags then they will retain their	 unitialised values, which surprise surprise, correspond	 to the default values.  */      if (bfd_get_arch_info (ibfd)->the_default)	return true;      elf_flags_init (obfd) = true;      elf_elfheader (obfd)->e_flags = in_flags;      if (bfd_get_arch (obfd) == bfd_get_arch (ibfd)	  && bfd_get_arch_info (obfd)->the_default)	{	  return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd));	}      return true;    }  /* Check flag compatibility.  */  if (in_flags == out_flags)    return true;  if ((in_flags & EF_M32R_ARCH) != (out_flags & EF_M32R_ARCH))    {      if ((in_flags & EF_M32R_ARCH) != E_M32R_ARCH)	{	  _bfd_error_handler (_("%s: Instruction set mismatch with previous modules"),			      bfd_get_filename (ibfd));	  bfd_set_error (bfd_error_bad_value);	  return false;	}    }  return true;}/* Display the flags field */static booleanm32r_elf_print_private_bfd_data (abfd, ptr)     bfd *   abfd;     PTR     ptr;{  FILE * file = (FILE *) ptr;  BFD_ASSERT (abfd != NULL && ptr != NULL)  _bfd_elf_print_private_bfd_data (abfd, ptr);  fprintf (file, _("private flags = %lx"), elf_elfheader (abfd)->e_flags);  switch (elf_elfheader (abfd)->e_flags & EF_M32R_ARCH)    {    default:    case E_M32R_ARCH:  fprintf (file, _(": m32r instructions"));  break;    case E_M32RX_ARCH: fprintf (file, _(": m32rx instructions")); break;    }  fputc ('\n', file);  return true;}asection *m32r_elf_gc_mark_hook (abfd, info, rel, h, sym)       bfd *abfd;       struct bfd_link_info *info ATTRIBUTE_UNUSED;       Elf_Internal_Rela *rel;       struct elf_link_hash_entry *h;       Elf_Internal_Sym *sym;{  if (h != NULL)    {      switch (ELF32_R_TYPE (rel->r_info))      {      case R_M32R_GNU_VTINHERIT:      case R_M32R_GNU_VTENTRY:        break;      default:        switch (h->root.type)          {          case bfd_link_hash_defined:          case bfd_link_hash_defweak:            return h->root.u.def.section;          case bfd_link_hash_common:            return h->root.u.c.p->section;	  default:	    break;          }       }     }   else     {       if (!(elf_bad_symtab (abfd)           && ELF_ST_BIND (sym->st_info) != STB_LOCAL)         && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE)                && sym->st_shndx != SHN_COMMON))          {            return bfd_section_from_elf_index (abfd, sym->st_shndx);          }      }  return NULL;}static booleanm32r_elf_gc_sweep_hook (abfd, info, sec, relocs)     bfd *abfd ATTRIBUTE_UNUSED;     struct bfd_link_info *info ATTRIBUTE_UNUSED;     asection *sec ATTRIBUTE_UNUSED;     const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;{  /* we don't use got and plt entries for m32r */  return true;}/* Look through the relocs for a section during the first phase.   Since we don't do .gots or .plts, we just need to consider the   virtual table relocs for gc.  */static booleanm32r_elf_check_relocs (abfd, info, sec, relocs)     bfd *abfd;     struct bfd_link_info *info;     asection *sec;     const Elf_Internal_Rela *relocs;{  Elf_Internal_Shdr *symtab_hdr;  struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;  const Elf_Internal_Rela *rel;  const Elf_Internal_Rela *rel_end;  if (info->relocateable)    return true;  symtab_hdr = &elf_tdata (abfd)->symtab_hdr;  sym_hashes = elf_sym_hashes (abfd);  sym_hashes_end = sym_hashes + symtab_hdr->sh_size/sizeof (Elf32_External_Sym);  if (!elf_bad_symtab (abfd))    sym_hashes_end -= symtab_hdr->sh_info;  rel_end = relocs + sec->reloc_count;  for (rel = relocs; rel < rel_end; rel++)    {      struct elf_link_hash_entry *h;      unsigned long r_symndx;    

⌨️ 快捷键说明

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