* solib-svr4.c (svr4_truncate_ptr): New function.
authorJim Blandy <jimb@codesourcery.com>
Tue, 5 Feb 2002 23:28:13 +0000 (23:28 +0000)
committerJim Blandy <jimb@codesourcery.com>
Tue, 5 Feb 2002 23:28:13 +0000 (23:28 +0000)
(svr4_relocate_section_addresses): Do the address arithmetic with
the appropriate truncation for target addresses, even when
CORE_ADDR is larger than a target address.

gdb/ChangeLog
gdb/solib-svr4.c

index c24a685a45b58c01760957e718ffb9f079bd80e6..8813e8f41620755bc7ed1ba73f6ba21dd6332e42 100644 (file)
@@ -1,3 +1,10 @@
+2002-02-05  Jim Blandy  <jimb@redhat.com>
+
+       * solib-svr4.c (svr4_truncate_ptr): New function.
+       (svr4_relocate_section_addresses): Do the address arithmetic with
+       the appropriate truncation for target addresses, even when
+       CORE_ADDR is larger than a target address.
+
 2002-02-05  Daniel Jacobowitz  <drow@mvista.com>
 
        * gdbserver/linux-low.c (mywait): Cast second argument of waitpid
index f46326f68c3a097ae4b0543119264abe031630b7..9c71509b6433bcd2e75843265c7334a713675b38 100644 (file)
@@ -1228,14 +1228,41 @@ svr4_free_so (struct so_list *so)
   xfree (so->lm_info);
 }
 
+
+/* Clear any bits of ADDR that wouldn't fit in a target-format
+   data pointer.  "Data pointer" here refers to whatever sort of
+   address the dynamic linker uses to manage its sections.  At the
+   moment, we don't support shared libraries on any processors where
+   code and data pointers are different sizes.
+
+   This isn't really the right solution.  What we really need here is
+   a way to do arithmetic on CORE_ADDR values that respects the
+   natural pointer/address correspondence.  (For example, on the MIPS,
+   converting a 32-bit pointer to a 64-bit CORE_ADDR requires you to
+   sign-extend the value.  There, simply truncating the bits above
+   TARGET_PTR_BIT, as we do below, is no good.)  This should probably
+   be a new gdbarch method or something.  */
+static CORE_ADDR
+svr4_truncate_ptr (CORE_ADDR addr)
+{
+  if (TARGET_PTR_BIT == sizeof (CORE_ADDR) * 8)
+    /* We don't need to truncate anything, and the bit twiddling below
+       will fail due to overflow problems.  */
+    return addr;
+  else
+    return addr & (((CORE_ADDR) 1 << TARGET_PTR_BIT) - 1);
+}
+
+
 static void
 svr4_relocate_section_addresses (struct so_list *so,
                                  struct section_table *sec)
 {
-  sec->addr += LM_ADDR (so);
-  sec->endaddr += LM_ADDR (so);
+  sec->addr    = svr4_truncate_ptr (sec->addr    + LM_ADDR (so));
+  sec->endaddr = svr4_truncate_ptr (sec->endaddr + LM_ADDR (so));
 }
 
+
 /* Fetch a link_map_offsets structure for native targets using struct
    definitions from link.h.  See solib-legacy.c for the function
    which does the actual work.
This page took 0.029009 seconds and 4 git commands to generate.