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

📄 obj-elf.c

📁 基于4个mips核的noc设计
💻 C
📖 第 1 页 / 共 4 页
字号:
/* ELF object file format   Copyright 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000   Free Software Foundation, Inc.   This file is part of GAS, the GNU Assembler.   GAS is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as   published by the Free Software Foundation; either version 2,   or (at your option) any later version.   GAS is distributed in the hope that it will be useful, but   WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See   the GNU General Public License for more details.   You should have received a copy of the GNU General Public License   along with GAS; see the file COPYING.  If not, write to the Free   Software Foundation, 59 Temple Place - Suite 330, Boston, MA   02111-1307, USA.  */#define OBJ_HEADER "obj-elf.h"#include "as.h"#include "subsegs.h"#include "obstack.h"#ifndef ECOFF_DEBUGGING#define ECOFF_DEBUGGING 0#else#define NEED_ECOFF_DEBUG#endif#ifdef NEED_ECOFF_DEBUG#include "ecoff.h"#endif#ifdef TC_ALPHA#include "elf/alpha.h"#endif#ifdef TC_MIPS#include "elf/mips.h"#endif#ifdef TC_PPC#include "elf/ppc.h"#endif#ifdef TC_I370#include "elf/i370.h"#endifstatic bfd_vma elf_s_get_size PARAMS ((symbolS *));static void elf_s_set_size PARAMS ((symbolS *, bfd_vma));static bfd_vma elf_s_get_align PARAMS ((symbolS *));static void elf_s_set_align PARAMS ((symbolS *, bfd_vma));static void elf_s_set_other PARAMS ((symbolS *, int));static void elf_copy_symbol_attributes PARAMS ((symbolS *, symbolS *));static int elf_sec_sym_ok_for_reloc PARAMS ((asection *));static void adjust_stab_sections PARAMS ((bfd *, asection *, PTR));static int elf_separate_stab_sections PARAMS ((void));static void elf_init_stab_section PARAMS ((segT));#ifdef NEED_ECOFF_DEBUGstatic boolean elf_get_extr PARAMS ((asymbol *, EXTR *));static void elf_set_index PARAMS ((asymbol *, bfd_size_type));#endifstatic void obj_elf_line PARAMS ((int));void obj_elf_version PARAMS ((int));static void obj_elf_size PARAMS ((int));static void obj_elf_type PARAMS ((int));static void obj_elf_ident PARAMS ((int));static void obj_elf_weak PARAMS ((int));static void obj_elf_local PARAMS ((int));static void obj_elf_visibility PARAMS ((int));static void obj_elf_symver PARAMS ((int));static void obj_elf_subsection PARAMS ((int));static void obj_elf_popsection PARAMS ((int));static const pseudo_typeS elf_pseudo_table[] ={  {"comm", obj_elf_common, 0},  {"common", obj_elf_common, 1},  {"ident", obj_elf_ident, 0},  {"local", obj_elf_local, 0},  {"previous", obj_elf_previous, 0},  {"section", obj_elf_section, 0},  {"section.s", obj_elf_section, 0},  {"sect", obj_elf_section, 0},  {"sect.s", obj_elf_section, 0},  {"pushsection", obj_elf_section, 1},  {"popsection", obj_elf_popsection, 0},  {"size", obj_elf_size, 0},  {"type", obj_elf_type, 0},  {"version", obj_elf_version, 0},  {"weak", obj_elf_weak, 0},  /* These define symbol visibility.  */  {"internal", obj_elf_visibility, STV_INTERNAL},  {"hidden", obj_elf_visibility, STV_HIDDEN},  {"protected", obj_elf_visibility, STV_PROTECTED},  /* These are used for stabs-in-elf configurations.  */  {"line", obj_elf_line, 0},  /* This is a GNU extension to handle symbol versions.  */  {"symver", obj_elf_symver, 0},  /* A GNU extension to change subsection only.  */  {"subsection", obj_elf_subsection, 0},  /* These are GNU extensions to aid in garbage collecting C++ vtables.  */  {"vtable_inherit", (void (*) PARAMS ((int))) &obj_elf_vtable_inherit, 0},  {"vtable_entry", (void (*) PARAMS ((int))) &obj_elf_vtable_entry, 0},  /* These are used for dwarf.  */  {"2byte", cons, 2},  {"4byte", cons, 4},  {"8byte", cons, 8},  /* We need to trap the section changing calls to handle .previous.  */  {"data", obj_elf_data, 0},  {"text", obj_elf_text, 0},  /* End sentinel.  */  {NULL, NULL, 0},};static const pseudo_typeS ecoff_debug_pseudo_table[] ={#ifdef NEED_ECOFF_DEBUG  /* COFF style debugging information for ECOFF. .ln is not used; .loc     is used instead.  */  { "def",	ecoff_directive_def,	0 },  { "dim",	ecoff_directive_dim,	0 },  { "endef",	ecoff_directive_endef,	0 },  { "file",	ecoff_directive_file,	0 },  { "scl",	ecoff_directive_scl,	0 },  { "tag",	ecoff_directive_tag,	0 },  { "val",	ecoff_directive_val,	0 },  /* COFF debugging requires pseudo-ops .size and .type, but ELF     already has meanings for those.  We use .esize and .etype     instead.  These are only generated by gcc anyhow.  */  { "esize",	ecoff_directive_size,	0 },  { "etype",	ecoff_directive_type,	0 },  /* ECOFF specific debugging information.  */  { "begin",	ecoff_directive_begin,	0 },  { "bend",	ecoff_directive_bend,	0 },  { "end",	ecoff_directive_end,	0 },  { "ent",	ecoff_directive_ent,	0 },  { "fmask",	ecoff_directive_fmask,	0 },  { "frame",	ecoff_directive_frame,	0 },  { "loc",	ecoff_directive_loc,	0 },  { "mask",	ecoff_directive_mask,	0 },  /* Other ECOFF directives.  */  { "extern",	ecoff_directive_extern,	0 },  /* These are used on Irix.  I don't know how to implement them.  */  { "alias",	s_ignore,		0 },  { "bgnb",	s_ignore,		0 },  { "endb",	s_ignore,		0 },  { "lab",	s_ignore,		0 },  { "noalias",	s_ignore,		0 },  { "verstamp",	s_ignore,		0 },  { "vreg",	s_ignore,		0 },#endif  {NULL, NULL, 0}			/* end sentinel */};#undef NO_RELOC#include "aout/aout64.h"/* This is called when the assembler starts.  */voidelf_begin (){  /* Add symbols for the known sections to the symbol table.  */  symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,								TEXT_SECTION_NAME)));  symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,								DATA_SECTION_NAME)));  symbol_table_insert (section_symbol (bfd_get_section_by_name (stdoutput,								BSS_SECTION_NAME)));}voidelf_pop_insert (){  pop_insert (elf_pseudo_table);  if (ECOFF_DEBUGGING)    pop_insert (ecoff_debug_pseudo_table);}static bfd_vmaelf_s_get_size (sym)     symbolS *sym;{  return S_GET_SIZE (sym);}static voidelf_s_set_size (sym, sz)     symbolS *sym;     bfd_vma sz;{  S_SET_SIZE (sym, sz);}static bfd_vmaelf_s_get_align (sym)     symbolS *sym;{  return S_GET_ALIGN (sym);}static voidelf_s_set_align (sym, align)     symbolS *sym;     bfd_vma align;{  S_SET_ALIGN (sym, align);}intelf_s_get_other (sym)     symbolS *sym;{  return elf_symbol (symbol_get_bfdsym (sym))->internal_elf_sym.st_other;}static voidelf_s_set_other (sym, other)     symbolS *sym;     int other;{  S_SET_OTHER (sym, other);}static voidelf_copy_symbol_attributes (dest, src)     symbolS *dest, *src;{  OBJ_COPY_SYMBOL_ATTRIBUTES (dest, src);}static intelf_sec_sym_ok_for_reloc (sec)     asection *sec;{  return obj_sec_sym_ok_for_reloc (sec);}voidelf_file_symbol (s)     const char *s;{  symbolS *sym;  sym = symbol_new (s, absolute_section, (valueT) 0, (struct frag *) 0);  symbol_set_frag (sym, &zero_address_frag);  symbol_get_bfdsym (sym)->flags |= BSF_FILE;  if (symbol_rootP != sym)    {      symbol_remove (sym, &symbol_rootP, &symbol_lastP);      symbol_insert (sym, symbol_rootP, &symbol_rootP, &symbol_lastP);#ifdef DEBUG      verify_symbol_chain (symbol_rootP, symbol_lastP);#endif    }#ifdef NEED_ECOFF_DEBUG  ecoff_new_file (s);#endif}voidobj_elf_common (is_common)     int is_common;{  char *name;  char c;  char *p;  int temp, size;  symbolS *symbolP;  int have_align;  if (flag_mri && is_common)    {      s_mri_common (0);      return;    }  name = input_line_pointer;  c = get_symbol_end ();  /* just after name is now '\0' */  p = input_line_pointer;  *p = c;  SKIP_WHITESPACE ();  if (*input_line_pointer != ',')    {      as_bad (_("Expected comma after symbol-name"));      ignore_rest_of_line ();      return;    }  input_line_pointer++;		/* skip ',' */  if ((temp = get_absolute_expression ()) < 0)    {      as_bad (_(".COMMon length (%d.) <0! Ignored."), temp);      ignore_rest_of_line ();      return;    }  size = temp;  *p = 0;  symbolP = symbol_find_or_make (name);  *p = c;  if (S_IS_DEFINED (symbolP) && ! S_IS_COMMON (symbolP))    {      as_bad (_("Ignoring attempt to re-define symbol"));      ignore_rest_of_line ();      return;    }  if (S_GET_VALUE (symbolP) != 0)    {      if (S_GET_VALUE (symbolP) != (valueT) size)	{	  as_warn (_("Length of .comm \"%s\" is already %ld. Not changed to %d."),		   S_GET_NAME (symbolP), (long) S_GET_VALUE (symbolP), size);	}    }  know (symbolP->sy_frag == &zero_address_frag);  if (*input_line_pointer != ',')    have_align = 0;  else    {      have_align = 1;      input_line_pointer++;      SKIP_WHITESPACE ();    }  if (! have_align || *input_line_pointer != '"')    {      if (! have_align)	temp = 0;      else	{	  temp = get_absolute_expression ();	  if (temp < 0)	    {	      temp = 0;	      as_warn (_("Common alignment negative; 0 assumed"));	    }	}      if (symbol_get_obj (symbolP)->local)	{	  segT old_sec;	  int old_subsec;	  char *pfrag;	  int align;	/* allocate_bss: */	  old_sec = now_seg;	  old_subsec = now_subseg;	  if (temp)	    {	      /* convert to a power of 2 alignment */	      for (align = 0; (temp & 1) == 0; temp >>= 1, ++align);	      if (temp != 1)		{		  as_bad (_("Common alignment not a power of 2"));		  ignore_rest_of_line ();		  return;		}	    }	  else	    align = 0;	  record_alignment (bss_section, align);	  subseg_set (bss_section, 0);	  if (align)	    frag_align (align, 0, 0);	  if (S_GET_SEGMENT (symbolP) == bss_section)	    symbol_get_frag (symbolP)->fr_symbol = 0;	  symbol_set_frag (symbolP, frag_now);	  pfrag = frag_var (rs_org, 1, 1, (relax_substateT) 0, symbolP,			    (offsetT) size, (char *) 0);	  *pfrag = 0;	  S_SET_SIZE (symbolP, size);	  S_SET_SEGMENT (symbolP, bss_section);	  S_CLEAR_EXTERNAL (symbolP);	  subseg_set (old_sec, old_subsec);	}      else	{	allocate_common:	  S_SET_VALUE (symbolP, (valueT) size);	  S_SET_ALIGN (symbolP, temp);	  S_SET_EXTERNAL (symbolP);	  S_SET_SEGMENT (symbolP, bfd_com_section_ptr);	}    }  else    {      input_line_pointer++;      /* @@ Some use the dot, some don't.  Can we get some consistency??  */      if (*input_line_pointer == '.')	input_line_pointer++;      /* @@ Some say data, some say bss.  */      if (strncmp (input_line_pointer, "bss\"", 4)	  && strncmp (input_line_pointer, "data\"", 5))	{	  while (*--input_line_pointer != '"')	    ;	  input_line_pointer--;	  goto bad_common_segment;	}      while (*input_line_pointer++ != '"')	;      goto allocate_common;    }  symbol_get_bfdsym (symbolP)->flags |= BSF_OBJECT;  demand_empty_rest_of_line ();  return;  {  bad_common_segment:    p = input_line_pointer;    while (*p && *p != '\n')      p++;    c = *p;    *p = '\0';    as_bad (_("bad .common segment %s"), input_line_pointer + 1);    *p = c;    input_line_pointer = p;    ignore_rest_of_line ();    return;  }}static voidobj_elf_local (ignore)     int ignore ATTRIBUTE_UNUSED;{  char *name;  int c;  symbolS *symbolP;  do    {      name = input_line_pointer;      c = get_symbol_end ();      symbolP = symbol_find_or_make (name);      *input_line_pointer = c;      SKIP_WHITESPACE ();      S_CLEAR_EXTERNAL (symbolP);      symbol_get_obj (symbolP)->local = 1;      if (c == ',')	{	  input_line_pointer++;	  SKIP_WHITESPACE ();	  if (*input_line_pointer == '\n')	    c = '\n';	}    }  while (c == ',');  demand_empty_rest_of_line ();}static voidobj_elf_weak (ignore)     int ignore ATTRIBUTE_UNUSED;{  char *name;  int c;  symbolS *symbolP;  do    {      name = input_line_pointer;      c = get_symbol_end ();      symbolP = symbol_find_or_make (name);      *input_line_pointer = c;      SKIP_WHITESPACE ();      S_SET_WEAK (symbolP);      symbol_get_obj (symbolP)->local = 1;      if (c == ',')	{	  input_line_pointer++;	  SKIP_WHITESPACE ();	  if (*input_line_pointer == '\n')	    c = '\n';	}    }  while (c == ',');  demand_empty_rest_of_line ();}static voidobj_elf_visibility (visibility)     int visibility;{  char *name;  int c;  symbolS *symbolP;  asymbol *bfdsym;  elf_symbol_type *elfsym;

⌨️ 快捷键说明

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