public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFA v3 3/6] Introduce partial_symbol::address
  2018-06-07 16:20 [RFA v3 0/6] Make psymbols independent of the progspace Tom Tromey
  2018-06-07 16:20 ` [RFA v3 1/6] Remove dead code in end_psymtab Tom Tromey
  2018-06-07 16:20 ` [RFA v3 4/6] Introduce accessors for psymtab high and low fields Tom Tromey
@ 2018-06-07 16:20 ` Tom Tromey
  2018-07-17 16:05   ` Simon Marchi
  2018-06-07 16:20 ` [RFA v3 2/6] Change representation of psymbol to flush out accessors Tom Tromey
                   ` (3 subsequent siblings)
  6 siblings, 1 reply; 15+ messages in thread
From: Tom Tromey @ 2018-06-07 16:20 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This introduces a partial_symbol::address method.  This method takes
an objfile argument.  This is necessary so that we can later relocate
a partial symbol at its point of use.  It also adds a "raw" form of
the accessor, to compute the unrelocated value; and a method to be
used for setting the field.

Note that the new method doesn't actually perform any relocation yet.
That will come in a subsequent patch.  However, the comments are
written to reflect the intended, rather than the temporary, semantics.

gdb/ChangeLog
2018-06-07  Tom Tromey  <tromey@redhat.com>

	* psympriv.h (struct partial_symbol) <raw_address, address,
	set_address>: New methods.
	* psymtab.c (find_pc_sect_psymtab_closer, find_pc_sect_psymbol)
	(fixup_psymbol_section, relocate_psymtabs): Update.
	(print_partial_symbols): Add 'objfile' parameter.  Update.
	(dump_psymtab, add_psymbol_to_bcache, psym_fill_psymbol_map):
	Update.
---
 gdb/ChangeLog  | 10 ++++++++++
 gdb/psympriv.h | 20 ++++++++++++++++++++
 gdb/psymtab.c  | 43 +++++++++++++++++++++++--------------------
 3 files changed, 53 insertions(+), 20 deletions(-)

diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index f3cb0a6ba15..ec2d9923c1b 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -44,6 +44,26 @@ struct partial_symbol : public general_symbol_info
     return nullptr;
   }
 
+  /* Return the unrelocated address of this partial symbol.  */
+  CORE_ADDR raw_address () const
+  {
+    return value.address;
+  }
+
+  /* Return the address of this partial symbol, relocated according to
+     the offsets provided in OBJFILE.  */
+  CORE_ADDR address (struct objfile *objfile) const
+  {
+    return value.address;
+  }
+
+  /* Set the address of this partial symbol.  The address must be
+     unrelocated.  */
+  void set_address (CORE_ADDR addr)
+  {
+    value.address = addr;
+  }
+
   /* Name space code.  */
 
   ENUM_BITFIELD(domain_enum_tag) domain : SYMBOL_DOMAIN_BITS;
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 9a06d68f91e..58df3c69a78 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -267,7 +267,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
 	     object's symbol table.  */
 	  p = find_pc_sect_psymbol (objfile, tpst, pc, section);
 	  if (p != NULL
-	      && (p->value.address == BMSYMBOL_VALUE_ADDRESS (msymbol)))
+	      && (p->address (objfile) == BMSYMBOL_VALUE_ADDRESS (msymbol)))
 	    return tpst;
 
 	  /* Also accept the textlow value of a psymtab as a
@@ -275,7 +275,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
 	     symbol tables with line information but no debug
 	     symbols (e.g. those produced by an assembler).  */
 	  if (p != NULL)
-	    this_addr = p->value.address;
+	    this_addr = p->address (objfile);
 	  else
 	    this_addr = tpst->textlow;
 
@@ -333,7 +333,8 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
 		 object's symbol table.  */
 	      p = find_pc_sect_psymbol (objfile, pst, pc, section);
 	      if (p == NULL
-		  || (p->value.address != BMSYMBOL_VALUE_ADDRESS (msymbol)))
+		  || (p->address (objfile)
+		      != BMSYMBOL_VALUE_ADDRESS (msymbol)))
 		goto next;
 	    }
 
@@ -425,10 +426,10 @@ find_pc_sect_psymbol (struct objfile *objfile,
 
       if (p->domain == VAR_DOMAIN
 	  && p->aclass == LOC_BLOCK
-	  && pc >= p->value.address
-	  && (p->value.address > best_pc
+	  && pc >= p->address (objfile)
+	  && (p->address (objfile) > best_pc
 	      || (psymtab->textlow == 0
-		  && best_pc == 0 && p->value.address == 0)))
+		  && best_pc == 0 && p->address (objfile) == 0)))
 	{
 	  if (section != NULL)  /* Match on a specific section.  */
 	    {
@@ -437,7 +438,7 @@ find_pc_sect_psymbol (struct objfile *objfile,
 					  section))
 		continue;
 	    }
-	  best_pc = p->value.address;
+	  best_pc = p->address (objfile);
 	  best = p;
 	}
     }
@@ -448,10 +449,10 @@ find_pc_sect_psymbol (struct objfile *objfile,
 
       if (p->domain == VAR_DOMAIN
 	  && p->aclass == LOC_BLOCK
-	  && pc >= p->value.address
-	  && (p->value.address > best_pc
+	  && pc >= p->address (objfile)
+	  && (p->address (objfile) > best_pc
 	      || (psymtab->textlow == 0
-		  && best_pc == 0 && p->value.address == 0)))
+		  && best_pc == 0 && p->address (objfile) == 0)))
 	{
 	  if (section != NULL)  /* Match on a specific section.  */
 	    {
@@ -460,7 +461,7 @@ find_pc_sect_psymbol (struct objfile *objfile,
 					  section))
 		continue;
 	    }
-	  best_pc = p->value.address;
+	  best_pc = p->address (objfile);
 	  best = p;
 	}
     }
@@ -486,7 +487,7 @@ fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
     case LOC_STATIC:
     case LOC_LABEL:
     case LOC_BLOCK:
-      addr = psym->value.address;
+      addr = psym->address (objfile);
       break;
     default:
       /* Nothing else will be listed in the minsyms -- no use looking
@@ -813,13 +814,15 @@ psym_relocate (struct objfile *objfile,
     {
       fixup_psymbol_section (psym, objfile);
       if (psym->section >= 0)
-	psym->value.address += ANOFFSET (delta, psym->section);
+	psym->set_address (psym->raw_address ()
+			   + ANOFFSET (delta, psym->section));
     }
   for (partial_symbol *psym : objfile->static_psymbols)
     {
       fixup_psymbol_section (psym, objfile);
       if (psym->section >= 0)
-	psym->value.address += ANOFFSET (delta, psym->section);
+	psym->set_address (psym->raw_address ()
+			   + ANOFFSET (delta, psym->section));
     }
 
   objfile->psymbol_map.clear ();
@@ -883,7 +886,7 @@ psym_forget_cached_source_info (struct objfile *objfile)
 }
 
 static void
-print_partial_symbols (struct gdbarch *gdbarch,
+print_partial_symbols (struct gdbarch *gdbarch, struct objfile *objfile,
 		       struct partial_symbol **p, int count, const char *what,
 		       struct ui_file *outfile)
 {
@@ -967,7 +970,7 @@ print_partial_symbols (struct gdbarch *gdbarch,
 	  break;
 	}
       fputs_filtered (", ", outfile);
-      fputs_filtered (paddress (gdbarch, (*p)->value.address), outfile);
+      fputs_filtered (paddress (gdbarch, (*p)->raw_address ()), outfile);
       fprintf_filtered (outfile, "\n");
       p++;
     }
@@ -1032,13 +1035,13 @@ dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
     }
   if (psymtab->n_global_syms > 0)
     {
-      print_partial_symbols (gdbarch,
+      print_partial_symbols (gdbarch, objfile,
 			     &objfile->global_psymbols[psymtab->globals_offset],
 			     psymtab->n_global_syms, "Global", outfile);
     }
   if (psymtab->n_static_syms > 0)
     {
-      print_partial_symbols (gdbarch,
+      print_partial_symbols (gdbarch, objfile,
 			     &objfile->static_psymbols[psymtab->statics_offset],
 			     psymtab->n_static_syms, "Static", outfile);
     }
@@ -1475,7 +1478,7 @@ psym_fill_psymbol_map (struct objfile *objfile,
 
       if (psym->aclass == LOC_STATIC)
 	{
-	  CORE_ADDR addr = psym->value.address;
+	  CORE_ADDR addr = psym->raw_address ();
 	  if (seen_addrs->find (addr) == seen_addrs->end ())
 	    {
 	      seen_addrs->insert (addr);
@@ -1718,7 +1721,7 @@ add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
 {
   struct partial_symbol psymbol;
 
-  psymbol.value.address = coreaddr;
+  psymbol.set_address (coreaddr);
   psymbol.section = -1;
   psymbol.domain = domain;
   psymbol.aclass = theclass;
-- 
2.13.6

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [RFA v3 6/6] Make psymbols and psymtabs independent of the program space
  2018-06-07 16:20 [RFA v3 0/6] Make psymbols independent of the progspace Tom Tromey
                   ` (3 preceding siblings ...)
  2018-06-07 16:20 ` [RFA v3 2/6] Change representation of psymbol to flush out accessors Tom Tromey
@ 2018-06-07 16:20 ` Tom Tromey
       [not found]   ` <17305a06-9fbb-84d1-c596-c9bfece81aab@ericsson.com>
  2018-06-07 16:20 ` [RFA v3 5/6] Add validity bits for psymtab high and low fields Tom Tromey
  2018-06-18 14:49 ` [RFA v3 0/6] Make psymbols independent of the progspace Tom Tromey
  6 siblings, 1 reply; 15+ messages in thread
From: Tom Tromey @ 2018-06-07 16:20 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This patch finally makes partial symbols and partial symtabs
independent of the program space.

Specifically:

It changes add_psymbol_to_list to accept a section index, and changes
the psymbol readers to pass this.  At the same time it removes the
code to add the objfile's section offset to the psymbol.

It adds an objfile argument to the psymtab textlow and texthigh
accessors and changes some code to use the raw variants instead.

It removes the "relocate" method from struct quick_symbol_functions,
as it is no longer needed any more.

It changes partial_symbol::address so that the relevant offset is now
applied at the point of use.

gdb/ChangeLog
2018-06-07  Tom Tromey  <tom@tromey.com>

	* dwarf-index-write.c (add_address_entry): Don't add objfile
	offsets.
	* dbxread.c (find_stab_function_addr): Use
	MSYMBOL_VALUE_RAW_ADDRESS.
	(read_dbx_symtab): Use raw_text_low, raw_text_high.
	Don't add objfile offsets.
	(end_psymtab): Use raw_text_low, raw_text_high,
	MSYMBOL_VALUE_RAW_ADDRESS.
	(read_ofile_symtab): Update.
	* dwarf2read.c (create_addrmap_from_index): Don't add objfile
	offsets.
	(dw2_relocate): Remove.
	(dw2_find_pc_sect_symtab): Bias PC by the text offset before
	searching addrmap.
	(dwarf2_gdb_index_functions, dwarf2_debug_names_functions):
	Update.
	(process_psymtab_comp_unit_reader, add_partial_symbol)
	(add_partial_subprogram, dwarf2_ranges_read): Don't add objfile
	offsets.  Update.
	(load_partial_dies): Update.
	(add_address_entry): Don't add objfile offsets.
	(dwarf2_build_include_psymtabs): Update.
	(create_addrmap_from_aranges): Don't add objfile offsets.
	(dw2_find_pc_sect_compunit_symtab): Update.
	* mdebugread.c (parse_symbol): Don't add objfile offsets.
	(parse_lines): Remove 'pst' parameter, replace with 'textlow'.
	Update.
	(parse_partial_symbols): Don't add objfile offsets.  Use
	raw_text_low, raw_text_high.  Update.
	(handle_psymbol_enumerators, psymtab_to_symtab_1): Update.
	* objfiles.c (objfile_relocate1): Don't relocate psymtabs_addrmap
	or call 'relocate' quick function.  Clear psymbol_map.
	* psympriv.h (struct partial_symbol) <address>: Add section
	offset.
	<raw_text_low, raw_text_high>: New methods.
	<text_low, text_high>: Add objfile parameter.
	(add_psymbol_to_bcache): Add 'section' parameter.
	* psymtab.c (find_pc_sect_psymtab_closer, find_pc_sect_psymtab)
	(find_pc_psymbol): Update.
	(fixup_psymbol_section, relocate_psymtabs): Remove.
	(dump_psymtab, psym_functions): Update.
	(add_psymbol_to_bcache, add_psymbol_to_list): Add 'section'
	parameter.
	(maintenance_info_psymtabs, maintenance_check_psymtabs): Update.
	(start_psymtab_common): Update.
	* symfile-debug.c (debug_qf_relocate): Remove.
	(debug_sym_quick_functions): Update.
	* symfile.h (struct quick_symbol_functions) <relocate>: Remove.
	* xcoffread.c (scan_xcoff_symtab): Don't add objfile offsets.
	Update.
---
 gdb/ChangeLog           |  53 ++++++++++++++++++++
 gdb/dbxread.c           |  80 ++++++++++++------------------
 gdb/dwarf-index-write.c |   8 +--
 gdb/dwarf2read.c        |  98 ++++++++++++++++++++-----------------
 gdb/mdebugread.c        | 107 ++++++++++++++++------------------------
 gdb/objfiles.c          |  11 ++---
 gdb/psympriv.h          |  25 ++++++++--
 gdb/psymtab.c           | 127 ++++++++++++------------------------------------
 gdb/symfile-debug.c     |  18 -------
 gdb/symfile.h           |   6 ---
 gdb/xcoffread.c         |  27 +++++-----
 11 files changed, 249 insertions(+), 311 deletions(-)

diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 204937a9db8..143dd1c9c96 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -938,7 +938,7 @@ find_stab_function_addr (const char *namestring, const char *filename,
       msym = lookup_minimal_symbol (p, NULL, objfile);
     }
 
-  return msym.minsym == NULL ? 0 : BMSYMBOL_VALUE_ADDRESS (msym);
+  return msym.minsym == NULL ? 0 : MSYMBOL_VALUE_RAW_ADDRESS (msym.minsym);
 }
 
 static void
@@ -1131,18 +1131,15 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 	      || (namestring[(nsl = strlen (namestring)) - 1] == 'o'
 		  && namestring[nsl - 2] == '.'))
 	    {
-	      nlist.n_value += ANOFFSET (objfile->section_offsets,
-					 SECT_OFF_TEXT (objfile));
-
 	      if (past_first_source_file && pst
 		  /* The gould NP1 uses low values for .o and -l symbols
 		     which are not the address.  */
-		  && nlist.n_value >= pst->text_low ())
+		  && nlist.n_value >= pst->raw_text_low ())
 		{
 		  dbx_end_psymtab (objfile, pst, psymtab_include_list,
 				   includes_used, symnum * symbol_size,
-				   nlist.n_value > pst->text_high ()
-				   ? nlist.n_value : pst->text_high (),
+				   nlist.n_value > pst->raw_text_high ()
+				   ? nlist.n_value : pst->raw_text_high (),
 				   dependency_list, dependencies_used,
 				   textlow_not_set);
 		  pst = (struct partial_symtab *) 0;
@@ -1229,8 +1226,7 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 	    static const char *dirname_nso;
 	    int prev_textlow_not_set;
 
-	    valu = nlist.n_value + ANOFFSET (objfile->section_offsets,
-					     SECT_OFF_TEXT (objfile));
+	    valu = nlist.n_value;
 
 	    prev_textlow_not_set = textlow_not_set;
 
@@ -1257,8 +1253,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		  {
 		    dbx_end_psymtab (objfile, pst, psymtab_include_list,
 				     includes_used, symnum * symbol_size,
-				     (valu > pst->text_high ()
-				      ? valu : pst->text_high ()),
+				     (valu > pst->raw_text_high ()
+				      ? valu : pst->raw_text_high ()),
 				     dependency_list, dependencies_used,
 				     prev_textlow_not_set);
 		    pst = (struct partial_symtab *) 0;
@@ -1432,7 +1428,7 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		 function relative stabs, or the address of the function's
 		 end for old style stabs.  */
 	      valu = nlist.n_value + last_function_start;
-	      if (pst->text_high () == 0 || valu > pst->text_high ())
+	      if (pst->raw_text_high () == 0 || valu > pst->raw_text_high ())
 		pst->set_text_high (valu);
 	      break;
 	    }
@@ -1472,25 +1468,22 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 	  switch (p[1])
 	    {
 	    case 'S':
-	      nlist.n_value += ANOFFSET (objfile->section_offsets,
-					 data_sect_index);
-
 	      if (gdbarch_static_transform_name_p (gdbarch))
 		gdbarch_static_transform_name (gdbarch, namestring);
 
 	      add_psymbol_to_list (sym_name, sym_len, 1,
 				   VAR_DOMAIN, LOC_STATIC,
+				   data_sect_index,
 				   &objfile->static_psymbols,
 				   nlist.n_value, psymtab_language, objfile);
 	      continue;
 
 	    case 'G':
-	      nlist.n_value += ANOFFSET (objfile->section_offsets,
-					 data_sect_index);
 	      /* The addresses in these entries are reported to be
 		 wrong.  See the code that reads 'G's for symtabs.  */
 	      add_psymbol_to_list (sym_name, sym_len, 1,
 				   VAR_DOMAIN, LOC_STATIC,
+				   data_sect_index,
 				   &objfile->global_psymbols,
 				   nlist.n_value, psymtab_language, objfile);
 	      continue;
@@ -1507,14 +1500,14 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		      && namestring[0] != ' '))
 		{
 		  add_psymbol_to_list (sym_name, sym_len, 1,
-				       STRUCT_DOMAIN, LOC_TYPEDEF,
+				       STRUCT_DOMAIN, LOC_TYPEDEF, -1,
 				       &objfile->static_psymbols,
 				       0, psymtab_language, objfile);
 		  if (p[2] == 't')
 		    {
 		      /* Also a typedef with the same name.  */
 		      add_psymbol_to_list (sym_name, sym_len, 1,
-					   VAR_DOMAIN, LOC_TYPEDEF,
+					   VAR_DOMAIN, LOC_TYPEDEF, -1,
 					   &objfile->static_psymbols,
 					   0, psymtab_language, objfile);
 		      p += 1;
@@ -1526,7 +1519,7 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 	      if (p != namestring)	/* a name is there, not just :T...  */
 		{
 		  add_psymbol_to_list (sym_name, sym_len, 1,
-				       VAR_DOMAIN, LOC_TYPEDEF,
+				       VAR_DOMAIN, LOC_TYPEDEF, -1,
 				       &objfile->static_psymbols,
 				       0, psymtab_language, objfile);
 		}
@@ -1587,7 +1580,7 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		      /* Note that the value doesn't matter for
 			 enum constants in psymtabs, just in symtabs.  */
 		      add_psymbol_to_list (p, q - p, 1,
-					   VAR_DOMAIN, LOC_CONST,
+					   VAR_DOMAIN, LOC_CONST, -1,
 					   &objfile->static_psymbols, 0,
 					   psymtab_language, objfile);
 		      /* Point past the name.  */
@@ -1605,7 +1598,7 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 	    case 'c':
 	      /* Constant, e.g. from "const" in Pascal.  */
 	      add_psymbol_to_list (sym_name, sym_len, 1,
-				   VAR_DOMAIN, LOC_CONST,
+				   VAR_DOMAIN, LOC_CONST, -1,
 				   &objfile->static_psymbols, 0,
 				   psymtab_language, objfile);
 	      continue;
@@ -1621,14 +1614,11 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		  function_outside_compilation_unit_complaint (name);
 		  xfree (name);
 		}
-	      nlist.n_value += ANOFFSET (objfile->section_offsets, 
-					 SECT_OFF_TEXT (objfile));
 	      /* Kludges for ELF/STABS with Sun ACC.  */
 	      last_function_name = namestring;
 	      /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
 		 value for the bottom of the text seg in those cases.  */
-	      if (nlist.n_value == ANOFFSET (objfile->section_offsets, 
-					     SECT_OFF_TEXT (objfile))
+	      if (nlist.n_value == 0
 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
 		{
 		  CORE_ADDR minsym_valu = 
@@ -1662,16 +1652,15 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		 the partial symbol table.  */
 	      if (pst
 		  && (textlow_not_set
-		      || (nlist.n_value < pst->text_low ()
-			  && (nlist.n_value
-			      != ANOFFSET (objfile->section_offsets,
-					   SECT_OFF_TEXT (objfile))))))
+		      || (nlist.n_value < pst->raw_text_low ()
+			  && (nlist.n_value != 0))))
 		{
 		  pst->set_text_low (nlist.n_value);
 		  textlow_not_set = 0;
 		}
 	      add_psymbol_to_list (sym_name, sym_len, 1,
 				   VAR_DOMAIN, LOC_BLOCK,
+				   SECT_OFF_TEXT (objfile),
 				   &objfile->static_psymbols,
 				   nlist.n_value, psymtab_language, objfile);
 	      continue;
@@ -1690,14 +1679,11 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		  function_outside_compilation_unit_complaint (name);
 		  xfree (name);
 		}
-	      nlist.n_value += ANOFFSET (objfile->section_offsets, 
-					 SECT_OFF_TEXT (objfile));
 	      /* Kludges for ELF/STABS with Sun ACC.  */
 	      last_function_name = namestring;
 	      /* Do not fix textlow==0 for .o or NLM files, as 0 is a legit
 		 value for the bottom of the text seg in those cases.  */
-	      if (nlist.n_value == ANOFFSET (objfile->section_offsets, 
-					     SECT_OFF_TEXT (objfile))
+	      if (nlist.n_value == 0
 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
 		{
 		  CORE_ADDR minsym_valu = 
@@ -1731,16 +1717,15 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		 the partial symbol table.  */
 	      if (pst
 		  && (textlow_not_set
-		      || (nlist.n_value < pst->text_low ()
-			  && (nlist.n_value
-			      != ANOFFSET (objfile->section_offsets,
-					   SECT_OFF_TEXT (objfile))))))
+		      || (nlist.n_value < pst->raw_text_low ()
+			  && (nlist.n_value != 0))))
 		{
 		  pst->set_text_low (nlist.n_value);
 		  textlow_not_set = 0;
 		}
 	      add_psymbol_to_list (sym_name, sym_len, 1,
 				   VAR_DOMAIN, LOC_BLOCK,
+				   SECT_OFF_TEXT (objfile),
 				   &objfile->global_psymbols,
 				   nlist.n_value, psymtab_language, objfile);
 	      continue;
@@ -1915,15 +1900,14 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
       /* Don't set PSYMTAB_TEXTHIGH(pst) lower than it already is.  */
       CORE_ADDR text_end =
 	(lowest_text_address == (CORE_ADDR) -1
-	 ? (text_addr + ANOFFSET (objfile->section_offsets,
-				  SECT_OFF_TEXT (objfile)))
+	 ? text_addr
 	 : lowest_text_address)
 	+ text_size;
 
       dbx_end_psymtab (objfile, pst, psymtab_include_list, includes_used,
 		       symnum * symbol_size,
-		       (text_end > pst->text_high ()
-			? text_end : pst->text_high ()),
+		       (text_end > pst->raw_text_high ()
+			? text_end : pst->raw_text_high ()),
 		       dependency_list, dependencies_used, textlow_not_set);
     }
 }
