coff-mcore.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 585 行 · 第 1/2 页
C
585 行
{ switch (code) { HOW2MAP (BFD_RELOC_32, IMAGE_REL_MCORE_ADDR32); HOW2MAP (BFD_RELOC_MCORE_PCREL_IMM8BY4, IMAGE_REL_MCORE_PCREL_IMM8BY4); HOW2MAP (BFD_RELOC_MCORE_PCREL_IMM11BY2, IMAGE_REL_MCORE_PCREL_IMM11BY2); HOW2MAP (BFD_RELOC_MCORE_PCREL_IMM4BY2, IMAGE_REL_MCORE_PCREL_IMM4BY2); HOW2MAP (BFD_RELOC_32_PCREL, IMAGE_REL_MCORE_PCREL_32); HOW2MAP (BFD_RELOC_MCORE_PCREL_JSR_IMM11BY2, IMAGE_REL_MCORE_PCREL_JSR_IMM11BY2); HOW2MAP (BFD_RELOC_RVA, IMAGE_REL_MCORE_RVA); default: return NULL; } /*NOTREACHED*/}#undef HOW2MAP#define RTYPE2HOWTO(cache_ptr, dst) \ (cache_ptr)->howto = mcore_coff_howto_table + (dst)->r_type;static reloc_howto_type *coff_mcore_rtype_to_howto (abfd, sec, rel, h, sym, addendp) bfd * abfd ATTRIBUTE_UNUSED; asection * sec; struct internal_reloc * rel; struct coff_link_hash_entry * h ATTRIBUTE_UNUSED; struct internal_syment * sym; bfd_vma * addendp;{ reloc_howto_type * howto; if (rel->r_type >= NUM_ELEM (mcore_coff_howto_table)) return NULL; howto = mcore_coff_howto_table + rel->r_type; if (rel->r_type == IMAGE_REL_MCORE_RVA) * addendp -= pe_data (sec->output_section->owner)->pe_opthdr.ImageBase; else if (howto->pc_relative) { * addendp = sec->vma - 2; /* XXX guess - is this right ? */ /* If the symbol is defined, then the generic code is going to add back the symbol value in order to cancel out an adjustment it made to the addend. However, we set the addend to 0 at the start of this function. We need to adjust here, to avoid the adjustment the generic code will make. FIXME: This is getting a bit hackish. */ if (sym != NULL && sym->n_scnum != 0) * addendp -= sym->n_value; } else * addendp = 0; return howto;}/* Return true if this relocation should appear in the output .reloc section. This function is referenced in pe_mkobject in peicode.h. */static booleanin_reloc_p (abfd, howto) bfd * abfd ATTRIBUTE_UNUSED; reloc_howto_type * howto;{ return ! howto->pc_relative && howto->type != IMAGE_REL_MCORE_RVA;}/* The reloc processing routine for the optimized COFF linker. */static booleancoff_mcore_relocate_section (output_bfd, info, input_bfd, input_section, contents, relocs, syms, sections) bfd * output_bfd; struct bfd_link_info * info; bfd * input_bfd; asection * input_section; bfd_byte * contents; struct internal_reloc * relocs; struct internal_syment * syms; asection ** sections;{ struct internal_reloc * rel; struct internal_reloc * relend; boolean hihalf; bfd_vma hihalf_val; /* If we are performing a relocateable link, we don't need to do a thing. The caller will take care of adjusting the reloc addresses and symbol indices. */ if (info->relocateable) return true; /* Check if we have the same endianess */ if ( input_bfd->xvec->byteorder != output_bfd->xvec->byteorder && output_bfd->xvec->byteorder != BFD_ENDIAN_UNKNOWN) { (*_bfd_error_handler) (_("%s: compiled for a %s endian system and target is %s endian.\n"), bfd_get_filename (input_bfd), bfd_big_endian (input_bfd) ? "big" : "little", bfd_big_endian (output_bfd) ? "big" : "little"); bfd_set_error (bfd_error_wrong_format); return false; } hihalf = false; hihalf_val = 0; rel = relocs; relend = rel + input_section->reloc_count; for (; rel < relend; rel++) { long symndx; struct internal_syment * sym; bfd_vma val; bfd_vma addend; bfd_reloc_status_type rstat; bfd_byte * loc; unsigned short r_type = rel->r_type; reloc_howto_type * howto = NULL; struct coff_link_hash_entry * h; const char * my_name; symndx = rel->r_symndx; loc = contents + rel->r_vaddr - input_section->vma; if (symndx == -1) { h = NULL; sym = NULL; } else { h = obj_coff_sym_hashes (input_bfd)[symndx]; sym = syms + symndx; } addend = 0; /* Get the howto and initialise the addend. */ howto = bfd_coff_rtype_to_howto (input_bfd, input_section, rel, h, sym, & addend); if (howto == NULL) return false; val = 0; if (h == NULL) { if (symndx == -1) my_name = "*ABS*"; else { asection * sec = sections[symndx]; val = (sym->n_value + sec->output_section->vma + sec->output_offset); if (sym == NULL) my_name = "*unknown*"; else if ( sym->_n._n_n._n_zeroes == 0 && sym->_n._n_n._n_offset != 0) my_name = obj_coff_strings (input_bfd) + sym->_n._n_n._n_offset; else { static char buf [SYMNMLEN + 1]; strncpy (buf, sym->_n._n_name, SYMNMLEN); buf[SYMNMLEN] = '\0'; my_name = buf; } } } else { if ( h->root.type == bfd_link_hash_defined || h->root.type == bfd_link_hash_defweak) { asection * sec = h->root.u.def.section; val = (h->root.u.def.value + sec->output_section->vma + sec->output_offset); } else { if (! ((*info->callbacks->undefined_symbol) (info, h->root.root.string, input_bfd, input_section, rel->r_vaddr - input_section->vma, true))) return false; } my_name = h->root.root.string; } rstat = bfd_reloc_ok; /* Each case must do its own relocation, setting rstat appropriately. */ switch (r_type) { default: _bfd_error_handler (_("%s: unsupported relocation type 0x%02x"), bfd_get_filename (input_bfd), r_type); bfd_set_error (bfd_error_bad_value); return false; case IMAGE_REL_MCORE_ABSOLUTE: fprintf (stderr, _("Warning: unsupported reloc %s <file %s, section %s>\n"), howto->name, bfd_get_filename (input_bfd), input_section->name); fprintf (stderr,"sym %ld (%s), r_vaddr %ld (%lx)\n", rel->r_symndx, my_name, (long) rel->r_vaddr, (unsigned long) rel->r_vaddr); break; case IMAGE_REL_MCORE_PCREL_IMM8BY4: case IMAGE_REL_MCORE_PCREL_IMM11BY2: case IMAGE_REL_MCORE_PCREL_IMM4BY2: case IMAGE_REL_MCORE_PCREL_32: case IMAGE_REL_MCORE_PCREL_JSR_IMM11BY2: case IMAGE_REL_MCORE_ADDR32: /* XXX fixme - shouldn't this be like the code for the RVA reloc ? */ rstat = _bfd_relocate_contents (howto, input_bfd, val, loc); break; case IMAGE_REL_MCORE_RVA: rstat = _bfd_final_link_relocate (howto, input_bfd, input_section, contents, rel->r_vaddr - input_section->vma, val, addend); break; } if (info->base_file) { /* Emit a reloc if the backend thinks it needs it. */ if (sym && pe_data (output_bfd)->in_reloc_p (output_bfd, howto)) mcore_emit_base_file_entry (info, output_bfd, input_section, rel->r_vaddr); } switch (rstat) { default: abort (); case bfd_reloc_ok: break; case bfd_reloc_overflow: if (! ((*info->callbacks->reloc_overflow) (info, my_name, howto->name, (bfd_vma) 0, input_bfd, input_section, rel->r_vaddr - input_section->vma))) return false; } } return true;}/* Tailor coffcode.h -- macro heaven. *//* We use the special COFF backend linker, with our own special touch. */#define coff_bfd_reloc_type_lookup mcore_coff_reloc_type_lookup#define coff_relocate_section coff_mcore_relocate_section#define coff_rtype_to_howto coff_mcore_rtype_to_howto#define SELECT_RELOC(internal, howto) {internal.r_type = howto->type;}#define COFF_PAGE_SIZE 0x1000#include "coffcode.h"/* Forward declaration to initialise alterbative_target field. */extern const bfd_target TARGET_LITTLE_SYM;/* The transfer vectors that lead the outside world to all of the above. */CREATE_BIG_COFF_TARGET_VEC (TARGET_BIG_SYM, TARGET_BIG_NAME, D_PAGED, (SEC_CODE | SEC_DATA | SEC_DEBUGGING | SEC_READONLY | SEC_LINK_ONCE | SEC_LINK_DUPLICATES), 0, & TARGET_LITTLE_SYM)CREATE_LITTLE_COFF_TARGET_VEC (TARGET_LITTLE_SYM, TARGET_LITTLE_NAME, D_PAGED, (SEC_CODE | SEC_DATA | SEC_DEBUGGING | SEC_READONLY | SEC_LINK_ONCE | SEC_LINK_DUPLICATES), 0, & TARGET_BIG_SYM)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?