coff-mcore.c

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

C
585
字号
/* BFD back-end for Motorola MCore COFF/PE   Copyright 1999, 2000, 2001 Free Software Foundation, Inc.This file is part of BFD, the Binary File Descriptor library.This program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or(at your option) any later version.This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, 59 Temple Place - Suite 330,Boston, MA 02111-1307, USA.  */#include "bfd.h"#include "sysdep.h"#include "libbfd.h"#include "coff/mcore.h"#include "coff/internal.h"#include "coff/pe.h"#include "libcoff.h"#ifdef BADMAG#undef BADMAG#endif#define BADMAG(x) MCOREBADMAG(x)#ifndef NUM_ELEM#define NUM_ELEM(A) (sizeof (A) / sizeof (A)[0])#endif/* This file is compiled more than once, but we only compile the   final_link routine once.  */extern boolean mcore_bfd_coff_final_link  PARAMS ((bfd *, struct bfd_link_info *));static struct bfd_link_hash_table * coff_mcore_link_hash_table_create  PARAMS ((bfd *));static bfd_reloc_status_type        mcore_coff_unsupported_reloc  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));static boolean                      coff_mcore_relocate_section  PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,	   struct internal_reloc *, struct internal_syment *, asection **));static reloc_howto_type *           mcore_coff_reloc_type_lookup  PARAMS ((bfd *, bfd_reloc_code_real_type));static reloc_howto_type *           coff_mcore_rtype_to_howto  PARAMS ((bfd *, asection *, struct internal_reloc *,	   struct coff_link_hash_entry *, struct internal_syment *, bfd_vma *));/* The NT loader points the toc register to &toc + 32768, in order to   use the complete range of a 16-bit displacement. We have to adjust   for this when we fix up loads displaced off the toc reg.  */#define TOC_LOAD_ADJUSTMENT (-32768)#define TOC_SECTION_NAME ".private.toc"/* The main body of code is in coffcode.h.  */#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER 2/* In case we're on a 32-bit machine, construct a 64-bit "-1" value   from smaller values.  Start with zero, widen, *then* decrement.  */#define MINUS_ONE	(((bfd_vma)0) - 1)static reloc_howto_type mcore_coff_howto_table[] ={  /* Unused: */  HOWTO (IMAGE_REL_MCORE_ABSOLUTE,/* type */	 0,	                 /* rightshift */	 0,	                 /* size (0 = byte, 1 = short, 2 = long) */	 0,	                 /* bitsize */	 false,	                 /* pc_relative */	 0,	                 /* bitpos */	 complain_overflow_dont, /* dont complain_on_overflow */	 NULL,		         /* special_function */	 "ABSOLUTE",             /* name */	 false,	                 /* partial_inplace */	 0x00,	 	         /* src_mask */	 0x00,        		 /* dst_mask */	 false),                 /* pcrel_offset */  HOWTO (IMAGE_REL_MCORE_ADDR32,/* type */	 0,	                /* rightshift */	 2,	                /* size (0 = byte, 1 = short, 2 = long) */	 32,	                /* bitsize */	 false,	                /* pc_relative */	 0,	                /* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 NULL,		        /* special_function */	 "ADDR32",              /* name */	 true,	                /* partial_inplace */	 0xffffffff,            /* src_mask */	 0xffffffff,            /* dst_mask */	 false),                /* pcrel_offset */  /* 8 bits + 2 zero bits; jmpi/jsri/lrw instructions.     Should not appear in object files.  */  HOWTO (IMAGE_REL_MCORE_PCREL_IMM8BY4,	/* type */	 2,			/* rightshift */	 1,			/* size (0 = byte, 1 = short, 2 = long) */	 8,			/* bitsize */	 true,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 mcore_coff_unsupported_reloc, /* special_function */	 "IMM8BY4",             /* name */	 false,			/* partial_inplace */	 0,			/* src_mask */	 0,			/* dst_mask */	 true),			/* pcrel_offset */  /* bsr/bt/bf/br instructions; 11 bits + 1 zero bit     Span 2k instructions == 4k bytes.     Only useful pieces at the relocated address are the opcode (5 bits) */  HOWTO (IMAGE_REL_MCORE_PCREL_IMM11BY2,/* type */	 1,			/* rightshift */	 1,			/* size (0 = byte, 1 = short, 2 = long) */	 11,			/* bitsize */	 true,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_signed, /* complain_on_overflow */	 NULL,	                /* special_function */	 "IMM11BY2",            /* name */	 false,			/* partial_inplace */	 0x0,			/* src_mask */	 0x7ff,			/* dst_mask */	 true),			/* pcrel_offset */  /* 4 bits + 1 zero bit; 'loopt' instruction only; unsupported.  */  HOWTO (IMAGE_REL_MCORE_PCREL_IMM4BY2,	/* type */	 1,			/* rightshift */	 1,			/* size (0 = byte, 1 = short, 2 = long) */	 4,			/* bitsize */	 true,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 mcore_coff_unsupported_reloc, /* special_function */	 "IMM4BY2",              /* name */	 false,			/* partial_inplace */	 0,			/* src_mask */	 0,			/* dst_mask */	 true),			/* pcrel_offset */  /* 32-bit pc-relative. Eventually this will help support PIC code.  */  HOWTO (IMAGE_REL_MCORE_PCREL_32,/* type */	 0,			/* rightshift */	 2,			/* size (0 = byte, 1 = short, 2 = long) */	 32,			/* bitsize */	 true,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 NULL,	                /* special_function */	 "PCREL_32",	        /* name */	 false,			/* partial_inplace */	 0x0,			/* src_mask */	 0xffffffff,		/* dst_mask */	 true),			/* pcrel_offset */  /* Like PCREL_IMM11BY2, this relocation indicates that there is a     'jsri' at the specified address. There is a separate relocation     entry for the literal pool entry that it references, but we     might be able to change the jsri to a bsr if the target turns out     to be close enough [even though we won't reclaim the literal pool     entry, we'll get some runtime efficiency back]. Note that this     is a relocation that we are allowed to safely ignore.  */  HOWTO (IMAGE_REL_MCORE_PCREL_JSR_IMM11BY2,/* type */	 1,			/* rightshift */	 1,			/* size (0 = byte, 1 = short, 2 = long) */	 11,			/* bitsize */	 true,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_signed, /* complain_on_overflow */	 NULL,	                /* special_function */	 "JSR_IMM11BY2",        /* name */	 false,			/* partial_inplace */	 0x0,			/* src_mask */	 0x7ff,			/* dst_mask */	 true),			/* pcrel_offset */  HOWTO (IMAGE_REL_MCORE_RVA,   /* type */	 0,			/* rightshift */	 2,			/* size (0 = byte, 1 = short, 2 = long) */	 32,			/* bitsize */	 false,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_signed, /* complain_on_overflow */	 NULL,                  /* special_function */	 "MCORE_RVA",           /* name */	 true,			/* partial_inplace */	 0xffffffff,		/* src_mask */	 0xffffffff,		/* dst_mask */	 true)			/* pcrel_offset */};/* Extend the coff_link_hash_table structure with a few M*Core specific fields.   This allows us to store global data here without actually creating any   global variables, which is a no-no in the BFD world.  */typedef struct coff_mcore_link_hash_table{  /* The original coff_link_hash_table structure.  MUST be first field.  */  struct coff_link_hash_table	root;  bfd *                         bfd_of_toc_owner;  long int                      global_toc_size;  long int                      import_table_size;  long int                      first_thunk_address;  long int                      thunk_size;}mcore_hash_table;/* Get the MCore coff linker hash table from a link_info structure.  */#define coff_mcore_hash_table(info) \  ((mcore_hash_table *) ((info)->hash))/* Create an MCore coff linker hash table.  */static struct bfd_link_hash_table *coff_mcore_link_hash_table_create (abfd)     bfd * abfd;{  mcore_hash_table * ret;  ret = ((mcore_hash_table *) bfd_alloc (abfd, sizeof (* ret)));  if (ret == (mcore_hash_table *) NULL)    return NULL;  if (! _bfd_coff_link_hash_table_init      (& ret->root, abfd, _bfd_coff_link_hash_newfunc))    {      bfd_release (abfd, ret);      return (struct bfd_link_hash_table *) NULL;    }  ret->bfd_of_toc_owner = NULL;  ret->global_toc_size  = 0;  ret->import_table_size = 0;  ret->first_thunk_address = 0;  ret->thunk_size = 0;  return & ret->root.root;}/* Add an entry to the base file.  */static voidmcore_emit_base_file_entry (info, output_bfd, input_section, reloc_offset)      struct bfd_link_info * info;      bfd *                  output_bfd;      asection *             input_section;      bfd_vma                reloc_offset;{  bfd_vma addr = reloc_offset                 - input_section->vma                 + input_section->output_offset                 + input_section->output_section->vma;  if (coff_data (output_bfd)->pe)     addr -= pe_data (output_bfd)->pe_opthdr.ImageBase;  fwrite (&addr, 1, sizeof (addr), (FILE *) info->base_file);}static bfd_reloc_status_typemcore_coff_unsupported_reloc (abfd, reloc_entry, symbol, data, input_section,			   output_bfd, error_message)     bfd * abfd;     arelent * reloc_entry;     asymbol * symbol ATTRIBUTE_UNUSED;     PTR data ATTRIBUTE_UNUSED;     asection * input_section ATTRIBUTE_UNUSED;     bfd * output_bfd ATTRIBUTE_UNUSED;     char ** error_message ATTRIBUTE_UNUSED;{  BFD_ASSERT (reloc_entry->howto != (reloc_howto_type *)0);  _bfd_error_handler (_("%s: Relocation %s (%d) is not currently supported.\n"),		      bfd_get_filename (abfd),		      reloc_entry->howto->name,		      reloc_entry->howto->type);  return bfd_reloc_notsupported;}/* A cheesy little macro to make the code a little more readable.  */#define HOW2MAP(bfd_rtype, mcore_rtype)  \ case bfd_rtype: return & mcore_coff_howto_table [mcore_rtype]static reloc_howto_type *mcore_coff_reloc_type_lookup (abfd, code)     bfd * abfd ATTRIBUTE_UNUSED;     bfd_reloc_code_real_type code;

⌨️ 快捷键说明

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