@@ -1995,7 +1979,7 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
      a reliable texthigh by taking the address plus size of the
      last function in the file.  */
 
-  if (pst->text_high () == 0 && last_function_name
+  if (pst->raw_text_high () == 0 && last_function_name
       && gdbarch_sofun_address_maybe_missing (gdbarch))
     {
       int n;
@@ -2022,7 +2006,7 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
 	}
 
       if (minsym.minsym)
-	pst->set_text_high (BMSYMBOL_VALUE_ADDRESS (minsym)
+	pst->set_text_high (MSYMBOL_VALUE_RAW_ADDRESS (minsym.minsym)
 			    + MSYMBOL_SIZE (minsym.minsym));
 
       last_function_name = NULL;
@@ -2032,7 +2016,7 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
     ;
   /* This test will be true if the last .o file is only data.  */
   else if (textlow_not_set)
-    pst->set_text_low (pst->text_high ());
+    pst->set_text_low (pst->raw_text_high ());
   else
     {
       struct partial_symtab *p1;
@@ -2045,7 +2029,7 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
       ALL_OBJFILE_PSYMTABS (objfile, p1)
       {
 	if (!p1->texthigh_valid && p1->textlow_valid && p1 != pst)
-	  p1->set_text_high (pst->text_low ());
+	  p1->set_text_high (pst->raw_text_low ());
       }
     }
 
@@ -2232,8 +2216,8 @@ read_ofile_symtab (struct objfile *objfile, struct partial_symtab *pst)
 
   sym_offset = LDSYMOFF (pst);
   sym_size = LDSYMLEN (pst);
-  text_offset = pst->text_low ();
-  text_size = pst->text_high () - pst->text_low ();
+  text_offset = pst->text_low (objfile);
+  text_size = pst->text_high (objfile) - pst->text_low (objfile);
   section_offsets = objfile->section_offsets;
 
   dbxread_objfile = objfile;
diff --git a/gdb/dwarf-index-write.c b/gdb/dwarf-index-write.c
index 0210d2e7194..fd245a09d89 100644
--- a/gdb/dwarf-index-write.c
+++ b/gdb/dwarf-index-write.c
@@ -427,12 +427,8 @@ static void
 add_address_entry (struct objfile *objfile, data_buf &addr_vec,
 		   CORE_ADDR start, CORE_ADDR end, unsigned int cu_index)
 {
-  CORE_ADDR baseaddr;
-
-  baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
-
-  addr_vec.append_uint (8, BFD_ENDIAN_LITTLE, start - baseaddr);
-  addr_vec.append_uint (8, BFD_ENDIAN_LITTLE, end - baseaddr);
+  addr_vec.append_uint (8, BFD_ENDIAN_LITTLE, start);
+  addr_vec.append_uint (8, BFD_ENDIAN_LITTLE, end);
   addr_vec.append_data (MAYBE_SWAP (cu_index));
 }
 
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index d29ff8b9bb8..e45c2d4ca11 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -3172,8 +3172,8 @@ create_addrmap_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
 	  continue;
 	}
 
-      lo = gdbarch_adjust_dwarf2_addr (gdbarch, lo + baseaddr);
-      hi = gdbarch_adjust_dwarf2_addr (gdbarch, hi + baseaddr);
+      lo = gdbarch_adjust_dwarf2_addr (gdbarch, lo + baseaddr) - baseaddr;
+      hi = gdbarch_adjust_dwarf2_addr (gdbarch, hi + baseaddr) - baseaddr;
       addrmap_set_empty (mutable_map, lo, hi - 1,
 			 dwarf2_per_objfile->get_cu (cu_index));
     }
@@ -3331,8 +3331,10 @@ create_addrmap_from_aranges (struct dwarf2_per_objfile *dwarf2_per_objfile,
 	      continue;
 	    }
 	  ULONGEST end = start + length;
-	  start = gdbarch_adjust_dwarf2_addr (gdbarch, start + baseaddr);
-	  end = gdbarch_adjust_dwarf2_addr (gdbarch, end + baseaddr);
+	  start = (gdbarch_adjust_dwarf2_addr (gdbarch, start + baseaddr)
+		   - baseaddr);
+	  end = (gdbarch_adjust_dwarf2_addr (gdbarch, end + baseaddr)
+		 - baseaddr);
 	  addrmap_set_empty (mutable_map, start, end - 1, per_cu);
 	}
     }
@@ -4094,14 +4096,6 @@ dw2_dump (struct objfile *objfile)
 }
 
 static void
-dw2_relocate (struct objfile *objfile,
-	      const struct section_offsets *new_offsets,
-	      const struct section_offsets *delta)
-{
-  /* There's nothing to relocate here.  */
-}
-
-static void
 dw2_expand_symtabs_for_function (struct objfile *objfile,
 				 const char *func_name)
 {
@@ -5232,8 +5226,10 @@ dw2_find_pc_sect_compunit_symtab (struct objfile *objfile,
   if (!objfile->psymtabs_addrmap)
     return NULL;
 
+  CORE_ADDR baseaddr;
+  baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
   data = (struct dwarf2_per_cu_data *) addrmap_find (objfile->psymtabs_addrmap,
-						     pc);
+						     pc - baseaddr);
   if (!data)
     return NULL;
 
@@ -5331,7 +5327,6 @@ const struct quick_symbol_functions dwarf2_gdb_index_functions =
   dw2_lookup_symbol,
   dw2_print_stats,
   dw2_dump,
-  dw2_relocate,
   dw2_expand_symtabs_for_function,
   dw2_expand_all_symtabs,
   dw2_expand_symtabs_with_fullname,
@@ -6144,7 +6139,6 @@ const struct quick_symbol_functions dwarf2_debug_names_functions =
   dw2_debug_names_lookup_symbol,
   dw2_print_stats,
   dw2_debug_names_dump,
-  dw2_relocate,
   dw2_debug_names_expand_symtabs_for_function,
   dw2_expand_all_symtabs,
   dw2_expand_symtabs_with_fullname,
@@ -6542,7 +6536,7 @@ dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
 
   /* NOTE: pst->dirname is DW_AT_comp_dir (if present).  */
   dwarf_decode_lines (lh.get (), pst->dirname, cu, pst,
-		      pst->text_low (), 1);
+		      pst->raw_text_low (), 1);
 }
 
 static hashval_t
@@ -7928,14 +7922,17 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
   cu_bounds_kind = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc,
 					 &best_highpc, cu, pst);
   if (cu_bounds_kind == PC_BOUNDS_HIGH_LOW && best_lowpc < best_highpc)
