diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index dac71f3..717408f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,45 @@
 2016-09-26  Tom Tromey  <tom@tromey.com>
 
+	* xcoffread.c (record_minimal_symbol, scan_xcoff_symtab): Add
+	"reader" argument.  Update.
+	(xcoff_initial_scan): Update.
+	* symfile.h (mdebug_build_psymtabs): Add "reader" argument.
+	* mipsread.c (mipscoff_symfile_read): Update.
+	(read_alphacoff_dynamic_symtab): Add "reader" argument.  Update.
+	* minsyms.h (scoped_minimal_symbol_reader) <record, record_full>:
+	Declare.
+	<msym_bunch, msym_bunch_index, msym_count>: New members.
+	<record_with_info>: New function, renamed from
+	prim_record_minimal_symbol_and_info.
+	* minsyms.c (msym_bunch, msym_bunch_index, msym_count): Remove
+	globals.
+	(scoped_minimal_symbol_reader): Initialize new members.
+	(scoped_minimal_symbol_reader::record): Renamed from
+	prim_record_minimal_symbol.
+	(scoped_minimal_symbol_reader::record_full): Renamed from
+	prim_record_minimal_symbol_full.
+	(prim_record_minimal_symbol_and_info): Move to minsyms.h; rename.
+	* mdebugread.c (mdebug_build_psymtabs, parse_partial_symbols)
+	(record_minimal_symbol): Add "reader" argument.  Update.
+	(elfmdebug_build_psymtabs): Update.
+	* machoread.c (macho_symtab_add_minsym, macho_symtab_read): Add
+	"reader" argument.  Update.
+	(macho_symfile_read): Update.
+	* elfread.c (record_minimal_symbol, elf_symtab_read)
+	(elf_rel_plt_read): Add "reader" argument.  Update.
+	(elf_read_minimal_symbols): Update.
+	* dbxread.c (record_minimal_symbol, read_dbx_dynamic_symtab)
+	(read_dbx_symtab): Add "reader" argument.  Update.
+	(dbx_symfile_read): Update.
+	* coffread.c (record_minimal_symbol, coff_symtab_read): Add
+	"reader" argument.  Update.
+	(coff_symfile_read): Update.
+	* coff-pe-read.h (read_pe_exported_syms): Add "reader" argument.
+	* coff-pe-read.c (add_pe_exported_sym, add_pe_forwarded_sym)
+	(read_pe_exported_syms): Add "reader" argument.  Update.
+
+2016-09-26  Tom Tromey  <tom@tromey.com>
+
 	* xcoffread.c (xcoff_initial_scan): Update.
 	* mipsread.c (mipscoff_symfile_read): Update.
 	* minsyms.c (scoped_minimal_symbol_reader): Add obj argument.
diff --git a/gdb/coff-pe-read.c b/gdb/coff-pe-read.c
index 8836361..d0fa4a8 100644
--- a/gdb/coff-pe-read.c
+++ b/gdb/coff-pe-read.c
@@ -150,7 +150,8 @@ get_section_vmas (bfd *abfd, asection *sectp, void *context)
    OBJFILE is the objfile struct of DLL_NAME.  */
 
 static void
