[PATCH]: shared libs on 32/64 bit systems.

Michael Snyder msnyder@cygnus.com
Wed Jun 7 18:00:00 GMT 2000


Mark Kettenis wrote:
> 
>    Date: Mon, 5 Jun 2000 17:31:46 -0700 (PDT)
>    From: msnyder@cygnus.com
> 
>    Specifically Sparc Solaris.  Jim Blandy, are you online?
>    Or do I need to find an alternate maintainer to review it?
> 
> [snip]
> 
>    + #if defined (__sparcv9)
>    + #define _SYSCALL32 /* for Sparc64 cross Sparc32 */
>    + #endif
> 
> Can this be moved to the appropriate sparc-specific header? The file
> is used by other systems besides Sparc too and it would be nice if we
> don't ``pollute'' it with too many system specific defines.

This define has to be made before certain system header files 
are included.  If I put it in a GDB header file, then I'm 
vulnerable to people changing the include ordering later
(that's assuming that I can find a GDB header file that's
included early enough).

> Are you sure using a processor-specific define is the right approach?
> What'll happen when Sun brings us __sparcv10?  Shouldn't you be using
> a #define based on the canonical target/host as detected by autoconf,
> or given by the user?

Actually, the if defined(__sparcv9) is only there to attempt
to limit the potential impact on other systems.  I don't need
it.  I can just define _SYSCALL32 unconditionally.  I was
just being nice.  ;-)

If you don't like the #ifdef, I'll take it out.  I can replace
all other occurrances of the ifdef with an autoconf variable, 
but not that one, 'cause that one has to come before all of
the #includes.

Here is a new diff that removes all occurances of __sparcv9
except for that one...

Index: configure.in
===================================================================
RCS file: /cvs/src/src/gdb/configure.in,v
retrieving revision 1.33
diff -p -r1.33 configure.in
*** configure.in	2000/06/07 01:14:07	1.33
--- configure.in	2000/06/08 00:41:16
*************** if test "$ac_cv_header_sys_procfs_h" = y
*** 217,224 ****
--- 217,247 ----
    BFD_HAVE_SYS_PROCFS_TYPE(fpregset_t)
    BFD_HAVE_SYS_PROCFS_TYPE(prgregset_t)
    BFD_HAVE_SYS_PROCFS_TYPE(prfpregset_t)
+   BFD_HAVE_SYS_PROCFS_TYPE(prgregset32_t)
+   BFD_HAVE_SYS_PROCFS_TYPE(prfpregset32_t)
    BFD_HAVE_SYS_PROCFS_TYPE(lwpid_t)
    BFD_HAVE_SYS_PROCFS_TYPE(psaddr_t)
+ 
+   dnl Check for struct link_map32 type, which allows a 64-bit Solaris
+   dnl debugger to debug a 32-bit Solaris app with 32-bit shared libraries.
+ 
+   AC_MSG_CHECKING(for struct link_map32 in sys/link.h)
+   AC_CACHE_VAL(gdb_cv_have_struct_link_map32, 
+     [AC_TRY_RUN([#define _SYSCALL32
+      #include <sys/link.h>
+      int main()
+      {
+        if (sizeof (struct link_map32) > 0)
+ 	 return 1;
+        return 0;
+      }],
+      gdb_cv_have_struct_link_map32=no,
+      gdb_cv_have_struct_link_map32=yes,
+      gdb_cv_have_struct_link_map32=yes)])
+   AC_MSG_RESULT($gdb_cv_have_struct_link_map32)
+   if test $gdb_cv_have_struct_link_map32 = yes; then
+     AC_DEFINE(HAVE_STRUCT_LINK_MAP32)
+   fi
  
    dnl Check for broken prfpregset_t type
  
Index: solib.c
===================================================================
RCS file: /cvs/src/src/gdb/solib.c,v
retrieving revision 1.16
diff -p -r1.16 solib.c
*** solib.c	2000/05/28 01:12:29	1.16
--- solib.c	2000/06/08 00:41:16
***************
*** 19,24 ****
--- 19,27 ----
     Foundation, Inc., 59 Temple Place - Suite 330,
     Boston, MA 02111-1307, USA.  */
  
+ #if defined (__sparcv9)
+ #define _SYSCALL32	/* for Sparc64 cross Sparc32 */
+ #endif
  
  #include "defs.h"
  