-    /* Store the contiguous range if it is not empty; it can be empty for
-       CUs with no code.  */
-    addrmap_set_empty (objfile->psymtabs_addrmap,
-		       gdbarch_adjust_dwarf2_addr (gdbarch,
-						   best_lowpc + baseaddr),
-		       gdbarch_adjust_dwarf2_addr (gdbarch,
-						   best_highpc + baseaddr) - 1,
-		       pst);
+    {
+      CORE_ADDR low
+	= (gdbarch_adjust_dwarf2_addr (gdbarch, best_lowpc + baseaddr)
+	   - baseaddr);
+      CORE_ADDR high
+	= (gdbarch_adjust_dwarf2_addr (gdbarch, best_highpc + baseaddr)
+	   - baseaddr - 1);
+      /* Store the contiguous range if it is not empty; it can be
+	 empty for CUs with no code.  */
+      addrmap_set_empty (objfile->psymtabs_addrmap, low, high, pst);
+    }
 
   /* Check if comp unit has_children.
      If so, read the rest of the partial symbols from this comp unit.
@@ -7967,9 +7964,11 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
 	}
     }
   pst->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch,
-						 best_lowpc + baseaddr));
+						 best_lowpc + baseaddr)
+		     - baseaddr);
   pst->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch,
-						  best_highpc + baseaddr));
+						  best_highpc + baseaddr)
+		      - baseaddr);
 
   end_psymtab_common (objfile, pst);
 
@@ -8006,8 +8005,8 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
 			  ", %d global, %d static syms\n",
 			  per_cu->is_debug_types ? "type" : "comp",
 			  sect_offset_str (per_cu->sect_off),
-			  paddress (gdbarch, pst->text_low ()),
-			  paddress (gdbarch, pst->text_high ()),
+			  paddress (gdbarch, pst->text_low (objfile)),
+			  paddress (gdbarch, pst->text_high (objfile)),
 			  pst->n_global_syms, pst->n_static_syms);
     }
 }
@@ -8801,7 +8800,8 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
     {
     case DW_TAG_inlined_subroutine:
     case DW_TAG_subprogram:
-      addr = gdbarch_adjust_dwarf2_addr (gdbarch, pdi->lowpc + baseaddr);
+      addr = (gdbarch_adjust_dwarf2_addr (gdbarch, pdi->lowpc + baseaddr)
+	      - baseaddr);
       if (pdi->is_external || cu->language == language_ada)
 	{
           /* brobecker/2007-12-26: Normally, only "external" DIEs are part
@@ -8811,16 +8811,20 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 	  add_psymbol_to_list (actual_name, strlen (actual_name),
 			       built_actual_name != NULL,
 			       VAR_DOMAIN, LOC_BLOCK,
+			       SECT_OFF_TEXT (objfile),
 			       &objfile->global_psymbols,
-			       addr, cu->language, objfile);
+			       addr,
+			       cu->language, objfile);
 	}
       else
 	{
 	  add_psymbol_to_list (actual_name, strlen (actual_name),
 			       built_actual_name != NULL,
 			       VAR_DOMAIN, LOC_BLOCK,
+			       SECT_OFF_TEXT (objfile),
 			       &objfile->static_psymbols,
-			       addr, cu->language, objfile);
+			       addr,
+			       cu->language, objfile);
 	}
 
       if (pdi->main_subprogram && actual_name != NULL)
@@ -8836,7 +8840,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 	  list = &objfile->static_psymbols;
 	add_psymbol_to_list (actual_name, strlen (actual_name),
 			     built_actual_name != NULL, VAR_DOMAIN, LOC_STATIC,
-			     list, 0, cu->language, objfile);
+			     -1, list, 0, cu->language, objfile);
       }
       break;
     case DW_TAG_variable:
@@ -8871,8 +8875,9 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 	    add_psymbol_to_list (actual_name, strlen (actual_name),
 				 built_actual_name != NULL,
 				 VAR_DOMAIN, LOC_STATIC,
+				 SECT_OFF_TEXT (objfile),
 				 &objfile->global_psymbols,
-				 addr + baseaddr,
+				 addr,
 				 cu->language, objfile);
 	}
       else
@@ -8890,8 +8895,9 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 	  add_psymbol_to_list (actual_name, strlen (actual_name),
 			       built_actual_name != NULL,
 			       VAR_DOMAIN, LOC_STATIC,
+			       SECT_OFF_TEXT (objfile),
 			       &objfile->static_psymbols,
-			       has_loc ? addr + baseaddr : (CORE_ADDR) 0,
+			       has_loc ? addr : 0,
 			       cu->language, objfile);
 	}
       break;
@@ -8900,7 +8906,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
     case DW_TAG_subrange_type:
       add_psymbol_to_list (actual_name, strlen (actual_name),
 			   built_actual_name != NULL,
-			   VAR_DOMAIN, LOC_TYPEDEF,
+			   VAR_DOMAIN, LOC_TYPEDEF, -1,
 			   &objfile->static_psymbols,
 			   0, cu->language, objfile);
       break;
@@ -8908,14 +8914,14 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
     case DW_TAG_namespace:
       add_psymbol_to_list (actual_name, strlen (actual_name),
 			   built_actual_name != NULL,
-			   VAR_DOMAIN, LOC_TYPEDEF,
+			   VAR_DOMAIN, LOC_TYPEDEF, -1,
 			   &objfile->global_psymbols,
 			   0, cu->language, objfile);
       break;
     case DW_TAG_module:
       add_psymbol_to_list (actual_name, strlen (actual_name),
 			   built_actual_name != NULL,
-			   MODULE_DOMAIN, LOC_TYPEDEF,
+			   MODULE_DOMAIN, LOC_TYPEDEF, -1,
 			   &objfile->global_psymbols,
 			   0, cu->language, objfile);
       break;
@@ -8939,7 +8945,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
 	 static vs. global.  */
       add_psymbol_to_list (actual_name, strlen (actual_name),
 			   built_actual_name != NULL,
-			   STRUCT_DOMAIN, LOC_TYPEDEF,
+			   STRUCT_DOMAIN, LOC_TYPEDEF, -1,
 			   cu->language == language_cplus
 			   ? &objfile->global_psymbols
 			   : &objfile->static_psymbols,
@@ -8949,7 +8955,7 @@ add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
     case DW_TAG_enumerator:
       add_psymbol_to_list (actual_name, strlen (actual_name),
 			   built_actual_name != NULL,
-			   VAR_DOMAIN, LOC_CONST,
+			   VAR_DOMAIN, LOC_CONST, -1,
 			   cu->language == language_cplus
 			   ? &objfile->global_psymbols
 			   : &objfile->static_psymbols,
@@ -9032,10 +9038,12 @@ add_partial_subprogram (struct partial_die_info *pdi,
 
 	      baseaddr = ANOFFSET (objfile->section_offsets,
 				   SECT_OFF_TEXT (objfile));
-	      lowpc = gdbarch_adjust_dwarf2_addr (gdbarch,
-						  pdi->lowpc + baseaddr);
-	      highpc = gdbarch_adjust_dwarf2_addr (gdbarch,
-						   pdi->highpc + baseaddr);
+	      lowpc = (gdbarch_adjust_dwarf2_addr (gdbarch,
+						   pdi->lowpc + baseaddr)
+		       - baseaddr);
+	      highpc = (gdbarch_adjust_dwarf2_addr (gdbarch,
+						    pdi->highpc + baseaddr)
+			- baseaddr);
 	      addrmap_set_empty (objfile->psymtabs_addrmap, lowpc, highpc - 1,
 				 cu->per_cu->v.psymtab);
 	    }
@@ -18215,7 +18223,7 @@ load_partial_dies (const struct die_reader_specs *reader,
 	{
 	  if (building_psymtab && pdi.name != NULL)
 	    add_psymbol_to_list (pdi.name, strlen (pdi.name), 0,
-				 VAR_DOMAIN, LOC_TYPEDEF,
+				 VAR_DOMAIN, LOC_TYPEDEF, -1,
 				 &objfile->static_psymbols,
 				 0, cu->language, objfile);
 	  info_ptr = locate_pdi_sibling (reader, &pdi, info_ptr);
@@ -18249,7 +18257,7 @@ load_partial_dies (const struct die_reader_specs *reader,
 	    complaint (_("malformed enumerator DIE ignored"));
 	  else if (building_psymtab)
 	    add_psymbol_to_list (pdi.name, strlen (pdi.name), 0,
-				 VAR_DOMAIN, LOC_CONST,
+				 VAR_DOMAIN, LOC_CONST, -1,
 				 cu->language == language_cplus
 				 ? &objfile->global_psymbols
 				 : &objfile->static_psymbols,
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 3deb8cf2a43..a5ac78f97e6 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -2161,12 +2161,9 @@ parse_external (EXTR *es, int bigend, struct section_offsets *section_offsets,
    numbers can go back and forth, apparently we can live
    with that and do not need to reorder our linetables.  */
 
-static void parse_lines (FDR *, PDR *, struct linetable *, int,
-			 struct partial_symtab *, CORE_ADDR);
-
 static void
 parse_lines (FDR *fh, PDR *pr, struct linetable *lt, int maxlines,
-	     struct partial_symtab *pst, CORE_ADDR lowest_pdr_addr)
+	     CORE_ADDR textlow, CORE_ADDR lowest_pdr_addr)
 {
   unsigned char *base;
   int j, k;
@@ -2197,7 +2194,7 @@ parse_lines (FDR *fh, PDR *pr, struct linetable *lt, int maxlines,
 	halt = base + fh->cbLine;
       base += pr->cbLineOffset;
 
-      adr = pst->text_low () + pr->adr - lowest_pdr_addr;
+      adr = textlow + pr->adr - lowest_pdr_addr;
 
       l = adr >> 2;		/* in words */
       for (lineno = pr->lnLow; base < halt;)
@@ -2620,12 +2617,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
       /* Determine the start address for this object file from the
          file header and relocate it, except for Irix 5.2 zero fh->adr.  */
       if (fh->cpd)
-	{
-	  textlow = fh->adr;
-	  if (relocatable || textlow != 0)
-	    textlow += ANOFFSET (objfile->section_offsets,
-				 SECT_OFF_TEXT (objfile));
-	}
+	textlow = fh->adr;
       else
 	textlow = 0;
       pst = start_psymtab_common (objfile,
@@ -2672,7 +2664,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 	psymtab_language = prev_language;
       PST_PRIVATE (pst)->pst_language = psymtab_language;
 
-      pst->set_text_high (pst->text_low ());
+      pst->set_text_high (pst->raw_text_low ());
 
       /* For stabs-in-ecoff files, the second symbol must be @stab.
          This symbol is emitted by mips-tfile to signal that the
@@ -2718,8 +2710,6 @@ parse_partial_symbols (minimal_symbol_reader &reader,
                                                  mst_file_text, sh.sc,
                                                  objfile);
 			}
-		      sh.value += ANOFFSET (objfile->section_offsets,
-					    SECT_OFF_TEXT (objfile));
 		      procaddr = sh.value;
 
 		      isym = AUX_GET_ISYM (fh->fBigendian,
@@ -2738,9 +2728,9 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 			  /* Kludge for Irix 5.2 zero fh->adr.  */
 			  if (!relocatable
 			      && (!pst->textlow_valid
-				  || procaddr < pst->text_low ()))
+				  || procaddr < pst->raw_text_low ()))
 			    pst->set_text_low (procaddr);
-			  if (high > pst->text_high ())
+			  if (high > pst->raw_text_high ())
 			    pst->set_text_high (high);
 			}
 		    }
@@ -2763,8 +2753,6 @@ parse_partial_symbols (minimal_symbol_reader &reader,
                           record_minimal_symbol (reader, namestring, sh.value,
                                                  mst_file_data, sh.sc,
                                                  objfile);
-			  sh.value += ANOFFSET (objfile->section_offsets,
-						SECT_OFF_DATA (objfile));
 			  break;
 
 			default:
@@ -2774,8 +2762,6 @@ parse_partial_symbols (minimal_symbol_reader &reader,
                           record_minimal_symbol (reader, namestring, sh.value,
                                                  mst_file_bss, sh.sc,
                                                  objfile);
-			  sh.value += ANOFFSET (objfile->section_offsets,
-						SECT_OFF_BSS (objfile));
 			  break;
 			}
 		    }
@@ -2828,22 +2814,16 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 
 		  case N_TEXT | N_EXT:
 		  case N_NBTEXT | N_EXT:
-		    sh.value += ANOFFSET (objfile->section_offsets,
-					  SECT_OFF_TEXT (objfile));
 		    goto record_it;
 
 		  case N_DATA | N_EXT:
 		  case N_NBDATA | N_EXT:
-		    sh.value += ANOFFSET (objfile->section_offsets,
-					  SECT_OFF_DATA (objfile));
 		    goto record_it;
 
 		  case N_BSS:
 		  case N_BSS | N_EXT:
 		  case N_NBBSS | N_EXT:
 		  case N_SETV | N_EXT:		/* FIXME, is this in BSS?  */
-		    sh.value += ANOFFSET (objfile->section_offsets,
-					  SECT_OFF_BSS (objfile));
 		    goto record_it;
 
 		  case N_ABS | N_EXT:
@@ -2866,8 +2846,6 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		    continue;
 
 		  case N_DATA:
-		    sh.value += ANOFFSET (objfile->section_offsets,
-					  SECT_OFF_DATA (objfile));
 		    goto record_it;
 
 		  case N_UNDF | N_EXT:
@@ -3068,27 +3046,24 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		    switch (p[1])
 		      {
 		      case 'S':
-			sh.value += ANOFFSET (objfile->section_offsets,
-					      SECT_OFF_DATA (objfile));
-
 			if (gdbarch_static_transform_name_p (gdbarch))
 			  namestring = gdbarch_static_transform_name
 					 (gdbarch, namestring);
 
 			add_psymbol_to_list (namestring, p - namestring, 1,
 					     VAR_DOMAIN, LOC_STATIC,
+					     SECT_OFF_DATA (objfile),
 					     &objfile->static_psymbols,
 					     sh.value,
 					     psymtab_language, objfile);
 			continue;
 		      case 'G':
-			sh.value += ANOFFSET (objfile->section_offsets,
-					      SECT_OFF_DATA (objfile));
 			/* The addresses in these entries are reported
 			   to be wrong.  See the code that reads 'G's
 			   for symtabs.  */
 			add_psymbol_to_list (namestring, p - namestring, 1,
 					     VAR_DOMAIN, LOC_STATIC,
+					     SECT_OFF_DATA (objfile),
 					     &objfile->global_psymbols,
 					     sh.value,
 					     psymtab_language, objfile);
@@ -3107,6 +3082,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 			  {
 			    add_psymbol_to_list (namestring, p - namestring, 1,
 						 STRUCT_DOMAIN, LOC_TYPEDEF,
+						 -1,
 						 &objfile->static_psymbols,
 						 0, psymtab_language, objfile);
 			    if (p[2] == 't')
@@ -3115,6 +3091,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 				add_psymbol_to_list (namestring,
 						     p - namestring, 1,
 						     VAR_DOMAIN, LOC_TYPEDEF,
+						     -1,
 						     &objfile->static_psymbols,
 						     0, psymtab_language,
 						     objfile);
@@ -3128,6 +3105,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 			  {
 			    add_psymbol_to_list (namestring, p - namestring, 1,
 						 VAR_DOMAIN, LOC_TYPEDEF,
+						 -1,
 						 &objfile->static_psymbols,
 						 0, psymtab_language, objfile);
 			  }
@@ -3192,6 +3170,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 				   symtabs.  */
 				add_psymbol_to_list (p, q - p, 1,
 						     VAR_DOMAIN, LOC_CONST,
+						     -1,
 						     &objfile->static_psymbols,
 						     0, psymtab_language,
 						     objfile);
@@ -3209,7 +3188,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		      case 'c':
 			/* Constant, e.g. from "const" in Pascal.  */
 			add_psymbol_to_list (namestring, p - namestring, 1,
-					     VAR_DOMAIN, LOC_CONST,
+					     VAR_DOMAIN, LOC_CONST, -1,
 					     &objfile->static_psymbols,
 					     0, psymtab_language, objfile);
 			continue;
@@ -3225,10 +3204,9 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 			    function_outside_compilation_unit_complaint (name);
 			    xfree (name);
 			  }
-			sh.value += ANOFFSET (objfile->section_offsets,
-					      SECT_OFF_TEXT (objfile));
 			add_psymbol_to_list (namestring, p - namestring, 1,
 					     VAR_DOMAIN, LOC_BLOCK,
+					     SECT_OFF_TEXT (objfile),
 					     &objfile->static_psymbols,
 					     sh.value,
 					     psymtab_language, objfile);
@@ -3249,10 +3227,9 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 			    function_outside_compilation_unit_complaint (name);
 			    xfree (name);
 			  }
-			sh.value += ANOFFSET (objfile->section_offsets,
-					      SECT_OFF_TEXT (objfile));
 			add_psymbol_to_list (namestring, p - namestring, 1,
 					     VAR_DOMAIN, LOC_BLOCK,
+					     SECT_OFF_TEXT (objfile),
 					     &objfile->global_psymbols,
 					     sh.value,
 					     psymtab_language, objfile);
@@ -3324,7 +3301,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		    continue;
 
 		  case N_RBRAC:
-		    if (sh.value > save_pst->text_high ())
+		    if (sh.value > save_pst->raw_text_high ())
 		      save_pst->set_text_high (sh.value);
 		    continue;
 		  case N_EINCL:
@@ -3380,6 +3357,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 	      char *name;
 	      enum address_class theclass;
 	      CORE_ADDR minsym_value;
+	      short section = -1;
 
 	      (*swap_sym_in) (cur_bfd,
 			      ((char *) debug_info->external_sym
@@ -3414,21 +3392,18 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		  /* The value of a stEnd symbol is the displacement from the
 		     corresponding start symbol value, do not relocate it.  */
 		  if (sh.st != stEnd)
-		    sh.value += ANOFFSET (objfile->section_offsets,
-					  SECT_OFF_TEXT (objfile));
+		    section = SECT_OFF_TEXT (objfile);
 		  break;
 		case scData:
 		case scSData:
 		case scRData:
 		case scPData:
 		case scXData:
-		  sh.value += ANOFFSET (objfile->section_offsets,
-					SECT_OFF_DATA (objfile));
+		  section = SECT_OFF_DATA (objfile);
 		  break;
 		case scBss:
 		case scSBss:
-		  sh.value += ANOFFSET (objfile->section_offsets,
-					SECT_OFF_BSS (objfile));
+		  section = SECT_OFF_BSS (objfile);
 		  break;
 		}
 
@@ -3492,11 +3467,13 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		  if (sh.st == stProc)
 		    add_psymbol_to_list (name, strlen (name), 1,
 					 VAR_DOMAIN, LOC_BLOCK,
+					 section,
 					 &objfile->global_psymbols,
 					 sh.value, psymtab_language, objfile);
 		  else
 		    add_psymbol_to_list (name, strlen (name), 1,
 					 VAR_DOMAIN, LOC_BLOCK,
+					 section,
 					 &objfile->static_psymbols,
 					 sh.value, psymtab_language, objfile);
 
@@ -3514,11 +3491,11 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		  /* Kludge for Irix 5.2 zero fh->adr.  */
 		  if (!relocatable
 		      && (!pst->textlow_valid
-			  || procaddr < pst->text_low ()))
+			  || procaddr < pst->raw_text_low ()))
 		    pst->set_text_low (procaddr);
 
 		  high = procaddr + sh.value;
-		  if (high > pst->text_high ())
+		  if (high > pst->raw_text_high ())
 		    pst->set_text_high (high);
 		  continue;
 
@@ -3562,7 +3539,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		      && sh.index != cur_sdx + 2)
 		    {
 		      add_psymbol_to_list (name, strlen (name), 1,
-					   STRUCT_DOMAIN, LOC_TYPEDEF,
+					   STRUCT_DOMAIN, LOC_TYPEDEF, -1,
 					   &objfile->static_psymbols,
 					   0, psymtab_language, objfile);
 		    }
@@ -3601,7 +3578,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		}
 	      /* Use this gdb symbol.  */
 	      add_psymbol_to_list (name, strlen (name), 1,
-				   VAR_DOMAIN, theclass,
+				   VAR_DOMAIN, theclass, section,
 				   &objfile->static_psymbols,
 				   sh.value, psymtab_language, objfile);
 	    skip:
@@ -3619,6 +3596,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 	      SYMR *psh;
 	      char *name;
 	      CORE_ADDR svalue;
+	      short section;
 
 	      if (ext_ptr->ifd != f_idx)
 		internal_error (__FILE__, __LINE__,
@@ -3632,23 +3610,21 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 	      svalue = psh->value;
 	      switch (psh->sc)
 		{
+		default:
 		case scText:
 		case scRConst:
-		  svalue += ANOFFSET (objfile->section_offsets,
-				      SECT_OFF_TEXT (objfile));
+		  section = SECT_OFF_TEXT (objfile);
 		  break;
 		case scData:
 		case scSData:
 		case scRData:
 		case scPData:
 		case scXData:
-		  svalue += ANOFFSET (objfile->section_offsets,
-				      SECT_OFF_DATA (objfile));
+		  section = SECT_OFF_DATA (objfile);
 		  break;
 		case scBss:
 		case scSBss:
-		  svalue += ANOFFSET (objfile->section_offsets,
-				      SECT_OFF_BSS (objfile));
+		  section = SECT_OFF_BSS (objfile);
 		  break;
 		}
 
@@ -3683,6 +3659,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 	      name = debug_info->ssext + psh->iss;
 	      add_psymbol_to_list (name, strlen (name), 1,
 				   VAR_DOMAIN, theclass,
+				   section,
 				   &objfile->global_psymbols,
 				   svalue, psymtab_language, objfile);
 	    }
@@ -3693,7 +3670,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
       fdr_to_pst[f_idx].pst
 	= dbx_end_psymtab (objfile, save_pst,
 			   psymtab_include_list, includes_used,
-			   -1, save_pst->text_high (),
+			   -1, save_pst->raw_text_high (),
 			   dependency_list, dependencies_used,
 			   textlow_not_set);
       includes_used = 0;
@@ -3718,9 +3695,9 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 	  ALL_OBJFILE_PSYMTABS (objfile, pst)
 	  {
 	    if (save_pst != pst
-		&& save_pst->text_low () >= pst->text_low ()
-		&& save_pst->text_low () < pst->text_high ()
-		&& save_pst->text_high () > pst->text_high ())
+		&& save_pst->raw_text_low () >= pst->raw_text_low ()
+		&& save_pst->raw_text_low () < pst->raw_text_high ()
+		&& save_pst->raw_text_high () > pst->raw_text_high ())
 	      {
 		objfile->flags |= OBJF_REORDERED;
 		break;
@@ -3843,9 +3820,9 @@ handle_psymbol_enumerators (struct objfile *objfile, FDR *fh, int stype,
       /* Note that the value doesn't matter for enum constants
          in psymtabs, just in symtabs.  */
       add_psymbol_to_list (name, strlen (name), 1,
-			   VAR_DOMAIN, LOC_CONST,
-			   &objfile->static_psymbols,
-			   0, psymtab_language, objfile);
+			   VAR_DOMAIN, LOC_CONST, -1,
+			   &objfile->static_psymbols, 0,
+			   psymtab_language, objfile);
       ext_sym += external_sym_size;
     }
 }
@@ -4072,7 +4049,7 @@ psymtab_to_symtab_1 (struct objfile *objfile,
 
       if (! last_symtab_ended)
 	{
-	  cust = end_symtab (pst->text_high (), SECT_OFF_TEXT (objfile));
+	  cust = end_symtab (pst->raw_text_high (), SECT_OFF_TEXT (objfile));
 	  end_stabs ();
 	}
 
@@ -4148,7 +4125,7 @@ psymtab_to_symtab_1 (struct objfile *objfile,
       top_stack->cur_st = COMPUNIT_FILETABS (cust);
       top_stack->cur_block
 	= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), STATIC_BLOCK);
-      BLOCK_START (top_stack->cur_block) = pst->text_low ();
+      BLOCK_START (top_stack->cur_block) = pst->text_low (objfile);
       BLOCK_END (top_stack->cur_block) = 0;
       top_stack->blocktype = stFile;
       top_stack->cur_type = 0;
@@ -4209,7 +4186,7 @@ psymtab_to_symtab_1 (struct objfile *objfile,
 		}
 
 	      parse_lines (fh, pr_block.data (), lines, maxlines,
-			   pst, lowest_pdr_addr);
+			   pst->text_low (objfile), lowest_pdr_addr);
 	      if (lines->nitems < fh->cline)
 		lines = shrink_linetable (lines);
 
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 0432ce62080..1c39188b36a 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -841,6 +841,10 @@ objfile_relocate1 (struct objfile *objfile,
     }
   }
 
