This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH 2/3] objdump: Handle x64 PE+ pdata with leading padding


I have an .exe (produced by compiling the DIA2Dump sample with MSVS 2015),
where the .pdata section has a leading padding of zeroes, as well as
trailing padding.

Currently objdump -p identifies there is .pdata, but refuses to dump any of
it.  On investigation, it seems that pex64_bfd_print_pdata_section() assumes
that any null _IMAGE_RUNTIME_FUNCTION_ENTRY entries will be trailing padding
and stops.

Fix this by ignoring all null entries.  This isn't quite perfect as null
entries in the middle of the table are possibly invalid, but there's no
clear specification that they are allowed at the beginning or end either.

Also, deal with bfa_vma prev_beginaddress being unsigned by assuming that 0
isn't ever going to be the BeginAddress of a valid entry, not by specially
arranging to not consider checking the first entry.

Also, fix the fractured grammar of 'has smaller begin address as
predecessor' by saying that it's not greater (the precise numbers will be
available on preceeding lines if it is important if it's equal or less).

No regressions when tested on Cygwin x86_64.

bfd/ChangeLog:

2016-03-09  Jon Turney  <jon.turney@dronecode.org.uk>

	* pei-x86_64.c (pex64_bfd_print_pdata_section): Handle leading
	pdata padding by ignoring it, rather than stopping on null pdata
	entries.  Deal with prev_beginaddress being unsigned by assuming
	that 0 isn't ever going to be the BeginAddress of a valid entry.
	Fix the fractured grammar of 'has smaller begin address as
	predecessor'.
---
 bfd/ChangeLog    |  9 +++++++++
 bfd/pei-x86_64.c | 15 +++++++--------
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/bfd/pei-x86_64.c b/bfd/pei-x86_64.c
index c19b946..dbb622a 100644
--- a/bfd/pei-x86_64.c
+++ b/bfd/pei-x86_64.c
@@ -469,7 +469,7 @@ pex64_bfd_print_pdata_section (bfd *abfd, void *vfile, asection *pdata_section)
   bfd_size_type i;
   bfd_size_type datasize;
   bfd_size_type stop;
-  bfd_vma prev_beginaddress = (bfd_vma) -1;
+  bfd_vma prev_beginaddress = (bfd_vma) 0;
   bfd_vma prev_unwinddata_rva = (bfd_vma) -1;
   bfd_vma imagebase;
   int onaline = PDATA_ROW_SIZE;
@@ -545,8 +545,8 @@ pex64_bfd_print_pdata_section (bfd *abfd, void *vfile, asection *pdata_section)
 
       if (rf.rva_BeginAddress == 0 && rf.rva_EndAddress == 0
 	  && rf.rva_UnwindData == 0)
-	/* We are probably into the padding of the section now.  */
-	break;
+	/* Ignore padding. */
+	continue;
       fputc (' ', file);
       fprintf_vma (file, i + pdata_section->vma);
       fprintf (file, ":\t");
@@ -556,11 +556,10 @@ pex64_bfd_print_pdata_section (bfd *abfd, void *vfile, asection *pdata_section)
       fprintf (file, " ");
       fprintf_vma (file, imagebase + rf.rva_UnwindData);
       fprintf (file, "\n");
-      if (i != 0 && rf.rva_BeginAddress <= prev_beginaddress)
+      if (rf.rva_BeginAddress <= prev_beginaddress)
 	{
 	  seen_error = 1;
-	  fprintf (file, "  has %s begin address as predecessor\n",
-	    (rf.rva_BeginAddress < prev_beginaddress ? "smaller" : "same"));
+	  fprintf (file, "  begin address not greater than predecessor\n");
         }
       prev_beginaddress = rf.rva_BeginAddress;
       /* Now we check for negative addresses.  */
@@ -646,8 +645,8 @@ pex64_bfd_print_pdata_section (bfd *abfd, void *vfile, asection *pdata_section)
 
       if (rf.rva_BeginAddress == 0 && rf.rva_EndAddress == 0
 	  && rf.rva_UnwindData == 0)
-	/* We are probably into the padding of the section now.  */
-	break;
+	/* Ignore padding.  */
+	continue;
       if (i == 0)
         fprintf (file, _("\nDump of %s\n"), xdata_section->name);
 
-- 
2.8.3


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]