--- ./gdb/buildsym.h.orig	2013-10-28 16:41:12 +0600
+++ ./gdb/buildsym.h	2013-10-28 14:06:45 +0600
@@ -224,6 +224,20 @@ EXTERN char *(*next_symbol_text_func) (s
 
 EXTERN struct type **type_vector;
 
+/* Vector of all the types which were defined in the pst of a file
+   which had the type declarations. This is useful when the debugee
+   is compiled with the xlc -qfuncsect or gcc --function-sections
+   options. These linker options split every function in a file into
+   different PSTs. SO type declarations happen in one PST while
+   references to it happen in another pst. */
+
+EXTERN struct type **all_type_vector;
+
+/* This is set when ever we need to save contents of type_vector
+   in all_type_vector.  */
+
+EXTERN int save_type_vector;
+
 /* Number of elements allocated for type_vector currently.  */
 
 EXTERN int type_vector_length;
--- ./gdb/xcoffread.c.orig	2013-10-28 16:35:09 +0600
+++ ./gdb/xcoffread.c	2013-10-28 16:34:53 +0600
@@ -56,6 +56,9 @@
 #include "aout/stab_gnu.h"
 
 
+/*Previously dependent pst.  */
+struct partial_symtab *pst_dependent_prev;
+
 /* We put a pointer to this structure in the read_symtab_private field
    of the psymtab.  */
 
@@ -1824,6 +1827,14 @@ xcoff_psymtab_to_symtab_1 (struct partia
 
   /* Read in all partial symtabs on which this one is dependent.  */
   for (i = 0; i < pst->number_of_dependencies; i++)
+   {
+    /* If the types defined in the dependent pst have never been
+       saved before, read the pst again.  */
+    if (pst->dependencies[i]->readin)
+    {
+     if (pst->dependencies[i] != pst_dependent_prev) /* && !all_type_vector)*/
+      pst->dependencies[i]->readin = 0;
+    }
     if (!pst->dependencies[i]->readin)
       {
 	/* Inform about additional files that need to be read in.  */
@@ -1837,8 +1848,19 @@ xcoff_psymtab_to_symtab_1 (struct partia
 	    wrap_here ("");	/* Flush output */
 	    gdb_flush (gdb_stdout);
 	  }
-	xcoff_psymtab_to_symtab_1 (pst->dependencies[i]);
+         /* Save the types defined in the pst as it may be referenced in
+           the other partial symtabs.  */
+
+         save_type_vector = 1;
+         pst_dependent_prev = pst->dependencies[i];
+         xcoff_psymtab_to_symtab_1 (pst->dependencies[i]);
+
+        /* Reinitialize save_type_vector back to 0 to avoid saving of
+           unnecessary types declared in following psymtabs.  */
+
+         save_type_vector = 0;	
       }
+   }
 
   if (((struct symloc *) pst->read_symtab_private)->numsyms != 0)
     {
@@ -2210,6 +2232,9 @@ scan_xcoff_symtab (struct objfile *objfi
   /* Current partial symtab */
   struct partial_symtab *pst;
 
+  /* Pst of any file which contains type declarations.  */
+  struct partial_symtab *pst_file;
+
   /* List of current psymtab's include files.  */
   const char **psymtab_include_list;
   int includes_allocated;
@@ -2231,6 +2256,7 @@ scan_xcoff_symtab (struct objfile *objfi
   int textlow_not_set = 1;
 
   pst = (struct partial_symtab *) 0;
+  pst_file = (struct partial_symtab *) 0;
 
   includes_allocated = 30;
   includes_used = 0;
@@ -2332,6 +2358,16 @@ scan_xcoff_symtab (struct objfile *objfi
 			       symnum_before,
 			       objfile->global_psymbols.next,
 			       objfile->static_psymbols.next);
+
+                          /* Mark pst dependent unless it is compiler generated. */
+                          if (strncmp (namestring, "@FIX", 4) != 0)
+                           {
+                            if (!strcmp(pst->filename, pst_file->filename))
+                             {
+                              dependency_list[dependencies_used] = pst_file;
+                              dependencies_used ++;
+                             }
+                           }
 			  }
 		      }
 		    /* Activate the misc_func_recorded mechanism for
@@ -2522,6 +2558,11 @@ scan_xcoff_symtab (struct objfile *objfi
 				       objfile->global_psymbols.next,
 				       objfile->static_psymbols.next);
 	    last_csect_name = NULL;
+
+           /* Initialize pst_file to NULL as we have encountered a new
+              file declaration.  */
+
+           pst_file = (struct partial_symtab *) 0;
 	  }
 	  break;
 
@@ -2642,6 +2683,19 @@ scan_xcoff_symtab (struct objfile *objfi
 	      }
 	    continue;
 	  }
+        case C_DECL:
+         /* We have encountered a new type declaration. The types
+            defined in this pst may be referenced by other psymtabs
+            in the same file itself. (This occurs when we use xlc
+            -qfuncsect or gcc --ffunction-section options.
+
+            So, if this is not marked as pst_file before or if pst_file
+            has not been defined for this particular file, then mark
+            this pst as pst_file.  */
+
+          if (!pst_file)
+           pst_file = pst;
+
 	case C_FUN:
 	  /* The value of the C_FUN is not the address of the function (it
 	     appears to be the address before linking), but as long as it
@@ -2650,7 +2704,6 @@ scan_xcoff_symtab (struct objfile *objfi
 
 	case C_GSYM:
 	case C_ECOML:
-	case C_DECL:
 	case C_STSYM:
 	  {
 	    char *p;
--- ./gdb/stabsread.c.orig	2013-10-28 16:40:35 +0600
+++ ./gdb/stabsread.c	2013-10-28 14:06:45 +0600
@@ -56,6 +56,9 @@
 
 extern void _initialize_stabsread (void);
 
+/* Check if all the types of the particluar pst must be saved. */
+int check_all_types;
+
 /* The routines that read and process a complete stabs for a C struct or 
    C++ class pass lists of data member fields and lists of member function
    fields in an instance of a field_info structure, as defined below.
@@ -263,6 +266,9 @@ dbx_lookup_type (int typenums[2], struct
 	      type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
 	      type_vector = (struct type **)
 		xmalloc (type_vector_length * sizeof (struct type *));
+	      if (save_type_vector)
+	       all_type_vector = (struct type **)
+		xmalloc (type_vector_length * sizeof (struct type *));
 	    }
 	  while (index >= type_vector_length)
 	    {
@@ -273,7 +279,26 @@ dbx_lookup_type (int typenums[2], struct
 		      (type_vector_length * sizeof (struct type *)));
 	  memset (&type_vector[old_len], 0,
 		  (type_vector_length - old_len) * sizeof (struct type *));
-	}
+	  
+	  if (save_type_vector)
+	   {
+	    all_type_vector = (struct type **)
+		  xrealloc ((char *) all_type_vector,
+			    (type_vector_length * sizeof (struct type *)));
+	    memset (&all_type_vector[old_len], 0,
+	            (type_vector_length - old_len) * sizeof (struct type *));
+	   } 
+	}
+
+      /* If the type has been declared in another pst which was
+	 stored in all_type_vector, then assign the type to that
+	 stored value. The check_all_types variable is set by
+	 the cleanup_undefined_types_noname().  */
+
+      if (check_all_types && all_type_vector[index])
+        {
+         type_vector[index] = all_type_vector[index];
+        }
       return (&type_vector[index]);
     }
   else
