PATCH: Dump additonal info for PE-COFF
H. J. Lu
hjl@lucon.org
Mon Mar 19 20:50:00 GMT 2007
More information about the Binutils mailing list
Mon Mar 19 20:50:00 GMT 2007
- Previous message (by thread): [PATCH] Solaris x86-64 fixes for binutils
- Next message (by thread): PATCH: Dump additonal info for PE-COFF
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Some of PE-COFF info aren't displayed by "objdump -p". This patch adds them. Before my patch, I got [hjl@gnu-2 newbin]$ objdump -p new.efi new.efi: file format efi-app-x86_64 Characteristics 0x206 executable line numbers stripped debugging information removed Time/Date Sat Mar 17 15:11:04 2007 ImageBase 0000000000000000 SectionAlignment 0000000000001000 FileAlignment 0000000000000200 ... With my patch, I got [hjl@gnu-2 newbin]$ ./objdump -p new.efi new.efi: file format efi-app-x86_64 Characteristics 0x206 executable line numbers stripped debugging information removed Time/Date Sat Mar 17 15:11:04 2007 Magic 020b (PE32+) MajorLinkerVersion 2 MinorLinkerVersion 56 SizeOfCode 00018e00 SizeOfInitializedData 0001ca00 SizeOfUninitializedData 00000000 AddressOfEntryPoint 0000000000004000 BaseOfCode 0000000000004000 ImageBase 0000000000000000 SectionAlignment 0000000000001000 FileAlignment 0000000000000200 ... H.J. ---- bfd/ 2003-03-19 H.J. Lu <hongjiu.lu@intel.com> * peXXigen.c (_bfd_XXi_swap_aouthdr_in): Store Magic, MajorLinkerVersion, MinorLinkerVersion, SizeOfCode, SizeOfInitializedData, SizeOfUninitializedData, AddressOfEntryPoint, BaseOfCode and BaseOfData in internal extra PE a.out header. (IMAGE_NT_OPTIONAL_HDR_MAGIC): Defined as 0x10b if not defined. (IMAGE_NT_OPTIONAL_HDR64_MAGIC): Defined as 0x20b if not defined. (IMAGE_NT_OPTIONAL_HDRROM_MAGIC): Defined as 0x107 if not defined. (_bfd_XX_print_private_bfd_data_common): Also print Magic, MajorLinkerVersion, MinorLinkerVersion, SizeOfCode, SizeOfInitializedData, SizeOfUninitializedData, AddressOfEntryPoint, BaseOfCode and BaseOfData from internal extra PE a.out header. include/coff/ 2003-03-19 H.J. Lu <hongjiu.lu@intel.com> * internal.h (internal_extra_pe_aouthdr): Add Magic, MajorLinkerVersion, MinorLinkerVersion, SizeOfCode, SizeOfInitializedData, SizeOfUninitializedData, AddressOfEntryPoint, BaseOfCode and BaseOfData. --- binutils/bfd/peXXigen.c.peinfo 2007-03-18 15:00:28.000000000 -0700 +++ binutils/bfd/peXXigen.c 2007-03-19 13:30:09.000000000 -0700 @@ -388,10 +388,11 @@ _bfd_XXi_swap_aouthdr_in (bfd * abfd, void * aouthdr_ext1, void * aouthdr_int1) { - struct internal_extra_pe_aouthdr *a; - PEAOUTHDR * src = (PEAOUTHDR *) (aouthdr_ext1); + PEAOUTHDR * src = (PEAOUTHDR *) aouthdr_ext1; AOUTHDR * aouthdr_ext = (AOUTHDR *) aouthdr_ext1; - struct internal_aouthdr *aouthdr_int = (struct internal_aouthdr *)aouthdr_int1; + struct internal_aouthdr *aouthdr_int + = (struct internal_aouthdr *) aouthdr_int1; + struct internal_extra_pe_aouthdr *a = &aouthdr_int->pe; aouthdr_int->magic = H_GET_16 (abfd, aouthdr_ext->magic); aouthdr_int->vstamp = H_GET_16 (abfd, aouthdr_ext->vstamp); @@ -405,9 +406,21 @@ _bfd_XXi_swap_aouthdr_in (bfd * abfd, /* PE32+ does not have data_start member! */ aouthdr_int->data_start = GET_AOUTHDR_DATA_START (abfd, aouthdr_ext->data_start); + a->BaseOfData = + GET_AOUTHDR_DATA_START (abfd, aouthdr_ext->data_start); #endif - a = &aouthdr_int->pe; + a->Magic = H_GET_16 (abfd, aouthdr_ext->magic); + a->MajorLinkerVersion = H_GET_8 (abfd, aouthdr_ext->vstamp); + a->MinorLinkerVersion = H_GET_8 (abfd, aouthdr_ext->vstamp + 1); + a->SizeOfCode = GET_AOUTHDR_TSIZE (abfd, aouthdr_ext->tsize); + a->SizeOfInitializedData + = GET_AOUTHDR_DSIZE (abfd, aouthdr_ext->dsize); + a->SizeOfUninitializedData + = GET_AOUTHDR_BSIZE (abfd, aouthdr_ext->bsize); + a->AddressOfEntryPoint = GET_AOUTHDR_ENTRY (abfd, aouthdr_ext->entry); + a->BaseOfCode = + GET_AOUTHDR_TEXT_START (abfd, aouthdr_ext->text_start); a->ImageBase = GET_OPTHDR_IMAGE_BASE (abfd, src->ImageBase); a->SectionAlignment = H_GET_32 (abfd, src->SectionAlignment); a->FileAlignment = H_GET_32 (abfd, src->FileAlignment); @@ -1808,6 +1821,7 @@ _bfd_XX_print_private_bfd_data_common (b pe_data_type *pe = pe_data (abfd); struct internal_extra_pe_aouthdr *i = &pe->pe_opthdr; const char *subsystem_name = NULL; + const char *name; /* The MS dumpbin program reportedly ands with 0xff0f before printing the characteristics field. Not sure why. No reason to @@ -1833,6 +1847,52 @@ _bfd_XX_print_private_bfd_data_common (b time_t t = pe->coff.timestamp; fprintf (file, "\nTime/Date\t\t%s", ctime (&t)); } + +#ifndef IMAGE_NT_OPTIONAL_HDR_MAGIC +# define IMAGE_NT_OPTIONAL_HDR_MAGIC 0x10b +#endif +#ifndef IMAGE_NT_OPTIONAL_HDR64_MAGIC +# define IMAGE_NT_OPTIONAL_HDR64_MAGIC 0x20b +#endif +#ifndef IMAGE_NT_OPTIONAL_HDRROM_MAGIC +# define IMAGE_NT_OPTIONAL_HDRROM_MAGIC 0x107 +#endif + + switch (i->Magic) + { + case IMAGE_NT_OPTIONAL_HDR_MAGIC: + name = "PE32"; + break; + case IMAGE_NT_OPTIONAL_HDR64_MAGIC: + name = "PE32+"; + break; + case IMAGE_NT_OPTIONAL_HDRROM_MAGIC: + name = "ROM"; + break; + default: + name = NULL; + break; + } + fprintf (file, "Magic\t\t\t%04x", i->Magic); + if (name) + fprintf (file, "\t(%s)",name); + fprintf (file, "\nMajorLinkerVersion\t%d\n", i->MajorLinkerVersion); + fprintf (file, "MinorLinkerVersion\t%d\n", i->MinorLinkerVersion); + fprintf (file, "SizeOfCode\t\t%08lx\n", i->SizeOfCode); + fprintf (file, "SizeOfInitializedData\t%08lx\n", + i->SizeOfInitializedData); + fprintf (file, "SizeOfUninitializedData\t%08lx\n", + i->SizeOfUninitializedData); + fprintf (file, "AddressOfEntryPoint\t"); + fprintf_vma (file, i->AddressOfEntryPoint); + fprintf (file, "\nBaseOfCode\t\t"); + fprintf_vma (file, i->BaseOfCode); +#if !defined(COFF_WITH_pep) && !defined(COFF_WITH_pex64) + /* PE32+ does not have data_start member! */ + fprintf (file, "\nBaseOfData\t\t"); + fprintf_vma (file, i->BaseOfData); +#endif + fprintf (file, "\nImageBase\t\t"); fprintf_vma (file, i->ImageBase); fprintf (file, "\nSectionAlignment\t"); --- binutils/include/coff/internal.h.peinfo 2006-12-05 11:27:59.000000000 -0800 +++ binutils/include/coff/internal.h 2007-03-19 12:41:20.000000000 -0700 @@ -138,6 +138,28 @@ typedef struct _IMAGE_DATA_DIRECTORY struct internal_extra_pe_aouthdr { + /* FIXME: The following entries are in AOUTHDR. But they aren't + available internally in bfd. We add them here so that objdump + can dump them. */ + /* The state of the image file */ + short Magic; + /* Linker major version number */ + char MajorLinkerVersion; + /* Linker minor version number */ + char MinorLinkerVersion; + /* Total size of all code sections */ + long SizeOfCode; + /* Total size of all initialized data sections */ + long SizeOfInitializedData; + /* Total size of all uninitialized data sections */ + long SizeOfUninitializedData; + /* Address of entry point relative to image base. */ + bfd_vma AddressOfEntryPoint; + /* Address of the first code section relative to image base. */ + bfd_vma BaseOfCode; + /* Address of the first data section relative to image base. */ + bfd_vma BaseOfData; + /* PE stuff */ bfd_vma ImageBase; /* address of specific location in memory that file is located, NT default 0x10000 */
- Previous message (by thread): [PATCH] Solaris x86-64 fixes for binutils
- Next message (by thread): PATCH: Dump additonal info for PE-COFF
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Binutils mailing list