elf32-v850.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,145 行 · 第 1/5 页
C
2,145 行
return true;}static booleanv850_elf_gc_sweep_hook (abfd, info, sec, relocs) bfd *abfd ATTRIBUTE_UNUSED; struct bfd_link_info *info ATTRIBUTE_UNUSED; asection *sec ATTRIBUTE_UNUSED; const Elf_Internal_Rela *relocs ATTRIBUTE_UNUSED;{ /* No got and plt entries for v850-elf */ return true;}static asection *v850_elf_gc_mark_hook (abfd, info, rel, h, sym) bfd *abfd; struct bfd_link_info *info ATTRIBUTE_UNUSED; Elf_Internal_Rela *rel; struct elf_link_hash_entry *h; Elf_Internal_Sym *sym;{ if (h != NULL) { switch (ELF32_R_TYPE (rel->r_info)) { case R_V850_GNU_VTINHERIT: case R_V850_GNU_VTENTRY: break; default: switch (h->root.type) { case bfd_link_hash_defined: case bfd_link_hash_defweak: return h->root.u.def.section; case bfd_link_hash_common: return h->root.u.c.p->section; default: break; } } } else { if (!(elf_bad_symtab (abfd) && ELF_ST_BIND (sym->st_info) != STB_LOCAL) && ! ((sym->st_shndx <= 0 || sym->st_shndx >= SHN_LORESERVE) && sym->st_shndx != SHN_COMMON)) { return bfd_section_from_elf_index (abfd, sym->st_shndx); } } return NULL;}/* Set the right machine number. */static booleanv850_elf_object_p (abfd) bfd *abfd;{ switch (elf_elfheader (abfd)->e_flags & EF_V850_ARCH) { default: case E_V850_ARCH: (void) bfd_default_set_arch_mach (abfd, bfd_arch_v850, 0); break; case E_V850E_ARCH: (void) bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850e); break; case E_V850EA_ARCH: (void) bfd_default_set_arch_mach (abfd, bfd_arch_v850, bfd_mach_v850ea); break; } return true;}/* Store the machine number in the flags field. */static voidv850_elf_final_write_processing (abfd, linker) bfd * abfd; boolean linker ATTRIBUTE_UNUSED;{ unsigned long val; switch (bfd_get_mach (abfd)) { default: case 0: val = E_V850_ARCH; break; case bfd_mach_v850e: val = E_V850E_ARCH; break; case bfd_mach_v850ea: val = E_V850EA_ARCH; break; } elf_elfheader (abfd)->e_flags &=~ EF_V850_ARCH; elf_elfheader (abfd)->e_flags |= val;}/* Function to keep V850 specific file flags. */static booleanv850_elf_set_private_flags (abfd, flags) bfd * abfd; flagword flags;{ BFD_ASSERT (!elf_flags_init (abfd) || elf_elfheader (abfd)->e_flags == flags); elf_elfheader (abfd)->e_flags = flags; elf_flags_init (abfd) = true; return true;}/* Copy backend specific data from one object module to another */static booleanv850_elf_copy_private_bfd_data (ibfd, obfd) bfd * ibfd; bfd * obfd;{ if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour || bfd_get_flavour (obfd) != bfd_target_elf_flavour) return true; BFD_ASSERT (!elf_flags_init (obfd) || (elf_elfheader (obfd)->e_flags == elf_elfheader (ibfd)->e_flags)); elf_gp (obfd) = elf_gp (ibfd); elf_elfheader (obfd)->e_flags = elf_elfheader (ibfd)->e_flags; elf_flags_init (obfd) = true; return true;}/* Merge backend specific data from an object file to the output object file when linking. */static booleanv850_elf_merge_private_bfd_data (ibfd, obfd) bfd * ibfd; bfd * obfd;{ flagword out_flags; flagword in_flags; if ( bfd_get_flavour (ibfd) != bfd_target_elf_flavour || bfd_get_flavour (obfd) != bfd_target_elf_flavour) return true; in_flags = elf_elfheader (ibfd)->e_flags; out_flags = elf_elfheader (obfd)->e_flags; if (! elf_flags_init (obfd)) { /* If the input is the default architecture then do not bother setting the flags for the output architecture, instead allow future merges to do this. If no future merges ever set these flags then they will retain their unitialised values, which surprise surprise, correspond to the default values. */ if (bfd_get_arch_info (ibfd)->the_default) return true; elf_flags_init (obfd) = true; elf_elfheader (obfd)->e_flags = in_flags; if (bfd_get_arch (obfd) == bfd_get_arch (ibfd) && bfd_get_arch_info (obfd)->the_default) { return bfd_set_arch_mach (obfd, bfd_get_arch (ibfd), bfd_get_mach (ibfd)); } return true; } /* Check flag compatibility. */ if (in_flags == out_flags) return true; if ((in_flags & EF_V850_ARCH) != (out_flags & EF_V850_ARCH) && (in_flags & EF_V850_ARCH) != E_V850_ARCH) _bfd_error_handler (_("%s: Architecture mismatch with previous modules"), bfd_get_filename (ibfd)); return true;}/* Display the flags field */static booleanv850_elf_print_private_bfd_data (abfd, ptr) bfd * abfd; PTR ptr;{ FILE * file = (FILE *) ptr; BFD_ASSERT (abfd != NULL && ptr != NULL); _bfd_elf_print_private_bfd_data (abfd, ptr); /* xgettext:c-format */ fprintf (file, _("private flags = %lx: "), elf_elfheader (abfd)->e_flags); switch (elf_elfheader (abfd)->e_flags & EF_V850_ARCH) { default: case E_V850_ARCH: fprintf (file, _("v850 architecture")); break; case E_V850E_ARCH: fprintf (file, _("v850e architecture")); break; case E_V850EA_ARCH: fprintf (file, _("v850ea architecture")); break; } fputc ('\n', file); return true;}/* V850 ELF uses four common sections. One is the usual one, and the others are for (small) objects in one of the special data areas: small, tiny and zero. All the objects are kept together, and then referenced via the gp register, the ep register or the r0 register respectively, which yields smaller, faster assembler code. This approach is copied from elf32-mips.c. */static asection v850_elf_scom_section;static asymbol v850_elf_scom_symbol;static asymbol * v850_elf_scom_symbol_ptr;static asection v850_elf_tcom_section;static asymbol v850_elf_tcom_symbol;static asymbol * v850_elf_tcom_symbol_ptr;static asection v850_elf_zcom_section;static asymbol v850_elf_zcom_symbol;static asymbol * v850_elf_zcom_symbol_ptr;/* Given a BFD section, try to locate the corresponding ELF section index. */static booleanv850_elf_section_from_bfd_section (abfd, hdr, sec, retval) bfd * abfd ATTRIBUTE_UNUSED; Elf32_Internal_Shdr * hdr ATTRIBUTE_UNUSED; asection * sec; int * retval;{ if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0) *retval = SHN_V850_SCOMMON; else if (strcmp (bfd_get_section_name (abfd, sec), ".tcommon") == 0) *retval = SHN_V850_TCOMMON; else if (strcmp (bfd_get_section_name (abfd, sec), ".zcommon") == 0) *retval = SHN_V850_ZCOMMON; else return false; return true;}/* Handle the special V850 section numbers that a symbol may use. */static voidv850_elf_symbol_processing (abfd, asym) bfd * abfd; asymbol * asym;{ elf_symbol_type * elfsym = (elf_symbol_type *) asym; unsigned short index; index = elfsym->internal_elf_sym.st_shndx; /* If the section index is an "ordinary" index, then it may refer to a v850 specific section created by the assembler. Check the section's type and change the index it matches. FIXME: Should we alter the st_shndx field as well ? */ if (index < elf_elfheader(abfd)[0].e_shnum) switch (elf_elfsections(abfd)[index]->sh_type) { case SHT_V850_SCOMMON: index = SHN_V850_SCOMMON; break; case SHT_V850_TCOMMON: index = SHN_V850_TCOMMON; break; case SHT_V850_ZCOMMON: index = SHN_V850_ZCOMMON; break; default: break; } switch (index) { case SHN_V850_SCOMMON: if (v850_elf_scom_section.name == NULL) { /* Initialize the small common section. */ v850_elf_scom_section.name = ".scommon"; v850_elf_scom_section.flags = SEC_IS_COMMON | SEC_ALLOC | SEC_DATA; v850_elf_scom_section.output_section = & v850_elf_scom_section; v850_elf_scom_section.symbol = & v850_elf_scom_symbol; v850_elf_scom_section.symbol_ptr_ptr = & v850_elf_scom_symbol_ptr; v850_elf_scom_symbol.name = ".scommon"; v850_elf_scom_symbol.flags = BSF_SECTION_SYM; v850_elf_scom_symbol.section = & v850_elf_scom_section; v850_elf_scom_symbol_ptr = & v850_elf_scom_symbol; } asym->section = & v850_elf_scom_section; asym->value = elfsym->internal_elf_sym.st_size; break; case SHN_V850_TCOMMON: if (v850_elf_tcom_section.name == NULL) { /* Initialize the tcommon section. */ v850_elf_tcom_section.name = ".tcommon"; v850_elf_tcom_section.flags = SEC_IS_COMMON; v850_elf_tcom_section.output_section = & v850_elf_tcom_section; v850_elf_tcom_section.symbol = & v850_elf_tcom_symbol; v850_elf_tcom_section.symbol_ptr_ptr = & v850_elf_tcom_symbol_ptr; v850_elf_tcom_symbol.name = ".tcommon"; v850_elf_tcom_symbol.flags = BSF_SECTION_SYM; v850_elf_tcom_symbol.section = & v850_elf_tcom_section; v850_elf_tcom_symbol_ptr = & v850_elf_tcom_symbol; } asym->section = & v850_elf_tcom_section; asym->value = elfsym->internal_elf_sym.st_size; break; case SHN_V850_ZCOMMON: if (v850_elf_zcom_section.name == NULL) { /* Initialize the zcommon section. */ v850_elf_zcom_section.name = ".zcommon"; v850_elf_zcom_section.flags = SEC_IS_COMMON; v850_elf_zcom_section.output_section = & v850_elf_zcom_section; v850_elf_zcom_section.symbol = & v850_elf_zcom_symbol; v850_elf_zcom_section.symbol_ptr_ptr = & v850_elf_zcom_symbol_ptr; v850_elf_zcom_symbol.name = ".zcommon"; v850_elf_zcom_symbol.flags = BSF_SECTION_SYM; v850_elf_zcom_symbol.section = & v850_elf_zcom_section; v850_elf_zcom_symbol_ptr = & v850_elf_zcom_symbol; } asym->section = & v850_elf_zcom_section; asym->value = elfsym->internal_elf_sym.st_size; break; }}/* Hook called by the linker routine which adds symbols from an object file. We must handle the special v850 section numbers here. */static booleanv850_elf_add_symbol_hook (abfd, info, sym, namep, flagsp, secp, valp) bfd * abfd; struct bfd_link_info * info ATTRIBUTE_UNUSED; const Elf_Internal_Sym * sym; const char ** namep ATTRIBUTE_UNUSED; flagword * flagsp ATTRIBUTE_UNUSED; asection ** secp; bfd_vma * valp;{ int index = sym->st_shndx; /* If the section index is an "ordinary" index, then it may refer to a v850 specific section created by the assembler. Check the section's type and change the index it matches. FIXME: Should we alter the st_shndx field as well ? */ if (index < elf_elfheader(abfd)[0].e_shnum) switch (elf_elfsections(abfd)[index]->sh_type) { case SHT_V850_SCOMMON: index = SHN_V850_SCOMMON; break; case SHT_V850_TCOMMON: index = SHN_V850_TCOMMON; break; case SHT_V850_ZCOMMON: index = SHN_V850_ZCOMMON; break; default: break; } switch (index) { case SHN_V850_SCOMMON: *secp = bfd_make_section_old_way (abfd, ".scommon"); (*secp)->flags |= SEC_IS_COMMON; *valp = sym->st_size; break; case SHN_V850_TCOMMON: *secp = bfd_make_section_old_way (abfd, ".tcommon"); (*secp)->flags |= SEC_IS_COMMON; *valp = sym->st_size; break; case SHN_V850_ZCOMMON: *secp = bfd_make_section_old_way (abfd, ".zcommon"); (*secp)->flags |= SEC_IS_COMMON; *valp = sym->st_size; break; } return true;}/*ARGSIGNORED*/static booleanv850_elf_link_output_symbol_hook (abfd, info, name, sym, input_sec) bfd * abfd ATTRIBUTE_UNUSED; struct bfd_link_info * info ATTRIBUTE_UNUSED; const char * name ATTRIBUTE_UNUSED; Elf_Internal_Sym * sym; asection * input_sec;{ /* If we see a common symbol, which implies a relocatable link, then if a symbol was in a special common section in an input file, mark it as a special common in the output file. */ if (sym->st_shndx == SHN_COMMON) { if (strcmp (input_sec->name, ".scommon") == 0) sym->st_shndx = SHN_V850_SCOMMON; else if (strcmp (input_sec->name, ".tcommon") == 0) sym->st_shndx = SHN_V850_TCOMMON; else if (strcmp (input_sec->name, ".zcommon") == 0) sym->st_shndx = SHN_V850_ZCOMMON; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?