*************** static char *main_name_list[] =
*** 106,130 ****
    "main_$main",
    NULL
  };
- 
- /* local data declarations */
  
! /* Macro to extract an address from a solib structure.
     When GDB is configured for some 32-bit targets (e.g. Solaris 2.7
     sparc), BFD is configured to handle 64-bit targets, so CORE_ADDR is
     64 bits.  We have to extract only the significant bits of addresses
!    to get the right address when accessing the core file BFD.  */
  
! #define SOLIB_EXTRACT_ADDRESS(member) \
!   extract_address (&member, sizeof (member))
  
  #ifndef SVR4_SHARED_LIBS
  
- #define LM_ADDR(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.lm_addr))
- #define LM_NEXT(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.lm_next))
- #define LM_NAME(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.lm_name))
- /* Test for first link map entry; first entry is a shared library. */
- #define IGNORE_FIRST_LINK_MAP_ENTRY(so) (0)
  static struct link_dynamic dynamic_copy;
  static struct link_dynamic_2 ld_2_copy;
  static struct ld_debug debug_copy;
--- 109,142 ----
    "main_$main",
    NULL
  };
  
! /* Function to extract an address from a solib structure.
     When GDB is configured for some 32-bit targets (e.g. Solaris 2.7
     sparc), BFD is configured to handle 64-bit targets, so CORE_ADDR is
     64 bits.  We have to extract only the significant bits of addresses
!    to get the right address when accessing the core file BFD.  
  
!    We'll use the BFD itself to determine the number of significant bits.  
!    MVS, June 2000  */
  
+ static CORE_ADDR
+ solib_extract_address (void *memberp)
+ {
+   return extract_address (memberp, 
+ 			  bfd_elf_get_arch_size (exec_bfd) / 8);
+ }
+ 
+ #define SOLIB_EXTRACT_ADDRESS(MEMBER) \
+         solib_extract_address (&MEMBER)
+ 
+ /* local data declarations */
+ 
  #ifndef SVR4_SHARED_LIBS
+ 
+ /* NOTE: converted the macros LM_ADDR, LM_NEXT, LM_NAME and
+    IGNORE_FIRST_LINK_MAP_ENTRY into functions (see below).
+    MVS, June 2000  */
  
  static struct link_dynamic dynamic_copy;
  static struct link_dynamic_2 ld_2_copy;
  static struct ld_debug debug_copy;
*************** static CORE_ADDR flag_addr;
*** 133,145 ****
  
  #else /* SVR4_SHARED_LIBS */
  
- #define LM_ADDR(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.l_addr))
- #define LM_NEXT(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.l_next))
- #define LM_NAME(so) (SOLIB_EXTRACT_ADDRESS ((so) -> lm.l_name))
- /* Test for first link map entry; first entry is the exec-file. */
- #define IGNORE_FIRST_LINK_MAP_ENTRY(so) \
-   (SOLIB_EXTRACT_ADDRESS ((so) -> lm.l_prev) == 0)
  static struct r_debug debug_copy;
  char shadow_contents[BREAKPOINT_MAX];	/* Stash old bkpt addr contents */
  
  #endif /* !SVR4_SHARED_LIBS */
--- 145,155 ----
  
  #else /* SVR4_SHARED_LIBS */
  
  static struct r_debug debug_copy;
+ #if defined (HAVE_STRUCT_LINK_MAP32)
+ static struct r_debug32 debug32_copy;	/* Sparc64 cross Sparc32 */
+ #endif
+ 
  char shadow_contents[BREAKPOINT_MAX];	/* Stash old bkpt addr contents */
  
  #endif /* !SVR4_SHARED_LIBS */
*************** struct so_list
*** 152,157 ****
--- 162,170 ----
  
      struct so_list *next;	/* next structure in linked list */
      struct link_map lm;		/* copy of link map from inferior */
+ #if defined (HAVE_STRUCT_LINK_MAP32)
+     struct link_map32 lm32;	/* copy of link map from 32-bit inferior */
+ #endif
      CORE_ADDR lmaddr;		/* addr in inferior lm was read from */
  
      /* Shared object file name, exactly as it appears in the
*************** struct so_list
*** 179,184 ****
--- 192,298 ----
    };
  
  static struct so_list *so_list_head;	/* List of known shared objects */
