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

📄 coffcode.h

📁 早期freebsd实现
💻 H
📖 第 1 页 / 共 5 页
字号:
  PUTHALF(abfd, scnhdr_int->s_nlnno, (bfd_byte *) scnhdr_ext->s_nlnno);  PUTHALF(abfd, scnhdr_int->s_nreloc, (bfd_byte *) scnhdr_ext->s_nreloc);#endif#if defined(I960)  PUTWORD(abfd, scnhdr_int->s_align, (bfd_byte *) scnhdr_ext->s_align);#endif  return sizeof(SCNHDR);}/*   initialize a section structure with information peculiar to this   particular implementation of coff*/static          booleanDEFUN(coff_new_section_hook,(abfd, section),      bfd            *abfd AND      asection       *section){  section->alignment_power = abfd->xvec->align_power_min;  /* Allocate aux records for section symbols, to store size and     related info.     @@ Shouldn't use constant multiplier here!  */  coffsymbol (section->symbol)->native =    (combined_entry_type *) bfd_zalloc (abfd,					sizeof (combined_entry_type) * 10);  return true;}static asection bfd_debug_section = { "*DEBUG*" };/* Take a section header read from a coff file (in HOST byte order),   and make a BFD "section" out of it.  */static          booleanDEFUN(make_a_section_from_file,(abfd, hdr, target_index),      bfd            *abfd AND      struct internal_scnhdr  *hdr AND      unsigned int target_index){  asection       *return_section;  char *name;      /* Assorted wastage to null-terminate the name, thanks AT&T! */  name = bfd_alloc(abfd, sizeof (hdr->s_name)+1);  if (name == NULL) {      bfd_error = no_memory;      return false;    }  strncpy(name, (char *) &hdr->s_name[0], sizeof (hdr->s_name));  name[sizeof (hdr->s_name)] = 0;  return_section = bfd_make_section(abfd, name);  if (return_section == NULL)   return false;  /* s_paddr is presumed to be = to s_vaddr */  return_section->vma = hdr->s_vaddr;  return_section->_raw_size = hdr->s_size;  return_section->filepos = hdr->s_scnptr;  return_section->rel_filepos =  hdr->s_relptr;  return_section->reloc_count = hdr->s_nreloc;#ifdef I960  /* FIXME, use a temp var rather than alignment_power */  return_section->alignment_power = hdr->s_align;{  unsigned int    i;  for (i = 0; i < 32; i++) {      if ((1 << i) >= (int) (return_section->alignment_power)) {	  return_section->alignment_power = i;	  break;	}    }}#endifreturn_section->line_filepos =  hdr->s_lnnoptr;  /*    return_section->linesize =   hdr->s_nlnno * sizeof (struct lineno);    */  return_section->lineno_count = hdr->s_nlnno;  return_section->userdata = NULL;  return_section->next = (asection *) NULL;  return_section->flags = styp_to_sec_flags(hdr->s_flags);  return_section->target_index = target_index;  if (hdr->s_nreloc != 0)   return_section->flags |= SEC_RELOC;  /* FIXME: should this check 'hdr->s_size > 0' */  if (hdr->s_scnptr != 0)   return_section->flags |= SEC_HAS_CONTENTS;  return true;}static          booleanDEFUN(coff_mkobject,(abfd),      bfd            *abfd){ abfd->tdata.coff_obj_data = (struct coff_tdata *)bfd_zalloc (abfd,sizeof(coff_data_type));  if (abfd->tdata.coff_obj_data == 0){    bfd_error = no_memory;    return false;  }  coff_data(abfd)->relocbase = 0;/*  make_abs_section(abfd);*/  return true;}staticbfd_target     *DEFUN(coff_real_object_p,(abfd, nscns, internal_f, internal_a),    bfd            *abfd AND    unsigned        nscns AND  struct internal_filehdr *internal_f AND  struct internal_aouthdr *internal_a){  coff_data_type *coff;  enum bfd_architecture arch;  long machine;  size_t          readsize;	/* length of file_info */  SCNHDR *external_sections;  /* Build a play area */  if (coff_mkobject(abfd) != true)    return 0;  coff = coff_data(abfd);  external_sections = (SCNHDR *)bfd_alloc(abfd, readsize = (nscns * SCNHSZ));  if (bfd_read((PTR)external_sections, 1, readsize, abfd) != readsize) {    goto fail;  }  /* Now copy data as required; construct all asections etc */  coff->symbol_index_slew = 0;  coff->relocbase =0;  coff->raw_syment_count = 0;  coff->raw_linenos = 0;  coff->raw_syments = 0;  coff->sym_filepos =0;  coff->flags = internal_f->f_flags;  if (nscns != 0) {    unsigned int    i;    for (i = 0; i < nscns; i++) {      struct internal_scnhdr tmp;      coff_swap_scnhdr_in(abfd, external_sections + i, &tmp);      make_a_section_from_file(abfd,&tmp, i+1);    }  }/*  make_abs_section(abfd);*/    /* Determine the machine architecture and type.  */machine = 0;  switch (internal_f->f_magic) {#ifdef I386MAGIC  case I386MAGIC:    arch = bfd_arch_i386;    machine = 0;    break;#endif#ifdef A29K_MAGIC_BIG  case  A29K_MAGIC_BIG:  case  A29K_MAGIC_LITTLE:    arch = bfd_arch_a29k;    machine = 0;    break;#endif#ifdef MIPS  case  MIPS_MAGIC_1:  case  MIPS_MAGIC_2:  case  MIPS_MAGIC_3:    arch = bfd_arch_mips;    machine = 0;    break;#endif#ifdef MC68MAGIC  case MC68MAGIC:  case M68MAGIC:    arch = bfd_arch_m68k;    machine = 68020;    break;#endif#ifdef MC88MAGIC  case MC88MAGIC:  case MC88DMAGIC:  case MC88OMAGIC:    arch = bfd_arch_m88k;    machine = 88100;    break;#endif#ifdef Z8KMAGIC   case Z8KMAGIC:    arch = bfd_arch_z8k;    switch (internal_f->f_flags & F_MACHMASK) {     case F_Z8001:      machine = bfd_mach_z8001;      break;     case F_Z8002:      machine = bfd_mach_z8002;      break;     default:      goto fail;    }    break;#endif#ifdef I960#ifdef I960ROMAGIC  case I960ROMAGIC:  case I960RWMAGIC:    arch = bfd_arch_i960;    switch (F_I960TYPE & internal_f->f_flags)	{	default:	case F_I960CORE:	  machine = bfd_mach_i960_core;	  break;	case F_I960KB:	  machine = bfd_mach_i960_kb_sb;	  break;	case  F_I960MC:	  machine = bfd_mach_i960_mc;	  break;	case F_I960XA:	  machine = bfd_mach_i960_xa;	  break;	case F_I960CA:	  machine = bfd_mach_i960_ca;	  break;	case F_I960KA:	  machine = bfd_mach_i960_ka_sa;	  break;	}    break;#endif#endif#ifdef U802ROMAGIC  case U802ROMAGIC:  case U802WRMAGIC:  case U802TOCMAGIC:    arch = bfd_arch_rs6000;    machine = 6000;    break;#endif#ifdef WE32KMAGIC  case WE32KMAGIC:    arch = bfd_arch_we32k;    machine = 0;    break;#endif#ifdef H8300MAGIC  case H8300MAGIC:    arch = bfd_arch_h8300;    machine = 0;    break;#endif  default:			/* Unreadable input file type */ arch = bfd_arch_obscure;    break;  }  bfd_default_set_arch_mach(abfd, arch, machine);  if (!(internal_f->f_flags & F_RELFLG))    abfd->flags |= HAS_RELOC;  if ((internal_f->f_flags & F_EXEC))    abfd->flags |= EXEC_P;  if (!(internal_f->f_flags & F_LNNO))    abfd->flags |= HAS_LINENO;  if (!(internal_f->f_flags & F_LSYMS))    abfd->flags |= HAS_LOCALS;  bfd_get_symcount(abfd) = internal_f->f_nsyms;  if (internal_f->f_nsyms)    abfd->flags |= HAS_SYMS;  coff->sym_filepos = internal_f->f_symptr;  /* These members communicate important constants about the symbol table    to GDB's symbol-reading code.  These `constants' unfortunately vary      from coff implementation to implementation...  */#ifndef NO_COFF_SYMBOLS  coff->local_n_btmask = N_BTMASK;  coff->local_n_btshft = N_BTSHFT;  coff->local_n_tmask  = N_TMASK;  coff->local_n_tshift = N_TSHIFT;  coff->local_symesz   = SYMESZ;  coff->local_auxesz   = AUXESZ;  coff->local_linesz   = LINESZ;#endif  coff->symbols = (coff_symbol_type *) NULL;  bfd_get_start_address(abfd) = internal_f->f_opthdr ? internal_a->entry : 0;  return abfd->xvec; fail:  bfd_release(abfd, coff);  return (bfd_target *)NULL;}static bfd_target *DEFUN(coff_object_p,(abfd),      bfd            *abfd){  int   nscns;  FILHDR filehdr;  AOUTHDR opthdr;  struct internal_filehdr internal_f;  struct internal_aouthdr internal_a;  bfd_error = system_call_error;  /* figure out how much to read */  if (bfd_read((PTR) &filehdr, 1, FILHSZ, abfd) != FILHSZ)    return 0;  bfd_swap_filehdr_in(abfd, &filehdr, &internal_f);  if (BADMAG(internal_f)) {    bfd_error = wrong_format;    return 0;  }  nscns =internal_f.f_nscns;  if (internal_f.f_opthdr) {    if (bfd_read((PTR) &opthdr, 1,AOUTSZ, abfd) != AOUTSZ) {      return 0;    }    bfd_swap_aouthdr_in(abfd, (char *)&opthdr, (char *)&internal_a);  }  /* Seek past the opt hdr stuff */  bfd_seek(abfd, (file_ptr) (internal_f.f_opthdr + FILHSZ), SEEK_SET);  /* if the optional header is NULL or not the correct size then     quit; the only difference I can see between m88k dgux headers (MC88DMAGIC)     and Intel 960 readwrite headers (I960WRMAGIC) is that the     optional header is of a different size.     But the mips keeps extra stuff in it's opthdr, so dont check     when doing that     */#if defined(M88) || defined(I960)  if (internal_f.f_opthdr != 0 && AOUTSZ != internal_f.f_opthdr)    return (bfd_target *)NULL;#endif  return coff_real_object_p(abfd, nscns, &internal_f, &internal_a);}#ifndef NO_COFF_LINENOSstatic voidDEFUN(coff_count_linenumbers,(abfd),      bfd            *abfd){  unsigned int    limit = bfd_get_symcount(abfd);  unsigned int    i;  asymbol       **p;    {      asection       *s = abfd->sections->output_section;      while (s) {	BFD_ASSERT(s->lineno_count == 0);	s = s->next;      }    }  for (p = abfd->outsymbols, i = 0; i < limit; i++, p++) {    asymbol        *q_maybe = *p;    if (q_maybe->the_bfd->xvec->flavour == bfd_target_coff_flavour) {      coff_symbol_type *q = coffsymbol(q_maybe);      if (q->lineno) {	/*	  This symbol has a linenumber, increment the owning	  section's linenumber count	  */	alent          *l = q->lineno;	q->symbol.section->output_section->lineno_count++;	l++;	while (l->line_number) {	  q->symbol.section->output_section->lineno_count++;	  l++;	}      }    }  }}#endif /* NO_COFF_LINENOS */#ifndef NO_COFF_SYMBOLS/*  Takes a bfd and a symbol, returns a pointer to the coff specific area  of the symbol if there is one.  */static coff_symbol_type *DEFUN(coff_symbol_from,(ignore_abfd, symbol),      bfd            *ignore_abfd AND      asymbol        *symbol){  if (symbol->the_bfd->xvec->flavour != bfd_target_coff_flavour)    return (coff_symbol_type *)NULL;  if (symbol->the_bfd->tdata.coff_obj_data == (coff_data_type*)NULL)    return (coff_symbol_type *)NULL;  return  (coff_symbol_type *) symbol;}static voidDEFUN(fixup_symbol_value,(coff_symbol_ptr, syment),coff_symbol_type *coff_symbol_ptr ANDstruct internal_syment *syment){  /* Normalize the symbol flags */  if (coff_symbol_ptr->symbol.section == &bfd_com_section) {    /* a common symbol is undefined with a value */    syment->n_scnum = N_UNDEF;

⌨️ 快捷键说明

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