coff-ppc.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,197 行 · 第 1/5 页
C
2,197 行
/* if TOCDEFN is on, ignore as someone else has allocated the toc entry */ if ( (r_flags & IMAGE_REL_PPC_TOCDEFN) != IMAGE_REL_PPC_TOCDEFN ) ok = ppc_record_toc_entry(abfd, info, sec, rel->r_symndx, default_toc); if (!ok) return false; break; case IMAGE_REL_PPC_IMGLUE: ppc_mark_symbol_as_glue(abfd, rel->r_symndx, rel); break; default: break; } } } return true;}#endifstatic bfd_reloc_status_typeppc_refhi_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd, error_message) bfd *abfd ATTRIBUTE_UNUSED; arelent *reloc_entry ATTRIBUTE_UNUSED; asymbol *symbol ATTRIBUTE_UNUSED; PTR data ATTRIBUTE_UNUSED; asection *input_section ATTRIBUTE_UNUSED; bfd *output_bfd; char **error_message ATTRIBUTE_UNUSED;{ UN_IMPL("REFHI"); DUMP_RELOC("REFHI",reloc_entry); if (output_bfd == (bfd *) NULL) return bfd_reloc_continue; return bfd_reloc_undefined;}#if 0static bfd_reloc_status_typeppc_reflo_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd, error_message) bfd *abfd; arelent *reloc_entry; asymbol *symbol; PTR data; asection *input_section; bfd *output_bfd; char **error_message;{ UN_IMPL("REFLO"); DUMP_RELOC("REFLO",reloc_entry); if (output_bfd == (bfd *) NULL) return bfd_reloc_continue; return bfd_reloc_undefined;}#endifstatic bfd_reloc_status_typeppc_pair_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd, error_message) bfd *abfd ATTRIBUTE_UNUSED; arelent *reloc_entry ATTRIBUTE_UNUSED; asymbol *symbol ATTRIBUTE_UNUSED; PTR data ATTRIBUTE_UNUSED; asection *input_section ATTRIBUTE_UNUSED; bfd *output_bfd; char **error_message ATTRIBUTE_UNUSED;{ UN_IMPL("PAIR"); DUMP_RELOC("PAIR",reloc_entry); if (output_bfd == (bfd *) NULL) return bfd_reloc_continue; return bfd_reloc_undefined;}static bfd_reloc_status_typeppc_toc16_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd, error_message) bfd *abfd ATTRIBUTE_UNUSED; arelent *reloc_entry ATTRIBUTE_UNUSED; asymbol *symbol ATTRIBUTE_UNUSED; PTR data ATTRIBUTE_UNUSED; asection *input_section ATTRIBUTE_UNUSED; bfd *output_bfd; char **error_message ATTRIBUTE_UNUSED;{ UN_IMPL("TOCREL16"); DUMP_RELOC("TOCREL16",reloc_entry); if (output_bfd == (bfd *) NULL) { return bfd_reloc_continue; } return bfd_reloc_ok;}#if 0/* ADDR32NB : 32 bit address relative to the virtual origin. *//* (On the alpha, this is always a linker generated thunk)*//* (i.e. 32bit addr relative to the image base) *//* *//* */static bfd_reloc_status_typeppc_addr32nb_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd, error_message) bfd *abfd; arelent *reloc_entry; asymbol *symbol; PTR data; asection *input_section; bfd *output_bfd; char **error_message;{ UN_IMPL("ADDR32NB"); DUMP_RELOC("ADDR32NB",reloc_entry); return bfd_reloc_ok;}#endifstatic bfd_reloc_status_typeppc_secrel_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd, error_message) bfd *abfd ATTRIBUTE_UNUSED; arelent *reloc_entry ATTRIBUTE_UNUSED; asymbol *symbol ATTRIBUTE_UNUSED; PTR data ATTRIBUTE_UNUSED; asection *input_section ATTRIBUTE_UNUSED; bfd *output_bfd; char **error_message ATTRIBUTE_UNUSED;{ UN_IMPL("SECREL"); DUMP_RELOC("SECREL",reloc_entry); if (output_bfd == (bfd *) NULL) return bfd_reloc_continue; return bfd_reloc_ok;}static bfd_reloc_status_typeppc_section_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd, error_message) bfd *abfd ATTRIBUTE_UNUSED; arelent *reloc_entry ATTRIBUTE_UNUSED; asymbol *symbol ATTRIBUTE_UNUSED; PTR data ATTRIBUTE_UNUSED; asection *input_section ATTRIBUTE_UNUSED; bfd *output_bfd; char **error_message ATTRIBUTE_UNUSED;{ UN_IMPL("SECTION"); DUMP_RELOC("SECTION",reloc_entry); if (output_bfd == (bfd *) NULL) return bfd_reloc_continue; return bfd_reloc_ok;}static bfd_reloc_status_typeppc_imglue_reloc (abfd, reloc_entry, symbol, data, input_section, output_bfd, error_message) bfd *abfd ATTRIBUTE_UNUSED; arelent *reloc_entry ATTRIBUTE_UNUSED; asymbol *symbol ATTRIBUTE_UNUSED; PTR data ATTRIBUTE_UNUSED; asection *input_section ATTRIBUTE_UNUSED; bfd *output_bfd; char **error_message ATTRIBUTE_UNUSED;{ UN_IMPL("IMGLUE"); DUMP_RELOC("IMGLUE",reloc_entry); if (output_bfd == (bfd *) NULL) return bfd_reloc_continue; return bfd_reloc_ok;}#define MAX_RELOC_INDEX \ (sizeof (ppc_coff_howto_table) / sizeof (ppc_coff_howto_table[0]) - 1)/* FIXME: There is a possiblity that when we read in a reloc from a file, that there are some bits encoded in the upper portion of the type field. Not yet implemented.*/static void ppc_coff_rtype2howto PARAMS ((arelent *relent, struct internal_reloc *internal));static voidppc_coff_rtype2howto (relent, internal) arelent *relent; struct internal_reloc *internal;{ /* We can encode one of three things in the type field, aside from the type: 1. IMAGE_REL_PPC_NEG - indicates the value field is a subtraction value, rather than an addition value 2. IMAGE_REL_PPC_BRTAKEN, IMAGE_REL_PPC_BRNTAKEN - indicates that the branch is expected to be taken or not. 3. IMAGE_REL_PPC_TOCDEFN - toc slot definition in the file For now, we just strip this stuff to find the type, and ignore it other than that. */ reloc_howto_type *howto; unsigned short r_type = EXTRACT_TYPE (internal->r_type); unsigned short r_flags = EXTRACT_FLAGS(internal->r_type); unsigned short junk = EXTRACT_JUNK (internal->r_type); /* the masking process only slices off the bottom byte for r_type. */ if ( r_type > MAX_RELOC_INDEX ) abort (); /* check for absolute crap */ if ( junk != 0 ) abort (); switch(r_type) { case IMAGE_REL_PPC_ADDR16: case IMAGE_REL_PPC_REL24: case IMAGE_REL_PPC_ADDR24: case IMAGE_REL_PPC_ADDR32: case IMAGE_REL_PPC_IFGLUE: case IMAGE_REL_PPC_ADDR32NB: case IMAGE_REL_PPC_SECTION: case IMAGE_REL_PPC_SECREL: DUMP_RELOC2(ppc_coff_howto_table[r_type].name, internal); howto = ppc_coff_howto_table + r_type; break; case IMAGE_REL_PPC_IMGLUE: DUMP_RELOC2(ppc_coff_howto_table[r_type].name, internal); howto = ppc_coff_howto_table + r_type; break; case IMAGE_REL_PPC_TOCREL16: DUMP_RELOC2(ppc_coff_howto_table[r_type].name, internal); if (r_flags & IMAGE_REL_PPC_TOCDEFN) howto = ppc_coff_howto_table + IMAGE_REL_PPC_TOCREL16_DEFN; else howto = ppc_coff_howto_table + IMAGE_REL_PPC_TOCREL16; break; default: fprintf (stderr, _("Warning: Unsupported reloc %s [%d] used -- it may not work.\n"), ppc_coff_howto_table[r_type].name, r_type); howto = ppc_coff_howto_table + r_type; break; } relent->howto = howto;}static reloc_howto_type *coff_ppc_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 ATTRIBUTE_UNUSED; bfd_vma *addendp;{ reloc_howto_type *howto; /* We can encode one of three things in the type field, aside from the type: 1. IMAGE_REL_PPC_NEG - indicates the value field is a subtraction value, rather than an addition value 2. IMAGE_REL_PPC_BRTAKEN, IMAGE_REL_PPC_BRNTAKEN - indicates that the branch is expected to be taken or not. 3. IMAGE_REL_PPC_TOCDEFN - toc slot definition in the file For now, we just strip this stuff to find the type, and ignore it other than that. */ unsigned short r_type = EXTRACT_TYPE (rel->r_type); unsigned short r_flags = EXTRACT_FLAGS(rel->r_type); unsigned short junk = EXTRACT_JUNK (rel->r_type); /* the masking process only slices off the bottom byte for r_type. */ if ( r_type > MAX_RELOC_INDEX ) abort (); /* check for absolute crap */ if ( junk != 0 ) abort (); switch(r_type) { case IMAGE_REL_PPC_ADDR32NB: DUMP_RELOC2(ppc_coff_howto_table[r_type].name, rel); *addendp -= pe_data(sec->output_section->owner)->pe_opthdr.ImageBase; howto = ppc_coff_howto_table + r_type; break; case IMAGE_REL_PPC_TOCREL16: DUMP_RELOC2(ppc_coff_howto_table[r_type].name, rel); if (r_flags & IMAGE_REL_PPC_TOCDEFN) howto = ppc_coff_howto_table + IMAGE_REL_PPC_TOCREL16_DEFN; else howto = ppc_coff_howto_table + IMAGE_REL_PPC_TOCREL16; break; case IMAGE_REL_PPC_ADDR16: case IMAGE_REL_PPC_REL24: case IMAGE_REL_PPC_ADDR24: case IMAGE_REL_PPC_ADDR32: case IMAGE_REL_PPC_IFGLUE: case IMAGE_REL_PPC_SECTION: case IMAGE_REL_PPC_SECREL: DUMP_RELOC2(ppc_coff_howto_table[r_type].name, rel); howto = ppc_coff_howto_table + r_type; break; case IMAGE_REL_PPC_IMGLUE: DUMP_RELOC2(ppc_coff_howto_table[r_type].name, rel); howto = ppc_coff_howto_table + r_type; break; default: fprintf (stderr, _("Warning: Unsupported reloc %s [%d] used -- it may not work.\n"), ppc_coff_howto_table[r_type].name, r_type); howto = ppc_coff_howto_table + r_type; break; } return howto;}/* a cheesy little macro to make the code a little more readable */#define HOW2MAP(bfd_rtype,ppc_rtype) \ case bfd_rtype: return &ppc_coff_howto_table[ppc_rtype]static reloc_howto_type *ppc_coff_reloc_type_lookupPARAMS ((bfd *, bfd_reloc_code_real_type));static reloc_howto_type *ppc_coff_reloc_type_lookup (abfd, code) bfd *abfd ATTRIBUTE_UNUSED; bfd_reloc_code_real_type code;{ switch (code) { HOW2MAP(BFD_RELOC_32_GOTOFF, IMAGE_REL_PPC_IMGLUE); HOW2MAP(BFD_RELOC_16_GOT_PCREL, IMAGE_REL_PPC_IFGLUE); HOW2MAP(BFD_RELOC_16, IMAGE_REL_PPC_ADDR16); HOW2MAP(BFD_RELOC_PPC_B26, IMAGE_REL_PPC_REL24); HOW2MAP(BFD_RELOC_PPC_BA26, IMAGE_REL_PPC_ADDR24); HOW2MAP(BFD_RELOC_PPC_TOC16, IMAGE_REL_PPC_TOCREL16); HOW2MAP(BFD_RELOC_16_GOTOFF, IMAGE_REL_PPC_TOCREL16_DEFN); HOW2MAP(BFD_RELOC_32, IMAGE_REL_PPC_ADDR32); HOW2MAP(BFD_RELOC_RVA, IMAGE_REL_PPC_ADDR32NB); default: return NULL; } /*NOTREACHED*/}#undef HOW2MAP/* Tailor coffcode.h -- macro heaven. */#define RTYPE2HOWTO(cache_ptr, dst) ppc_coff_rtype2howto (cache_ptr, dst)#ifndef COFF_IMAGE_WITH_PEstatic void ppc_coff_swap_sym_in_hook PARAMS ((bfd *, PTR, PTR));#endif/* We use the special COFF backend linker, with our own special touch. */#define coff_bfd_reloc_type_lookup ppc_coff_reloc_type_lookup#define coff_rtype_to_howto coff_ppc_rtype_to_howto#define coff_relocate_section coff_ppc_relocate_section#define coff_bfd_final_link ppc_bfd_coff_final_link#ifndef COFF_IMAGE_WITH_PE/* FIXME: This no longer works. */#define coff_swap_sym_in_hook ppc_coff_swap_sym_in_hook#endif#define SELECT_RELOC(internal, howto) {in
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?