relocate the entry point address when used
authorTom Tromey <tromey@redhat.com>
Tue, 31 Dec 2013 13:52:33 +0000 (06:52 -0700)
committerTom Tromey <tromey@redhat.com>
Wed, 15 Jan 2014 18:02:23 +0000 (11:02 -0700)
This changes the entry point to be unrelocated in the objfile, and
instead applies the relocation when it is used.

2014-01-15  Tom Tromey  <tromey@redhat.com>

* objfiles.c (entry_point_address_query): Relocate entry point
address.
(objfile_relocate1): Do not relocate entry point address.
* objfiles.h (struct entry_info) <entry_point>: Update comment.
<the_bfd_section_index>: New field.
* symfile.c (init_entry_point_info): Find the entry point's
section.

gdb/ChangeLog
gdb/objfiles.c
gdb/objfiles.h
gdb/symfile.c

index f1b12771e69dda120f2bf0c96c3676b56a7c919d..4259030d92986839ce80832c64a75c7ced9b0896 100644 (file)
@@ -1,3 +1,13 @@
+2014-01-15  Tom Tromey  <tromey@redhat.com>
+
+       * objfiles.c (entry_point_address_query): Relocate entry point
+       address.
+       (objfile_relocate1): Do not relocate entry point address.
+       * objfiles.h (struct entry_info) <entry_point>: Update comment.
+       <the_bfd_section_index>: New field.
+       * symfile.c (init_entry_point_info): Find the entry point's
+       section.
+
 2014-01-15  Tom Tromey  <tromey@redhat.com>
 
        * solib-frv.c (enable_break): Use entry_point_address_query.
index 9cc0054557ec7cd9af688d2f3cd8d5956ddcc12c..a80d4c729c43dba452bc0848aecb0e49faf55b7c 100644 (file)
@@ -367,7 +367,9 @@ entry_point_address_query (CORE_ADDR *entry_p)
   if (symfile_objfile == NULL || !symfile_objfile->ei.entry_point_p)
     return 0;
 
-  *entry_p = symfile_objfile->ei.entry_point;
+  *entry_p = (symfile_objfile->ei.entry_point
+             + ANOFFSET (symfile_objfile->section_offsets,
+                         symfile_objfile->ei.the_bfd_section_index));
 
   return 1;
 }
@@ -794,22 +796,6 @@ objfile_relocate1 (struct objfile *objfile,
      to be out of order.  */
   msymbols_sort (objfile);
 
-  if (objfile->ei.entry_point_p)
-    {
-      /* Relocate ei.entry_point with its section offset, use SECT_OFF_TEXT
-        only as a fallback.  */
-      struct obj_section *s;
-      s = find_pc_section (objfile->ei.entry_point);
-      if (s)
-       {
-         int idx = gdb_bfd_section_index (objfile->obfd, s->the_bfd_section);
-
-         objfile->ei.entry_point += ANOFFSET (delta, idx);
-       }
-      else
-        objfile->ei.entry_point += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
-    }
-
   {
     int i;
 
index c2b617754e8ce0de68ce1653ede0fd0ca86d5f11..620d7e8eb9e0565b190b30d46c729c085e492a40 100644 (file)
@@ -101,9 +101,12 @@ struct objfile_data;
 
 struct entry_info
   {
-    /* The relocated value we should use for this objfile entry point.  */
+    /* The unrelocated value we should use for this objfile entry point.  */
     CORE_ADDR entry_point;
 
+    /* The index of the section in which the entry point appears.  */
+    int the_bfd_section_index;
+
     /* Set to 1 iff ENTRY_POINT contains a valid value.  */
     unsigned entry_point_p : 1;
   };
index d863282c7119a98a4411cb2be8bd1d0a21a1d3e2..bd125524a7920bb80a9593b99e7b666e63a9670f 100644 (file)
@@ -894,7 +894,9 @@ init_entry_point_info (struct objfile *objfile)
 
   if (objfile->ei.entry_point_p)
     {
+      struct obj_section *osect;
       CORE_ADDR entry_point =  objfile->ei.entry_point;
+      int found;
 
       /* Make certain that the address points at real code, and not a
         function descriptor.  */
@@ -907,6 +909,25 @@ init_entry_point_info (struct objfile *objfile)
         symbol table.  */
       objfile->ei.entry_point
        = gdbarch_addr_bits_remove (get_objfile_arch (objfile), entry_point);
+
+      found = 0;
+      ALL_OBJFILE_OSECTIONS (objfile, osect)
+       {
+         struct bfd_section *sect = osect->the_bfd_section;
+
+         if (entry_point >= bfd_get_section_vma (objfile->obfd, sect)
+             && entry_point < (bfd_get_section_vma (objfile->obfd, sect)
+                               + bfd_get_section_size (sect)))
+           {
+             objfile->ei.the_bfd_section_index
+               = gdb_bfd_section_index (objfile->obfd, sect);
+             found = 1;
+             break;
+           }
+       }
+
+      if (!found)
+       objfile->ei.the_bfd_section_index = SECT_OFF_TEXT (objfile);
     }
 }