pexxigen.c
来自「基于4个mips核的noc设计」· C语言 代码 · 共 2,044 行 · 第 1/5 页
C
2,044 行
} em_data = ((eh_handler & 0x1) << 2) | (prolog_end_addr & 0x3); eh_handler &= ~(bfd_vma) 0x3; prolog_end_addr &= ~(bfd_vma) 0x3; fputc (' ', file); fprintf_vma (file, i + section->vma); fputc ('\t', file); fprintf_vma (file, begin_addr); fputc (' ', file); fprintf_vma (file, end_addr); fputc (' ', file); fprintf_vma (file, eh_handler);#ifndef COFF_WITH_pep fputc (' ', file); fprintf_vma (file, eh_data); fputc (' ', file); fprintf_vma (file, prolog_end_addr); fprintf (file, " %x", em_data);#endif#ifdef POWERPC_LE_PE if (eh_handler == 0 && eh_data != 0) { /* Special bits here, although the meaning may be a little mysterious. The only one I know for sure is 0x03. */ /* Code Significance */ /* 0x00 None */ /* 0x01 Register Save Millicode */ /* 0x02 Register Restore Millicode */ /* 0x03 Glue Code Sequence */ switch (eh_data) { case 0x01: fprintf (file, _(" Register save millicode")); break; case 0x02: fprintf (file, _(" Register restore millicode")); break; case 0x03: fprintf (file, _(" Glue code sequence")); break; default: break; } }#endif fprintf (file, "\n"); } free (data); return true;}#define IMAGE_REL_BASED_HIGHADJ 4static const char * const tbl[] = { "ABSOLUTE", "HIGH", "LOW", "HIGHLOW", "HIGHADJ", "MIPS_JMPADDR", "SECTION", "REL32", "RESERVED1", "MIPS_JMPADDR16", "DIR64", "HIGH3ADJ" "UNKNOWN", /* MUST be last */};static booleanpe_print_reloc (abfd, vfile) bfd *abfd; PTR vfile;{ FILE *file = (FILE *) vfile; bfd_byte *data = 0; asection *section = bfd_get_section_by_name (abfd, ".reloc"); bfd_size_type datasize = 0; bfd_size_type i; bfd_size_type start, stop; if (section == NULL) return true; if (bfd_section_size (abfd, section) == 0) return true; fprintf (file, _("\n\nPE File Base Relocations (interpreted .reloc section contents)\n")); data = (bfd_byte *) bfd_malloc ((size_t) bfd_section_size (abfd, section)); datasize = bfd_section_size (abfd, section); if (data == NULL && datasize != 0) return false; bfd_get_section_contents (abfd, section, (PTR) data, 0, bfd_section_size (abfd, section)); start = 0; stop = bfd_section_size (abfd, section); for (i = start; i < stop;) { int j; bfd_vma virtual_address; long number, size; /* The .reloc section is a sequence of blocks, with a header consisting of two 32 bit quantities, followed by a number of 16 bit entries */ virtual_address = bfd_get_32 (abfd, data+i); size = bfd_get_32 (abfd, data+i+4); number = (size - 8) / 2; if (size == 0) { break; } fprintf (file, _("\nVirtual Address: %08lx Chunk size %ld (0x%lx) Number of fixups %ld\n"), (unsigned long) virtual_address, size, size, number); for (j = 0; j < number; ++j) { unsigned short e = bfd_get_16 (abfd, data + i + 8 + j * 2); unsigned int t = (e & 0xF000) >> 12; int off = e & 0x0FFF; if (t >= sizeof (tbl) / sizeof (tbl[0])) t = (sizeof (tbl) / sizeof (tbl[0])) - 1; fprintf (file, _("\treloc %4d offset %4x [%4lx] %s"), j, off, (long) (off + virtual_address), tbl[t]); /* HIGHADJ takes an argument, - the next record *is* the low 16 bits of addend. */ if (t == IMAGE_REL_BASED_HIGHADJ) { fprintf (file, " (%4x)", ((unsigned int) bfd_get_16 (abfd, data + i + 8 + j * 2 + 2))); j++; } fprintf (file, "\n"); } i += size; } free (data); return true;}/* Print out the program headers. */boolean_bfd_XX_print_private_bfd_data_common (abfd, vfile) bfd *abfd; PTR vfile;{ FILE *file = (FILE *) vfile; int j; pe_data_type *pe = pe_data (abfd); struct internal_extra_pe_aouthdr *i = &pe->pe_opthdr; const char *subsystem_name = NULL; /* The MS dumpbin program reportedly ands with 0xff0f before printing the characteristics field. Not sure why. No reason to emulate it here. */ fprintf (file, _("\nCharacteristics 0x%x\n"), pe->real_flags);#undef PF#define PF(x, y) if (pe->real_flags & x) { fprintf (file, "\t%s\n", y); } PF (F_RELFLG, "relocations stripped"); PF (F_EXEC, "executable"); PF (F_LNNO, "line numbers stripped"); PF (F_LSYMS, "symbols stripped"); PF (0x80, "little endian"); PF (F_AR32WR, "32 bit words"); PF (0x200, "debugging information removed"); PF (0x1000, "system file"); PF (F_DLL, "DLL"); PF (0x8000, "big endian");#undef PF /* ctime implies '\n'. */ fprintf (file, "\nTime/Date\t\t%s", ctime (&pe->coff.timestamp)); fprintf (file, "\nImageBase\t\t"); fprintf_vma (file, i->ImageBase); fprintf (file, "\nSectionAlignment\t"); fprintf_vma (file, i->SectionAlignment); fprintf (file, "\nFileAlignment\t\t"); fprintf_vma (file, i->FileAlignment); fprintf (file, "\nMajorOSystemVersion\t%d\n", i->MajorOperatingSystemVersion); fprintf (file, "MinorOSystemVersion\t%d\n", i->MinorOperatingSystemVersion); fprintf (file, "MajorImageVersion\t%d\n", i->MajorImageVersion); fprintf (file, "MinorImageVersion\t%d\n", i->MinorImageVersion); fprintf (file, "MajorSubsystemVersion\t%d\n", i->MajorSubsystemVersion); fprintf (file, "MinorSubsystemVersion\t%d\n", i->MinorSubsystemVersion); fprintf (file, "Win32Version\t\t%08lx\n", i->Reserved1); fprintf (file, "SizeOfImage\t\t%08lx\n", i->SizeOfImage); fprintf (file, "SizeOfHeaders\t\t%08lx\n", i->SizeOfHeaders); fprintf (file, "CheckSum\t\t%08lx\n", i->CheckSum); switch (i->Subsystem) { case IMAGE_SUBSYSTEM_UNKNOWN: subsystem_name = "unspecified"; break; case IMAGE_SUBSYSTEM_NATIVE: subsystem_name = "NT native"; break; case IMAGE_SUBSYSTEM_WINDOWS_GUI: subsystem_name = "Windows GUI"; break; case IMAGE_SUBSYSTEM_WINDOWS_CUI: subsystem_name = "Windows CUI"; break; case IMAGE_SUBSYSTEM_POSIX_CUI: subsystem_name = "POSIX CUI"; break; case IMAGE_SUBSYSTEM_WINDOWS_CE_GUI: subsystem_name = "Wince CUI"; break; case IMAGE_SUBSYSTEM_EFI_APPLICATION: subsystem_name = "EFI application"; break; case IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER: subsystem_name = "EFI boot service driver"; break; case IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER: subsystem_name = "EFI runtime driver"; break; } fprintf (file, "Subsystem\t\t%08x", i->Subsystem); if (subsystem_name) fprintf (file, "\t(%s)", subsystem_name); fprintf (file, "\nDllCharacteristics\t%08x\n", i->DllCharacteristics); fprintf (file, "SizeOfStackReserve\t"); fprintf_vma (file, i->SizeOfStackReserve); fprintf (file, "\nSizeOfStackCommit\t"); fprintf_vma (file, i->SizeOfStackCommit); fprintf (file, "\nSizeOfHeapReserve\t"); fprintf_vma (file, i->SizeOfHeapReserve); fprintf (file, "\nSizeOfHeapCommit\t"); fprintf_vma (file, i->SizeOfHeapCommit); fprintf (file, "\nLoaderFlags\t\t%08lx\n", i->LoaderFlags); fprintf (file, "NumberOfRvaAndSizes\t%08lx\n", i->NumberOfRvaAndSizes); fprintf (file, "\nThe Data Directory\n"); for (j = 0; j < IMAGE_NUMBEROF_DIRECTORY_ENTRIES; j++) { fprintf (file, "Entry %1x ", j); fprintf_vma (file, i->DataDirectory[j].VirtualAddress); fprintf (file, " %08lx ", i->DataDirectory[j].Size); fprintf (file, "%s\n", dir_names[j]); } pe_print_idata (abfd, vfile); pe_print_edata (abfd, vfile); pe_print_pdata (abfd, vfile); pe_print_reloc (abfd, vfile); return true;}/* Copy any private info we understand from the input bfd to the output bfd. */boolean_bfd_XX_bfd_copy_private_bfd_data_common (ibfd, obfd) bfd *ibfd, *obfd;{ /* One day we may try to grok other private data. */ if (ibfd->xvec->flavour != bfd_target_coff_flavour || obfd->xvec->flavour != bfd_target_coff_flavour) return true; pe_data (obfd)->pe_opthdr = pe_data (ibfd)->pe_opthdr; pe_data (obfd)->dll = pe_data (ibfd)->dll; /* for strip: if we removed .reloc, we'll make a real mess of things if we don't remove this entry as well. */ if (! pe_data (obfd)->has_reloc_section) { pe_data (obfd)->pe_opthdr.DataDirectory[5].VirtualAddress = 0; pe_data (obfd)->pe_opthdr.DataDirectory[5].Size = 0; } return true;}/* Copy private section data. */boolean_bfd_XX_bfd_copy_private_section_data (ibfd, isec, obfd, osec) bfd *ibfd; asection *isec; bfd *obfd; asection *osec;{ if (bfd_get_flavour (ibfd) != bfd_target_coff_flavour || bfd_get_flavour (obfd) != bfd_target_coff_flavour) return true; if (coff_section_data (ibfd, isec) != NULL && pei_section_data (ibfd, isec) != NULL) { if (coff_section_data (obfd, osec) == NULL) { osec->used_by_bfd = (PTR) bfd_zalloc (obfd, sizeof (struct coff_section_tdata)); if (osec->used_by_bfd == NULL) return false; } if (pei_section_data (obfd, osec) == NULL) { coff_section_data (obfd, osec)->tdata = (PTR) bfd_zalloc (obfd, sizeof (struct pei_section_tdata)); if (coff_section_data (obfd, osec)->tdata == NULL) return false; } pei_section_data (obfd, osec)->virt_size = pei_section_data (ibfd, isec)->virt_size; pei_section_data (obfd, osec)->pe_flags = pei_section_data (ibfd, isec)->pe_flags; } return true;}void_bfd_XX_get_symbol_info (abfd, symbol, ret) bfd *abfd; asymbol *symbol; symbol_info *ret;{ coff_get_symbol_info (abfd, symbol, ret);#if 0 /* This code no longer appears to be necessary. ImageBase has already been added in by coff_swap_scnhdr_in. */ if (pe_data (abfd) != NULL && ((symbol->flags & BSF_DEBUGGING) == 0 || (symbol->flags & BSF_DEBUGGING_RELOC) != 0) && ! bfd_is_abs_section (symbol->section)) ret->value += pe_data (abfd)->pe_opthdr.ImageBase;#endif}/* Handle the .idata section and other things that need symbol table access. */boolean_bfd_XXi_final_link_postscript (abfd, pfinfo) bfd *abfd; struct coff_final_link_info *pfinfo;{ struct coff_link_hash_entry *h1; struct bfd_link_info *info = pfinfo->info; /* There are a few fields that need to be filled in now while we have symbol table access. The .idata subsections aren't directly available as sections, but they are in the symbol table, so get them from there. */ /* The import directory. This is the address of .idata$2, with size of .idata$2 + .idata$3. */ h1 = coff_link_hash_lookup (coff_hash_table (info), ".idata$2", false, false, true); if (h1 != NULL) { pe_data (abfd)->pe_opthdr.DataDirectory[1].VirtualAddress = (h1->root.u.def.value + h1->root.u.def.section->output_section->vma + h1->root.u.def.section->output_offset); h1 = coff_link_hash_lookup (coff_hash_table (info), ".idata$4", false, false, true); pe_data (abfd)->pe_opthdr.DataDirectory[1].Size = ((h1->root.u.def.value + h1->root.u.def.section->output_section->vma + h1->root.u.def.section->output_offset) - pe_data (abfd)->pe_opthdr.DataDirectory[1].VirtualAddress); /* The import address table. This is the size/address of .idata$5. */ h1 = coff_link_hash_lookup (coff_hash_table (info), ".idata$5", false, false, true); pe_data (abfd)->pe_opthdr.DataDirectory[12].VirtualAddress = (h1->root.u.def.value + h1->root.u.def.section->output_section->vma + h1->root.u.def.section->output_offset); h1 = coff_link_hash_lookup (coff_hash_table (info), ".idata$6", false, false, true); pe_data (abfd)->pe_opthdr.DataDirectory[12].Size = ((h1->root.u.def.value + h1->root.u.def.section->output_section->vma + h1->root.u.def.section->output_offset) - pe_data (abfd)->pe_opthdr.DataDirectory[12].VirtualAddress); } /* If we couldn't find idata$2, we either have an excessively trivial program or are in DEEP trouble; we have to assume trivial program.... */ return true;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?