coff-sh.c

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

C
2,052
字号
/* BFD back-end for Hitachi Super-H COFF binaries.   Copyright 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000   Free Software Foundation, Inc.   Contributed by Cygnus Support.   Written by Steve Chamberlain, <sac@cygnus.com>.   Relaxing code written by Ian Lance Taylor, <ian@cygnus.com>.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, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */#include "bfd.h"#include "sysdep.h"#include "libbfd.h"#include "bfdlink.h"#include "coff/sh.h"#include "coff/internal.h"#ifdef COFF_WITH_PE#include "coff/pe.h"#ifndef COFF_IMAGE_WITH_PEstatic boolean sh_align_load_span  PARAMS ((bfd *, asection *, bfd_byte *,	   boolean (*) (bfd *, asection *, PTR, bfd_byte *, bfd_vma),	   PTR, bfd_vma **, bfd_vma *, bfd_vma, bfd_vma, boolean *));#define _bfd_sh_align_load_span sh_align_load_span#endif#endif#include "libcoff.h"/* Internal functions.  */static bfd_reloc_status_type sh_reloc  PARAMS ((bfd *, arelent *, asymbol *, PTR, asection *, bfd *, char **));static long get_symbol_value PARAMS ((asymbol *));static boolean sh_relax_section  PARAMS ((bfd *, asection *, struct bfd_link_info *, boolean *));static boolean sh_relax_delete_bytes  PARAMS ((bfd *, asection *, bfd_vma, int));#ifndef COFF_IMAGE_WITH_PEstatic const struct sh_opcode *sh_insn_info PARAMS ((unsigned int));#endifstatic boolean sh_align_loads  PARAMS ((bfd *, asection *, struct internal_reloc *, bfd_byte *, boolean *));static boolean sh_swap_insns  PARAMS ((bfd *, asection *, PTR, bfd_byte *, bfd_vma));static boolean sh_relocate_section  PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *,	   struct internal_reloc *, struct internal_syment *, asection **));static bfd_byte *sh_coff_get_relocated_section_contents  PARAMS ((bfd *, struct bfd_link_info *, struct bfd_link_order *,	   bfd_byte *, boolean, asymbol **));#ifdef COFF_WITH_PE/* Can't build import tables with 2**4 alignment.  */#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER	2#else/* Default section alignment to 2**4.  */#define COFF_DEFAULT_SECTION_ALIGNMENT_POWER	4#endif#ifdef COFF_IMAGE_WITH_PE/* Align PE executables.  */#define COFF_PAGE_SIZE 0x1000#endif/* Generate long file names.  */#define COFF_LONG_FILENAMES#ifdef COFF_WITH_PE/* Return true if this relocation should   appear in the output .reloc section.  */static boolean in_reloc_p (abfd, howto)     bfd * abfd ATTRIBUTE_UNUSED;     reloc_howto_type * howto;{  return ! howto->pc_relative && howto->type != R_SH_IMAGEBASE;}#endif/* The supported relocations.  There are a lot of relocations defined   in coff/internal.h which we do not expect to ever see.  */static reloc_howto_type sh_coff_howtos[] ={  EMPTY_HOWTO (0),  EMPTY_HOWTO (1),#ifdef COFF_WITH_PE  /* Windows CE */  HOWTO (R_SH_IMM32CE,		/* type */	 0,			/* rightshift */	 2,			/* size (0 = byte, 1 = short, 2 = long) */	 32,			/* bitsize */	 false,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 sh_reloc,		/* special_function */	 "r_imm32ce",		/* name */	 true,			/* partial_inplace */	 0xffffffff,		/* src_mask */	 0xffffffff,		/* dst_mask */	 false),		/* pcrel_offset */#else  EMPTY_HOWTO (2),#endif  EMPTY_HOWTO (3), /* R_SH_PCREL8 */  EMPTY_HOWTO (4), /* R_SH_PCREL16 */  EMPTY_HOWTO (5), /* R_SH_HIGH8 */  EMPTY_HOWTO (6), /* R_SH_IMM24 */  EMPTY_HOWTO (7), /* R_SH_LOW16 */  EMPTY_HOWTO (8),  EMPTY_HOWTO (9), /* R_SH_PCDISP8BY4 */  HOWTO (R_SH_PCDISP8BY2,	/* type */	 1,			/* rightshift */	 1,			/* size (0 = byte, 1 = short, 2 = long) */	 8,			/* bitsize */	 true,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_signed, /* complain_on_overflow */	 sh_reloc,		/* special_function */	 "r_pcdisp8by2",	/* name */	 true,			/* partial_inplace */	 0xff,			/* src_mask */	 0xff,			/* dst_mask */	 true),			/* pcrel_offset */  EMPTY_HOWTO (11), /* R_SH_PCDISP8 */  HOWTO (R_SH_PCDISP,		/* type */	 1,			/* rightshift */	 1,			/* size (0 = byte, 1 = short, 2 = long) */	 12,			/* bitsize */	 true,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_signed, /* complain_on_overflow */	 sh_reloc,		/* special_function */	 "r_pcdisp12by2",	/* name */	 true,			/* partial_inplace */	 0xfff,			/* src_mask */	 0xfff,			/* dst_mask */	 true),			/* pcrel_offset */  EMPTY_HOWTO (13),  HOWTO (R_SH_IMM32,		/* type */	 0,			/* rightshift */	 2,			/* size (0 = byte, 1 = short, 2 = long) */	 32,			/* bitsize */	 false,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 sh_reloc,		/* special_function */	 "r_imm32",		/* name */	 true,			/* partial_inplace */	 0xffffffff,		/* src_mask */	 0xffffffff,		/* dst_mask */	 false),		/* pcrel_offset */  EMPTY_HOWTO (15),#ifdef COFF_WITH_PE  HOWTO (R_SH_IMAGEBASE,        /* type */	 0,	                /* rightshift */	 2,	                /* size (0 = byte, 1 = short, 2 = long) */	 32,	                /* bitsize */	 false,	                /* pc_relative */	 0,	                /* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 sh_reloc,       	/* special_function */	 "rva32",	        /* name */	 true,	                /* partial_inplace */	 0xffffffff,            /* src_mask */	 0xffffffff,            /* dst_mask */	 false),                /* pcrel_offset */#else  EMPTY_HOWTO (16), /* R_SH_IMM8 */#endif  EMPTY_HOWTO (17), /* R_SH_IMM8BY2 */  EMPTY_HOWTO (18), /* R_SH_IMM8BY4 */  EMPTY_HOWTO (19), /* R_SH_IMM4 */  EMPTY_HOWTO (20), /* R_SH_IMM4BY2 */  EMPTY_HOWTO (21), /* R_SH_IMM4BY4 */  HOWTO (R_SH_PCRELIMM8BY2,	/* type */	 1,			/* rightshift */	 1,			/* size (0 = byte, 1 = short, 2 = long) */	 8,			/* bitsize */	 true,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_unsigned, /* complain_on_overflow */	 sh_reloc,		/* special_function */	 "r_pcrelimm8by2",	/* name */	 true,			/* partial_inplace */	 0xff,			/* src_mask */	 0xff,			/* dst_mask */	 true),			/* pcrel_offset */  HOWTO (R_SH_PCRELIMM8BY4,	/* type */	 2,			/* rightshift */	 1,			/* size (0 = byte, 1 = short, 2 = long) */	 8,			/* bitsize */	 true,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_unsigned, /* complain_on_overflow */	 sh_reloc,		/* special_function */	 "r_pcrelimm8by4",	/* name */	 true,			/* partial_inplace */	 0xff,			/* src_mask */	 0xff,			/* dst_mask */	 true),			/* pcrel_offset */  HOWTO (R_SH_IMM16,		/* type */	 0,			/* rightshift */	 1,			/* size (0 = byte, 1 = short, 2 = long) */	 16,			/* bitsize */	 false,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 sh_reloc,		/* special_function */	 "r_imm16",		/* name */	 true,			/* partial_inplace */	 0xffff,		/* src_mask */	 0xffff,		/* dst_mask */	 false),		/* pcrel_offset */  HOWTO (R_SH_SWITCH16,		/* type */	 0,			/* rightshift */	 1,			/* size (0 = byte, 1 = short, 2 = long) */	 16,			/* bitsize */	 false,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 sh_reloc,		/* special_function */	 "r_switch16",		/* name */	 true,			/* partial_inplace */	 0xffff,		/* src_mask */	 0xffff,		/* dst_mask */	 false),		/* pcrel_offset */  HOWTO (R_SH_SWITCH32,		/* type */	 0,			/* rightshift */	 2,			/* size (0 = byte, 1 = short, 2 = long) */	 32,			/* bitsize */	 false,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 sh_reloc,		/* special_function */	 "r_switch32",		/* name */	 true,			/* partial_inplace */	 0xffffffff,		/* src_mask */	 0xffffffff,		/* dst_mask */	 false),		/* pcrel_offset */  HOWTO (R_SH_USES,		/* type */	 0,			/* rightshift */	 1,			/* size (0 = byte, 1 = short, 2 = long) */	 16,			/* bitsize */	 false,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 sh_reloc,		/* special_function */	 "r_uses",		/* name */	 true,			/* partial_inplace */	 0xffff,		/* src_mask */	 0xffff,		/* dst_mask */	 false),		/* pcrel_offset */  HOWTO (R_SH_COUNT,		/* type */	 0,			/* rightshift */	 2,			/* size (0 = byte, 1 = short, 2 = long) */	 32,			/* bitsize */	 false,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 sh_reloc,		/* special_function */	 "r_count",		/* name */	 true,			/* partial_inplace */	 0xffffffff,		/* src_mask */	 0xffffffff,		/* dst_mask */	 false),		/* pcrel_offset */  HOWTO (R_SH_ALIGN,		/* type */	 0,			/* rightshift */	 2,			/* size (0 = byte, 1 = short, 2 = long) */	 32,			/* bitsize */	 false,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 sh_reloc,		/* special_function */	 "r_align",		/* name */	 true,			/* partial_inplace */	 0xffffffff,		/* src_mask */	 0xffffffff,		/* dst_mask */	 false),		/* pcrel_offset */  HOWTO (R_SH_CODE,		/* type */	 0,			/* rightshift */	 2,			/* size (0 = byte, 1 = short, 2 = long) */	 32,			/* bitsize */	 false,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 sh_reloc,		/* special_function */	 "r_code",		/* name */	 true,			/* partial_inplace */	 0xffffffff,		/* src_mask */	 0xffffffff,		/* dst_mask */	 false),		/* pcrel_offset */  HOWTO (R_SH_DATA,		/* type */	 0,			/* rightshift */	 2,			/* size (0 = byte, 1 = short, 2 = long) */	 32,			/* bitsize */	 false,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 sh_reloc,		/* special_function */	 "r_data",		/* name */	 true,			/* partial_inplace */	 0xffffffff,		/* src_mask */	 0xffffffff,		/* dst_mask */	 false),		/* pcrel_offset */  HOWTO (R_SH_LABEL,		/* type */	 0,			/* rightshift */	 2,			/* size (0 = byte, 1 = short, 2 = long) */	 32,			/* bitsize */	 false,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 sh_reloc,		/* special_function */	 "r_label",		/* name */	 true,			/* partial_inplace */	 0xffffffff,		/* src_mask */	 0xffffffff,		/* dst_mask */	 false),		/* pcrel_offset */  HOWTO (R_SH_SWITCH8,		/* type */	 0,			/* rightshift */	 0,			/* size (0 = byte, 1 = short, 2 = long) */	 8,			/* bitsize */	 false,			/* pc_relative */	 0,			/* bitpos */	 complain_overflow_bitfield, /* complain_on_overflow */	 sh_reloc,		/* special_function */	 "r_switch8",		/* name */	 true,			/* partial_inplace */	 0xff,			/* src_mask */	 0xff,			/* dst_mask */	 false)			/* pcrel_offset */};#define SH_COFF_HOWTO_COUNT (sizeof sh_coff_howtos / sizeof sh_coff_howtos[0])/* Check for a bad magic number.  */#define BADMAG(x) SHBADMAG(x)/* Customize coffcode.h (this is not currently used).  */#define SH 1/* FIXME: This should not be set here.  */#define __A_MAGIC_SET__#ifndef COFF_WITH_PE/* Swap the r_offset field in and out.  */#define SWAP_IN_RELOC_OFFSET  bfd_h_get_32#define SWAP_OUT_RELOC_OFFSET bfd_h_put_32/* Swap out extra information in the reloc structure.  */#define SWAP_OUT_RELOC_EXTRA(abfd, src, dst)	\  do						\    {						\      dst->r_stuff[0] = 'S';			\      dst->r_stuff[1] = 'C';			\    }						\  while (0)#endif/* Get the value of a symbol, when performing a relocation.  */static longget_symbol_value (symbol)     asymbol *symbol;{  bfd_vma relocation;  if (bfd_is_com_section (symbol->section))    relocation = 0;  else    relocation = (symbol->value +		  symbol->section->output_section->vma +		  symbol->section->output_offset);  return relocation;}#ifdef COFF_WITH_PE/* Convert an rtype to howto for the COFF backend linker.

⌨️ 快捷键说明

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