@@ -2049,6 +2074,13 @@ again:
   if (type_size != -1)
     TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
 
+  /* Save all the types into all_type_vector if the current pst
+     has C_DECL variable declarations and is a dependent pst to
+     another pst.  */
+
+  if (save_type_vector && (typenums[1] > 0))
+   all_type_vector[typenums[1]] = type_vector[typenums[1]];
+
   return type;
 }
 
@@ -4486,6 +4518,23 @@ cleanup_undefined_types_noname (struct o
       struct type **type;
 
       type = dbx_lookup_type (nat.typenums, objfile);
+
+/* If a type is undefined, it may be because of the use of xlc
+   -qfuncsect or gcc --function-sections option which causes types
+   to be defined in one pst while references to it may happen in
+   another pst.
+   
+   So, if we find an undefined type, check it against the 
+   all_type_vector and assign it to the previously defined type.  */
+
+      if (nat.type == *type && TYPE_CODE (*type) == TYPE_CODE_UNDEF)
+        {
+	 if (all_type_vector)
+         check_all_types = 1;
+         type = dbx_lookup_type(nat.typenums, objfile);
+         check_all_types = 0;
+        }
+
       if (nat.type != *type && TYPE_CODE (*type) != TYPE_CODE_UNDEF)
         {
           /* The instance flags of the undefined type are still unset,