+ 
+ /* link map access functions */
+ 
+ #ifndef SVR4_SHARED_LIBS
+ 
+ static CORE_ADDR
+ LM_ADDR (so)
+      struct so_list *so;
+ {
+ #if defined (HAVE_STRUCT_LINK_MAP32)
+   if (bfd_elf_get_arch_size (exec_bfd) == 32)
+     return extract_address (&so->lm32.lm_addr, sizeof (so->lm32.lm_addr));
+   else
+ #endif
+     return extract_address (&so->lm.lm_addr, sizeof (so->lm.lm_addr));
+ }
+ 
+ static CORE_ADDR
+ LM_NEXT (so)
+      struct so_list *so;
+ {
+ #if defined (HAVE_STRUCT_LINK_MAP32)
+   if (bfd_elf_get_arch_size (exec_bfd) == 32)
+     return extract_address (&so->lm32.lm_next, sizeof (so->lm32.lm_next));
+   else
+ #endif
+     return extract_address (&so->lm.lm_next, sizeof (so->lm.lm_next));
+ }
+ 
+ static CORE_ADDR
+ LM_NAME (so)
+      struct so_list *so;
+ {
+ #if defined (HAVE_STRUCT_LINK_MAP32)
+   if (bfd_elf_get_arch_size (exec_bfd) == 32)
+     return extract_address (&so->lm32.lm_name, sizeof (so->lm32.lm_name));
+   else
+ #endif
+     return extract_address (&so->lm.lm_name, sizeof (so->lm.lm_name));
+ }
+ 
+ static int 
+ IGNORE_FIRST_LINK_MAP_ENTRY (so)
+      struct so_list *so;
+ {
+   return 0;
+ }
+ 
+ #else /* SVR4_SHARED_LIBS */
+ 
+ static CORE_ADDR
+ LM_ADDR (so)
+      struct so_list *so;
+ {
+ #if defined (HAVE_STRUCT_LINK_MAP32)
+   if (bfd_elf_get_arch_size (exec_bfd) == 32)
+     return extract_address (&so->lm32.l_addr, sizeof (so->lm32.l_addr));
+   else
+ #endif
+     return extract_address (&so->lm.l_addr, sizeof (so->lm.l_addr));
+ }
+ 
+ static CORE_ADDR
+ LM_NEXT (so)
+      struct so_list *so;
+ {
+ #if defined (HAVE_STRUCT_LINK_MAP32)
+   if (bfd_elf_get_arch_size (exec_bfd) == 32)
+     return extract_address (&so->lm32.l_next, sizeof (so->lm32.l_next));
+   else
+ #endif
+     return extract_address (&so->lm.l_next, sizeof (so->lm.l_next));
+ }
+ 
+ static CORE_ADDR
+ LM_NAME (so)
+      struct so_list *so;
+ {
+ #if defined (HAVE_STRUCT_LINK_MAP32)
+   if (bfd_elf_get_arch_size (exec_bfd) == 32)
+     return extract_address (&so->lm32.l_name, sizeof (so->lm32.l_name));
+   else
+ #endif
+     return extract_address (&so->lm.l_name, sizeof (so->lm.l_name));
+ }
+ 
+ static int
+ IGNORE_FIRST_LINK_MAP_ENTRY (so)
+      struct so_list *so;
+ {
+ #if defined (HAVE_STRUCT_LINK_MAP32)
+   if (bfd_elf_get_arch_size (exec_bfd) == 32)
+     return (solib_extract_address (&(so) -> lm32.l_prev) == 0);
+   else
+ #endif
+     return (solib_extract_address (&(so) -> lm.l_prev) == 0);
+ }
+ 
+ #endif /* !SVR4_SHARED_LIBS */
+ 
+ 
  static CORE_ADDR debug_base;	/* Base of dynamic linker structures */
  static CORE_ADDR breakpoint_addr;	/* Address where end bkpt is set */
  
*************** first_link_map_member ()
*** 902,913 ****
      }
  
  #else /* SVR4_SHARED_LIBS */
! 
!   read_memory (debug_base, (char *) &debug_copy, sizeof (struct r_debug));
    /* FIXME:  Perhaps we should validate the info somehow, perhaps by
       checking r_version for a known version number, or r_state for
       RT_CONSISTENT. */
-   lm = SOLIB_EXTRACT_ADDRESS (debug_copy.r_map);
  
  #endif /* !SVR4_SHARED_LIBS */
  
