patches/gdb/6.3/740-debian_make-cv-type-crash.patch
author "Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
Mon Jul 30 21:09:12 2007 +0000 (2007-07-30)
changeset 306 1984d7bcea28
permissions -rw-r--r--
Small typo fix.
     1 2004-11-04  Jim Blandy  <jimb@redhat.com>
     2 
     3 	* gdbtypes.c (make_qualified_type): Doc fix.  Add assertion to
     4 	prevent cross-objfile references.
     5 	(make_cv_type): Doc fix.  Don't create cross-objfile references,
     6 	even for stub types.
     7 	(replace_type): Add assertion to prevent cross-objfile references.
     8 	(check_typedef): Never resolve a stub type by copying over a type
     9 	from another file.
    10 
    11 Index: src/gdb/gdbtypes.c
    12 ===================================================================
    13 RCS file: /big/fsf/rsync/src-cvs/src/gdb/gdbtypes.c,v
    14 retrieving revision 1.92
    15 retrieving revision 1.93
    16 diff -u -p -r1.92 -r1.93
    17 --- src/gdb/gdbtypes.c	8 Aug 2004 17:18:16 -0000	1.92
    18 +++ src/gdb/gdbtypes.c	4 Nov 2004 17:50:16 -0000	1.93
    19 @@ -433,7 +433,9 @@ address_space_int_to_name (int space_fla
    20  }
    21  
    22  /* Create a new type with instance flags NEW_FLAGS, based on TYPE.
    23 -   If STORAGE is non-NULL, create the new type instance there.  */
    24 +
    25 +   If STORAGE is non-NULL, create the new type instance there.
    26 +   STORAGE must be in the same obstack as TYPE.  */
    27  
    28  static struct type *
    29  make_qualified_type (struct type *type, int new_flags,
    30 @@ -453,6 +455,12 @@ make_qualified_type (struct type *type, 
    31      ntype = alloc_type_instance (type);
    32    else
    33      {
    34 +      /* If STORAGE was provided, it had better be in the same objfile as
    35 +	 TYPE.  Otherwise, we can't link it into TYPE's cv chain: if one
    36 +	 objfile is freed and the other kept, we'd have dangling
    37 +	 pointers.  */
    38 +      gdb_assert (TYPE_OBJFILE (type) == TYPE_OBJFILE (storage));
    39 +
    40        ntype = storage;
    41        TYPE_MAIN_TYPE (ntype) = TYPE_MAIN_TYPE (type);
    42        TYPE_CHAIN (ntype) = ntype;
    43 @@ -501,11 +509,12 @@ make_type_with_address_space (struct typ
    44     CNST is a flag for setting the const attribute
    45     VOLTL is a flag for setting the volatile attribute
    46     TYPE is the base type whose variant we are creating.
    47 -   TYPEPTR, if nonzero, points
    48 -   to a pointer to memory where the reference type should be stored.
    49 -   If *TYPEPTR is zero, update it to point to the reference type we return.
    50 -   We allocate new memory if needed.  */
    51  
    52 +   If TYPEPTR and *TYPEPTR are non-zero, then *TYPEPTR points to
    53 +   storage to hold the new qualified type; *TYPEPTR and TYPE must be
    54 +   in the same objfile.  Otherwise, allocate fresh memory for the new
    55 +   type whereever TYPE lives.  If TYPEPTR is non-zero, set it to the
    56 +   new type we construct.  */
    57  struct type *
    58  make_cv_type (int cnst, int voltl, struct type *type, struct type **typeptr)
    59  {
    60 @@ -524,20 +533,19 @@ make_cv_type (int cnst, int voltl, struc
    61  
    62    if (typeptr && *typeptr != NULL)
    63      {
    64 -      /* Objfile is per-core-type.  This const-qualified type had best
    65 -	 belong to the same objfile as the type it is qualifying, unless
    66 -	 we are overwriting a stub type, in which case the safest thing
    67 -	 to do is to copy the core type into the new objfile.  */
    68 -
    69 -      gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type)
    70 -		  || TYPE_STUB (*typeptr));
    71 -      if (TYPE_OBJFILE (*typeptr) != TYPE_OBJFILE (type))
    72 -	{
    73 -	  TYPE_MAIN_TYPE (*typeptr)
    74 -	    = TYPE_ALLOC (*typeptr, sizeof (struct main_type));
    75 -	  *TYPE_MAIN_TYPE (*typeptr)
    76 -	    = *TYPE_MAIN_TYPE (type);
    77 -	}
    78 +      /* TYPE and *TYPEPTR must be in the same objfile.  We can't have
    79 +	 a C-V variant chain that threads across objfiles: if one
    80 +	 objfile gets freed, then the other has a broken C-V chain.
    81 +
    82 +	 This code used to try to copy over the main type from TYPE to
    83 +	 *TYPEPTR if they were in different objfiles, but that's
    84 +	 wrong, too: TYPE may have a field list or member function
    85 +	 lists, which refer to types of their own, etc. etc.  The
    86 +	 whole shebang would need to be copied over recursively; you
    87 +	 can't have inter-objfile pointers.  The only thing to do is
    88 +	 to leave stub types as stub types, and look them up afresh by
    89 +	 name each time you encounter them.  */
    90 +      gdb_assert (TYPE_OBJFILE (*typeptr) == TYPE_OBJFILE (type));
    91      }
    92    
    93    ntype = make_qualified_type (type, new_flags, typeptr ? *typeptr : NULL);
    94 @@ -562,6 +570,12 @@ replace_type (struct type *ntype, struct
    95  {
    96    struct type *chain;
    97  
    98 +  /* These two types had better be in the same objfile.  Otherwise,
    99 +     the assignment of one type's main type structure to the other
   100 +     will produce a type with references to objects (names; field
   101 +     lists; etc.) allocated on an objfile other than its own.  */
   102 +  gdb_assert (TYPE_OBJFILE (ntype) == TYPE_OBJFILE (ntype));
   103 +
   104    *TYPE_MAIN_TYPE (ntype) = *TYPE_MAIN_TYPE (type);
   105  
   106    /* The type length is not a part of the main type.  Update it for each
   107 @@ -1416,8 +1430,24 @@ check_typedef (struct type *type)
   108  	  return type;
   109  	}
   110        newtype = lookup_transparent_type (name);
   111 +
   112        if (newtype)
   113 -	make_cv_type (is_const, is_volatile, newtype, &type);
   114 +	{
   115 +	  /* If the resolved type and the stub are in the same objfile,
   116 +	     then replace the stub type with the real deal.  But if
   117 +	     they're in separate objfiles, leave the stub alone; we'll
   118 +	     just look up the transparent type every time we call
   119 +	     check_typedef.  We can't create pointers between types
   120 +	     allocated to different objfiles, since they may have
   121 +	     different lifetimes.  Trying to copy NEWTYPE over to TYPE's
   122 +	     objfile is pointless, too, since you'll have to move over any
   123 +	     other types NEWTYPE refers to, which could be an unbounded
   124 +	     amount of stuff.  */
   125 +	  if (TYPE_OBJFILE (newtype) == TYPE_OBJFILE (type))
   126 +	    make_cv_type (is_const, is_volatile, newtype, &type);
   127 +	  else
   128 +	    type = newtype;
   129 +	}
   130      }
   131    /* Otherwise, rely on the stub flag being set for opaque/stubbed types */
   132    else if (TYPE_STUB (type) && !currently_reading_symtab)