This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB 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]

Re: [patch 06/15] PIE: Fix displacement of separate debug info files


On Tue, 10 Nov 2009 20:04:19 +0100, Tom Tromey wrote:
> >>>>> "Jan" == Jan Kratochvil <jan.kratochvil@redhat.com> writes:
> Jan> -  if (addrs)
> Jan> -    {
> Jan> -      orig_addrs = copy_section_addr_info (addrs);
> 
> I think this was the last call to copy_section_addr_info, so this patch
> should remove that function as well (unless you use it in a different
> patch in the series?  I didn't check).

OK, removed copy_section_addr_info; just this its last caller has been already
removed by:
Re: [RFA] Make sym_read routines handle separate debug files
http://sourceware.org/ml/gdb-patches/2009-12/msg00117.html
http://sourceware.org/ml/gdb-cvs/2009-12/msg00042.html
commit ffb64a120e667bad7b2a79c5e617bdea7328f996
Author: Tristan Gingold <gingold@adacore.com>


> Ok with this change.

Checked-in.

Just updated it so that objfile_relocate is now using new
objfile_separate_debug_iterate for all the separate debug info files.

But now thinking about it - is it correct, Tristan?  Haven't I broke the OSX
support by this check-in (by remapping all the object files to single
address)? Unaware how the OSX files look but the objfile_relocate caller will
come in later patch.

Also build_section_addr_info_from_objfile was already checked-in so just
extended it for biarch support (which has been already approved before).

No regressions on {x86_64,x86_64-m32,i686}-fedora12-linux-gnu.


Thanks,
Jan


http://sourceware.org/ml/gdb-cvs/2010-01/msg00085.html

--- src/gdb/ChangeLog	2010/01/09 05:03:34	1.11227
+++ src/gdb/ChangeLog	2010/01/09 09:10:59	1.11228
@@ -1,3 +1,19 @@
+2010-01-09  Jan Kratochvil  <jan.kratochvil@redhat.com>
+
+	Fix displacement of separate debug info files.
+	* objfiles.c (objfile_relocate): Rename to ...
+	(objfile_relocate1): ... here and make it static.  Extend the comment.
+	(objfile_relocate): New function.
+	* solib-spu.c (spu_relocate_main_executable): Explicitly check if
+	SYMFILE_OBJFILE is NULL.  Remove variables objfile and old_chain.
+	Remove following of SEPARATE_DEBUG_OBJFILE.  new_offsets is now
+	allocated using alloca.
+	* symfile.c (copy_section_addr_info): Remove.
+	(build_section_addr_info_from_objfile): Make it global.  New variables
+	addr_bit and mask, use them.
+	* symfile.h (build_section_addr_info_from_objfile): New prototype.
+	(copy_section_addr_info): Remove.
+
 2010-01-09  Joel Brobecker  <brobecker@adacore.com>
 
 	Signal unwinder for mips-irix N32.
--- src/gdb/objfiles.c	2010/01/06 10:11:04	1.107
+++ src/gdb/objfiles.c	2010/01/09 09:10:59	1.108
@@ -693,9 +693,10 @@
 }
 
 /* Relocate OBJFILE to NEW_OFFSETS.  There should be OBJFILE->NUM_SECTIONS
-   entries in new_offsets.  */
-void
-objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
+   entries in new_offsets.  SEPARATE_DEBUG_OBJFILE is not touched here.  */
+
+static void
+objfile_relocate1 (struct objfile *objfile, struct section_offsets *new_offsets)
 {
   struct obj_section *s;
   struct section_offsets *delta =
@@ -849,6 +850,54 @@
       exec_set_section_address (bfd_get_filename (objfile->obfd), idx,
 				obj_section_addr (s));
     }
+}
+
+/* Relocate OBJFILE to NEW_OFFSETS.  There should be OBJFILE->NUM_SECTIONS
+   entries in new_offsets.  Process also OBJFILE's SEPARATE_DEBUG_OBJFILEs.
+
+   The number and ordering of sections does differ between the two objfiles.
+   Only their names match.  Also the file offsets will differ (objfile being
+   possibly prelinked but separate_debug_objfile is probably not prelinked) but
+   the in-memory absolute address as specified by NEW_OFFSETS must match both
+   files.  */
+
+void
+objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
+{
+  struct objfile *debug_objfile;
+
+  objfile_relocate1 (objfile, new_offsets);
+
+  for (debug_objfile = objfile->separate_debug_objfile;
+       debug_objfile;
+       debug_objfile = objfile_separate_debug_iterate (objfile, debug_objfile))
+    {
+      struct section_addr_info *objfile_addrs;
+      struct section_offsets *new_debug_offsets;
+      int new_debug_num_sections;
+      struct cleanup *my_cleanups;
+
+      objfile_addrs = build_section_addr_info_from_objfile (objfile);
+      my_cleanups = make_cleanup (xfree, objfile_addrs);
+
+      /* Here OBJFILE_ADDRS contain the correct absolute addresses, the
+	 relative ones must be already created according to debug_objfile.  */
+
+      addr_info_make_relative (objfile_addrs, debug_objfile->obfd);
+
+      gdb_assert (debug_objfile->num_sections
+		  == bfd_count_sections (debug_objfile->obfd));
+      new_debug_offsets = xmalloc (SIZEOF_N_SECTION_OFFSETS
+						 (debug_objfile->num_sections));
+      make_cleanup (xfree, new_debug_offsets);
+      relative_addr_info_to_section_offsets (new_debug_offsets,
+					     debug_objfile->num_sections,
+					     objfile_addrs);
+
+      objfile_relocate1 (debug_objfile, new_debug_offsets);
+
+      do_cleanups (my_cleanups);
+    }
 
   /* Relocate breakpoints as necessary, after things are relocated. */
   breakpoint_re_set ();
--- src/gdb/solib-spu.c	2010/01/08 22:52:03	1.4
+++ src/gdb/solib-spu.c	2010/01/09 09:11:00	1.5
@@ -50,25 +50,19 @@
 static void
 spu_relocate_main_executable (int spufs_fd)
 {
-  struct objfile *objfile;
-  struct cleanup *old_chain;
   struct section_offsets *new_offsets;
   int i;
 
-  for (objfile = symfile_objfile;
-       objfile;
-       objfile = objfile->separate_debug_objfile)
-    {
-      new_offsets = xcalloc (objfile->num_sections,
-			     sizeof (struct section_offsets));
-      old_chain = make_cleanup (xfree, new_offsets);
+  if (symfile_objfile == NULL)
+    return;
 
-      for (i = 0; i < objfile->num_sections; i++)
-        new_offsets->offsets[i] = SPUADDR (spufs_fd, 0);
+  new_offsets = alloca (symfile_objfile->num_sections
+			* sizeof (struct section_offsets));
 
-      objfile_relocate (objfile, new_offsets);
-      do_cleanups (old_chain);
-    }
+  for (i = 0; i < symfile_objfile->num_sections; i++)
+    new_offsets->offsets[i] = SPUADDR (spufs_fd, 0);
+
+  objfile_relocate (symfile_objfile, new_offsets);
 }
 
 /* When running a stand-alone SPE executable, we may need to skip one more
--- src/gdb/symfile.c	2010/01/08 22:55:15	1.266
+++ src/gdb/symfile.c	2010/01/09 09:11:00	1.267
@@ -328,32 +328,6 @@
   return sap;
 }
 
-
-/* Return a freshly allocated copy of ADDRS.  The section names, if
-   any, are also freshly allocated copies of those in ADDRS.  */
-struct section_addr_info *
-copy_section_addr_info (struct section_addr_info *addrs)
-{
-  struct section_addr_info *copy
-    = alloc_section_addr_info (addrs->num_sections);
-  int i;
-
-  copy->num_sections = addrs->num_sections;
-  for (i = 0; i < addrs->num_sections; i++)
-    {
-      copy->other[i].addr = addrs->other[i].addr;
-      if (addrs->other[i].name)
-        copy->other[i].name = xstrdup (addrs->other[i].name);
-      else
-        copy->other[i].name = NULL;
-      copy->other[i].sectindex = addrs->other[i].sectindex;
-    }
-
-  return copy;
-}
-
-
-
 /* Build (allocate and populate) a section_addr_info struct from
    an existing section table. */
 
@@ -386,12 +360,17 @@
 
 /* Create a section_addr_info from section offsets in OBJFILE.  */
 
-static struct section_addr_info *
+struct section_addr_info *
 build_section_addr_info_from_objfile (const struct objfile *objfile)
 {
   struct section_addr_info *sap;
   int i;
   struct bfd_section *sec;
+  int addr_bit = gdbarch_addr_bit (objfile->gdbarch);
+  CORE_ADDR mask = CORE_ADDR_MAX;
+
+  if (addr_bit < (sizeof (CORE_ADDR) * HOST_CHAR_BIT))
+    mask = ((CORE_ADDR) 1 << addr_bit) - 1;
 
   sap = alloc_section_addr_info (objfile->num_sections);
   for (i = 0, sec = objfile->obfd->sections;
@@ -400,7 +379,7 @@
     {
       gdb_assert (sec != NULL);
       sap->other[i].addr = (bfd_get_section_vma (objfile->obfd, sec)
-                            + objfile->section_offsets->offsets[i]);
+                            + objfile->section_offsets->offsets[i]) & mask;
       sap->other[i].name = xstrdup (bfd_get_section_name (objfile->obfd, sec));
       sap->other[i].sectindex = sec->index;
     }
--- src/gdb/symfile.h	2010/01/08 22:55:15	1.61
+++ src/gdb/symfile.h	2010/01/09 09:11:00	1.62
@@ -174,6 +174,9 @@
 
 };
 
+extern struct section_addr_info *
+	   build_section_addr_info_from_objfile (const struct objfile *objfile);
+
 extern void relative_addr_info_to_section_offsets
   (struct section_offsets *section_offsets, int num_sections,
    struct section_addr_info *addrs);
@@ -254,11 +257,6 @@
 extern struct section_addr_info *alloc_section_addr_info (size_t
 							  num_sections);
 
-/* Return a freshly allocated copy of ADDRS.  The section names, if
-   any, are also freshly allocated copies of those in ADDRS.  */
-extern struct section_addr_info *(copy_section_addr_info 
-                                  (struct section_addr_info *addrs));
-
 /* Build (allocate and populate) a section_addr_info struct from an
    existing section table.  */
 


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