--- 1016,1038 ----
      }
  
  #else /* SVR4_SHARED_LIBS */
! #if defined (HAVE_STRUCT_LINK_MAP32)
!   if (bfd_elf_get_arch_size (exec_bfd) == 32)
!     {
!       read_memory (debug_base, (char *) &debug32_copy, 
! 		   sizeof (struct r_debug32));
!       lm = SOLIB_EXTRACT_ADDRESS (debug32_copy.r_map);
!     }
!   else
! #endif
!     {
!       read_memory (debug_base, (char *) &debug_copy, 
! 		   sizeof (struct r_debug));
!       lm = SOLIB_EXTRACT_ADDRESS (debug_copy.r_map);
!     }
    /* FIXME:  Perhaps we should validate the info somehow, perhaps by
       checking r_version for a known version number, or r_state for
       RT_CONSISTENT. */
  
  #endif /* !SVR4_SHARED_LIBS */
  
*************** open_symbol_file_object (from_ttyp)
*** 939,945 ****
       int *from_ttyp;	/* sneak past catch_errors */
  {
    CORE_ADDR lm;
-   struct link_map lmcopy;
    char *filename;
    int errcode;
  
--- 1064,1069 ----
*************** open_symbol_file_object (from_ttyp)
*** 953,968 ****
    /* First link map member should be the executable.  */
    if ((lm = first_link_map_member ()) == 0)
      return 0;	/* failed somehow... */
- 
-   /* Read from target memory to GDB.  */
-   read_memory (lm, (void *) &lmcopy, sizeof (lmcopy));
  
!   if (lmcopy.l_name == 0)
!     return 0;	/* no filename.  */
  
-   /* Now fetch the filename from target memory.  */
-   target_read_string (SOLIB_EXTRACT_ADDRESS (lmcopy.l_name), &filename, 
- 		      MAX_PATH_SIZE - 1, &errcode);
    if (errcode)
      {
        warning ("failed to read exec filename from attached file: %s",
--- 1077,1112 ----
    /* First link map member should be the executable.  */
    if ((lm = first_link_map_member ()) == 0)
      return 0;	/* failed somehow... */
  
! #if defined (HAVE_STRUCT_LINK_MAP32)
!   if (bfd_elf_get_arch_size (exec_bfd) == 32)
!     {
!       struct link_map32 lmcopy;
!       /* Read from target memory to GDB.  */
!       read_memory (lm, (void *) &lmcopy, sizeof (lmcopy));
! 
!       if (lmcopy.l_name == 0)
! 	return 0;	/* no filename.  */
! 
!       /* Now fetch the filename from target memory.  */
!       target_read_string (SOLIB_EXTRACT_ADDRESS (lmcopy.l_name), 
! 			  &filename, MAX_PATH_SIZE - 1, &errcode);
!     }
!   else
! #endif /* HAVE_STRUCT_LINK_MAP32 */
!     {
!       struct link_map lmcopy;
!       /* Read from target memory to GDB.  */
!       read_memory (lm, (void *) &lmcopy, sizeof (lmcopy));
! 
!       if (lmcopy.l_name == 0)
! 	return 0;	/* no filename.  */
! 
!       /* Now fetch the filename from target memory.  */
!       target_read_string (SOLIB_EXTRACT_ADDRESS (lmcopy.l_name), &filename, 
! 			  MAX_PATH_SIZE - 1, &errcode);
!     }
  
    if (errcode)
      {
        warning ("failed to read exec filename from attached file: %s",
*************** current_sos ()
*** 1092,1098 ****
        memset (new, 0, sizeof (*new));
  
        new->lmaddr = lm;
!       read_memory (lm, (char *) &(new->lm), sizeof (struct link_map));
  
        lm = LM_NEXT (new);
  
--- 1236,1248 ----
        memset (new, 0, sizeof (*new));
  
        new->lmaddr = lm;
! 
! #if defined (HAVE_STRUCT_LINK_MAP32)
!       if (bfd_elf_get_arch_size (exec_bfd) == 32)
! 	read_memory (lm, (char *) &(new->lm32), sizeof (struct link_map32));
!       else
! #endif
! 	read_memory (lm, (char *) &(new->lm), sizeof (struct link_map));
  
        lm = LM_NEXT (new);
  




More information about the Gdb-patches mailing list