+  /* This stores relocated addresses and so must be cleared.  This
+     will cause it to be recreated on demand.  */
+  objfile->psymbol_map.clear ();
+
   /* Relocate isolated symbols.  */
   {
     struct symbol *iter;
@@ -849,13 +853,6 @@ objfile_relocate1 (struct objfile *objfile,
       relocate_one_symbol (iter, objfile, delta);
   }
 
-  if (objfile->psymtabs_addrmap)
-    addrmap_relocate (objfile->psymtabs_addrmap,
-		      ANOFFSET (delta, SECT_OFF_TEXT (objfile)));
-
-  if (objfile->sf)
-    objfile->sf->qf->relocate (objfile, new_offsets, delta);
-
   {
     int i;
 
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 30e81dbe5bc..faf286cf3a2 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -54,7 +54,7 @@ struct partial_symbol : public general_symbol_info
      the offsets provided in OBJFILE.  */
   CORE_ADDR address (struct objfile *objfile) const
   {
-    return value.address;
+    return value.address + ANOFFSET (objfile->section_offsets, section);
   }
 
   /* Set the address of this partial symbol.  The address must be
@@ -98,18 +98,32 @@ enum psymtab_search_status
 
 struct partial_symtab
 {
-  /* Return the low text address of this partial_symtab.  */
-  CORE_ADDR text_low () const
+  /* Return the raw low text address of this partial_symtab.  */
+  CORE_ADDR raw_text_low () const
   {
     return m_textlow;
   }
 
-  /* Return the high text address of this partial_symtab.  */
-  CORE_ADDR text_high () const
+  /* Return the raw high text address of this partial_symtab.  */
+  CORE_ADDR raw_text_high () const
   {
     return m_texthigh;
   }
 
+  /* Return the relocated low text address of this partial_symtab.  */
+  CORE_ADDR text_low (struct objfile *objfile) const
+  {
+    return m_textlow + ANOFFSET (objfile->section_offsets,
+				 SECT_OFF_TEXT (objfile));
+  }
+
+  /* Return the relocated high text address of this partial_symtab.  */
+  CORE_ADDR text_high (struct objfile *objfile) const
+  {
+    return m_texthigh + ANOFFSET (objfile->section_offsets,
+				  SECT_OFF_TEXT (objfile));
+  }
+
   /* Set the low text address of this partial_symtab.  */
   void set_text_low (CORE_ADDR addr)
   {
@@ -269,6 +283,7 @@ struct partial_symtab
 extern void add_psymbol_to_list (const char *, int,
 				 int, domain_enum,
 				 enum address_class,
+				 short /* section */,
 				 std::vector<partial_symbol *> *,
 				 CORE_ADDR,
 				 enum language, struct objfile *);
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 44587fbf785..db97d01e053 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -62,9 +62,6 @@ static struct partial_symbol *find_pc_sect_psymbol (struct objfile *,
 						    CORE_ADDR,
 						    struct obj_section *);
 
-static void fixup_psymbol_section (struct partial_symbol *psym,
-				   struct objfile *objfile);
-
 static struct compunit_symtab *psymtab_to_symtab (struct objfile *objfile,
 						  struct partial_symtab *pst);
 
@@ -232,7 +229,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
 {
   struct partial_symtab *tpst;
   struct partial_symtab *best_pst = pst;
-  CORE_ADDR best_addr = pst->text_low ();
+  CORE_ADDR best_addr = pst->text_low (objfile);
 
   gdb_assert (!pst->psymtabs_addrmap_supported);
 
@@ -256,7 +253,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
      that is closest and still less than the given PC.  */
   for (tpst = pst; tpst != NULL; tpst = tpst->next)
     {
-      if (pc >= tpst->text_low () && pc < tpst->text_high ())
+      if (pc >= tpst->text_low (objfile) && pc < tpst->text_high (objfile))
 	{
 	  struct partial_symbol *p;
 	  CORE_ADDR this_addr;
@@ -277,7 +274,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
 	  if (p != NULL)
 	    this_addr = p->address (objfile);
 	  else
-	    this_addr = tpst->text_low ();
+	    this_addr = tpst->text_low (objfile);
 
 	  /* Check whether it is closer than our current
 	     BEST_ADDR.  Since this symbol address is
@@ -310,6 +307,8 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
 		      struct bound_minimal_symbol msymbol)
 {
   struct partial_symtab *pst;
+  CORE_ADDR baseaddr = ANOFFSET (objfile->section_offsets,
+				 SECT_OFF_TEXT (objfile));
 
   /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
      than the later used TEXTLOW/TEXTHIGH one.  */
@@ -317,7 +316,7 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
   if (objfile->psymtabs_addrmap != NULL)
     {
       pst = ((struct partial_symtab *)
-	     addrmap_find (objfile->psymtabs_addrmap, pc));
+	     addrmap_find (objfile->psymtabs_addrmap, pc - baseaddr));
       if (pst != NULL)
 	{
 	  /* FIXME: addrmaps currently do not handle overlayed sections,
@@ -361,7 +360,7 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
 
   ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
     if (!pst->psymtabs_addrmap_supported
-	&& pc >= pst->text_low () && pc < pst->text_high ())
+	&& pc >= pst->text_low (objfile) && pc < pst->text_high (objfile))
       {
 	struct partial_symtab *best_pst;
 
@@ -411,12 +410,12 @@ find_pc_sect_psymbol (struct objfile *objfile,
 {
   struct partial_symbol *best = NULL;
   CORE_ADDR best_pc;
+  const CORE_ADDR textlow = psymtab->text_low (objfile);
 
   gdb_assert (psymtab != NULL);
 
   /* Cope with programs that start at address 0.  */
-  best_pc = ((psymtab->text_low () != 0)
-	     ? psymtab->text_low () - 1 : 0);
+  best_pc = (textlow != 0) ? textlow - 1 : 0;
 
   /* Search the global symbols as well as the static symbols, so that
      find_pc_partial_function doesn't use a minimal symbol and thus
@@ -429,12 +428,11 @@ find_pc_sect_psymbol (struct objfile *objfile,
 	  && p->aclass == LOC_BLOCK
 	  && pc >= p->address (objfile)
 	  && (p->address (objfile) > best_pc
-	      || (psymtab->text_low () == 0
+	      || (psymtab->text_low (objfile) == 0
 		  && best_pc == 0 && p->address (objfile) == 0)))
 	{
 	  if (section != NULL)  /* Match on a specific section.  */
 	    {
-	      fixup_psymbol_section (p, objfile);
 	      if (!matching_obj_sections (p->obj_section (objfile),
 					  section))
 		continue;
@@ -452,12 +450,11 @@ find_pc_sect_psymbol (struct objfile *objfile,
 	  && p->aclass == LOC_BLOCK
 	  && pc >= p->address (objfile)
 	  && (p->address (objfile) > best_pc
-	      || (psymtab->text_low () == 0
+	      || (psymtab->text_low (objfile) == 0
 		  && best_pc == 0 && p->address (objfile) == 0)))
 	{
 	  if (section != NULL)  /* Match on a specific section.  */
 	    {
-	      fixup_psymbol_section (p, objfile);
 	      if (!matching_obj_sections (p->obj_section (objfile),
 					  section))
 		continue;
@@ -470,35 +467,6 @@ find_pc_sect_psymbol (struct objfile *objfile,
   return best;
 }
 
-static void
-fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
-{
-  CORE_ADDR addr;
-
-  if (psym == NULL)
-    return;
-
-  if (psym->section >= 0)
-    return;
-
-  gdb_assert (objfile);
-
-  switch (psym->aclass)
-    {
-    case LOC_STATIC:
-    case LOC_LABEL:
-    case LOC_BLOCK:
-      addr = psym->address (objfile);
-      break;
-    default:
-      /* Nothing else will be listed in the minsyms -- no use looking
-	 it up.  */
-      return;
-    }
-
-  fixup_section (psym, addr, objfile);
-}
-
 /* Psymtab version of lookup_symbol.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
@@ -795,42 +763,6 @@ psymtab_to_symtab (struct objfile *objfile, struct partial_symtab *pst)
   return pst->compunit_symtab;
 }
 
-/* Psymtab version of relocate.  See its definition in
-   the definition of quick_symbol_functions in symfile.h.  */
-
-static void
-psym_relocate (struct objfile *objfile,
-	       const struct section_offsets *new_offsets,
-	       const struct section_offsets *delta)
-{
-  struct partial_symtab *p;
-
-  ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
-    {
-      p->set_text_low (p->text_low ()
-		       + ANOFFSET (delta, SECT_OFF_TEXT (objfile)));
-      p->set_text_high (p->text_high ()
-			+ ANOFFSET (delta, SECT_OFF_TEXT (objfile)));
-    }
-
-  for (partial_symbol *psym : objfile->global_psymbols)
-    {
-      fixup_psymbol_section (psym, objfile);
-      if (psym->section >= 0)
-	psym->set_address (psym->raw_address ()
-			   + ANOFFSET (delta, psym->section));
-    }
-  for (partial_symbol *psym : objfile->static_psymbols)
-    {
-      fixup_psymbol_section (psym, objfile);
-      if (psym->section >= 0)
-	psym->set_address (psym->raw_address ()
-			   + ANOFFSET (delta, psym->section));
-    }
-
-  objfile->psymbol_map.clear ();
-}
-
 /* Psymtab version of find_last_source_symtab.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
@@ -1015,9 +947,9 @@ dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
     }
 
   fprintf_filtered (outfile, "  Symbols cover text addresses ");
-  fputs_filtered (paddress (gdbarch, psymtab->text_low ()), outfile);
+  fputs_filtered (paddress (gdbarch, psymtab->text_low (objfile)), outfile);
   fprintf_filtered (outfile, "-");
-  fputs_filtered (paddress (gdbarch, psymtab->text_high ()), outfile);
+  fputs_filtered (paddress (gdbarch, psymtab->text_high (objfile)), outfile);
   fprintf_filtered (outfile, "\n");
   fprintf_filtered (outfile, "  Address map supported - %s.\n",
 		    psymtab->psymtabs_addrmap_supported ? "yes" : "no");
@@ -1551,7 +1483,6 @@ const struct quick_symbol_functions psym_functions =
   psym_lookup_symbol,
   psym_print_stats,
   psym_dump,
-  psym_relocate,
   psym_expand_symtabs_for_function,
   psym_expand_all_symtabs,
   psym_expand_symtabs_with_fullname,
@@ -1598,7 +1529,7 @@ start_psymtab_common (struct objfile *objfile,
 
   psymtab = allocate_psymtab (filename, objfile);
   psymtab->set_text_low (textlow);
-  psymtab->set_text_high (psymtab->text_low ()); /* default */
+  psymtab->set_text_high (psymtab->raw_text_low ()); /* default */
   psymtab->globals_offset = global_psymbols.size ();
   psymtab->statics_offset = static_psymbols.size ();
   return psymtab;
@@ -1718,6 +1649,7 @@ static struct partial_symbol *
 add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
 		       domain_enum domain,
 		       enum address_class theclass,
+		       short section,
 		       CORE_ADDR coreaddr,
 		       enum language language, struct objfile *objfile,
 		       int *added)
@@ -1725,7 +1657,7 @@ add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
   struct partial_symbol psymbol;
 
   psymbol.set_address (coreaddr);
-  psymbol.section = -1;
+  psymbol.section = section;
   psymbol.domain = domain;
   psymbol.aclass = theclass;
 
@@ -1759,6 +1691,7 @@ void
 add_psymbol_to_list (const char *name, int namelength, int copy_name,
 		     domain_enum domain,
 		     enum address_class theclass,
+		     short section,
 		     std::vector<partial_symbol *> *list,
 		     CORE_ADDR coreaddr,
 		     enum language language, struct objfile *objfile)
@@ -1769,7 +1702,7 @@ add_psymbol_to_list (const char *name, int namelength, int copy_name,
 
   /* Stash the partial symbol away in the cache.  */
   psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, theclass,
-				coreaddr, language, objfile, &added);
+				section, coreaddr, language, objfile, &added);
 
   /* Do not duplicate global partial symbols.  */
   if (list == &objfile->global_psymbols
@@ -2150,10 +2083,10 @@ maintenance_info_psymtabs (const char *regexp, int from_tty)
 			       psymtab->fullname
 			       ? psymtab->fullname : "(null)");
 	      printf_filtered ("    text addresses ");
-	      fputs_filtered (paddress (gdbarch, psymtab->text_low ()),
+	      fputs_filtered (paddress (gdbarch, psymtab->text_low (objfile)),
 			      gdb_stdout);
 	      printf_filtered (" -- ");
-	      fputs_filtered (paddress (gdbarch, psymtab->text_high ()),
+	      fputs_filtered (paddress (gdbarch, psymtab->text_high (objfile)),
 			      gdb_stdout);
 	      printf_filtered ("\n");
 	      printf_filtered ("    psymtabs_addrmap_supported %s\n",
@@ -2233,14 +2166,16 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
     cust = ps->compunit_symtab;
 
     /* First do some checks that don't require the associated symtab.  */
-    if (ps->text_high () < ps->text_low ())
+    if (ps->text_high (objfile) < ps->text_low (objfile))
       {
 	printf_filtered ("Psymtab ");
 	puts_filtered (ps->filename);
 	printf_filtered (" covers bad range ");
-	fputs_filtered (paddress (gdbarch, ps->text_low ()), gdb_stdout);
+	fputs_filtered (paddress (gdbarch, ps->text_low (objfile)),
+			gdb_stdout);
 	printf_filtered (" - ");
-	fputs_filtered (paddress (gdbarch, ps->text_high ()), gdb_stdout);
+	fputs_filtered (paddress (gdbarch, ps->text_high (objfile)),
+			gdb_stdout);
 	printf_filtered ("\n");
 	continue;
       }
@@ -2285,16 +2220,18 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
 	  }
 	psym++;
       }
-    if (ps->text_high () != 0
-	&& (ps->text_low () < BLOCK_START (b)
-	    || ps->text_high () > BLOCK_END (b)))
+    if (ps->raw_text_high () != 0
+	&& (ps->text_low (objfile) < BLOCK_START (b)
+	    || ps->text_high (objfile) > BLOCK_END (b)))
       {
 	printf_filtered ("Psymtab ");
 	puts_filtered (ps->filename);
 	printf_filtered (" covers ");
-	fputs_filtered (paddress (gdbarch, ps->text_low ()), gdb_stdout);
+	fputs_filtered (paddress (gdbarch, ps->text_low (objfile)),
+			gdb_stdout);
 	printf_filtered (" - ");
-	fputs_filtered (paddress (gdbarch, ps->text_high ()), gdb_stdout);
+	fputs_filtered (paddress (gdbarch, ps->text_high (objfile)),
+			gdb_stdout);
 	printf_filtered (" but symtab covers only ");
 	fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
 	printf_filtered (" - ");
diff --git a/gdb/symfile-debug.c b/gdb/symfile-debug.c
index 9d8007d92e9..3aab1736b4d 100644
--- a/gdb/symfile-debug.c
+++ b/gdb/symfile-debug.c
@@ -194,23 +194,6 @@ debug_qf_dump (struct objfile *objfile)
 }
 
 static void
-debug_qf_relocate (struct objfile *objfile,
-		   const struct section_offsets *new_offsets,
-		   const struct section_offsets *delta)
-{
-  const struct debug_sym_fns_data *debug_data
-    = ((const struct debug_sym_fns_data *)
-       objfile_data (objfile, symfile_debug_objfile_data_key));
-
-  fprintf_filtered (gdb_stdlog, "qf->relocate (%s, %s, %s)\n",
-		    objfile_debug_name (objfile),
-		    host_address_to_string (new_offsets),
-		    host_address_to_string (delta));
-
-  debug_data->real_sf->qf->relocate (objfile, new_offsets, delta);
-}
-
-static void
 debug_qf_expand_symtabs_for_function (struct objfile *objfile,
 				      const char *func_name)
 {
@@ -401,7 +384,6 @@ static const struct quick_symbol_functions debug_sym_quick_functions =
   debug_qf_lookup_symbol,
   debug_qf_print_stats,
   debug_qf_dump,
-  debug_qf_relocate,
   debug_qf_expand_symtabs_for_function,
   debug_qf_expand_all_symtabs,
   debug_qf_expand_symtabs_with_fullname,
diff --git a/gdb/symfile.h b/gdb/symfile.h
index d9185092eec..358e42b3f2b 100644
--- a/gdb/symfile.h
+++ b/gdb/symfile.h
@@ -189,12 +189,6 @@ struct quick_symbol_functions
      gdb_stdout.  This is used for "maint print objfiles".  */
   void (*dump) (struct objfile *objfile);
 
-  /* This is called by objfile_relocate to relocate any indices loaded
-     for OBJFILE.  */
-  void (*relocate) (struct objfile *objfile,
-		    const struct section_offsets *new_offsets,
-		    const struct section_offsets *delta);
-
   /* Find all the symbols in OBJFILE named FUNC_NAME, and ensure that
      the corresponding symbol tables are loaded.  */
   void (*expand_symtabs_for_function) (struct objfile *objfile,
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index cf402fabe30..f6c2f5ed647 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -2344,10 +2344,10 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 			CORE_ADDR highval =
 			  symbol.n_value + csect_aux.x_csect.x_scnlen.l;
 
-			if (highval > pst->text_high ())
+			if (highval > pst->raw_text_high ())
 			  pst->set_text_high (highval);
 			if (!pst->textlow_valid
-			    || symbol.n_value < pst->text_low ())
+			    || symbol.n_value < pst->raw_text_low ())
 			  pst->set_text_low (symbol.n_value);
 		      }
 		    misc_func_recorded = 0;
@@ -2661,27 +2661,24 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 	    switch (p[1])
 	      {
 	      case 'S':
-		symbol.n_value += ANOFFSET (objfile->section_offsets,
-					    SECT_OFF_DATA (objfile));
-
 		if (gdbarch_static_transform_name_p (gdbarch))
 		  namestring = gdbarch_static_transform_name
 				 (gdbarch, namestring);
 
 		add_psymbol_to_list (namestring, p - namestring, 1,
 				     VAR_DOMAIN, LOC_STATIC,
+				     SECT_OFF_DATA (objfile),
 				     &objfile->static_psymbols,
 				     symbol.n_value,
 				     psymtab_language, objfile);
 		continue;
 
 	      case 'G':
-		symbol.n_value += ANOFFSET (objfile->section_offsets,
-					    SECT_OFF_DATA (objfile));
 		/* The addresses in these entries are reported to be
 		   wrong.  See the code that reads 'G's for symtabs.  */
 		add_psymbol_to_list (namestring, p - namestring, 1,
 				     VAR_DOMAIN, LOC_STATIC,
+				     SECT_OFF_DATA (objfile),
 				     &objfile->global_psymbols,
 				     symbol.n_value,
 				     psymtab_language, objfile);
@@ -2699,14 +2696,14 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 			&& namestring[0] != ' '))
 		  {
 		    add_psymbol_to_list (namestring, p - namestring, 1,
-					 STRUCT_DOMAIN, LOC_TYPEDEF,
+					 STRUCT_DOMAIN, LOC_TYPEDEF, -1,
 					 &objfile->static_psymbols,
 					 0, psymtab_language, objfile);
 		    if (p[2] == 't')
 		      {
 			/* Also a typedef with the same name.  */
 			add_psymbol_to_list (namestring, p - namestring, 1,
-					     VAR_DOMAIN, LOC_TYPEDEF,
+					     VAR_DOMAIN, LOC_TYPEDEF, -1,
 					     &objfile->static_psymbols,
 					     0, psymtab_language, objfile);
 			p += 1;
@@ -2718,7 +2715,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 		if (p != namestring)	/* a name is there, not just :T...  */
 		  {
 		    add_psymbol_to_list (namestring, p - namestring, 1,
-					 VAR_DOMAIN, LOC_TYPEDEF,
+					 VAR_DOMAIN, LOC_TYPEDEF, -1,
 					 &objfile->static_psymbols,
 					 0, psymtab_language, objfile);
 		  }
@@ -2780,7 +2777,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 			/* Note that the value doesn't matter for
 			   enum constants in psymtabs, just in symtabs.  */
 			add_psymbol_to_list (p, q - p, 1,
-					     VAR_DOMAIN, LOC_CONST,
+					     VAR_DOMAIN, LOC_CONST, -1,
 					     &objfile->static_psymbols,
 					     0, psymtab_language, objfile);
 			/* Point past the name.  */
@@ -2798,7 +2795,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 	      case 'c':
 		/* Constant, e.g. from "const" in Pascal.  */
 		add_psymbol_to_list (namestring, p - namestring, 1,
-				     VAR_DOMAIN, LOC_CONST,
+				     VAR_DOMAIN, LOC_CONST, -1,
 				     &objfile->static_psymbols,
 				     0, psymtab_language, objfile);
 		continue;
@@ -2814,10 +2811,9 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 		    function_outside_compilation_unit_complaint (name);
 		    xfree (name);
 		  }
-		symbol.n_value += ANOFFSET (objfile->section_offsets,
-					    SECT_OFF_TEXT (objfile));
 		add_psymbol_to_list (namestring, p - namestring, 1,
 				     VAR_DOMAIN, LOC_BLOCK,
+				     SECT_OFF_TEXT (objfile),
 				     &objfile->static_psymbols,
 				     symbol.n_value,
 				     psymtab_language, objfile);
@@ -2845,10 +2841,9 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 		if (startswith (namestring, "@FIX"))
 		  continue;
 
-		symbol.n_value += ANOFFSET (objfile->section_offsets,
-					    SECT_OFF_TEXT (objfile));
 		add_psymbol_to_list (namestring, p - namestring, 1,
 				     VAR_DOMAIN, LOC_BLOCK,
+				     SECT_OFF_TEXT (objfile),
 				     &objfile->global_psymbols,
 				     symbol.n_value,
 				     psymtab_language, objfile);
-- 
2.13.6

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [RFA v3 0/6] Make psymbols independent of the progspace
@ 2018-06-07 16:20 Tom Tromey
  2018-06-07 16:20 ` [RFA v3 1/6] Remove dead code in end_psymtab Tom Tromey
                   ` (6 more replies)
  0 siblings, 7 replies; 15+ messages in thread
From: Tom Tromey @ 2018-06-07 16:20 UTC (permalink / raw)
  To: gdb-patches

Here is version 3 of the series to make psymbols independent of the
progspace.

This version addresses Simon's review comments, in particular
replacing macros either with direct field accesses, or with accessor
methods.

See the version 2 intro here as well:

    https://sourceware.org/ml/gdb-patches/2018-05/msg00074.html

Tested by the buildbot.

Tom

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [RFA v3 5/6] Add validity bits for psymtab high and low fields
  2018-06-07 16:20 [RFA v3 0/6] Make psymbols independent of the progspace Tom Tromey
                   ` (4 preceding siblings ...)
  2018-06-07 16:20 ` [RFA v3 6/6] Make psymbols and psymtabs independent of the program space Tom Tromey
@ 2018-06-07 16:20 ` Tom Tromey
  2018-07-17 16:18   ` Simon Marchi
  2018-06-18 14:49 ` [RFA v3 0/6] Make psymbols independent of the progspace Tom Tromey
  6 siblings, 1 reply; 15+ messages in thread
From: Tom Tromey @ 2018-06-07 16:20 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

Right now some psymtab code checks whether a psymtab's textlow or
texthigh fields are valid by comparing against 0.

I imagine this is mildly wrong in the current environment, but once
psymtabs are relocated dynamically, it will no longer be correct,
because it will be much more normal to see a psymtab with a textlow of
zero -- this will just mean it appears at the start of the text
section.

This patch introduces validity bits to handle this situation more
nicely, and changes users of the code to follow.

gdb/ChangeLog
2018-06-07  Tom Tromey  <tromey@redhat.com>

	* dbxread.c (end_psymtab): Use texthigh_valid and textlow_valid.
	* mdebugread.c (parse_partial_symbols): Use textlow_valid.
	(psymtab_to_symtab_1): Use texthigh_valid and textlow_valid.
	* psympriv.h (struct partial_symtab) <m_textlow, m_texthigh>: Update
	comment.
	<textlow_valid, texthigh_valid>: New fields.
	<set_text_low, set_text_high>: Update.
	* xcoffread.c (scan_xcoff_symtab): Use textlow_valid.
---
 gdb/ChangeLog    | 11 +++++++++++
 gdb/dbxread.c    |  6 ++----
 gdb/mdebugread.c |  8 ++++----
 gdb/psympriv.h   | 11 ++++++++++-
 gdb/xcoffread.c  |  2 +-
 5 files changed, 28 insertions(+), 10 deletions(-)

diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index e011b5cf417..204937a9db8 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -2040,13 +2040,11 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
       /* If we know our own starting text address, then walk through all other
          psymtabs for this objfile, and if any didn't know their ending text
          address, set it to our starting address.  Take care to not set our
-         own ending address to our starting address, nor to set addresses on
-         `dependency' files that have both textlow and texthigh zero.  */
+         own ending address to our starting address.  */
 
       ALL_OBJFILE_PSYMTABS (objfile, p1)
       {
-	if (p1->text_high () == 0 && p1->text_low () != 0
-	    && p1 != pst)
+	if (!p1->texthigh_valid && p1->textlow_valid && p1 != pst)
 	  p1->set_text_high (pst->text_low ());
       }
     }
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 2699cb99b19..3deb8cf2a43 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -2737,7 +2737,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 
 			  /* Kludge for Irix 5.2 zero fh->adr.  */
 			  if (!relocatable
-			      && (pst->text_low () == 0
+			      && (!pst->textlow_valid
 				  || procaddr < pst->text_low ()))
 			    pst->set_text_low (procaddr);
 			  if (high > pst->text_high ())
@@ -3513,7 +3513,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 
 		  /* Kludge for Irix 5.2 zero fh->adr.  */
 		  if (!relocatable
-		      && (pst->text_low () == 0
+		      && (!pst->textlow_valid
 			  || procaddr < pst->text_low ()))
 		    pst->set_text_low (procaddr);
 
@@ -3712,7 +3712,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
          other cases.  */
       save_pst = fdr_to_pst[f_idx].pst;
       if (save_pst != NULL
-	  && save_pst->text_low () != 0
+	  && save_pst->textlow_valid
 	  && !(objfile->flags & OBJF_REORDERED))
 	{
 	  ALL_OBJFILE_PSYMTABS (objfile, pst)
@@ -3923,7 +3923,7 @@ psymtab_to_symtab_1 (struct objfile *objfile,
   /* Do nothing if this is a dummy psymtab.  */
 
   if (pst->n_global_syms == 0 && pst->n_static_syms == 0
-      && pst->text_low () == 0 && pst->text_high () == 0)
+      && !pst->textlow_valid && !pst->texthigh_valid)
     return;
 
   /* Now read the symbols for this symtab.  */
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index c1f1defd58c..30e81dbe5bc 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -114,12 +114,14 @@ struct partial_symtab
   void set_text_low (CORE_ADDR addr)
   {
     m_textlow = addr;
+    textlow_valid = 1;
   }
 
   /* Set the hight text address of this partial_symtab.  */
   void set_text_high (CORE_ADDR addr)
   {
     m_texthigh = addr;
+    texthigh_valid = 1;
   }
 
 
@@ -144,7 +146,9 @@ struct partial_symtab
   /* Range of text addresses covered by this file; texthigh is the
      beginning of the next section.  Do not use if PSYMTABS_ADDRMAP_SUPPORTED
      is set.  Do not refer directly to these fields.  Instead, use the
-     accessors.  */
+     accessors.  The validity of these fields is determined by the
+     textlow_valid and texthigh_valid fields; these are located later
+     in this structure for better packing.  */
 
   CORE_ADDR m_textlow;
   CORE_ADDR m_texthigh;
@@ -230,6 +234,11 @@ struct partial_symtab
 
   ENUM_BITFIELD (psymtab_search_status) searched_flag : 2;
 
+  /* Validity of the textlow_ and texthigh_ fields.  */
+
+  unsigned int textlow_valid : 1;
+  unsigned int texthigh_valid : 1;
+
   /* Pointer to compunit eventually allocated for this source file, 0 if
      !readin or if we haven't looked for the symtab after it was readin.  */
 
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 5e621e608d7..cf402fabe30 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -2346,7 +2346,7 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 
 			if (highval > pst->text_high ())
 			  pst->set_text_high (highval);
-			if (pst->text_low () == 0
+			if (!pst->textlow_valid
 			    || symbol.n_value < pst->text_low ())
 			  pst->set_text_low (symbol.n_value);
 		      }
-- 
2.13.6

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [RFA v3 1/6] Remove dead code in end_psymtab
  2018-06-07 16:20 [RFA v3 0/6] Make psymbols independent of the progspace Tom Tromey
@ 2018-06-07 16:20 ` Tom Tromey
  2018-06-07 16:20 ` [RFA v3 4/6] Introduce accessors for psymtab high and low fields Tom Tromey
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Tom Tromey @ 2018-06-07 16:20 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

I noticed that there is a bit of dead code in end_psymtab.
This deletes it.

Normally I would investigate a fix for the code.  However, considering
that the code has been this way a long time (since the first import to
sourceware) and considering that dbxread.c is not as important any
more, I think it's safe to just consider that there's no bug.

gdb/ChangeLog
2018-06-07  Tom Tromey  <tromey@redhat.com>

	* dbxread.c (end_psymtab): Remove dead code.
---
 gdb/ChangeLog | 4 ++++
 gdb/dbxread.c | 8 +-------
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 1b524ec0e22..4092d1cab74 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -2045,13 +2045,7 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
       ALL_OBJFILE_PSYMTABS (objfile, p1)
       {
 	if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst)
-	  {
-	    p1->texthigh = pst->textlow;
-	    /* If this file has only data, then make textlow match
-	       texthigh.  */
-	    if (p1->textlow == 0)
-	      p1->textlow = p1->texthigh;
-	  }
+	  p1->texthigh = pst->textlow;
       }
     }
 
-- 
2.13.6

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [RFA v3 4/6] Introduce accessors for psymtab high and low fields
  2018-06-07 16:20 [RFA v3 0/6] Make psymbols independent of the progspace Tom Tromey
  2018-06-07 16:20 ` [RFA v3 1/6] Remove dead code in end_psymtab Tom Tromey
@ 2018-06-07 16:20 ` Tom Tromey
  2018-07-17 16:12   ` Simon Marchi
  2018-06-07 16:20 ` [RFA v3 3/6] Introduce partial_symbol::address Tom Tromey
                   ` (4 subsequent siblings)
  6 siblings, 1 reply; 15+ messages in thread
From: Tom Tromey @ 2018-06-07 16:20 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This introduces accessors for the partial symbol table textlow and
texthigh fields.  This lets us later arrange to relocate these values
at their point of use.

I did this conversion by renaming the fields.  I didn't rename the
fields back afterward, thinking that on the off chance that someone
has a patch touching this area, then a merge would helpfully break
their compile.

I looked at making the fields private, but this interferes with the
memset in allocate_psymtab, and I didn't want to chase this down.
This conversion can be done later if need be.

gdb/ChangeLog
2018-06-07  Tom Tromey  <tom@tromey.com>

	* dbxread.c (read_dbx_symtab, end_psymtab, read_ofile_symtab):
	Update.
	* dwarf2read.c (dwarf2_create_include_psymtab): Don't initialize
	textlow and texthigh fields.
	(process_psymtab_comp_unit_reader, dwarf2_build_include_psymtabs):
	Update.
	* mdebugread.c (parse_lines, parse_partial_symbols)
	(psymtab_to_symtab_1): Update.
	* psympriv.h (struct partial_symtab) <m_textlow, m_texthigh>: Rename
	fields.  Update comment.  Now private.
	<text_low, text_high, set_text_low, set_text_high>: New methods.
	* psymtab.c (find_pc_sect_psymtab_closer, find_pc_sect_psymtab)
	(find_pc_sect_psymbol, relocate_psymtabs, dump_psymtab)
	(start_psymtab_common, maintenance_info_psymtabs)
	(maintenance_check_psymtabs): Update.
	* xcoffread.c (xcoff_end_psymtab): Don't initialize textlow and
	texthigh fields.
	(scan_xcoff_symtab): Update.
---
 gdb/ChangeLog    | 21 ++++++++++++++++++
 gdb/dbxread.c    | 66 ++++++++++++++++++++++++++++----------------------------
 gdb/dwarf2read.c | 16 +++++++-------
 gdb/mdebugread.c | 46 ++++++++++++++++++++-------------------
 gdb/psympriv.h   | 39 ++++++++++++++++++++++++++++++---
 gdb/psymtab.c    | 48 ++++++++++++++++++++++-------------------
 gdb/xcoffread.c  | 11 +++++-----
 7 files changed, 153 insertions(+), 94 deletions(-)

diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index 4092d1cab74..e011b5cf417 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -1137,12 +1137,12 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 	      if (past_first_source_file && pst
 		  /* The gould NP1 uses low values for .o and -l symbols
 		     which are not the address.  */
-		  && nlist.n_value >= pst->textlow)
+		  && nlist.n_value >= pst->text_low ())
 		{
 		  dbx_end_psymtab (objfile, pst, psymtab_include_list,
 				   includes_used, symnum * symbol_size,
-				   nlist.n_value > pst->texthigh
-				   ? nlist.n_value : pst->texthigh,
+				   nlist.n_value > pst->text_high ()
+				   ? nlist.n_value : pst->text_high (),
 				   dependency_list, dependencies_used,
 				   textlow_not_set);
 		  pst = (struct partial_symtab *) 0;
@@ -1257,8 +1257,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		  {
 		    dbx_end_psymtab (objfile, pst, psymtab_include_list,
 				     includes_used, symnum * symbol_size,
-				     valu > pst->texthigh
-				     ? valu : pst->texthigh,
+				     (valu > pst->text_high ()
+				      ? valu : pst->text_high ()),
 				     dependency_list, dependencies_used,
 				     prev_textlow_not_set);
 		    pst = (struct partial_symtab *) 0;
@@ -1432,8 +1432,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		 function relative stabs, or the address of the function's
 		 end for old style stabs.  */
 	      valu = nlist.n_value + last_function_start;
-	      if (pst->texthigh == 0 || valu > pst->texthigh)
-		pst->texthigh = valu;
+	      if (pst->text_high () == 0 || valu > pst->text_high ())
+		pst->set_text_high (valu);
 	      break;
 	    }
 
@@ -1647,7 +1647,7 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 	      if (pst && textlow_not_set
 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
 		{
-		  pst->textlow = nlist.n_value;
+		  pst->set_text_low (nlist.n_value);
 		  textlow_not_set = 0;
 		}
 	      /* End kludge.  */
@@ -1662,12 +1662,12 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		 the partial symbol table.  */
 	      if (pst
 		  && (textlow_not_set
-		      || (nlist.n_value < pst->textlow
+		      || (nlist.n_value < pst->text_low ()
 			  && (nlist.n_value
 			      != ANOFFSET (objfile->section_offsets,
 					   SECT_OFF_TEXT (objfile))))))
 		{
-		  pst->textlow = nlist.n_value;
+		  pst->set_text_low (nlist.n_value);
 		  textlow_not_set = 0;
 		}
 	      add_psymbol_to_list (sym_name, sym_len, 1,
@@ -1716,7 +1716,7 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 	      if (pst && textlow_not_set
 		  && gdbarch_sofun_address_maybe_missing (gdbarch))
 		{
-		  pst->textlow = nlist.n_value;
+		  pst->set_text_low (nlist.n_value);
 		  textlow_not_set = 0;
 		}
 	      /* End kludge.  */
@@ -1731,12 +1731,12 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 		 the partial symbol table.  */
 	      if (pst
 		  && (textlow_not_set
-		      || (nlist.n_value < pst->textlow
+		      || (nlist.n_value < pst->text_low ()
 			  && (nlist.n_value
 			      != ANOFFSET (objfile->section_offsets,
 					   SECT_OFF_TEXT (objfile))))))
 		{
-		  pst->textlow = nlist.n_value;
+		  pst->set_text_low (nlist.n_value);
 		  textlow_not_set = 0;
 		}
 	      add_psymbol_to_list (sym_name, sym_len, 1,
@@ -1848,10 +1848,10 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 	  continue;
 
 	case N_ENDM:
-	  /* Solaris 2 end of module, finish current partial symbol table.
-	     dbx_end_psymtab will set pst->texthigh to the proper value, which
-	     is necessary if a module compiled without debugging info
-	     follows this module.  */
+	  /* Solaris 2 end of module, finish current partial symbol
+	     table.  dbx_end_psymtab will set PSYMTAB_TEXTHIGH(pst) to
+	     the proper value, which is necessary if a module compiled
+	     without debugging info follows this module.  */
 	  if (pst && gdbarch_sofun_address_maybe_missing (gdbarch))
 	    {
 	      dbx_end_psymtab (objfile, pst,
@@ -1912,7 +1912,7 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
   /* If there's stuff to be cleaned up, clean it up.  */
   if (pst)
     {
-      /* Don't set pst->texthigh lower than it already is.  */
+      /* Don't set PSYMTAB_TEXTHIGH(pst) lower than it already is.  */
       CORE_ADDR text_end =
 	(lowest_text_address == (CORE_ADDR) -1
 	 ? (text_addr + ANOFFSET (objfile->section_offsets,
@@ -1922,7 +1922,8 @@ read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 
       dbx_end_psymtab (objfile, pst, psymtab_include_list, includes_used,
 		       symnum * symbol_size,
-		       text_end > pst->texthigh ? text_end : pst->texthigh,
+		       (text_end > pst->text_high ()
+			? text_end : pst->text_high ()),
 		       dependency_list, dependencies_used, textlow_not_set);
     }
 }
@@ -1977,7 +1978,7 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
 
   if (capping_symbol_offset != -1)
     LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
-  pst->texthigh = capping_text;
+  pst->set_text_high (capping_text);
 
   /* Under Solaris, the N_SO symbols always have a value of 0,
      instead of the usual address of the .o file.  Therefore,
@@ -1994,7 +1995,7 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
      a reliable texthigh by taking the address plus size of the
      last function in the file.  */
 
-  if (pst->texthigh == 0 && last_function_name
+  if (pst->text_high () == 0 && last_function_name
       && gdbarch_sofun_address_maybe_missing (gdbarch))
     {
       int n;
@@ -2021,8 +2022,8 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
 	}
 
       if (minsym.minsym)
-	pst->texthigh = (BMSYMBOL_VALUE_ADDRESS (minsym)
-			 + MSYMBOL_SIZE (minsym.minsym));
+	pst->set_text_high (BMSYMBOL_VALUE_ADDRESS (minsym)
+			    + MSYMBOL_SIZE (minsym.minsym));
 
       last_function_name = NULL;
     }
@@ -2031,7 +2032,7 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
     ;
   /* This test will be true if the last .o file is only data.  */
   else if (textlow_not_set)
-    pst->textlow = pst->texthigh;
+    pst->set_text_low (pst->text_high ());
   else
     {
       struct partial_symtab *p1;
@@ -2044,8 +2045,9 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
 
       ALL_OBJFILE_PSYMTABS (objfile, p1)
       {
-	if (p1->texthigh == 0 && p1->textlow != 0 && p1 != pst)
-	  p1->texthigh = pst->textlow;
+	if (p1->text_high () == 0 && p1->text_low () != 0
+	    && p1 != pst)
+	  p1->set_text_high (pst->text_low ());
       }
     }
 
@@ -2073,9 +2075,7 @@ dbx_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
       subpst->read_symtab_private =
 	XOBNEW (&objfile->objfile_obstack, struct symloc);
       LDSYMOFF (subpst) =
-	LDSYMLEN (subpst) =
-	subpst->textlow =
-	subpst->texthigh = 0;
+	LDSYMLEN (subpst) = 0;
 
       /* We could save slight bits of space by only making one of these,
          shared by the entire set of include files.  FIXME-someday.  */
@@ -2234,8 +2234,8 @@ read_ofile_symtab (struct objfile *objfile, struct partial_symtab *pst)
 
   sym_offset = LDSYMOFF (pst);
   sym_size = LDSYMLEN (pst);
-  text_offset = pst->textlow;
-  text_size = pst->texthigh - pst->textlow;
+  text_offset = pst->text_low ();
+  text_size = pst->text_high () - pst->text_low ();
   section_offsets = objfile->section_offsets;
 
   dbxread_objfile = objfile;
@@ -2364,13 +2364,13 @@ read_ofile_symtab (struct objfile *objfile, struct partial_symtab *pst)
 
   /* In a Solaris elf file, this variable, which comes from the
      value of the N_SO symbol, will still be 0.  Luckily, text_offset,
-     which comes from pst->textlow is correct.  */
+     which comes from PSYMTAB_TEXTLOW(pst) is correct.  */
   if (last_source_start_addr == 0)
     last_source_start_addr = text_offset;
 
   /* In reordered executables last_source_start_addr may not be the
      lower bound for this symtab, instead use text_offset which comes
-     from pst->textlow which is correct.  */
+     from PSYMTAB_TEXTLOW(pst) which is correct.  */
   if (last_source_start_addr > text_offset)
     last_source_start_addr = text_offset;
 
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c
index 1cabfbb0d45..d29ff8b9bb8 100644
--- a/gdb/dwarf2read.c
+++ b/gdb/dwarf2read.c
@@ -6503,9 +6503,6 @@ dwarf2_create_include_psymtab (const char *name, struct partial_symtab *pst,
       subpst->dirname = pst->dirname;
     }
 
-  subpst->textlow = 0;
-  subpst->texthigh = 0;
-
   subpst->dependencies
     = XOBNEW (&objfile->objfile_obstack, struct partial_symtab *);
   subpst->dependencies[0] = pst;
@@ -6544,7 +6541,8 @@ dwarf2_build_include_psymtabs (struct dwarf2_cu *cu,
     return;  /* No linetable, so no includes.  */
 
   /* NOTE: pst->dirname is DW_AT_comp_dir (if present).  */
-  dwarf_decode_lines (lh.get (), pst->dirname, cu, pst, pst->textlow, 1);
+  dwarf_decode_lines (lh.get (), pst->dirname, cu, pst,
+		      pst->text_low (), 1);
 }
 
 static hashval_t
@@ -7968,8 +7966,10 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
 	  best_highpc = highpc;
 	}
     }
-  pst->textlow = gdbarch_adjust_dwarf2_addr (gdbarch, best_lowpc + baseaddr);
-  pst->texthigh = gdbarch_adjust_dwarf2_addr (gdbarch, best_highpc + baseaddr);
+  pst->set_text_low (gdbarch_adjust_dwarf2_addr (gdbarch,
+						 best_lowpc + baseaddr));
+  pst->set_text_high (gdbarch_adjust_dwarf2_addr (gdbarch,
+						  best_highpc + baseaddr));
 
   end_psymtab_common (objfile, pst);
 
@@ -8006,8 +8006,8 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
 			  ", %d global, %d static syms\n",
 			  per_cu->is_debug_types ? "type" : "comp",
 			  sect_offset_str (per_cu->sect_off),
-			  paddress (gdbarch, pst->textlow),
-			  paddress (gdbarch, pst->texthigh),
+			  paddress (gdbarch, pst->text_low ()),
+			  paddress (gdbarch, pst->text_high ()),
 			  pst->n_global_syms, pst->n_static_syms);
     }
 }
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 98f10b465e5..2699cb99b19 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -2197,7 +2197,7 @@ parse_lines (FDR *fh, PDR *pr, struct linetable *lt, int maxlines,
 	halt = base + fh->cbLine;
       base += pr->cbLineOffset;
 
-      adr = pst->textlow + pr->adr - lowest_pdr_addr;
+      adr = pst->text_low () + pr->adr - lowest_pdr_addr;
 
       l = adr >> 2;		/* in words */
       for (lineno = pr->lnLow; base < halt;)
@@ -2672,7 +2672,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 	psymtab_language = prev_language;
       PST_PRIVATE (pst)->pst_language = psymtab_language;
 
-      pst->texthigh = pst->textlow;
+      pst->set_text_high (pst->text_low ());
 
       /* For stabs-in-ecoff files, the second symbol must be @stab.
          This symbol is emitted by mips-tfile to signal that the
@@ -2737,10 +2737,11 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 
 			  /* Kludge for Irix 5.2 zero fh->adr.  */
 			  if (!relocatable
-			  && (pst->textlow == 0 || procaddr < pst->textlow))
-			    pst->textlow = procaddr;
-			  if (high > pst->texthigh)
-			    pst->texthigh = high;
+			      && (pst->text_low () == 0
+				  || procaddr < pst->text_low ()))
+			    pst->set_text_low (procaddr);
+			  if (high > pst->text_high ())
+			    pst->set_text_high (high);
 			}
 		    }
 		  else if (sh.st == stStatic)
@@ -3310,8 +3311,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		  case N_ENDM:
 		    /* Solaris 2 end of module, finish current partial
 		       symbol table.  dbx_end_psymtab will set
-		       pst->texthigh to the proper value, which is
-		       necessary if a module compiled without
+		       PSYMTAB_TEXTHIGH(pst) to the proper value,
+		       which is necessary if a module compiled without
 		       debugging info follows this module.  */
 		    if (pst
 			&& gdbarch_sofun_address_maybe_missing (gdbarch))
@@ -3323,8 +3324,8 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 		    continue;
 
 		  case N_RBRAC:
-		    if (sh.value > save_pst->texthigh)
-		      save_pst->texthigh = sh.value;
+		    if (sh.value > save_pst->text_high ())
+		      save_pst->set_text_high (sh.value);
 		    continue;
 		  case N_EINCL:
 		  case N_DSLINE:
@@ -3512,12 +3513,13 @@ parse_partial_symbols (minimal_symbol_reader &reader,
 
 		  /* Kludge for Irix 5.2 zero fh->adr.  */
 		  if (!relocatable
-		      && (pst->textlow == 0 || procaddr < pst->textlow))
-		    pst->textlow = procaddr;
+		      && (pst->text_low () == 0
+			  || procaddr < pst->text_low ()))
+		    pst->set_text_low (procaddr);
 
 		  high = procaddr + sh.value;
-		  if (high > pst->texthigh)
-		    pst->texthigh = high;
+		  if (high > pst->text_high ())
+		    pst->set_text_high (high);
 		  continue;
 
 		case stStatic:	/* Variable */
@@ -3691,7 +3693,7 @@ parse_partial_symbols (minimal_symbol_reader &reader,
       fdr_to_pst[f_idx].pst
 	= dbx_end_psymtab (objfile, save_pst,
 			   psymtab_include_list, includes_used,
-			   -1, save_pst->texthigh,
+			   -1, save_pst->text_high (),
 			   dependency_list, dependencies_used,
 			   textlow_not_set);
       includes_used = 0;
@@ -3710,15 +3712,15 @@ parse_partial_symbols (minimal_symbol_reader &reader,
          other cases.  */
       save_pst = fdr_to_pst[f_idx].pst;
       if (save_pst != NULL
-	  && save_pst->textlow != 0
+	  && save_pst->text_low () != 0
 	  && !(objfile->flags & OBJF_REORDERED))
 	{
 	  ALL_OBJFILE_PSYMTABS (objfile, pst)
 	  {
 	    if (save_pst != pst
-		&& save_pst->textlow >= pst->textlow
-		&& save_pst->textlow < pst->texthigh
-		&& save_pst->texthigh > pst->texthigh)
+		&& save_pst->text_low () >= pst->text_low ()
+		&& save_pst->text_low () < pst->text_high ()
+		&& save_pst->text_high () > pst->text_high ())
 	      {
 		objfile->flags |= OBJF_REORDERED;
 		break;
@@ -3921,7 +3923,7 @@ psymtab_to_symtab_1 (struct objfile *objfile,
   /* Do nothing if this is a dummy psymtab.  */
 
   if (pst->n_global_syms == 0 && pst->n_static_syms == 0
-      && pst->textlow == 0 && pst->texthigh == 0)
+      && pst->text_low () == 0 && pst->text_high () == 0)
     return;
 
   /* Now read the symbols for this symtab.  */
@@ -4070,7 +4072,7 @@ psymtab_to_symtab_1 (struct objfile *objfile,
 
       if (! last_symtab_ended)
 	{
-	  cust = end_symtab (pst->texthigh, SECT_OFF_TEXT (objfile));
+	  cust = end_symtab (pst->text_high (), SECT_OFF_TEXT (objfile));
 	  end_stabs ();
 	}
 
@@ -4146,7 +4148,7 @@ psymtab_to_symtab_1 (struct objfile *objfile,
       top_stack->cur_st = COMPUNIT_FILETABS (cust);
       top_stack->cur_block
 	= BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), STATIC_BLOCK);
-      BLOCK_START (top_stack->cur_block) = pst->textlow;
+      BLOCK_START (top_stack->cur_block) = pst->text_low ();
       BLOCK_END (top_stack->cur_block) = 0;
       top_stack->blocktype = stFile;
       top_stack->cur_type = 0;
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index ec2d9923c1b..c1f1defd58c 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -98,6 +98,31 @@ enum psymtab_search_status
 
 struct partial_symtab
 {
+  /* Return the low text address of this partial_symtab.  */
+  CORE_ADDR text_low () const
+  {
+    return m_textlow;
+  }
+
+  /* Return the high text address of this partial_symtab.  */
+  CORE_ADDR text_high () const
+  {
+    return m_texthigh;
+  }
+
+  /* Set the low text address of this partial_symtab.  */
+  void set_text_low (CORE_ADDR addr)
+  {
+    m_textlow = addr;
+  }
+
+  /* Set the hight text address of this partial_symtab.  */
+  void set_text_high (CORE_ADDR addr)
+  {
+    m_texthigh = addr;
+  }
+
+
   /* Chain of all existing partial symtabs.  */
 
   struct partial_symtab *next;
@@ -118,10 +143,11 @@ struct partial_symtab
 
   /* Range of text addresses covered by this file; texthigh is the
      beginning of the next section.  Do not use if PSYMTABS_ADDRMAP_SUPPORTED
-     is set.  */
+     is set.  Do not refer directly to these fields.  Instead, use the
+     accessors.  */
 
-  CORE_ADDR textlow;
-  CORE_ADDR texthigh;
+  CORE_ADDR m_textlow;
+  CORE_ADDR m_texthigh;
 
   /* If NULL, this is an ordinary partial symbol table.
 
@@ -222,6 +248,13 @@ struct partial_symtab
   void *read_symtab_private;
 };
 
+/* Compute a section offset given an objfile, a section_offsets field
+   from a partial symtab, and an index.  */
+
+#define PST_OFFSET(OBJF, OFFS, INDEX)				\
+  (ANOFFSET ((OBJF)->section_offsets, (INDEX))			\
+   + ((((OFFS) == NULL)) ? 0 : ANOFFSET ((OFFS), (INDEX))))
+
 /* Add any kind of symbol to a partial_symbol vector.  */
 
 extern void add_psymbol_to_list (const char *, int,
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 58df3c69a78..44587fbf785 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -232,7 +232,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
 {
   struct partial_symtab *tpst;
   struct partial_symtab *best_pst = pst;
-  CORE_ADDR best_addr = pst->textlow;
+  CORE_ADDR best_addr = pst->text_low ();
 
   gdb_assert (!pst->psymtabs_addrmap_supported);
 
@@ -256,7 +256,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
      that is closest and still less than the given PC.  */
   for (tpst = pst; tpst != NULL; tpst = tpst->next)
     {
-      if (pc >= tpst->textlow && pc < tpst->texthigh)
+      if (pc >= tpst->text_low () && pc < tpst->text_high ())
 	{
 	  struct partial_symbol *p;
 	  CORE_ADDR this_addr;
@@ -277,7 +277,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
 	  if (p != NULL)
 	    this_addr = p->address (objfile);
 	  else
-	    this_addr = tpst->textlow;
+	    this_addr = tpst->text_low ();
 
 	  /* Check whether it is closer than our current
 	     BEST_ADDR.  Since this symbol address is
@@ -361,7 +361,7 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
 
   ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
     if (!pst->psymtabs_addrmap_supported
-	&& pc >= pst->textlow && pc < pst->texthigh)
+	&& pc >= pst->text_low () && pc < pst->text_high ())
       {
 	struct partial_symtab *best_pst;
 
@@ -415,7 +415,8 @@ find_pc_sect_psymbol (struct objfile *objfile,
   gdb_assert (psymtab != NULL);
 
   /* Cope with programs that start at address 0.  */
-  best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
+  best_pc = ((psymtab->text_low () != 0)
+	     ? psymtab->text_low () - 1 : 0);
 
   /* Search the global symbols as well as the static symbols, so that
      find_pc_partial_function doesn't use a minimal symbol and thus
@@ -428,7 +429,7 @@ find_pc_sect_psymbol (struct objfile *objfile,
 	  && p->aclass == LOC_BLOCK
 	  && pc >= p->address (objfile)
 	  && (p->address (objfile) > best_pc
-	      || (psymtab->textlow == 0
+	      || (psymtab->text_low () == 0
 		  && best_pc == 0 && p->address (objfile) == 0)))
 	{
 	  if (section != NULL)  /* Match on a specific section.  */
@@ -451,7 +452,7 @@ find_pc_sect_psymbol (struct objfile *objfile,
 	  && p->aclass == LOC_BLOCK
 	  && pc >= p->address (objfile)
 	  && (p->address (objfile) > best_pc
-	      || (psymtab->textlow == 0
+	      || (psymtab->text_low () == 0
 		  && best_pc == 0 && p->address (objfile) == 0)))
 	{
 	  if (section != NULL)  /* Match on a specific section.  */
@@ -806,8 +807,10 @@ psym_relocate (struct objfile *objfile,
 
   ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
     {
-      p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
-      p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
+      p->set_text_low (p->text_low ()
+		       + ANOFFSET (delta, SECT_OFF_TEXT (objfile)));
+      p->set_text_high (p->text_high ()
+			+ ANOFFSET (delta, SECT_OFF_TEXT (objfile)));
     }
 
   for (partial_symbol *psym : objfile->global_psymbols)
@@ -1012,9 +1015,9 @@ dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
     }
 
   fprintf_filtered (outfile, "  Symbols cover text addresses ");
-  fputs_filtered (paddress (gdbarch, psymtab->textlow), outfile);
+  fputs_filtered (paddress (gdbarch, psymtab->text_low ()), outfile);
   fprintf_filtered (outfile, "-");
-  fputs_filtered (paddress (gdbarch, psymtab->texthigh), outfile);
+  fputs_filtered (paddress (gdbarch, psymtab->text_high ()), outfile);
   fprintf_filtered (outfile, "\n");
   fprintf_filtered (outfile, "  Address map supported - %s.\n",
 		    psymtab->psymtabs_addrmap_supported ? "yes" : "no");
@@ -1594,8 +1597,8 @@ start_psymtab_common (struct objfile *objfile,
   struct partial_symtab *psymtab;
 
   psymtab = allocate_psymtab (filename, objfile);
-  psymtab->textlow = textlow;
-  psymtab->texthigh = psymtab->textlow;		/* default */
+  psymtab->set_text_low (textlow);
+  psymtab->set_text_high (psymtab->text_low ()); /* default */
   psymtab->globals_offset = global_psymbols.size ();
   psymtab->statics_offset = static_psymbols.size ();
   return psymtab;
@@ -2147,10 +2150,10 @@ maintenance_info_psymtabs (const char *regexp, int from_tty)
 			       psymtab->fullname
 			       ? psymtab->fullname : "(null)");
 	      printf_filtered ("    text addresses ");
-	      fputs_filtered (paddress (gdbarch, psymtab->textlow),
+	      fputs_filtered (paddress (gdbarch, psymtab->text_low ()),
 			      gdb_stdout);
 	      printf_filtered (" -- ");
-	      fputs_filtered (paddress (gdbarch, psymtab->texthigh),
+	      fputs_filtered (paddress (gdbarch, psymtab->text_high ()),
 			      gdb_stdout);
 	      printf_filtered ("\n");
 	      printf_filtered ("    psymtabs_addrmap_supported %s\n",
@@ -2230,14 +2233,14 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
     cust = ps->compunit_symtab;
 
     /* First do some checks that don't require the associated symtab.  */
-    if (ps->texthigh < ps->textlow)
+    if (ps->text_high () < ps->text_low ())
       {
 	printf_filtered ("Psymtab ");
 	puts_filtered (ps->filename);
 	printf_filtered (" covers bad range ");
-	fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
+	fputs_filtered (paddress (gdbarch, ps->text_low ()), gdb_stdout);
 	printf_filtered (" - ");
-	fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
+	fputs_filtered (paddress (gdbarch, ps->text_high ()), gdb_stdout);
 	printf_filtered ("\n");
 	continue;
       }
@@ -2282,15 +2285,16 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
 	  }
 	psym++;
       }
-    if (ps->texthigh != 0
-	&& (ps->textlow < BLOCK_START (b) || ps->texthigh > BLOCK_END (b)))
+    if (ps->text_high () != 0
+	&& (ps->text_low () < BLOCK_START (b)
+	    || ps->text_high () > BLOCK_END (b)))
       {
 	printf_filtered ("Psymtab ");
 	puts_filtered (ps->filename);
 	printf_filtered (" covers ");
-	fputs_filtered (paddress (gdbarch, ps->textlow), gdb_stdout);
+	fputs_filtered (paddress (gdbarch, ps->text_low ()), gdb_stdout);
 	printf_filtered (" - ");
-	fputs_filtered (paddress (gdbarch, ps->texthigh), gdb_stdout);
+	fputs_filtered (paddress (gdbarch, ps->text_high ()), gdb_stdout);
 	printf_filtered (" but symtab covers only ");
 	fputs_filtered (paddress (gdbarch, BLOCK_START (b)), gdb_stdout);
 	printf_filtered (" - ");
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 7b9694bcff9..5e621e608d7 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -2095,8 +2095,6 @@ xcoff_end_psymtab (struct objfile *objfile, struct partial_symtab *pst,
       subpst->read_symtab_private = XOBNEW (&objfile->objfile_obstack, symloc);
       ((struct symloc *) subpst->read_symtab_private)->first_symnum = 0;
       ((struct symloc *) subpst->read_symtab_private)->numsyms = 0;
-      subpst->textlow = 0;
-      subpst->texthigh = 0;
 
       /* We could save slight bits of space by only making one of these,
          shared by the entire set of include files.  FIXME-someday.  */
@@ -2346,10 +2344,11 @@ scan_xcoff_symtab (minimal_symbol_reader &reader,
 			CORE_ADDR highval =
 			  symbol.n_value + csect_aux.x_csect.x_scnlen.l;
 
-			if (highval > pst->texthigh)
-			  pst->texthigh = highval;
-			if (pst->textlow == 0 || symbol.n_value < pst->textlow)
-			  pst->textlow = symbol.n_value;
+			if (highval > pst->text_high ())
+			  pst->set_text_high (highval);
+			if (pst->text_low () == 0
+			    || symbol.n_value < pst->text_low ())
+			  pst->set_text_low (symbol.n_value);
 		      }
 		    misc_func_recorded = 0;
 		    break;
-- 
2.13.6

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [RFA v3 2/6] Change representation of psymbol to flush out accessors
  2018-06-07 16:20 [RFA v3 0/6] Make psymbols independent of the progspace Tom Tromey
                   ` (2 preceding siblings ...)
  2018-06-07 16:20 ` [RFA v3 3/6] Introduce partial_symbol::address Tom Tromey
@ 2018-06-07 16:20 ` Tom Tromey
  2018-06-07 16:20 ` [RFA v3 6/6] Make psymbols and psymtabs independent of the program space Tom Tromey
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 15+ messages in thread
From: Tom Tromey @ 2018-06-07 16:20 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

This is the psymbol analog to the patch to change the representation
of minimal symbols:

    https://sourceware.org/ml/gdb-patches/2013-10/msg00524.html

It has the same rationale: namely, that we're going to change the code
to apply psymbol offsets at runtime.  This will be done by adding an
argument to the SYMBOL_VALUE_ADDRESS macro -- but since we can't
convert all the symbol types at once, we need a new approach.

Because gdb now is in C++, this patch changes partial_symbol to
inherit from general_symbol_info, rather than renaming the field.
This simplifies code in some places.

Also, as noted before, these macros implement a kind of "phony
polymorphism" that is not actually useful in practice; so this patch
removes the macros in favor of simply referring directly to members.
In a few cases -- obj_section in this patch and the symbol address in
the future -- methods will be used instead.

Note that this removes the blanket memset from add_psymbol_to_bcache.
This hasn't really been needed since bcache was modified to allow
holes in objects and since psymtab took advantage of that.  This
deletion was required due to changing partial_symbol to derive from
general_symbol_info.

gdb/ChangeLog
2018-06-07  Tom Tromey  <tom@tromey.com>

	* dwarf-index-write.c (write_psymbols, debug_names::insert)
	(debug_names::write_psymbols): Update.
	* psympriv.h (struct partial_symbol): Derive from
	general_symbol_info.
	<obj_section>: New method.
	(PSYMBOL_DOMAIN, PSYMBOL_CLASS): Remove.n
	* psymtab.c (find_pc_sect_psymtab_closer, find_pc_sect_psymtab)
	(find_pc_sect_psymbol, fixup_psymbol_section)
	(match_partial_symbol, lookup_partial_symbol, relocate_psymtabs)
	(print_partial_symbols, recursively_search_psymtabs)
	(compare_psymbols, psymbol_hash, psymbol_compare)
	(add_psymbol_to_bcache, maintenance_check_psymtabs)
	(psymbol_name_matches, psym_fill_psymbol_map): Update.
---
 gdb/ChangeLog           |  16 +++++
 gdb/dwarf-index-write.c |  16 ++---
 gdb/psympriv.h          |  16 +++--
 gdb/psymtab.c           | 168 +++++++++++++++++++++++-------------------------
 4 files changed, 115 insertions(+), 101 deletions(-)

diff --git a/gdb/dwarf-index-write.c b/gdb/dwarf-index-write.c
index d2831461ca3..0210d2e7194 100644
--- a/gdb/dwarf-index-write.c
+++ b/gdb/dwarf-index-write.c
@@ -499,8 +499,8 @@ write_address_map (struct objfile *objfile, data_buf &addr_vec,
 static gdb_index_symbol_kind
 symbol_kind (struct partial_symbol *psym)
 {
-  domain_enum domain = PSYMBOL_DOMAIN (psym);
-  enum address_class aclass = PSYMBOL_CLASS (psym);
+  domain_enum domain = psym->domain;
+  enum address_class aclass = psym->aclass;
 
   switch (domain)
     {
@@ -546,7 +546,7 @@ write_psymbols (struct mapped_symtab *symtab,
     {
       struct partial_symbol *psym = *psymp;
 
-      if (SYMBOL_LANGUAGE (psym) == language_ada)
+      if (psym->language == language_ada)
 	error (_("Ada is not currently supported by the index"));
 
       /* Only add a given psymbol once.  */
@@ -554,7 +554,7 @@ write_psymbols (struct mapped_symtab *symtab,
 	{
 	  gdb_index_symbol_kind kind = symbol_kind (psym);
 
-	  add_index_entry (symtab, SYMBOL_SEARCH_NAME (psym),
+	  add_index_entry (symtab, symbol_search_name (psym),
 			   is_static, kind, cu_index);
 	}
     }
@@ -688,7 +688,7 @@ public:
     const int dwarf_tag = psymbol_tag (psym);
     if (dwarf_tag == 0)
       return;
-    const char *const name = SYMBOL_SEARCH_NAME (psym);
+    const char *const name = symbol_search_name (psym);
     const auto insertpair
       = m_name_to_value_set.emplace (c_str_view (name),
 				     std::set<symbol_value> ());
@@ -1141,8 +1141,8 @@ private:
      GDB as a DWARF-5 index consumer.  */
   static int psymbol_tag (const struct partial_symbol *psym)
   {
-    domain_enum domain = PSYMBOL_DOMAIN (psym);
-    enum address_class aclass = PSYMBOL_CLASS (psym);
+    domain_enum domain = psym->domain;
+    enum address_class aclass = psym->aclass;
 
     switch (domain)
       {
@@ -1183,7 +1183,7 @@ private:
       {
 	struct partial_symbol *psym = *psymp;
 
-	if (SYMBOL_LANGUAGE (psym) == language_ada)
+	if (psym->language == language_ada)
 	  error (_("Ada is not currently supported by the index"));
 
 	/* Only add a given psymbol once.  */
diff --git a/gdb/psympriv.h b/gdb/psympriv.h
index 45746a26a7d..f3cb0a6ba15 100644
--- a/gdb/psympriv.h
+++ b/gdb/psympriv.h
@@ -33,11 +33,16 @@
 /* This structure is space critical.  See space comments at the top of
    symtab.h.  */
 
-struct partial_symbol
+struct partial_symbol : public general_symbol_info
 {
-  /* The general symbol info required for all types of symbols.  */
-
-  struct general_symbol_info ginfo;
+  /* Return the section for this partial symbol, or nullptr if no
+     section has been set.  */
+  struct obj_section *obj_section (struct objfile *objfile) const
+  {
+    if (section >= 0)
+      return &objfile->sections[section];
+    return nullptr;
+  }
 
   /* Name space code.  */
 
@@ -50,9 +55,6 @@ struct partial_symbol
   ENUM_BITFIELD(address_class) aclass : SYMBOL_ACLASS_BITS;
 };
 
-#define PSYMBOL_DOMAIN(psymbol)	(psymbol)->domain
-#define PSYMBOL_CLASS(psymbol)		(psymbol)->aclass
-
 /* A convenience enum to give names to some constants used when
    searching psymtabs.  This is internal to psymtab and should not be
    used elsewhere.  */
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index fa59ee2b0fb..9a06d68f91e 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -267,8 +267,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
 	     object's symbol table.  */
 	  p = find_pc_sect_psymbol (objfile, tpst, pc, section);
 	  if (p != NULL
-	      && (SYMBOL_VALUE_ADDRESS (p)
-		  == BMSYMBOL_VALUE_ADDRESS (msymbol)))
+	      && (p->value.address == BMSYMBOL_VALUE_ADDRESS (msymbol)))
 	    return tpst;
 
 	  /* Also accept the textlow value of a psymtab as a
@@ -276,7 +275,7 @@ find_pc_sect_psymtab_closer (struct objfile *objfile,
 	     symbol tables with line information but no debug
 	     symbols (e.g. those produced by an assembler).  */
 	  if (p != NULL)
-	    this_addr = SYMBOL_VALUE_ADDRESS (p);
+	    this_addr = p->value.address;
 	  else
 	    this_addr = tpst->textlow;
 
@@ -334,8 +333,7 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
 		 object's symbol table.  */
 	      p = find_pc_sect_psymbol (objfile, pst, pc, section);
 	      if (p == NULL
-		  || (SYMBOL_VALUE_ADDRESS (p)
-		      != BMSYMBOL_VALUE_ADDRESS (msymbol)))
+		  || (p->value.address != BMSYMBOL_VALUE_ADDRESS (msymbol)))
 		goto next;
 	    }
 
@@ -425,21 +423,21 @@ find_pc_sect_psymbol (struct objfile *objfile,
     {
       partial_symbol *p = objfile->global_psymbols[psymtab->globals_offset + i];
 
-      if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
-	  && PSYMBOL_CLASS (p) == LOC_BLOCK
-	  && pc >= SYMBOL_VALUE_ADDRESS (p)
-	  && (SYMBOL_VALUE_ADDRESS (p) > best_pc
+      if (p->domain == VAR_DOMAIN
+	  && p->aclass == LOC_BLOCK
+	  && pc >= p->value.address
+	  && (p->value.address > best_pc
 	      || (psymtab->textlow == 0
-		  && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
+		  && best_pc == 0 && p->value.address == 0)))
 	{
 	  if (section != NULL)  /* Match on a specific section.  */
 	    {
 	      fixup_psymbol_section (p, objfile);
-	      if (!matching_obj_sections (SYMBOL_OBJ_SECTION (objfile, p),
+	      if (!matching_obj_sections (p->obj_section (objfile),
 					  section))
 		continue;
 	    }
-	  best_pc = SYMBOL_VALUE_ADDRESS (p);
+	  best_pc = p->value.address;
 	  best = p;
 	}
     }
@@ -448,21 +446,21 @@ find_pc_sect_psymbol (struct objfile *objfile,
     {
       partial_symbol *p = objfile->static_psymbols[psymtab->statics_offset + i];
 
-      if (SYMBOL_DOMAIN (p) == VAR_DOMAIN
-	  && PSYMBOL_CLASS (p) == LOC_BLOCK
-	  && pc >= SYMBOL_VALUE_ADDRESS (p)
-	  && (SYMBOL_VALUE_ADDRESS (p) > best_pc
+      if (p->domain == VAR_DOMAIN
+	  && p->aclass == LOC_BLOCK
+	  && pc >= p->value.address
+	  && (p->value.address > best_pc
 	      || (psymtab->textlow == 0
-		  && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
+		  && best_pc == 0 && p->value.address == 0)))
 	{
 	  if (section != NULL)  /* Match on a specific section.  */
 	    {
 	      fixup_psymbol_section (p, objfile);
-	      if (!matching_obj_sections (SYMBOL_OBJ_SECTION (objfile, p),
+	      if (!matching_obj_sections (p->obj_section (objfile),
 					  section))
 		continue;
 	    }
-	  best_pc = SYMBOL_VALUE_ADDRESS (p);
+	  best_pc = p->value.address;
 	  best = p;
 	}
     }
@@ -478,17 +476,17 @@ fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
   if (psym == NULL)
     return;
 
-  if (SYMBOL_SECTION (psym) >= 0)
+  if (psym->section >= 0)
     return;
 
   gdb_assert (objfile);
 
-  switch (PSYMBOL_CLASS (psym))
+  switch (psym->aclass)
     {
     case LOC_STATIC:
     case LOC_LABEL:
     case LOC_BLOCK:
-      addr = SYMBOL_VALUE_ADDRESS (psym);
+      addr = psym->value.address;
       break;
     default:
       /* Nothing else will be listed in the minsyms -- no use looking
@@ -496,7 +494,7 @@ fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
       return;
     }
 
-  fixup_section (&psym->ginfo, addr, objfile);
+  fixup_section (psym, addr, objfile);
 }
 
 /* Psymtab version of lookup_symbol.  See its definition in
@@ -554,10 +552,10 @@ static bool
 psymbol_name_matches (partial_symbol *psym,
 		      const lookup_name_info &lookup_name)
 {
-  const language_defn *lang = language_def (SYMBOL_LANGUAGE (psym));
+  const language_defn *lang = language_def (psym->language);
   symbol_name_matcher_ftype *name_match
     = get_symbol_name_matcher (lang, lookup_name);
-  return name_match (SYMBOL_SEARCH_NAME (psym), lookup_name, NULL);
+  return name_match (symbol_search_name (psym), lookup_name, NULL);
 }
 
 /* Look in PST for a symbol in DOMAIN whose name matches NAME.  Search
@@ -607,11 +605,11 @@ match_partial_symbol (struct objfile *objfile,
 	  center = bottom + (top - bottom) / 2;
 	  gdb_assert (center < top);
 
-	  enum language lang = SYMBOL_LANGUAGE (*center);
+	  enum language lang = (*center)->language;
 	  const char *lang_ln
 	    = lookup_name.language_lookup_name (lang).c_str ();
 
-	  if (ordered_compare (SYMBOL_SEARCH_NAME (*center), lang_ln) >= 0)
+	  if (ordered_compare (symbol_search_name (*center), lang_ln) >= 0)
 	    top = center;
 	  else
 	    bottom = center + 1;
@@ -621,8 +619,8 @@ match_partial_symbol (struct objfile *objfile,
       while (top <= real_top
 	     && psymbol_name_matches (*top, lookup_name))
 	{
-	  if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
-				     SYMBOL_DOMAIN (*top), domain))
+	  if (symbol_matches_domain ((*top)->language,
+				     (*top)->domain, domain))
 	    return *top;
 	  top++;
 	}
@@ -635,8 +633,8 @@ match_partial_symbol (struct objfile *objfile,
     {
       for (psym = start; psym < start + length; psym++)
 	{
-	  if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
-				     SYMBOL_DOMAIN (*psym), domain)
+	  if (symbol_matches_domain ((*psym)->language,
+				     (*psym)->domain, domain)
 	      && psymbol_name_matches (*psym, lookup_name))
 	    return *psym;
 	}
@@ -718,7 +716,7 @@ lookup_partial_symbol (struct objfile *objfile,
 	  if (!(center < top))
 	    internal_error (__FILE__, __LINE__,
 			    _("failed internal consistency check"));
-	  if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
+	  if (strcmp_iw_ordered (symbol_search_name (*center),
 				 search_name.get ()) >= 0)
 	    {
 	      top = center;
@@ -734,16 +732,16 @@ lookup_partial_symbol (struct objfile *objfile,
 
       /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
 	 search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME.  */
-      while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, lookup_name))
+      while (top >= start && symbol_matches_search_name (*top, lookup_name))
 	top--;
 
       /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME.  */
       top++;
 
-      while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, lookup_name))
+      while (top <= real_top && symbol_matches_search_name (*top, lookup_name))
 	{
-	  if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
-				     SYMBOL_DOMAIN (*top), domain))
+	  if (symbol_matches_domain ((*top)->language,
+				     (*top)->domain, domain))
 	    return *top;
 	  top++;
 	}
@@ -756,9 +754,9 @@ lookup_partial_symbol (struct objfile *objfile,
     {
       for (psym = start; psym < start + length; psym++)
 	{
-	  if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
-				     SYMBOL_DOMAIN (*psym), domain)
-	      && SYMBOL_MATCHES_SEARCH_NAME (*psym, lookup_name))
+	  if (symbol_matches_domain ((*psym)->language,
+				     (*psym)->domain, domain)
+	      && symbol_matches_search_name (*psym, lookup_name))
 	    return *psym;
 	}
     }
@@ -814,14 +812,14 @@ psym_relocate (struct objfile *objfile,
   for (partial_symbol *psym : objfile->global_psymbols)
     {
       fixup_psymbol_section (psym, objfile);
-      if (SYMBOL_SECTION (psym) >= 0)
-	SYMBOL_VALUE_ADDRESS (psym) += ANOFFSET (delta, SYMBOL_SECTION (psym));
+      if (psym->section >= 0)
+	psym->value.address += ANOFFSET (delta, psym->section);
     }
   for (partial_symbol *psym : objfile->static_psymbols)
     {
       fixup_psymbol_section (psym, objfile);
-      if (SYMBOL_SECTION (psym) >= 0)
-	SYMBOL_VALUE_ADDRESS (psym) += ANOFFSET (delta, SYMBOL_SECTION (psym));
+      if (psym->section >= 0)
+	psym->value.address += ANOFFSET (delta, psym->section);
     }
 
   objfile->psymbol_map.clear ();
@@ -893,13 +891,13 @@ print_partial_symbols (struct gdbarch *gdbarch,
   while (count-- > 0)
     {
       QUIT;
-      fprintf_filtered (outfile, "    `%s'", SYMBOL_LINKAGE_NAME (*p));
-      if (SYMBOL_DEMANGLED_NAME (*p) != NULL)
+      fprintf_filtered (outfile, "    `%s'", (*p)->name);
+      if (symbol_demangled_name (*p) != NULL)
 	{
-	  fprintf_filtered (outfile, "  `%s'", SYMBOL_DEMANGLED_NAME (*p));
+	  fprintf_filtered (outfile, "  `%s'", symbol_demangled_name (*p));
 	}
       fputs_filtered (", ", outfile);
-      switch (SYMBOL_DOMAIN (*p))
+      switch ((*p)->domain)
 	{
 	case UNDEF_DOMAIN:
 	  fputs_filtered ("undefined domain, ", outfile);
@@ -917,7 +915,7 @@ print_partial_symbols (struct gdbarch *gdbarch,
 	  fputs_filtered ("<invalid domain>, ", outfile);
 	  break;
 	}
-      switch (PSYMBOL_CLASS (*p))
+      switch ((*p)->aclass)
 	{
 	case LOC_UNDEF:
 	  fputs_filtered ("undefined", outfile);
@@ -969,7 +967,7 @@ print_partial_symbols (struct gdbarch *gdbarch,
 	  break;
 	}
       fputs_filtered (", ", outfile);
-      fputs_filtered (paddress (gdbarch, SYMBOL_VALUE_ADDRESS (*p)), outfile);
+      fputs_filtered (paddress (gdbarch, (*p)->value.address), outfile);
       fprintf_filtered (outfile, "\n");
       p++;
     }
@@ -1364,14 +1362,14 @@ recursively_search_psymtabs
 
 	  if ((domain == ALL_DOMAIN
 	       || (domain == VARIABLES_DOMAIN
-		   && PSYMBOL_CLASS (*psym) != LOC_TYPEDEF
-		   && PSYMBOL_CLASS (*psym) != LOC_BLOCK)
+		   && (*psym)->aclass != LOC_TYPEDEF
+		   && (*psym)->aclass != LOC_BLOCK)
 	       || (domain == FUNCTIONS_DOMAIN
-		   && PSYMBOL_CLASS (*psym) == LOC_BLOCK)
+		   && (*psym)->aclass == LOC_BLOCK)
 	       || (domain == TYPES_DOMAIN
-		   && PSYMBOL_CLASS (*psym) == LOC_TYPEDEF))
+		   && (*psym)->aclass == LOC_TYPEDEF))
 	      && psymbol_name_matches (*psym, lookup_name)
-	      && (sym_matcher == NULL || sym_matcher (SYMBOL_SEARCH_NAME (*psym))))
+	      && (sym_matcher == NULL || sym_matcher (symbol_search_name (*psym))))
 	    {
 	      /* Found a match, so notify our caller.  */
 	      result = PST_SEARCHED_AND_FOUND;
@@ -1475,9 +1473,9 @@ psym_fill_psymbol_map (struct objfile *objfile,
     {
       struct partial_symbol *psym = symbols[start + i];
 
-      if (PSYMBOL_CLASS (psym) == LOC_STATIC)
+      if (psym->aclass == LOC_STATIC)
 	{
-	  CORE_ADDR addr = SYMBOL_VALUE_ADDRESS (psym);
+	  CORE_ADDR addr = psym->value.address;
 	  if (seen_addrs->find (addr) == seen_addrs->end ())
 	    {
 	      seen_addrs->insert (addr);
@@ -1573,8 +1571,8 @@ sort_pst_symbols (struct objfile *objfile, struct partial_symtab *pst)
 
   std::sort (begin, end, [] (partial_symbol *s1, partial_symbol *s2)
     {
-      return strcmp_iw_ordered (SYMBOL_SEARCH_NAME (s1),
-				SYMBOL_SEARCH_NAME (s2)) < 0;
+      return strcmp_iw_ordered (symbol_search_name (s1),
+				symbol_search_name (s2)) < 0;
     });
 }
 
@@ -1621,17 +1619,18 @@ psymbol_hash (const void *addr, int length)
 {
   unsigned long h = 0;
   struct partial_symbol *psymbol = (struct partial_symbol *) addr;
-  unsigned int lang = psymbol->ginfo.language;
-  unsigned int domain = PSYMBOL_DOMAIN (psymbol);
-  unsigned int theclass = PSYMBOL_CLASS (psymbol);
+  unsigned int lang = psymbol->language;
+  unsigned int domain = psymbol->domain;
+  unsigned int theclass = psymbol->aclass;
 
-  h = hash_continue (&psymbol->ginfo.value, sizeof (psymbol->ginfo.value), h);
+  h = hash_continue (&psymbol->value, sizeof (psymbol->value), h);
   h = hash_continue (&lang, sizeof (unsigned int), h);
   h = hash_continue (&domain, sizeof (unsigned int), h);
   h = hash_continue (&theclass, sizeof (unsigned int), h);
   /* Note that psymbol names are interned via symbol_set_names, so
      there's no need to hash the contents of the name here.  */
-  h = hash_continue (&psymbol->ginfo.name, sizeof (psymbol->ginfo.name), h);
+  h = hash_continue (&psymbol->name,
+		     sizeof (psymbol->name), h);
 
   return h;
 }
@@ -1646,15 +1645,15 @@ psymbol_compare (const void *addr1, const void *addr2, int length)
   struct partial_symbol *sym1 = (struct partial_symbol *) addr1;
   struct partial_symbol *sym2 = (struct partial_symbol *) addr2;
 
-  return (memcmp (&sym1->ginfo.value, &sym2->ginfo.value,
-                  sizeof (sym1->ginfo.value)) == 0
-	  && sym1->ginfo.language == sym2->ginfo.language
-          && PSYMBOL_DOMAIN (sym1) == PSYMBOL_DOMAIN (sym2)
-          && PSYMBOL_CLASS (sym1) == PSYMBOL_CLASS (sym2)
+  return (memcmp (&sym1->value, &sym2->value,
+                  sizeof (sym1->value)) == 0
+	  && sym1->language == sym2->language
+          && sym1->domain == sym2->domain
+          && sym1->aclass == sym2->aclass
 	  /* Note that psymbol names are interned via
 	     symbol_set_names, so there's no need to compare the
 	     contents of the name here.  */
-          && sym1->ginfo.name == sym2->ginfo.name);
+          && sym1->name == sym2->name);
 }
 
 /* Initialize a partial symbol bcache.  */
@@ -1719,18 +1718,15 @@ add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
 {
   struct partial_symbol psymbol;
 
-  /* We must ensure that the entire struct has been zeroed before
-     assigning to it, because an assignment may not touch some of the
-     holes.  */
-  memset (&psymbol, 0, sizeof (psymbol));
+  psymbol.value.address = coreaddr;
+  psymbol.section = -1;
+  psymbol.domain = domain;
+  psymbol.aclass = theclass;
 
-  SYMBOL_VALUE_ADDRESS (&psymbol) = coreaddr;
-  SYMBOL_SECTION (&psymbol) = -1;
-  SYMBOL_SET_LANGUAGE (&psymbol, language, &objfile->objfile_obstack);
-  PSYMBOL_DOMAIN (&psymbol) = domain;
-  PSYMBOL_CLASS (&psymbol) = theclass;
-
-  SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
+  memset (&psymbol.language_specific, 0, sizeof (psymbol.language_specific));
+  psymbol.ada_mangled = 0;
+  symbol_set_language (&psymbol, language, &objfile->objfile_obstack);
+  symbol_set_names (&psymbol, name, namelength, copy_name, objfile);
 
   /* Stash the partial symbol away in the cache.  */
   return psymbol_bcache_full (&psymbol, objfile->psymbol_cache, added);
@@ -2252,13 +2248,13 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
     length = ps->n_static_syms;
     while (length--)
       {
-	sym = block_lookup_symbol (b, SYMBOL_SEARCH_NAME (*psym),
+	sym = block_lookup_symbol (b, symbol_search_name (*psym),
 				   symbol_name_match_type::SEARCH_NAME,
-				   SYMBOL_DOMAIN (*psym));
+				   (*psym)->domain);
 	if (!sym)
 	  {
 	    printf_filtered ("Static symbol `");
-	    puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
+	    puts_filtered ((*psym)->name);
 	    printf_filtered ("' only found in ");
 	    puts_filtered (ps->filename);
 	    printf_filtered (" psymtab\n");
@@ -2270,13 +2266,13 @@ maintenance_check_psymtabs (const char *ignore, int from_tty)
     length = ps->n_global_syms;
     while (length--)
       {
-	sym = block_lookup_symbol (b, SYMBOL_SEARCH_NAME (*psym),
+	sym = block_lookup_symbol (b, symbol_search_name (*psym),
 				   symbol_name_match_type::SEARCH_NAME,
-				   SYMBOL_DOMAIN (*psym));
+				   (*psym)->domain);
 	if (!sym)
 	  {
 	    printf_filtered ("Global symbol `");
-	    puts_filtered (SYMBOL_LINKAGE_NAME (*psym));
+	    puts_filtered ((*psym)->name);
 	    printf_filtered ("' only found in ");
 	    puts_filtered (ps->filename);
 	    printf_filtered (" psymtab\n");
-- 
2.13.6

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFA v3 0/6] Make psymbols independent of the progspace
  2018-06-07 16:20 [RFA v3 0/6] Make psymbols independent of the progspace Tom Tromey
                   ` (5 preceding siblings ...)
  2018-06-07 16:20 ` [RFA v3 5/6] Add validity bits for psymtab high and low fields Tom Tromey
@ 2018-06-18 14:49 ` Tom Tromey
  2018-07-16 16:33   ` Tom Tromey
  6 siblings, 1 reply; 15+ messages in thread
From: Tom Tromey @ 2018-06-18 14:49 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

Tom> Here is version 3 of the series to make psymbols independent of the
Tom> progspace.

Tom> This version addresses Simon's review comments, in particular
Tom> replacing macros either with direct field accesses, or with accessor
Tom> methods.

Tom> See the version 2 intro here as well:

Tom>     https://sourceware.org/ml/gdb-patches/2018-05/msg00074.html

Tom> Tested by the buildbot.

Ping.

Tom

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFA v3 0/6] Make psymbols independent of the progspace
  2018-06-18 14:49 ` [RFA v3 0/6] Make psymbols independent of the progspace Tom Tromey
@ 2018-07-16 16:33   ` Tom Tromey
  0 siblings, 0 replies; 15+ messages in thread
From: Tom Tromey @ 2018-07-16 16:33 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:

>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:
Tom> Here is version 3 of the series to make psymbols independent of the
Tom> progspace.

Tom> This version addresses Simon's review comments, in particular
Tom> replacing macros either with direct field accesses, or with accessor
Tom> methods.

Tom> See the version 2 intro here as well:

Tom> https://sourceware.org/ml/gdb-patches/2018-05/msg00074.html

Tom> Tested by the buildbot.

Tom> Ping.

Ping.

Tom

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFA v3 3/6] Introduce partial_symbol::address
  2018-06-07 16:20 ` [RFA v3 3/6] Introduce partial_symbol::address Tom Tromey
@ 2018-07-17 16:05   ` Simon Marchi
  2018-07-18 17:48     ` Tom Tromey
  0 siblings, 1 reply; 15+ messages in thread
From: Simon Marchi @ 2018-07-17 16:05 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

Hi Tom,

I have some naming suggestions below, but the patch LGTM either way.

> diff --git a/gdb/psympriv.h b/gdb/psympriv.h
> index f3cb0a6ba15..ec2d9923c1b 100644
> --- a/gdb/psympriv.h
> +++ b/gdb/psympriv.h
> @@ -44,6 +44,26 @@ struct partial_symbol : public general_symbol_info
>      return nullptr;
>    }
>  
> +  /* Return the unrelocated address of this partial symbol.  */
> +  CORE_ADDR raw_address () const
> +  {
> +    return value.address;
> +  }

I think it would be clearer to name this "unrelocated_address".

> +  /* Return the address of this partial symbol, relocated according to
> +     the offsets provided in OBJFILE.  */
> +  CORE_ADDR address (struct objfile *objfile) const
> +  {
> +    return value.address;
> +  }
> +
> +  /* Set the address of this partial symbol.  The address must be
> +     unrelocated.  */
> +  void set_address (CORE_ADDR addr)
> +  {
> +    value.address = addr;
> +  }

Since this is the mirror of raw_address (or unrelocated_address), it might good to
name it set_raw_address (or set_unrelocated_address).  Bugs in the calling code
would be more apparent.  If you're playing with a relocated address and call
set_unrelocated_address, it's quite obvious something is wrong.

Except it's not actually true as of this patch (we still pass a relocated address),
so maybe it can be renamed later, when it is the case.

Simon

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFA v3 4/6] Introduce accessors for psymtab high and low fields
  2018-06-07 16:20 ` [RFA v3 4/6] Introduce accessors for psymtab high and low fields Tom Tromey
@ 2018-07-17 16:12   ` Simon Marchi
  0 siblings, 0 replies; 15+ messages in thread
From: Simon Marchi @ 2018-07-17 16:12 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

Hi Tom,

There are some stale references to PSYMTAB_TEXTHIGH.  Just some really tiny
nits, but otherwise it LGTM.

On 2018-06-07 12:19 PM, Tom Tromey wrote:
> diff --git a/gdb/psympriv.h b/gdb/psympriv.h
> index ec2d9923c1b..c1f1defd58c 100644
> --- a/gdb/psympriv.h
> +++ b/gdb/psympriv.h
> @@ -98,6 +98,31 @@ enum psymtab_search_status
>  
>  struct partial_symtab
>  {
> +  /* Return the low text address of this partial_symtab.  */
> +  CORE_ADDR text_low () const
> +  {
> +    return m_textlow;
> +  }
> +
> +  /* Return the high text address of this partial_symtab.  */
> +  CORE_ADDR text_high () const
> +  {
> +    return m_texthigh;
> +  }
> +
> +  /* Set the low text address of this partial_symtab.  */
> +  void set_text_low (CORE_ADDR addr)
> +  {
> +    m_textlow = addr;
> +  }
> +
> +  /* Set the hight text address of this partial_symtab.  */
> +  void set_text_high (CORE_ADDR addr)
> +  {
> +    m_texthigh = addr;
> +  }

I am mildly bothered by the inconsistent naming :).  Can you rename
m_texthigh -> m_text_high (and same for low) so it matches the
accessors?

> @@ -222,6 +248,13 @@ struct partial_symtab
>    void *read_symtab_private;
>  };
>  
> +/* Compute a section offset given an objfile, a section_offsets field
> +   from a partial symtab, and an index.  */
> +
> +#define PST_OFFSET(OBJF, OFFS, INDEX)				\
> +  (ANOFFSET ((OBJF)->section_offsets, (INDEX))			\
> +   + ((((OFFS) == NULL)) ? 0 : ANOFFSET ((OFFS), (INDEX))))
> +

This is not needed I think.

Simon

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFA v3 5/6] Add validity bits for psymtab high and low fields
  2018-06-07 16:20 ` [RFA v3 5/6] Add validity bits for psymtab high and low fields Tom Tromey
@ 2018-07-17 16:18   ` Simon Marchi
  0 siblings, 0 replies; 15+ messages in thread
From: Simon Marchi @ 2018-07-17 16:18 UTC (permalink / raw)
  To: Tom Tromey, gdb-patches

On 2018-06-07 12:19 PM, Tom Tromey wrote:
> Right now some psymtab code checks whether a psymtab's textlow or
> texthigh fields are valid by comparing against 0.
> 
> I imagine this is mildly wrong in the current environment, but once
> psymtabs are relocated dynamically, it will no longer be correct,
> because it will be much more normal to see a psymtab with a textlow of
> zero -- this will just mean it appears at the start of the text
> section.
> 
> This patch introduces validity bits to handle this situation more
> nicely, and changes users of the code to follow.

This LGTM.

If you could rename texthigh_valid -> text_high_valid, textlow_valid ->
text_low_valid, it would really help my OCD though.

Thanks!

Simon

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFA v3 6/6] Make psymbols and psymtabs independent of the program space
       [not found]   ` <17305a06-9fbb-84d1-c596-c9bfece81aab@ericsson.com>
@ 2018-07-18  2:16     ` Simon Marchi
  2018-07-18 18:12       ` Tom Tromey
  0 siblings, 1 reply; 15+ messages in thread
From: Simon Marchi @ 2018-07-18  2:16 UTC (permalink / raw)
  To: Tom Tromey, GDB Patches

I failed to reply-all once again, here's what I sent earlier.

On 2018-07-17 01:21 PM, Simon Marchi wrote:
> Hi Tom,
> 
> Because this change can have repercussion at many places, I'm not very confident
> in my capacity to spot any missing or wrong change, especially in the older debug
> info formats.  I have some questions, the rest of what I've seen LGTM.
> 
> Is the call site of addrmap_set_empty in dwarf2_ranges_read problematic?
> It puts unrelocated addresses in objfile->psymtabs_addrmap.
> 
>> diff --git a/gdb/dbxread.c b/gdb/dbxread.c
>> index 204937a9db8..143dd1c9c96 100644
>> --- a/gdb/dbxread.c
>> +++ b/gdb/dbxread.c
>> @@ -938,7 +938,7 @@ find_stab_function_addr (const char *namestring, const char *filename,
>>        msym = lookup_minimal_symbol (p, NULL, objfile);
>>      }
>>  
>> -  return msym.minsym == NULL ? 0 : BMSYMBOL_VALUE_ADDRESS (msym);
>> +  return msym.minsym == NULL ? 0 : MSYMBOL_VALUE_RAW_ADDRESS (msym.minsym);
> 
> Didn't this previously return a relocated address, and now returns an unrelocated one?



^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFA v3 3/6] Introduce partial_symbol::address
  2018-07-17 16:05   ` Simon Marchi
@ 2018-07-18 17:48     ` Tom Tromey
  0 siblings, 0 replies; 15+ messages in thread
From: Tom Tromey @ 2018-07-18 17:48 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Tom Tromey, gdb-patches

>>>>> "Simon" == Simon Marchi <simon.marchi@ericsson.com> writes:

Simon> I think it would be clearer to name this "unrelocated_address".

I made this change.

>> +  /* Set the address of this partial symbol.  The address must be
>> +     unrelocated.  */
>> +  void set_address (CORE_ADDR addr)
>> +  {
>> +    value.address = addr;
>> +  }

Simon> Since this is the mirror of raw_address (or unrelocated_address), it might good to
Simon> name it set_raw_address (or set_unrelocated_address).  Bugs in the calling code
Simon> would be more apparent.  If you're playing with a relocated address and call
Simon> set_unrelocated_address, it's quite obvious something is wrong.

Simon> Except it's not actually true as of this patch (we still pass a relocated address),
Simon> so maybe it can be renamed later, when it is the case.

I've changed the final patch to rename it to set_unrelocated_address.

Tom

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFA v3 6/6] Make psymbols and psymtabs independent of the program space
  2018-07-18  2:16     ` Simon Marchi
@ 2018-07-18 18:12       ` Tom Tromey
  0 siblings, 0 replies; 15+ messages in thread
From: Tom Tromey @ 2018-07-18 18:12 UTC (permalink / raw)
  To: Simon Marchi; +Cc: Tom Tromey, GDB Patches

>>>>> "Simon" == Simon Marchi <simon.marchi@ericsson.com> writes:

Simon> Is the call site of addrmap_set_empty in dwarf2_ranges_read problematic?
Simon> It puts unrelocated addresses in objfile->psymtabs_addrmap.

Yes, thanks for noticing this!

I looked at the other calls to gdbarch_adjust_dwarf2_addr to see if I
missed any other spots, but I didn't find any that looked suspicious.

>>> -  return msym.minsym == NULL ? 0 : BMSYMBOL_VALUE_ADDRESS (msym);
>>> +  return msym.minsym == NULL ? 0 : MSYMBOL_VALUE_RAW_ADDRESS (msym.minsym);

Simon> Didn't this previously return a relocated address, and now
Simon> returns an unrelocated one?

I looked at this again.  Mostly, this is the right thing to do --
previously the callers were dealing with relocated addresses, but now
they are dealing with unrelocated addresses.

However, I think the zero checks like this are now incorrect:

		  /* find_stab_function_addr will return 0 if the minimal
		     symbol wasn't found.  (Unfortunately, this might also
		     be a valid address.)  Anyway, if it *does* return 0,
		     it is likely that the value was set correctly to begin
		     with...  */
		  if (minsym_valu != 0)
		    nlist.n_value = minsym_valu;

And, I think the use in process_one_symbol is now incorrect.

I'll fix these up and look at the patch some more.

Tom

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2018-07-18 18:12 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-07 16:20 [RFA v3 0/6] Make psymbols independent of the progspace Tom Tromey
2018-06-07 16:20 ` [RFA v3 1/6] Remove dead code in end_psymtab Tom Tromey
2018-06-07 16:20 ` [RFA v3 4/6] Introduce accessors for psymtab high and low fields Tom Tromey
2018-07-17 16:12   ` Simon Marchi
2018-06-07 16:20 ` [RFA v3 3/6] Introduce partial_symbol::address Tom Tromey
2018-07-17 16:05   ` Simon Marchi
2018-07-18 17:48     ` Tom Tromey
2018-06-07 16:20 ` [RFA v3 2/6] Change representation of psymbol to flush out accessors Tom Tromey
2018-06-07 16:20 ` [RFA v3 6/6] Make psymbols and psymtabs independent of the program space Tom Tromey
     [not found]   ` <17305a06-9fbb-84d1-c596-c9bfece81aab@ericsson.com>
2018-07-18  2:16     ` Simon Marchi
2018-07-18 18:12       ` Tom Tromey
2018-06-07 16:20 ` [RFA v3 5/6] Add validity bits for psymtab high and low fields Tom Tromey
2018-07-17 16:18   ` Simon Marchi
2018-06-18 14:49 ` [RFA v3 0/6] Make psymbols independent of the progspace Tom Tromey
2018-07-16 16:33   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).