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

📄 coffcode.h

📁 早期freebsd实现
💻 H
📖 第 1 页 / 共 5 页
字号:
    syment->n_value = coff_symbol_ptr->symbol.value;  }  else if (coff_symbol_ptr->symbol.flags & BSF_DEBUGGING) {    syment->n_value = coff_symbol_ptr->symbol.value;  }  else if (coff_symbol_ptr->symbol.section == & bfd_und_section) {    syment->n_scnum = N_UNDEF;    syment->n_value = 0;  }  else {    if (coff_symbol_ptr->symbol.section) {      syment->n_scnum	 =       coff_symbol_ptr->symbol.section->output_section->target_index;      syment->n_value =       coff_symbol_ptr->symbol.value +	coff_symbol_ptr->symbol.section->output_offset +	 coff_symbol_ptr->symbol.section->output_section->vma;    }    else {	BFD_ASSERT(0);      /* This can happen, but I don't know why yet (steve@cygnus.com) */      syment->n_scnum = N_ABS;      syment->n_value = coff_symbol_ptr->symbol.value;    }  }}/* run through all the symbols in the symbol table and work out what   their indexes into the symbol table will be when output Coff requires that each C_FILE symbol points to the next one in the chain, and that the last one points to the first external symbol. We do that here too.*/static voidDEFUN(coff_renumber_symbols,(bfd_ptr),      bfd *bfd_ptr){  unsigned int symbol_count = bfd_get_symcount(bfd_ptr);  asymbol **symbol_ptr_ptr = bfd_ptr->outsymbols;  unsigned int native_index = 0;  struct internal_syment *last_file = (struct internal_syment *)NULL;  unsigned int symbol_index;  /* COFF demands that undefined symbols come after all other symbols.     Since we don't need to impose this extra knowledge on all our client     programs, deal with that here.  Sort the symbol table; just move the     undefined symbols to the end, leaving the rest alone.  */  /* @@ Do we have some condition we could test for, so we don't always     have to do this?  I don't think relocatability is quite right, but     I'm not certain.  [raeburn:19920508.1711EST]  */  {    asymbol **newsyms;    int i;    newsyms = (asymbol **) bfd_alloc_by_size_t (bfd_ptr,						sizeof (asymbol *)						* (symbol_count + 1));    bfd_ptr->outsymbols = newsyms;    for (i = 0; i < symbol_count; i++)      if (symbol_ptr_ptr[i]->section != &bfd_und_section)	*newsyms++ = symbol_ptr_ptr[i];    for (i = 0; i < symbol_count; i++)      if (symbol_ptr_ptr[i]->section == &bfd_und_section)	*newsyms++ = symbol_ptr_ptr[i];    *newsyms = (asymbol *) NULL;    symbol_ptr_ptr = bfd_ptr->outsymbols;  }  for (symbol_index = 0; symbol_index < symbol_count; symbol_index++)      {	coff_symbol_type *coff_symbol_ptr = coff_symbol_from(bfd_ptr, symbol_ptr_ptr[symbol_index]);	if (coff_symbol_ptr && coff_symbol_ptr->native) {	  combined_entry_type *s = coff_symbol_ptr->native;	  int i;	  if (s->u.syment.n_sclass == C_FILE)	      {		if (last_file != (struct internal_syment *)NULL) {		  last_file->n_value = native_index;		}		last_file = &(s->u.syment);	      }	  else {	    /* Modify the symbol values according to their section and	       type */	    fixup_symbol_value(coff_symbol_ptr, &(s->u.syment));	  }	  for (i = 0; i < s->u.syment.n_numaux + 1; i++) {	    s[i].offset = native_index ++;	  }	}	else {	  native_index++;	}      }  obj_conv_table_size (bfd_ptr) = native_index;}/* Run thorough the symbol table again, and fix it so that all pointers to entries are changed to the entries' index in the output symbol table.*/static voidDEFUN(coff_mangle_symbols,(bfd_ptr),      bfd *bfd_ptr){  unsigned int symbol_count = bfd_get_symcount(bfd_ptr);  asymbol **symbol_ptr_ptr = bfd_ptr->outsymbols;  unsigned int symbol_index;  for (symbol_index = 0; symbol_index < symbol_count; symbol_index++)      {	coff_symbol_type *coff_symbol_ptr =	  coff_symbol_from(bfd_ptr, symbol_ptr_ptr[symbol_index]);	if (coff_symbol_ptr && coff_symbol_ptr->native) {	  int i;	  combined_entry_type *s = coff_symbol_ptr->native;	  for (i = 0; i < s->u.syment.n_numaux ; i++) {	    combined_entry_type *a = s + i + 1;	    if (a->fix_tag) {	      a->u.auxent.x_sym.x_tagndx.l =		a->u.auxent.x_sym.x_tagndx.p->offset;	      a->fix_tag = 0;	    }	    if (a->fix_end) {	      a->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.l =		a->u.auxent.x_sym.x_fcnary.x_fcn.x_endndx.p->offset;	      a->fix_end = 0;	      	    }	  }	}      }}static int string_size;static voidDEFUN(coff_fix_symbol_name,(ignore_abfd, symbol, native),  bfd *ignore_abfd AND  asymbol *symbol AND  combined_entry_type *native){  unsigned int    name_length;  union internal_auxent *auxent;  char *  name = ( char *)(symbol->name);  if (name == (char *) NULL) {    /* coff symbols always have names, so we'll make one up */    symbol->name = "strange";    name = (char *)symbol->name;  }  name_length = strlen(name);  if (native->u.syment.n_sclass == C_FILE) {    strncpy(native->u.syment._n._n_name, ".file", SYMNMLEN);    auxent = &(native+1)->u.auxent;#ifdef COFF_LONG_FILENAMES    if (name_length <= FILNMLEN) {      strncpy(auxent->x_file.x_fname, name, FILNMLEN);    }    else {      auxent->x_file.x_n.x_offset = string_size + 4;      auxent->x_file.x_n.x_zeroes = 0;      string_size += name_length + 1;    }#else    strncpy(auxent->x_file.x_fname, name, FILNMLEN);    if (name_length > FILNMLEN) {      name[FILNMLEN] = '\0';    }#endif  }  else      {				/* NOT A C_FILE SYMBOL */	if (name_length <= SYMNMLEN) {	  /* This name will fit into the symbol neatly */	  strncpy(native->u.syment._n._n_name, symbol->name, SYMNMLEN);	}	else {	  native->u.syment._n._n_n._n_offset =  string_size + 4;	  native->u.syment._n._n_n._n_zeroes = 0;	  string_size += name_length + 1;	}      }}static unsigned intDEFUN(coff_write_symbol,(abfd, symbol, native, written),bfd *abfd ANDasymbol *symbol ANDcombined_entry_type *native ANDunsigned int written){  unsigned int    numaux = native->u.syment.n_numaux;  int             type = native->u.syment.n_type;  int             class =  native->u.syment.n_sclass;  SYMENT buf;  unsigned int j;  /* @@ bfd_debug_section isn't accessible outside this file, but we know     that C_FILE symbols belong there.  So move them.  */  if (native->u.syment.n_sclass == C_FILE)    symbol->section = &bfd_debug_section;  if (symbol->section == &bfd_abs_section)   {    native->u.syment.n_scnum = N_ABS;  }  else if (symbol->section == &bfd_debug_section)   {    native->u.syment.n_scnum = N_DEBUG;  }  else if (symbol->section == &bfd_und_section)     {    native->u.syment.n_scnum = N_UNDEF;  }  else   {    native->u.syment.n_scnum =     symbol->section->output_section->target_index;  }      coff_fix_symbol_name(abfd, symbol, native);  coff_swap_sym_out(abfd, &native->u.syment, &buf);  bfd_write((PTR)& buf, 1, SYMESZ, abfd);  for (j = 0; j < native->u.syment.n_numaux;  j++)  {    AUXENT buf1;    memset((PTR)&buf, 0, AUXESZ);    coff_swap_aux_out(abfd,		      &( (native + j + 1)->u.auxent), type, class, &buf1);    bfd_write((PTR) (&buf1), 1, AUXESZ, abfd);  }  /*    Reuse somewhere in the symbol to keep the index    */  set_index(symbol, written);  return   written + 1 + numaux;}static unsigned intDEFUN(coff_write_alien_symbol,(abfd, symbol, written),      bfd *abfd AND      asymbol *symbol AND      unsigned int written){  /*    This symbol has been created by the loader, or come from a non    coff format. It  has no native element to inherit, make our    own    */  combined_entry_type *native;  combined_entry_type dummy;  native = &dummy;  native->u.syment.n_type =  T_NULL;#ifdef I960  native->u.syment.n_flags =  0;#endif  if (symbol->section == &bfd_und_section)   {      native->u.syment.n_scnum =  N_UNDEF;      native->u.syment.n_value =  symbol->value;    }  else if (symbol->section == &bfd_com_section)   {      native->u.syment.n_scnum =  N_UNDEF;      native->u.syment.n_value =  symbol->value;  }    else if (symbol->flags & BSF_DEBUGGING) {      /*	remove name so it doesn't take up any space	*/      symbol->name = "";    }  else {      native->u.syment.n_scnum  =   symbol->section->output_section->target_index;      native->u.syment.n_value =   symbol->value +       symbol->section->output_section->vma +	symbol->section->output_offset;#ifdef I960      /* Copy the any flags from the the file hdr into the symbol  */    {      coff_symbol_type *c = coff_symbol_from(abfd, symbol);      if (c != (coff_symbol_type *)NULL) {	  native->u.syment.n_flags =   c->symbol.the_bfd->flags;	}    }#endif    }#ifdef HASPAD1  native->u.syment.pad1[0] = 0;  native->u.syment.pad1[0] = 0;#endif  native->u.syment.n_type =  0;  if (symbol->flags & BSF_LOCAL)   native->u.syment.n_sclass =  C_STAT;  else   native->u.syment.n_sclass =  C_EXT;  native->u.syment.n_numaux =  0;  return   coff_write_symbol(abfd, symbol, native, written);}static unsigned intDEFUN(coff_write_native_symbol,(abfd, symbol,   written),bfd *abfd ANDcoff_symbol_type *symbol ANDunsigned int written){  /*    Does this symbol have an ascociated line number - if so then    make it remember this symbol index. Also tag the auxent of    this symbol to point to the right place in the lineno table    */  combined_entry_type *native = symbol->native;  alent          *lineno = symbol->lineno;  if (lineno && !symbol->done_lineno) {    unsigned int    count = 0;    lineno[count].u.offset = written;    if (native->u.syment.n_numaux) {      union internal_auxent  *a = &((native+1)->u.auxent);      a->x_sym.x_fcnary.x_fcn.x_lnnoptr =	symbol->symbol.section->output_section->moving_line_filepos;    }    /*      And count and relocate all other linenumbers      */    count++;    while (lineno[count].line_number) {#if 0/* 13 april 92. sac I've been told this, but still need proof:> The second bug is also in `bfd/coffcode.h'.  This bug causes the linker to screw> up the pc-relocations for all the line numbers in COFF code.  This bug isn't> only specific to A29K implementations, but affects all systems using COFF> format binaries.  Note that in COFF object files, the line number core offsets> output by the assembler are relative to the start of each procedure, not> to the start of the .text section.  This patch relocates the line numbers> relative to the `native->u.syment.n_value' instead of the section virtual> address.  modular!olson@cs.arizona.edu (Jon Olson)*/       lineno[count].u.offset += native->u.syment.n_value;#else      lineno[count].u.offset +=	symbol->symbol.section->output_section->vma +	  symbol->symbol.section->output_offset;#endif      count++;    }    symbol->done_lineno = true;        symbol->symbol.section->output_section->moving_line_filepos +=      count * LINESZ;  }  return coff_write_symbol(abfd, &( symbol->symbol), native,written);}static voidDEFUN(coff_write_symbols,(abfd),      bfd            *abfd){  unsigned int    i;  unsigned int    limit = bfd_get_symcount(abfd);  unsigned int    written = 0;  asymbol       **p;  string_size = 0;  /* Seek to the right place */  bfd_seek(abfd, obj_sym_filepos(abfd), SEEK_SET);  /* Output all the symbols we have */  written = 0;  for (p = abfd->outsymbols, i = 0; i < limit; i++, p++)      {	asymbol        *symbol = *p;	coff_symbol_type *c_symbol = coff_symbol_from(abfd, symbol);	if (c_symbol == (coff_symbol_type *) NULL ||	    c_symbol->native == (combined_entry_type *)NULL)	    {	      written = coff_write_alien_symbol(abfd, symbol, written);	    }	else	    {	      written = coff_write_native_symbol(abfd, c_symbol, written);	    }      }  bfd_get_symcount(abfd) = written;  /* Now write out strings */  if (string_size != 0)   {     unsigned int    size = string_size + 4;     bfd_byte buffer[4];     bfd_h_put_32(abfd, size, buffer);     bfd_write((PTR) buffer, 1, sizeof(buffer), abfd);     for (p = abfd->outsymbols, i = 0;	  i < limit;	  i++, p++)	 {	   asymbol        *q = *p;	   size_t          name_length = strlen(q->name);	   int maxlen;	   coff_symbol_type*	   c_symbol = coff_symbol_from(abfd, q);	   maxlen = ((c_symbol != NULL && c_symbol->native != NULL) &&		     (c_symbol->native->u.syment.n_sclass == C_FILE)) ?	     FILNMLEN : SYMNMLEN;	   if (name_length > maxlen) {

⌨️ 快捷键说明

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