OSDN Git Service

Do not assume that the first thunk is located in the same section as the
authorNick Clifton <nickc@redhat.com>
Wed, 15 May 2002 15:28:12 +0000 (15:28 +0000)
committerNick Clifton <nickc@redhat.com>
Wed, 15 May 2002 15:28:12 +0000 (15:28 +0000)
import table.  Instead check, and if necessary load the section containing
the thunk.

bfd/ChangeLog
bfd/peXXigen.c

index e27782a..f7f28b6 100644 (file)
@@ -1,3 +1,9 @@
+2002-05-15  Laurent Pinchart <laurent.pinchart@skynet.be>
+
+       * peXXigen.c (pe_print_idata): Do not assume that the first thunk
+       is located in the same section as the import table.  Instead
+       check, and if necessary load the section containing the thunk.
+
 2002-05-15  Nick Clifton  <nickc@cambridge.redhat.com>
 
        * aix5ppc-core.c (xcoff64_core_p): Replace bfd_read with
index 04b7419..22f2e3f 100644 (file)
@@ -1219,10 +1219,58 @@ pe_print_idata (abfd, vfile)
 
       if (hint_addr != first_thunk && time_stamp == 0)
        {
+          bfd_byte *ft_data;
+         asection *ft_section;
+         bfd_vma ft_addr;
+         bfd_size_type ft_datasize;
+         int ft_idx;
          int differ = 0;
-         int idx2;
+         int ft_allocated = 0;
 
-         idx2 = first_thunk - adj;
+          ft_addr = first_thunk + extra->ImageBase;
+
+         /* Find the section which contains the first thunk.  */
+         for (ft_section = abfd->sections;
+              ft_section != NULL;
+              ft_section = ft_section->next)
+           {
+             ft_datasize = bfd_section_size (abfd, ft_section);
+             if (ft_addr >= ft_section->vma
+                 && ft_addr < ft_section->vma + ft_datasize)
+               break;
+           }
+
+         if (ft_section == NULL)
+           {
+             fprintf (file,
+                  _("\nThere is a first thunk, but the section containing it could not be found\n"));
+             continue;
+           }
+
+         /* Now check to see if this section is the same as our current
+            section.  If it is not then we will have to load its data in.  */
+         if (ft_section == section)
+           {
+             ft_data = data;
+              ft_idx = first_thunk - adj;
+           }
+         else
+           {
+              ft_idx = first_thunk - (ft_section->vma - extra->ImageBase);
+             ft_data = (bfd_byte *) bfd_malloc (datasize);
+             if (ft_data == NULL)
+               continue;
+
+             /* Read datasize bfd_bytes starting at offset ft_idx.  */
+             if (! bfd_get_section_contents (abfd, ft_section, (PTR) ft_data, (bfd_vma) ft_idx, datasize))
+               {
+                 free (ft_data);
+                 continue;
+               }
+
+             ft_idx = 0;
+             ft_allocated = 1;
+           }
 
          for (j = 0; j < datasize; j += 4)
            {
@@ -1233,7 +1281,7 @@ pe_print_idata (abfd, vfile)
 
              if (hint_addr != 0)
                hint_member = bfd_get_32 (abfd, data + idx + j);
-             iat_member = bfd_get_32 (abfd, data + idx2 + j);
+             iat_member = bfd_get_32 (abfd, ft_data + ft_idx + j);
 
              if (hint_addr == 0 && iat_member == 0)
                break;
@@ -1269,6 +1317,9 @@ pe_print_idata (abfd, vfile)
          if (differ == 0)
            fprintf (file,
                     _("\tThe Import Address Table is identical\n"));
+
+         if (ft_allocated)
+           free (ft_data);
        }
 
       fprintf (file, "\n");