-add_pe_exported_sym (const char *sym_name,
+add_pe_exported_sym (scoped_minimal_symbol_reader &reader,
+		     const char *sym_name,
 		     unsigned long func_rva,
 		     int ordinal,
 		     const struct read_pe_section_data *section_data,
@@ -176,13 +177,12 @@ add_pe_exported_sym (const char *sym_name,
 			" for entry \"%s\" in dll \"%s\"\n"),
 			section_data->section_name, sym_name, dll_name);
 
-  prim_record_minimal_symbol_and_info (qualified_name, vma,
-				       section_data->ms_type,
-				       section_data->index, objfile);
+  reader.record_with_info (qualified_name, vma, section_data->ms_type,
+			   section_data->index);
 
   /* Enter the plain name as well, which might not be unique.  */
-  prim_record_minimal_symbol_and_info (bare_name, vma, section_data->ms_type,
-				       section_data->index, objfile);
+  reader.record_with_info (bare_name, vma, section_data->ms_type,
+			   section_data->index);
   if (debug_coff_pe_read > 1)
     fprintf_unfiltered (gdb_stdlog, _("Adding exported symbol \"%s\""
 			" in dll \"%s\"\n"), sym_name, dll_name);
@@ -200,7 +200,8 @@ add_pe_exported_sym (const char *sym_name,
    OBJFILE is the objfile struct of DLL_NAME.  */
 
 static int
-add_pe_forwarded_sym (const char *sym_name, const char *forward_dll_name,
+add_pe_forwarded_sym (scoped_minimal_symbol_reader &reader,
+		      const char *sym_name, const char *forward_dll_name,
 		      const char *forward_func_name, int ordinal,
 		      const char *dll_name, struct objfile *objfile)
 {
@@ -266,12 +267,10 @@ add_pe_forwarded_sym (const char *sym_name, const char *forward_dll_name,
      code.  */
   baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
 
-  prim_record_minimal_symbol_and_info (qualified_name, vma - baseaddr,
-				       msymtype, section, objfile);
+  reader.record_with_info (qualified_name, vma - baseaddr, msymtype, section);
 
   /* Enter the plain name as well, which might not be unique.  */
-  prim_record_minimal_symbol_and_info (bare_name, vma - baseaddr, msymtype,
-				       section, objfile);
+  reader.record_with_info (bare_name, vma - baseaddr, msymtype, section);
   xfree (qualified_name);
   xfree (bare_name);
 
@@ -331,7 +330,8 @@ pe_as32 (void *ptr)
    pe_implied_import_dll in pe-dll.c.  */
 
 void
-read_pe_exported_syms (struct objfile *objfile)
+read_pe_exported_syms (scoped_minimal_symbol_reader &reader,
+		       struct objfile *objfile)
 {
   bfd *dll = objfile->obfd;
   unsigned long nbnormal, nbforward;
@@ -580,7 +580,7 @@ read_pe_exported_syms (struct objfile *objfile)
 	      forward_dll_name[len] = '\0';
 	      forward_func_name = ++sep;
 	    }
-	  if (add_pe_forwarded_sym (funcname, forward_dll_name,
+	  if (add_pe_forwarded_sym (reader, funcname, forward_dll_name,
 				    forward_func_name, ordinal,
 				    dll_name, objfile) != 0)
 	    ++nbforward;
@@ -595,7 +595,7 @@ read_pe_exported_syms (struct objfile *objfile)
 	      char *sym_name = (char *) (erva + name_rva);
 
 	      section_found = 1;
-	      add_pe_exported_sym (sym_name, func_rva, ordinal,
+	      add_pe_exported_sym (reader, sym_name, func_rva, ordinal,
 				   section_data + sectix, dll_name, objfile);
 	      ++nbnormal;
 	      break;
@@ -607,7 +607,7 @@ read_pe_exported_syms (struct objfile *objfile)
 
 	  if (name_rva == 0)
 	    {
-	      add_pe_exported_sym (NULL, func_rva, ordinal,
+	      add_pe_exported_sym (reader, NULL, func_rva, ordinal,
 				   section_data, dll_name, objfile);
 	      ++nbnormal;
 	    }
diff --git a/gdb/coff-pe-read.h b/gdb/coff-pe-read.h
index 8a74a60..9f29a3d 100644
--- a/gdb/coff-pe-read.h
+++ b/gdb/coff-pe-read.h
@@ -27,7 +27,8 @@ struct bfd;
 
 /* Read the export table and convert it to minimal symbol table
    entries */
-extern void read_pe_exported_syms (struct objfile *objfile);
+extern void read_pe_exported_syms (scoped_minimal_symbol_reader &reader,
+				   struct objfile *objfile);
 
 /* Extract from ABFD the offset of the .text section.
    Returns default value 0x1000 if information is not found.  */
diff --git a/gdb/coffread.c b/gdb/coffread.c
index a86f223..8f8fe4b 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -207,7 +207,8 @@ static void read_one_sym (struct coff_symbol *,
 			  struct internal_syment *,
 			  union internal_auxent *);
 
-static void coff_symtab_read (long, unsigned int, struct objfile *);
+static void coff_symtab_read (scoped_minimal_symbol_reader &,
+			      long, unsigned int, struct objfile *);
 
 /* We are called once per section from coff_symfile_read.  We
    need to examine each section we are passed, check to see
@@ -461,7 +462,8 @@ is_import_fixup_symbol (struct coff_symbol *cs,
 }
 
 static struct minimal_symbol *
-record_minimal_symbol (struct coff_symbol *cs, CORE_ADDR address,
+record_minimal_symbol (scoped_minimal_symbol_reader &reader,
+		       struct coff_symbol *cs, CORE_ADDR address,
 		       enum minimal_symbol_type type, int section, 
 		       struct objfile *objfile)
 {
@@ -479,8 +481,7 @@ record_minimal_symbol (struct coff_symbol *cs, CORE_ADDR address,
       return NULL;
     }
 
-  return prim_record_minimal_symbol_and_info (cs->c_name, address,
-					      type, section, objfile);
+  return reader.record_with_info (cs->c_name, address, type, section);
 }
 
 /* coff_symfile_init ()
@@ -650,7 +651,7 @@ coff_symfile_read (struct objfile *objfile, int symfile_flags)
   /* Now that the executable file is positioned at symbol table,
      process it and define symbols accordingly.  */
 
-  coff_symtab_read ((long) symtab_offset, num_symbols, objfile);
+  coff_symtab_read (reader, (long) symtab_offset, num_symbols, objfile);
 
   /* Install any minimal symbols that have been collected as the
      current minimal symbols for this objfile.  */
@@ -778,7 +779,8 @@ coff_symfile_finish (struct objfile *objfile)
    We read them one at a time using read_one_sym ().  */
 
 static void
-coff_symtab_read (long symtab_offset, unsigned int nsyms,
+coff_symtab_read (scoped_minimal_symbol_reader &reader,
+		  long symtab_offset, unsigned int nsyms,
 		  struct objfile *objfile)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
@@ -876,7 +878,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
 	  int section = cs_to_section (cs, objfile);
 
 	  tmpaddr = cs->c_value;
-	  record_minimal_symbol (cs, tmpaddr, mst_text,
+	  record_minimal_symbol (reader, cs, tmpaddr, mst_text,
 				 section, objfile);
 
 	  fcn_line_ptr = main_aux.x_sym.x_fcnary.x_fcn.x_lnnoptr;
@@ -1036,7 +1038,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
 		  ms_type = mst_unknown;
 	      }
 
-	    msym = record_minimal_symbol (cs, tmpaddr, ms_type,
+	    msym = record_minimal_symbol (reader, cs, tmpaddr, ms_type,
 					  sec, objfile);
 	    if (msym)
 	      gdbarch_coff_make_msymbol_special (gdbarch,
@@ -1198,7 +1200,7 @@ coff_symtab_read (long symtab_offset, unsigned int nsyms,
     {
       /* We've got no debugging symbols, but it's a portable
 	 executable, so try to read the export table.  */
-      read_pe_exported_syms (objfile);
+      read_pe_exported_syms (reader, objfile);
     }
 
   if (get_last_source_file ())
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 59c809a..2a666c3 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -262,9 +262,10 @@ static void dbx_read_symtab (struct partial_symtab *self,
 
 static void dbx_psymtab_to_symtab_1 (struct objfile *, struct partial_symtab *);
 
-static void read_dbx_dynamic_symtab (struct objfile *objfile);
+static void read_dbx_dynamic_symtab (scoped_minimal_symbol_reader &reader,
+				     struct objfile *objfile);
 
-static void read_dbx_symtab (struct objfile *);
+static void read_dbx_symtab (scoped_minimal_symbol_reader &, struct objfile *);
 
 static void free_bincl_list (struct objfile *);
 
@@ -286,7 +287,8 @@ static void dbx_symfile_read (struct objfile *, int);
 
 static void dbx_symfile_finish (struct objfile *);
 
-static void record_minimal_symbol (const char *, CORE_ADDR, int,
+static void record_minimal_symbol (scoped_minimal_symbol_reader &,
+				   const char *, CORE_ADDR, int,
 				   struct objfile *);
 
 static void add_new_header_file (char *, int);
@@ -429,7 +431,8 @@ explicit_lookup_type (int real_filenum, int index)
 #endif
 
 static void
-record_minimal_symbol (const char *name, CORE_ADDR address, int type,
+record_minimal_symbol (scoped_minimal_symbol_reader &reader,
+		       const char *name, CORE_ADDR address, int type,
 		       struct objfile *objfile)
 {
   enum minimal_symbol_type ms_type;
@@ -508,8 +511,7 @@ record_minimal_symbol (const char *name, CORE_ADDR address, int type,
       && address < lowest_text_address)
     lowest_text_address = address;
 
-  prim_record_minimal_symbol_and_info
-    (name, address, ms_type, section, objfile);
+  reader.record_with_info (name, address, ms_type, section);
 }
 
 /* Scan and build partial symbols for a symbol file.
@@ -562,11 +564,11 @@ dbx_symfile_read (struct objfile *objfile, int symfile_flags)
 
   /* Read stabs data from executable file and define symbols.  */
 
-  read_dbx_symtab (objfile);
+  read_dbx_symtab (reader, objfile);
 
   /* Add the dynamic symbols.  */
 
-  read_dbx_dynamic_symtab (objfile);
+  read_dbx_dynamic_symtab (reader, objfile);
 
   /* Install any minimal symbols that have been collected as the current
      minimal symbols for this objfile.  */
@@ -978,7 +980,8 @@ set_namestring (struct objfile *objfile, const struct internal_nlist *nlist)
    add them to the minimal symbol table.  */
 
 static void
-read_dbx_dynamic_symtab (struct objfile *objfile)
+read_dbx_dynamic_symtab (scoped_minimal_symbol_reader &reader,
+			 struct objfile *objfile)
 {
   bfd *abfd = objfile->obfd;
   struct cleanup *back_to;
@@ -1052,7 +1055,7 @@ read_dbx_dynamic_symtab (struct objfile *objfile)
 	  if (sym->flags & BSF_GLOBAL)
 	    type |= N_EXT;
 
-	  record_minimal_symbol (bfd_asymbol_name (sym), sym_value,
+	  record_minimal_symbol (reader, bfd_asymbol_name (sym), sym_value,
 				 type, objfile);
 	}
     }
@@ -1105,8 +1108,7 @@ read_dbx_dynamic_symtab (struct objfile *objfile)
 	}
 
       name = bfd_asymbol_name (*rel->sym_ptr_ptr);
-      prim_record_minimal_symbol (name, address, mst_solib_trampoline,
-				  objfile);
+      reader.record (name, address, mst_solib_trampoline);
     }
 
   do_cleanups (back_to);
@@ -1169,7 +1171,7 @@ function_outside_compilation_unit_complaint (const char *arg1)
    debugging information is available.  */
 
 static void
-read_dbx_symtab (struct objfile *objfile)
+read_dbx_symtab (scoped_minimal_symbol_reader &reader, struct objfile *objfile)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   struct external_nlist *bufp = 0;	/* =0 avoids gcc -Wall glitch.  */
@@ -1325,7 +1327,7 @@ read_dbx_symtab (struct objfile *objfile)
 	  record_it:
 	  namestring = set_namestring (objfile, &nlist);
 
-	  record_minimal_symbol (namestring, nlist.n_value,
+	  record_minimal_symbol (reader, namestring, nlist.n_value,
 				 nlist.n_type, objfile);	/* Always */
 	  continue;
 
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 98574ca..09ac507 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -191,7 +191,8 @@ elf_locate_sections (bfd *ignore_abfd, asection *sectp, void *eip)
 }
 
 static struct minimal_symbol *
-record_minimal_symbol (const char *name, int name_len, int copy_name,
+record_minimal_symbol (scoped_minimal_symbol_reader &reader,
+		       const char *name, int name_len, int copy_name,
 		       CORE_ADDR address,
 		       enum minimal_symbol_type ms_type,
 		       asection *bfd_section, struct objfile *objfile)
@@ -202,11 +203,10 @@ record_minimal_symbol (const char *name, int name_len, int copy_name,
       || ms_type == mst_text_gnu_ifunc)
     address = gdbarch_addr_bits_remove (gdbarch, address);
 
-  return prim_record_minimal_symbol_full (name, name_len, copy_name, address,
-					  ms_type,
-					  gdb_bfd_section_index (objfile->obfd,
-								 bfd_section),
-					  objfile);
+  return reader.record_full (name, name_len, copy_name, address,
+			     ms_type,
+			     gdb_bfd_section_index (objfile->obfd,
+						    bfd_section));
 }
 
 /* Read the symbol table of an ELF file.
@@ -226,7 +226,8 @@ record_minimal_symbol (const char *name, int name_len, int copy_name,
 #define ST_SYNTHETIC 2
 
 static void
-elf_symtab_read (struct objfile *objfile, int type,
+elf_symtab_read (scoped_minimal_symbol_reader &reader,
+		 struct objfile *objfile, int type,
 		 long number_of_symbols, asymbol **symbol_table,
 		 int copy_names)
 {
@@ -318,7 +319,7 @@ elf_symtab_read (struct objfile *objfile, int type,
 	    continue;
 
 	  msym = record_minimal_symbol
-	    (sym->name, strlen (sym->name), copy_names,
+	    (reader, sym->name, strlen (sym->name), copy_names,
 	     symaddr, mst_solib_trampoline, sect, objfile);
 	  if (msym != NULL)
 	    {
@@ -458,7 +459,7 @@ elf_symtab_read (struct objfile *objfile, int type,
 	      continue;	/* Skip this symbol.  */
 	    }
 	  msym = record_minimal_symbol
-	    (sym->name, strlen (sym->name), copy_names, symaddr,
+	    (reader, sym->name, strlen (sym->name), copy_names, symaddr,
 	     ms_type, sym->section, objfile);
 
 	  if (msym)
@@ -487,7 +488,7 @@ elf_symtab_read (struct objfile *objfile, int type,
 		{
 		  int len = atsign - sym->name;
 
-		  record_minimal_symbol (sym->name, len, 1, symaddr,
+		  record_minimal_symbol (reader, sym->name, len, 1, symaddr,
 					 ms_type, sym->section, objfile);
 		}
 	    }
@@ -504,7 +505,7 @@ elf_symtab_read (struct objfile *objfile, int type,
 		{
 		  struct minimal_symbol *mtramp;
 
-		  mtramp = record_minimal_symbol (sym->name, len - 4, 1,
+		  mtramp = record_minimal_symbol (reader, sym->name, len - 4, 1,
 						  symaddr,
 						  mst_solib_trampoline,
 						  sym->section, objfile);
@@ -531,7 +532,8 @@ elf_symtab_read (struct objfile *objfile, int type,
    DYN_SYMBOL_TABLE is no longer easily available for OBJFILE.  */
 
 static void
-elf_rel_plt_read (struct objfile *objfile, asymbol **dyn_symbol_table)
+elf_rel_plt_read (scoped_minimal_symbol_reader &reader,
+		  struct objfile *objfile, asymbol **dyn_symbol_table)
 {
   bfd *obfd = objfile->obfd;
   const struct elf_backend_data *bed = get_elf_backend_data (obfd);
@@ -608,7 +610,8 @@ elf_rel_plt_read (struct objfile *objfile, asymbol **dyn_symbol_table)
       memcpy (&string_buffer[name_len], SYMBOL_GOT_PLT_SUFFIX,
 	      got_suffix_len + 1);
 
-      msym = record_minimal_symbol (string_buffer, name_len + got_suffix_len,
+      msym = record_minimal_symbol (reader, string_buffer,
+				    name_len + got_suffix_len,
                                     1, address, mst_slot_got_plt, got_plt,
 				    objfile);
       if (msym)
@@ -1077,7 +1080,7 @@ elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
 	       bfd_get_filename (objfile->obfd),
 	       bfd_errmsg (bfd_get_error ()));
 
-      elf_symtab_read (objfile, ST_REGULAR, symcount, symbol_table, 0);
+      elf_symtab_read (reader, objfile, ST_REGULAR, symcount, symbol_table, 0);
     }
 
   /* Add the dynamic symbols.  */
@@ -1102,9 +1105,10 @@ elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
 	       bfd_get_filename (objfile->obfd),
 	       bfd_errmsg (bfd_get_error ()));
 
-      elf_symtab_read (objfile, ST_DYNAMIC, dynsymcount, dyn_symbol_table, 0);
+      elf_symtab_read (reader, objfile, ST_DYNAMIC, dynsymcount,
+		       dyn_symbol_table, 0);
 
-      elf_rel_plt_read (objfile, dyn_symbol_table);
+      elf_rel_plt_read (reader, objfile, dyn_symbol_table);
     }
 
   /* Contrary to binutils --strip-debug/--only-keep-debug the strip command from
@@ -1139,7 +1143,7 @@ elf_read_minimal_symbols (struct objfile *objfile, int symfile_flags,
       for (i = 0; i < synthcount; i++)
 	synth_symbol_table[i] = synthsyms + i;
       make_cleanup (xfree, synth_symbol_table);
-      elf_symtab_read (objfile, ST_SYNTHETIC, synthcount,
+      elf_symtab_read (reader, objfile, ST_SYNTHETIC, synthcount,
 		       synth_symbol_table, 1);
     }
 
diff --git a/gdb/machoread.c b/gdb/machoread.c
index 0eb438a..df0333a 100644
--- a/gdb/machoread.c
+++ b/gdb/machoread.c
@@ -96,7 +96,8 @@ macho_register_oso (VEC (oso_el) **oso_vector_ptr,
 /* Add symbol SYM to the minimal symbol table of OBJFILE.  */
 
 static void
-macho_symtab_add_minsym (struct objfile *objfile, const asymbol *sym)
+macho_symtab_add_minsym (scoped_minimal_symbol_reader &reader,
+			 struct objfile *objfile, const asymbol *sym)
 {
   if (sym->name == NULL || *sym->name == '\0')
     {
@@ -146,10 +147,9 @@ macho_symtab_add_minsym (struct objfile *objfile, const asymbol *sym)
       else
         return;	/* Skip this symbol.  */
 
-      prim_record_minimal_symbol_and_info
-        (sym->name, symaddr, ms_type,
-	 gdb_bfd_section_index (objfile->obfd, sym->section),
-	 objfile);
+      reader.record_with_info (sym->name, symaddr, ms_type,
+			       gdb_bfd_section_index (objfile->obfd,
+						      sym->section));
     }
 }
 
@@ -157,7 +157,8 @@ macho_symtab_add_minsym (struct objfile *objfile, const asymbol *sym)
    NUMBER_OF_SYMBOLS for OBJFILE.  Registers OSO filenames found.  */
 
 static void
-macho_symtab_read (struct objfile *objfile,
+macho_symtab_read (scoped_minimal_symbol_reader &reader,
+		   struct objfile *objfile,
 		   long number_of_symbols, asymbol **symbol_table,
 		   VEC (oso_el) **oso_vector_ptr)
 {
@@ -226,7 +227,7 @@ macho_symtab_read (struct objfile *objfile,
           else
             {
               /* Non-debugging symbols go to the minimal symbol table.  */
-              macho_symtab_add_minsym (objfile, sym);
+              macho_symtab_add_minsym (reader, objfile, sym);
             }
           break;
 
@@ -870,7 +871,8 @@ macho_symfile_read (struct objfile *objfile, int symfile_flags)
 		   bfd_get_filename (objfile->obfd),
 		   bfd_errmsg (bfd_get_error ()));
 
-	  macho_symtab_read (objfile, symcount, symbol_table, &oso_vector);
+	  macho_symtab_read (reader, objfile, symcount, symbol_table,
+			     &oso_vector);
 
           reader.install ();
 	}
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index b93024b..c2bdd6f 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -222,7 +222,8 @@ static int found_ecoff_debugging_info;
 static int upgrade_type (int, struct type **, int, union aux_ext *,
 			 int, char *);
 
-static void parse_partial_symbols (struct objfile *);
+static void parse_partial_symbols (scoped_minimal_symbol_reader &,
+				   struct objfile *);
 
 static int has_opaque_xref (FDR *, SYMR *);
 
@@ -336,7 +337,8 @@ fdr_name (FDR *f)
    different sections are relocated via the SECTION_OFFSETS.  */
 
 void
-mdebug_build_psymtabs (struct objfile *objfile,
+mdebug_build_psymtabs (scoped_minimal_symbol_reader &reader,
+		       struct objfile *objfile,
 		       const struct ecoff_debug_swap *swap,
 		       struct ecoff_debug_info *info)
 {
@@ -367,7 +369,7 @@ mdebug_build_psymtabs (struct objfile *objfile,
 	(*swap->swap_fdr_in) (objfile->obfd, fdr_src, fdr_ptr);
     }
 
-  parse_partial_symbols (objfile);
+  parse_partial_symbols (reader, objfile);
 
 #if 0
   /* Check to make sure file was compiled with -g.  If not, warn the
@@ -2260,7 +2262,8 @@ function_outside_compilation_unit_complaint (const char *arg1)
    belongs to, and then records this new minimal symbol.  */
 
 static void
-record_minimal_symbol (const char *name, const CORE_ADDR address,
+record_minimal_symbol (scoped_minimal_symbol_reader &reader,
+		       const char *name, const CORE_ADDR address,
                        enum minimal_symbol_type ms_type, int storage_class,
                        struct objfile *objfile)
 {
@@ -2316,15 +2319,15 @@ record_minimal_symbol (const char *name, const CORE_ADDR address,
         section = -1;
     }
 
-  prim_record_minimal_symbol_and_info (name, address, ms_type,
-                                       section, objfile);
+  reader.record_with_info (name, address, ms_type, section);
 }
 
 /* Master parsing procedure for first-pass reading of file symbols
    into a partial_symtab.  */
 
 static void
-parse_partial_symbols (struct objfile *objfile)
+parse_partial_symbols (scoped_minimal_symbol_reader &reader,
+		       struct objfile *objfile)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
@@ -2624,7 +2627,7 @@ parse_partial_symbols (struct objfile *objfile)
 	  unknown_ext_complaint (name);
 	}
       if (!ECOFF_IN_ELF (cur_bfd))
-        record_minimal_symbol (name, svalue, ms_type, ext_in->asym.sc,
+        record_minimal_symbol (reader, name, svalue, ms_type, ext_in->asym.sc,
                                objfile);
     }
 
@@ -2741,7 +2744,7 @@ parse_partial_symbols (struct objfile *objfile)
 		      if (sh.st == stStaticProc)
 			{
 			  namestring = debug_info->ss + fh->issBase + sh.iss;
-                          record_minimal_symbol (namestring, sh.value,
+                          record_minimal_symbol (reader, namestring, sh.value,
                                                  mst_file_text, sh.sc,
                                                  objfile);
 			}
@@ -2786,7 +2789,7 @@ parse_partial_symbols (struct objfile *objfile)
 			case scPData:
 			case scXData:
 			  namestring = debug_info->ss + fh->issBase + sh.iss;
-                          record_minimal_symbol (namestring, sh.value,
+                          record_minimal_symbol (reader, namestring, sh.value,
                                                  mst_file_data, sh.sc,
                                                  objfile);
 			  sh.value += ANOFFSET (objfile->section_offsets,
@@ -2797,7 +2800,7 @@ parse_partial_symbols (struct objfile *objfile)
 			  /* FIXME!  Shouldn't this use cases for bss, 
 			     then have the default be abs?  */
 			  namestring = debug_info->ss + fh->issBase + sh.iss;
-                          record_minimal_symbol (namestring, sh.value,
+                          record_minimal_symbol (reader, namestring, sh.value,
                                                  mst_file_bss, sh.sc,
                                                  objfile);
 			  sh.value += ANOFFSET (objfile->section_offsets,
@@ -3467,10 +3470,9 @@ parse_partial_symbols (struct objfile *objfile)
 		  int new_sdx;
 
 		case stStaticProc:
-		  prim_record_minimal_symbol_and_info (name, minsym_value,
-						       mst_file_text,
-						       SECT_OFF_TEXT (objfile),
-						       objfile);
+		  reader.record_with_info (name, minsym_value,
+					   mst_file_text,
+					   SECT_OFF_TEXT (objfile));
 
 		  /* FALLTHROUGH */
 
@@ -3553,15 +3555,13 @@ parse_partial_symbols (struct objfile *objfile)
 
 		case stStatic:	/* Variable */
 		  if (SC_IS_DATA (sh.sc))
-		    prim_record_minimal_symbol_and_info (name, minsym_value,
-							 mst_file_data,
-							 SECT_OFF_DATA (objfile),
-							 objfile);
+		    reader.record_with_info (name, minsym_value,
+					     mst_file_data,
+					     SECT_OFF_DATA (objfile));
 		  else
-		    prim_record_minimal_symbol_and_info (name, minsym_value,
-							 mst_file_bss,
-							 SECT_OFF_BSS (objfile),
-							 objfile);
+		    reader.record_with_info (name, minsym_value,
+					     mst_file_bss,
+					     SECT_OFF_BSS (objfile));
 		  theclass = LOC_STATIC;
 		  break;
 
@@ -4885,7 +4885,7 @@ elfmdebug_build_psymtabs (struct objfile *objfile,
     error (_("Error reading ECOFF debugging information: %s"),
 	   bfd_errmsg (bfd_get_error ()));
 
-  mdebug_build_psymtabs (objfile, swap, info);
+  mdebug_build_psymtabs (reader, objfile, swap, info);
 
   reader.install ();
 }
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index b6f306b..8fa5bba 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -64,19 +64,6 @@ struct msym_bunch
     struct minimal_symbol contents[BUNCH_SIZE];
   };
 
-/* Bunch currently being filled up.
-   The next field points to chain of filled bunches.  */
-
-static struct msym_bunch *msym_bunch;
-
-/* Number of slots filled in current bunch.  */
-
-static int msym_bunch_index;
-
-/* Total number of minimal symbols recorded so far for the objfile.  */
-
-static int msym_count;
-
 /* See minsyms.h.  */
 
 unsigned int
@@ -922,14 +909,14 @@ get_symbol_leading_char (bfd *abfd)
 /* See minsyms.h.  */
 
 scoped_minimal_symbol_reader::scoped_minimal_symbol_reader (struct objfile *obj)
-: objfile (obj)
-{
-  msym_count = 0;
-  msym_bunch = NULL;
+: objfile (obj),
+  msym_bunch (NULL),
   /* Note that presetting msym_bunch_index to BUNCH_SIZE causes the
      first call to save a minimal symbol to allocate the memory for
      the first bunch.  */
-  msym_bunch_index = BUNCH_SIZE;
+  msym_bunch_index (BUNCH_SIZE),
+  msym_count (0)
+{
 }
 
 /* Discard the currently collected minimal symbols, if any.  If we wish
@@ -955,9 +942,8 @@ scoped_minimal_symbol_reader::~scoped_minimal_symbol_reader ()
 /* See minsyms.h.  */
 
 void
-prim_record_minimal_symbol (const char *name, CORE_ADDR address,
-			    enum minimal_symbol_type ms_type,
-			    struct objfile *objfile)
+scoped_minimal_symbol_reader::record (const char *name, CORE_ADDR address,
+				      enum minimal_symbol_type ms_type)
 {
   int section;
 
@@ -981,18 +967,17 @@ prim_record_minimal_symbol (const char *name, CORE_ADDR address,
       section = -1;
     }
 
-  prim_record_minimal_symbol_and_info (name, address, ms_type,
-				       section, objfile);
+  record_with_info (name, address, ms_type, section);
 }
 
 /* See minsyms.h.  */
 
 struct minimal_symbol *
-prim_record_minimal_symbol_full (const char *name, int name_len, int copy_name,
-				 CORE_ADDR address,
-				 enum minimal_symbol_type ms_type,
-				 int section,
-				 struct objfile *objfile)
+scoped_minimal_symbol_reader::record_full (const char *name, int name_len,
+					   int copy_name,
+					   CORE_ADDR address,
+					   enum minimal_symbol_type ms_type,
+					   int section)
 {
   struct msym_bunch *newobj;
   struct minimal_symbol *msymbol;
@@ -1056,19 +1041,6 @@ prim_record_minimal_symbol_full (const char *name, int name_len, int copy_name,
   return msymbol;
 }
 
-/* See minsyms.h.  */
-
-struct minimal_symbol *
-prim_record_minimal_symbol_and_info (const char *name, CORE_ADDR address,
-				     enum minimal_symbol_type ms_type,
-				     int section,
-				     struct objfile *objfile)
-{
-  return prim_record_minimal_symbol_full (name, strlen (name), 1,
-					  address, ms_type,
-					  section, objfile);
-}
-
 /* Compare two minimal symbols by address and return a signed result based
    on unsigned comparisons, so that we sort into unsigned numeric order.
    Within groups with the same address, sort by name.  */
diff --git a/gdb/minsyms.h b/gdb/minsyms.h
index 7ba5991..af75267 100644
--- a/gdb/minsyms.h
+++ b/gdb/minsyms.h
@@ -53,16 +53,17 @@ struct bound_minimal_symbol
    as opaque and use functions provided by minsyms.c to inspect them.
 */
 
+struct msym_bunch;
+
 // An RAII-based object that is used to record minimal symbols while
 // they are being read.
 class scoped_minimal_symbol_reader
 {
  public:
 
-  /* Prepare to start collecting minimal symbols.  This should be called
-     by a symbol reader to initialize the minimal symbol module.
-     Currently, minimal symbol table creation is not reentrant; it
-     relies on global (static) variables in minsyms.c.  */
+  /* Prepare to start collecting minimal symbols.  This should be
+     called by a symbol reader to initialize the minimal symbol
+     module.  */
 
   explicit scoped_minimal_symbol_reader (struct objfile *);
 
@@ -73,6 +74,56 @@ class scoped_minimal_symbol_reader
 
   void install ();
 
+  /* Record a new minimal symbol.  This is the "full" entry point;
+     simpler convenience entry points are also provided below.
+   
+     This returns a new minimal symbol.  It is ok to modify the returned
+     minimal symbol (though generally not necessary).  It is not ok,
+     though, to stash the pointer anywhere; as minimal symbols may be
+     moved after creation.  The memory for the returned minimal symbol
+     is still owned by the minsyms.c code, and should not be freed.
+   
+     Arguments are:
+
+     NAME - the symbol's name
+     NAME_LEN - the length of the name
+     COPY_NAME - if true, the minsym code must make a copy of NAME.  If
+     false, then NAME must be NUL-terminated, and must have a lifetime
+     that is at least as long as OBJFILE's lifetime.
+     ADDRESS - the address of the symbol
+     MS_TYPE - the type of the symbol
+     SECTION - the symbol's section
+     appropriate obj_section for the minimal symbol.  This can be NULL.
+     OBJFILE - the objfile associated with the minimal symbol.  */
+
+  struct minimal_symbol *record_full (const char *name,
+				      int name_len,
+				      int copy_name,
+				      CORE_ADDR address,
+				      enum minimal_symbol_type ms_type,
+				      int section);
+
+  /* Like record_full, but:
+     - uses strlen to compute NAME_LEN,
+     - passes COPY_NAME = 1,
+     - and passes a default SECTION, depending on the type
+
+     This variant does not return the new symbol.  */
+
+  void record (const char *, CORE_ADDR, enum minimal_symbol_type);
+
+  /* Like record_full, but:
+     - uses strlen to compute NAME_LEN,
+     - passes COPY_NAME = 1.  */
+
+  struct minimal_symbol *record_with_info (const char *name,
+					   CORE_ADDR address,
+					   enum minimal_symbol_type ms_type,
+					   int section)
+  {
+    return record_full (name, strlen (name), 1, address, ms_type, section);
+  }
+
  private:
 
   // No need for these.  They are intentionally not defined anywhere.
@@ -81,60 +132,21 @@ class scoped_minimal_symbol_reader
   scoped_minimal_symbol_reader (const scoped_minimal_symbol_reader &);
 
   struct objfile *objfile;
-};
 
-/* Record a new minimal symbol.  This is the "full" entry point;
-   simpler convenience entry points are also provided below.
-   
-   This returns a new minimal symbol.  It is ok to modify the returned
-   minimal symbol (though generally not necessary).  It is not ok,
-   though, to stash the pointer anywhere; as minimal symbols may be
-   moved after creation.  The memory for the returned minimal symbol
-   is still owned by the minsyms.c code, and should not be freed.
-   
-   Arguments are:
-
-   NAME - the symbol's name
-   NAME_LEN - the length of the name
-   COPY_NAME - if true, the minsym code must make a copy of NAME.  If
-   false, then NAME must be NUL-terminated, and must have a lifetime
-   that is at least as long as OBJFILE's lifetime.
-   ADDRESS - the address of the symbol
-   MS_TYPE - the type of the symbol
-   SECTION - the symbol's section
-   appropriate obj_section for the minimal symbol.  This can be NULL.
-   OBJFILE - the objfile associated with the minimal symbol.  */
-
-struct minimal_symbol *prim_record_minimal_symbol_full
-    (const char *name,
-     int name_len,
-     int copy_name,
-     CORE_ADDR address,
-     enum minimal_symbol_type ms_type,
-     int section,
-     struct objfile *objfile);
-
-/* Like prim_record_minimal_symbol_full, but:
-   - uses strlen to compute NAME_LEN,
-   - passes COPY_NAME = 1,
-   - and passes a default SECTION, depending on the type
-   
-   This variant does not return the new symbol.  */
+  /* Bunch currently being filled up.
+     The next field points to chain of filled bunches.  */
 
-void prim_record_minimal_symbol (const char *, CORE_ADDR,
-				 enum minimal_symbol_type,
-				 struct objfile *);
+  struct msym_bunch *msym_bunch;
 
-/* Like prim_record_minimal_symbol_full, but:
-   - uses strlen to compute NAME_LEN,
-   - passes COPY_NAME = 1.  */
+  /* Number of slots filled in current bunch.  */
 
-struct minimal_symbol *prim_record_minimal_symbol_and_info
-    (const char *,
-     CORE_ADDR,
-     enum minimal_symbol_type,
-     int section,
-     struct objfile *);
+  int msym_bunch_index;
+
+  /* Total number of minimal symbols recorded so far for the
+     objfile.  */
+
+  int msym_count;
+};
 
 /* Create the terminating entry of OBJFILE's minimal symbol table.
    If OBJFILE->msymbols is zero, allocate a single entry from
diff --git a/gdb/mipsread.c b/gdb/mipsread.c
index e5285d2..ae59747 100644
--- a/gdb/mipsread.c
+++ b/gdb/mipsread.c
@@ -42,7 +42,8 @@
 #include "psymtab.h"
 
 static void
-read_alphacoff_dynamic_symtab (struct section_offsets *,
+read_alphacoff_dynamic_symtab (scoped_minimal_symbol_reader &,
+			       struct section_offsets *,
 			       struct objfile *objfile);
 
 /* Initialize anything that needs initializing when a completely new
@@ -79,12 +80,12 @@ mipscoff_symfile_read (struct objfile *objfile, int symfile_flags)
 	(abfd, (asection *) NULL, &ecoff_data (abfd)->debug_info)))
     error (_("Error reading symbol table: %s"), bfd_errmsg (bfd_get_error ()));
 
-  mdebug_build_psymtabs (objfile, &ecoff_backend (abfd)->debug_swap,
+  mdebug_build_psymtabs (reader, objfile, &ecoff_backend (abfd)->debug_swap,
 			 &ecoff_data (abfd)->debug_info);
 
   /* Add alpha coff dynamic symbols.  */
 
-  read_alphacoff_dynamic_symtab (objfile->section_offsets, objfile);
+  read_alphacoff_dynamic_symtab (reader, objfile->section_offsets, objfile);
 
   /* Install any minimal symbols that have been collected as the current
      minimal symbols for this objfile.  */
@@ -173,7 +174,8 @@ alphacoff_locate_sections (bfd *ignore_abfd, asection *sectp, void *sip)
    them to the minimal symbol table.  */
 
 static void
-read_alphacoff_dynamic_symtab (struct section_offsets *section_offsets,
+read_alphacoff_dynamic_symtab (scoped_minimal_symbol_reader &reader,
+			       struct section_offsets *section_offsets,
 			       struct objfile *objfile)
 {
   bfd *abfd = objfile->obfd;
@@ -388,7 +390,7 @@ read_alphacoff_dynamic_symtab (struct section_offsets *section_offsets,
 	    }
 	}
 
-      prim_record_minimal_symbol (name, sym_value, ms_type, objfile);
+      reader.record (name, sym_value, ms_type);
     }
 
   do_cleanups (cleanups);
diff --git a/gdb/symfile.h b/gdb/symfile.h
index a11c48a..aad9d88 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -652,7 +652,8 @@ void dwarf2_free_objfile (struct objfile *);
 
 /* From mdebugread.c */
 
-extern void mdebug_build_psymtabs (struct objfile *,
+extern void mdebug_build_psymtabs (scoped_minimal_symbol_reader &,
+				   struct objfile *,
 				   const struct ecoff_debug_swap *,
 				   struct ecoff_debug_info *);
 
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 6545e94..de18d7f 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -197,7 +197,8 @@ eb_complaint (int arg1)
 
 static void xcoff_initial_scan (struct objfile *, int);
 
-static void scan_xcoff_symtab (struct objfile *);
+static void scan_xcoff_symtab (scoped_minimal_symbol_reader &,
+			       struct objfile *);
 
 static char *xcoff_next_symbol_text (struct objfile *);
 
@@ -908,10 +909,10 @@ enter_line_range (struct subfile *subfile, unsigned beginoffset,
    This function can read past the end of the symbol table
    (into the string table) but this does no harm.  */
 
-/* Create a new minimal symbol (using prim_record_minimal_symbol_and_info).
+/* Create a new minimal symbol (using record_with_info).
 
    Creation of all new minimal symbols should go through this function
-   rather than calling the various prim_record_[...] functions in order
+   rather than calling the various record functions in order
    to make sure that all symbol addresses get properly relocated.
 
    Arguments are:
@@ -925,18 +926,17 @@ enter_line_range (struct subfile *subfile, unsigned beginoffset,
    OBJFILE - the objfile associated with the minimal symbol.  */
 
 static void
-record_minimal_symbol (const char *name, CORE_ADDR address,
+record_minimal_symbol (scoped_minimal_symbol_reader &reader,
+		       const char *name, CORE_ADDR address,
 		       enum minimal_symbol_type ms_type,
 		       int n_scnum,
 		       struct objfile *objfile)
 {
-
   if (name[0] == '.')
     ++name;
 
-  prim_record_minimal_symbol_and_info (name, address, ms_type,
-				       secnum_to_section (n_scnum, objfile),
-				       objfile);
+  reader.record_with_info (name, address, ms_type,
+			   secnum_to_section (n_scnum, objfile));
 }
 
 /* xcoff has static blocks marked in `.bs', `.es' pairs.  They cannot be
@@ -2178,7 +2178,8 @@ function_outside_compilation_unit_complaint (const char *arg1)
 }
 
 static void
-scan_xcoff_symtab (struct objfile *objfile)
+scan_xcoff_symtab (scoped_minimal_symbol_reader &reader,
+		   struct objfile *objfile)
 {
   struct gdbarch *gdbarch = get_objfile_arch (objfile);
   CORE_ADDR toc_offset = 0;	/* toc offset value in data section.  */
@@ -2288,7 +2289,7 @@ scan_xcoff_symtab (struct objfile *objfile)
 			if (!misc_func_recorded)
 			  {
 			    record_minimal_symbol
-			      (last_csect_name, last_csect_val,
+			      (reader, last_csect_name, last_csect_val,
 			       mst_text, last_csect_sec, objfile);
 			    misc_func_recorded = 1;
 			  }
@@ -2343,7 +2344,7 @@ scan_xcoff_symtab (struct objfile *objfile)
 		       table, except for section symbols.  */
 		    if (*namestring != '.')
 		      record_minimal_symbol
-			(namestring, symbol.n_value,
+			(reader, namestring, symbol.n_value,
 			 sclass == C_HIDEXT ? mst_file_data : mst_data,
 			 symbol.n_scnum, objfile);
 		    break;
@@ -2381,7 +2382,7 @@ scan_xcoff_symtab (struct objfile *objfile)
 			main_aux[0].x_sym.x_fcnary.x_fcn.x_lnnoptr;
 
 		    record_minimal_symbol
-		      (namestring, symbol.n_value,
+		      (reader, namestring, symbol.n_value,
 		       sclass == C_HIDEXT ? mst_file_text : mst_text,
 		       symbol.n_scnum, objfile);
 		    misc_func_recorded = 1;
@@ -2396,7 +2397,7 @@ scan_xcoff_symtab (struct objfile *objfile)
 		       symbols, we will choose mst_text over
 		       mst_solib_trampoline.  */
 		    record_minimal_symbol
-		      (namestring, symbol.n_value,
+		      (reader, namestring, symbol.n_value,
 		       mst_solib_trampoline, symbol.n_scnum, objfile);
 		    misc_func_recorded = 1;
 		    break;
@@ -2418,7 +2419,7 @@ scan_xcoff_symtab (struct objfile *objfile)
 		       XMC_BS might be possible too.  */
 		    if (*namestring != '.')
 		      record_minimal_symbol
-			(namestring, symbol.n_value,
+			(reader, namestring, symbol.n_value,
 			 sclass == C_HIDEXT ? mst_file_data : mst_data,
 			 symbol.n_scnum, objfile);
 		    break;
@@ -2434,7 +2435,7 @@ scan_xcoff_symtab (struct objfile *objfile)
 		       table, except for section symbols.  */
 		    if (*namestring != '.')
 		      record_minimal_symbol
-			(namestring, symbol.n_value,
+			(reader, namestring, symbol.n_value,
 			 sclass == C_HIDEXT ? mst_file_bss : mst_bss,
 			 symbol.n_scnum, objfile);
 		    break;
@@ -2462,7 +2463,7 @@ scan_xcoff_symtab (struct objfile *objfile)
 		   it as a function.  This will take care of functions like
 		   strcmp() compiled by xlc.  */
 
-		record_minimal_symbol (last_csect_name, last_csect_val,
+		record_minimal_symbol (reader, last_csect_name, last_csect_val,
 				       mst_text, last_csect_sec, objfile);
 		misc_func_recorded = 1;
 	      }
@@ -3011,7 +3012,7 @@ xcoff_initial_scan (struct objfile *objfile, int symfile_flags)
   /* Now that the symbol table data of the executable file are all in core,
      process them and define symbols accordingly.  */
 
-  scan_xcoff_symtab (objfile);
+  scan_xcoff_symtab (reader, objfile);
 
   /* Install any minimal symbols that have been collected as the current
      minimal symbols for this objfile.  */
