[3/6] Pass section index to start_compunit_symtab

Message ID 20230118153025.342512-4-tromey@adacore.com
State New
Headers
Series Change how symbol section indices are set |

Commit Message

Tom Tromey Jan. 18, 2023, 3:30 p.m. UTC
  Right now, the appropriate section index (apparently always
SECT_OFF_TEXT) is passed to end_compunit_symtab.  However, it's more
convenient to have this section index available when setting the
symbol's block.  So, this patch rearranges the code to pass the
section index to start_compunit_symtab, and then to store the index in
the buildsym_compunit object.
---
 gdb/buildsym-legacy.c |  9 +++++----
 gdb/buildsym-legacy.h |  6 +++---
 gdb/buildsym.c        | 29 +++++++++++++----------------
 gdb/buildsym.h        | 28 ++++++++++++++++++----------
 gdb/coffread.c        |  5 +++--
 gdb/ctfread.c         | 18 +++++++++---------
 gdb/dbxread.c         |  8 ++++----
 gdb/dwarf2/cu.c       |  3 ++-
 gdb/dwarf2/read.c     |  5 ++---
 gdb/mdebugread.c      |  5 ++---
 gdb/xcoffread.c       | 20 ++++++++++----------
 11 files changed, 71 insertions(+), 65 deletions(-)
  

Comments

Simon Marchi Jan. 18, 2023, 9:55 p.m. UTC | #1
>  /* Subroutine of augment_type_symtab to simplify it.
> diff --git a/gdb/buildsym.h b/gdb/buildsym.h
> index 9724607f3d9..0464c738114 100644
> --- a/gdb/buildsym.h
> +++ b/gdb/buildsym.h
> @@ -146,18 +146,23 @@ struct buildsym_compunit
>       (or NULL if not known).
>  
>       NAME and NAME_FOR_ID have the same purpose as for the start_subfile
> -     method.  */
> +     method.
> +
> +     SECTION_INDEX is the index of the section for the compunit and
> +     for block symbols in this compunit.  Normally SECT_OFF_TEXT.  */

I don't understand this comment, specifically how a compunit can "have"
a single section.  Don't compunits define data and text symbols, which
have different sections, for instance?

From what I can see, this section index is ultimately use to apply /
unapply a relocation offset when dealing with call sites (e.g.
compunit_symtab::find_call_site), so it makes sense that we want the
text section (call site addresses are code addresses).  So maybe the
comment and / or the field name could reflect that this is the section
index for the code / text section.  Just saying "section index" doesn't
tell much about which section it is.

I'm curious to know why we have to store that and we can't always use
SECT_OFF_TEXT, but I guess that will come with the following patches.

Simon
  
Tom Tromey Jan. 18, 2023, 10:02 p.m. UTC | #2
>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:

>> +     SECTION_INDEX is the index of the section for the compunit and
>> +     for block symbols in this compunit.  Normally SECT_OFF_TEXT.  */

Simon> I don't understand this comment, specifically how a compunit can "have"
Simon> a single section.  Don't compunits define data and text symbols, which
Simon> have different sections, for instance?

I can reword it, this only refers to the section for blocks.  See
compunit_symtab::m_block_line_section.

Simon> I'm curious to know why we have to store that and we can't always use
Simon> SECT_OFF_TEXT, but I guess that will come with the following patches.

I suspect this is dead code, I just didn't change it in this series.
I could though if you'd prefer.

Tom
  
Simon Marchi Jan. 18, 2023, 10:06 p.m. UTC | #3
On 1/18/23 17:02, Tom Tromey via Gdb-patches wrote:
>>>>>> "Simon" == Simon Marchi <simark@simark.ca> writes:
> 
>>> +     SECTION_INDEX is the index of the section for the compunit and
>>> +     for block symbols in this compunit.  Normally SECT_OFF_TEXT.  */
> 
> Simon> I don't understand this comment, specifically how a compunit can "have"
> Simon> a single section.  Don't compunits define data and text symbols, which
> Simon> have different sections, for instance?
> 
> I can reword it, this only refers to the section for blocks.  See
> compunit_symtab::m_block_line_section.
> 
> Simon> I'm curious to know why we have to store that and we can't always use
> Simon> SECT_OFF_TEXT, but I guess that will come with the following patches.
> 
> I suspect this is dead code, I just didn't change it in this series.
> I could though if you'd prefer.

I suppose that if it's indeed always the text section that is passed, it
would be easy to spot.

Simon
  
Tom Tromey Jan. 19, 2023, 1:36 p.m. UTC | #4
Simon> I'm curious to know why we have to store that and we can't always use
Simon> SECT_OFF_TEXT, but I guess that will come with the following patches.

>> I suspect this is dead code, I just didn't change it in this series.
>> I could though if you'd prefer.

Simon> I suppose that if it's indeed always the text section that is passed, it
Simon> would be easy to spot.

I've updated patch #3 to just remove the section index from
end_compunit_symtab, and I've added a new patch to the series to remove
compunit_symtab::m_block_line_section.

Tom
  
Tom Tromey Feb. 8, 2023, 4:28 p.m. UTC | #5
>>>>> "Tom" == Tom Tromey via Gdb-patches <gdb-patches@sourceware.org> writes:

Tom> I've updated patch #3 to just remove the section index from
Tom> end_compunit_symtab, and I've added a new patch to the series to remove
Tom> compunit_symtab::m_block_line_section.

Here's that patch.  I realized I forgot to send it to the list, but I
thought I should note it here before pushing this series.

Tom

commit d401e7bf04c0949dcc5e3d83143b75efc19d5f1e
Author: Tom Tromey <tromey@adacore.com>
Date:   Thu Jan 19 06:14:49 2023 -0700

    Remove compunit_symtab::m_block_line_section
    
    The previous patch hard-coded SECT_OFF_TEXT into the buildsym code.
    After this, it's clear that there is only one caller of
    compunit_symtab::set_block_line_section, and it always passes
    SECT_OFF_TEXT.  So, remove compunit_symtab::m_block_line_section and
    use SECT_OFF_TEXT instead.

diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index 41df0f061c1..d82c7672f7c 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -974,8 +974,6 @@ buildsym_compunit::end_compunit_symtab_with_blockvector
     set_block_compunit_symtab (b, cu);
   }
 
-  cu->set_block_line_section (SECT_OFF_TEXT (m_objfile));
-
   cu->set_macro_table (release_macros ());
 
   /* Default any symbols without a specified symtab to the primary symtab.  */
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index fe91d609f19..236ad820462 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -718,9 +718,7 @@ call_site_target::iterate_over_addresses
     case call_site_target::PHYSADDR:
       {
 	dwarf2_per_objfile *per_objfile = call_site->per_objfile;
-	compunit_symtab *cust = per_objfile->get_symtab (call_site->per_cu);
-	int sect_idx = cust->block_line_section ();
-	CORE_ADDR delta = per_objfile->objfile->section_offsets[sect_idx];
+	CORE_ADDR delta = per_objfile->objfile->text_section_offset ();
 
 	callback (m_loc.physaddr + delta);
       }
@@ -729,9 +727,7 @@ call_site_target::iterate_over_addresses
     case call_site_target::ADDRESSES:
       {
 	dwarf2_per_objfile *per_objfile = call_site->per_objfile;
-	compunit_symtab *cust = per_objfile->get_symtab (call_site->per_cu);
-	int sect_idx = cust->block_line_section ();
-	CORE_ADDR delta = per_objfile->objfile->section_offsets[sect_idx];
+	CORE_ADDR delta = per_objfile->objfile->text_section_offset ();
 
 	for (unsigned i = 0; i < m_loc.addresses.length; ++i)
 	  callback (m_loc.addresses.values[i] + delta);
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index 6a4c5976f18..45751c9c895 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -6436,9 +6436,7 @@ objfile_type (struct objfile *objfile)
 CORE_ADDR
 call_site::pc () const
 {
-  compunit_symtab *cust = this->per_objfile->get_symtab (this->per_cu);
-  CORE_ADDR delta
-	= this->per_objfile->objfile->section_offsets[cust->block_line_section ()];
+  CORE_ADDR delta = this->per_objfile->objfile->text_section_offset ();
   return m_unrelocated_pc + delta;
 }
 
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index e4fe3562c12..bf5057e723d 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -629,7 +629,7 @@ objfile_relocate1 (struct objfile *objfile,
 	    if (l)
 	      {
 		for (int i = 0; i < l->nitems; ++i)
-		  l->item[i].pc += delta[cust->block_line_section ()];
+		  l->item[i].pc += delta[SECT_OFF_TEXT (objfile)];
 	      }
 	  }
       }
@@ -637,7 +637,7 @@ objfile_relocate1 (struct objfile *objfile,
     for (compunit_symtab *cust : objfile->compunits ())
       {
 	struct blockvector *bv = cust->blockvector ();
-	int block_line_section = cust->block_line_section ();
+	int block_line_section = SECT_OFF_TEXT (objfile);
 
 	if (bv->map () != nullptr)
 	  bv->map ()->relocate (delta[block_line_section]);
diff --git a/gdb/symtab.c b/gdb/symtab.c
index a120c1d5e15..bf3a3e3caaa 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -342,8 +342,7 @@ compunit_symtab::find_call_site (CORE_ADDR pc) const
   if (m_call_site_htab == nullptr)
     return nullptr;
 
-  CORE_ADDR delta
-    = this->objfile ()->section_offsets[this->block_line_section ()];
+  CORE_ADDR delta = this->objfile ()->text_section_offset ();
   CORE_ADDR unrelocated_pc = pc - delta;
 
   struct call_site call_site_local (unrelocated_pc, nullptr, nullptr);
diff --git a/gdb/symtab.h b/gdb/symtab.h
index 484644f6129..50ce7525793 100644
--- a/gdb/symtab.h
+++ b/gdb/symtab.h
@@ -1786,16 +1786,6 @@ struct compunit_symtab
     m_blockvector = blockvector;
   }
 
-  int block_line_section () const
-  {
-    return m_block_line_section;
-  }
-
-  void set_block_line_section (int block_line_section)
-  {
-    m_block_line_section = block_line_section;
-  }
-
   bool locations_valid () const
   {
     return m_locations_valid;
@@ -1884,10 +1874,6 @@ struct compunit_symtab
      all symtabs in a given compilation unit.  */
   struct blockvector *m_blockvector;
 
-  /* Section in objfile->section_offsets for the blockvector and
-     the linetable.  Probably always SECT_OFF_TEXT.  */
-  int m_block_line_section;
-
   /* Symtab has been compiled with both optimizations and debug info so that
      GDB may stop skipping prologues as variables locations are valid already
      at function entry points.  */
  

Patch

diff --git a/gdb/buildsym-legacy.c b/gdb/buildsym-legacy.c
index e4194b69403..c4a767951f8 100644
--- a/gdb/buildsym-legacy.c
+++ b/gdb/buildsym-legacy.c
@@ -171,11 +171,11 @@  free_buildsym_compunit (void)
 }
 
 struct compunit_symtab *
-end_compunit_symtab (CORE_ADDR end_addr, int section)
+end_compunit_symtab (CORE_ADDR end_addr)
 {
   gdb_assert (buildsym_compunit != nullptr);
   struct compunit_symtab *result
-    = buildsym_compunit->end_compunit_symtab (end_addr, section);
+    = buildsym_compunit->end_compunit_symtab (end_addr);
   free_buildsym_compunit ();
   return result;
 }
@@ -228,14 +228,15 @@  record_line (struct subfile *subfile, int line, CORE_ADDR pc)
 struct compunit_symtab *
 start_compunit_symtab (struct objfile *objfile, const char *name,
 		       const char *comp_dir, CORE_ADDR start_addr,
-		       enum language language)
+		       enum language language, int section_index)
 {
   /* These should have been reset either by successful completion of building
      a symtab, or by the scoped_free_pendings destructor.  */
   gdb_assert (buildsym_compunit == nullptr);
 
   buildsym_compunit = new struct buildsym_compunit (objfile, name, comp_dir,
-						    language, start_addr);
+						    language, start_addr,
+						    section_index);
 
   return buildsym_compunit->get_compunit_symtab ();
 }
diff --git a/gdb/buildsym-legacy.h b/gdb/buildsym-legacy.h
index b553eb7e054..438d9ccb381 100644
--- a/gdb/buildsym-legacy.h
+++ b/gdb/buildsym-legacy.h
@@ -70,8 +70,7 @@  extern void push_subfile ();
 
 extern const char *pop_subfile ();
 
-extern struct compunit_symtab *end_compunit_symtab (CORE_ADDR end_addr,
-						    int section);
+extern struct compunit_symtab *end_compunit_symtab (CORE_ADDR end_addr);
 
 extern struct context_stack *push_context (int desc, CORE_ADDR valu);
 
@@ -83,7 +82,8 @@  extern struct compunit_symtab *start_compunit_symtab (struct objfile *objfile,
 						      const char *name,
 						      const char *comp_dir,
 						      CORE_ADDR start_addr,
-						      enum language language);
+						      enum language language,
+						      int section_index);
 
 /* Record the name of the debug format in the current pending symbol
    table.  FORMAT must be a string with a lifetime at least as long as
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index adab927235c..8c61223b1a0 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -54,12 +54,14 @@  buildsym_compunit::buildsym_compunit (struct objfile *objfile_,
 				      const char *comp_dir_,
 				      const char *name_for_id,
 				      enum language language_,
-				      CORE_ADDR last_addr)
+				      CORE_ADDR last_addr,
+				      int section_index)
   : m_objfile (objfile_),
     m_last_source_file (name == nullptr ? nullptr : xstrdup (name)),
     m_comp_dir (comp_dir_ == nullptr ? "" : comp_dir_),
     m_language (language_),
-    m_last_source_start_addr (last_addr)
+    m_last_source_start_addr (last_addr),
+    m_section_index (section_index)
 {
   /* Allocate the compunit symtab now.  The caller needs it to allocate
      non-primary symtabs.  It is also needed by get_macro_table.  */
@@ -854,7 +856,7 @@  buildsym_compunit::end_compunit_symtab_get_static_block (CORE_ADDR end_addr,
 
 struct compunit_symtab *
 buildsym_compunit::end_compunit_symtab_with_blockvector
-  (struct block *static_block, int section, int expandable)
+  (struct block *static_block, int expandable)
 {
   struct compunit_symtab *cu = m_compunit_symtab;
   struct blockvector *blockvector;
@@ -974,7 +976,7 @@  buildsym_compunit::end_compunit_symtab_with_blockvector
     set_block_compunit_symtab (b, cu);
   }
 
-  cu->set_block_line_section (section);
+  cu->set_block_line_section (m_section_index);
 
   cu->set_macro_table (release_macros ());
 
@@ -1014,15 +1016,12 @@  buildsym_compunit::end_compunit_symtab_with_blockvector
 /* Implementation of the second part of end_compunit_symtab.  Pass STATIC_BLOCK
    as value returned by end_compunit_symtab_get_static_block.
 
-   SECTION is the same as for end_compunit_symtab: the section number
-   (in objfile->section_offsets) of the blockvector and linetable.
-
    If EXPANDABLE is non-zero the GLOBAL_BLOCK dictionary is made
    expandable.  */
 
 struct compunit_symtab *
 buildsym_compunit::end_compunit_symtab_from_static_block
-  (struct block *static_block, int section, int expandable)
+  (struct block *static_block, int expandable)
 {
   struct compunit_symtab *cu;
 
@@ -1040,7 +1039,7 @@  buildsym_compunit::end_compunit_symtab_from_static_block
       cu = NULL;
     }
   else
-    cu = end_compunit_symtab_with_blockvector (static_block, section, expandable);
+    cu = end_compunit_symtab_with_blockvector (static_block, expandable);
 
   return cu;
 }
@@ -1050,9 +1049,7 @@  buildsym_compunit::end_compunit_symtab_from_static_block
    them), then make the struct symtab for that file and put it in the
    list of all such.
 
-   END_ADDR is the address of the end of the file's text.  SECTION is
-   the section number (in objfile->section_offsets) of the blockvector
-   and linetable.
+   END_ADDR is the address of the end of the file's text.
 
    Note that it is possible for end_compunit_symtab() to return NULL.  In
    particular, for the DWARF case at least, it will return NULL when
@@ -1067,24 +1064,24 @@  buildsym_compunit::end_compunit_symtab_from_static_block
    end_compunit_symtab_from_static_block yourself.  */
 
 struct compunit_symtab *
-buildsym_compunit::end_compunit_symtab (CORE_ADDR end_addr, int section)
+buildsym_compunit::end_compunit_symtab (CORE_ADDR end_addr)
 {
   struct block *static_block;
 
   static_block = end_compunit_symtab_get_static_block (end_addr, 0, 0);
-  return end_compunit_symtab_from_static_block (static_block, section, 0);
+  return end_compunit_symtab_from_static_block (static_block, 0);
 }
 
 /* Same as end_compunit_symtab except create a symtab that can be later added
    to.  */
 
 struct compunit_symtab *
-buildsym_compunit::end_expandable_symtab (CORE_ADDR end_addr, int section)
+buildsym_compunit::end_expandable_symtab (CORE_ADDR end_addr)
 {
   struct block *static_block;
 
   static_block = end_compunit_symtab_get_static_block (end_addr, 1, 0);
-  return end_compunit_symtab_from_static_block (static_block, section, 1);
+  return end_compunit_symtab_from_static_block (static_block, 1);
 }
 
 /* Subroutine of augment_type_symtab to simplify it.
diff --git a/gdb/buildsym.h b/gdb/buildsym.h
index 9724607f3d9..0464c738114 100644
--- a/gdb/buildsym.h
+++ b/gdb/buildsym.h
@@ -146,18 +146,23 @@  struct buildsym_compunit
      (or NULL if not known).
 
      NAME and NAME_FOR_ID have the same purpose as for the start_subfile
-     method.  */
+     method.
+
+     SECTION_INDEX is the index of the section for the compunit and
+     for block symbols in this compunit.  Normally SECT_OFF_TEXT.  */
 
   buildsym_compunit (struct objfile *objfile_, const char *name,
 		     const char *comp_dir_, const char *name_for_id,
-		     enum language language_, CORE_ADDR last_addr);
+		     enum language language_, CORE_ADDR last_addr,
+		     int section_index);
 
   /* Same as above, but passes NAME for NAME_FOR_ID.  */
 
   buildsym_compunit (struct objfile *objfile_, const char *name,
 		     const char *comp_dir_, enum language language_,
-		     CORE_ADDR last_addr)
-    : buildsym_compunit (objfile_, name, comp_dir_, name, language_, last_addr)
+		     CORE_ADDR last_addr, int section_index)
+    : buildsym_compunit (objfile_, name, comp_dir_, name, language_, last_addr,
+			 section_index)
   {}
 
   /* Reopen an existing compunit_symtab so that additional symbols can
@@ -172,7 +177,8 @@  struct buildsym_compunit
       m_comp_dir (comp_dir_ == nullptr ? "" : comp_dir_),
       m_compunit_symtab (cust),
       m_language (language_),
-      m_last_source_start_addr (last_addr)
+      m_last_source_start_addr (last_addr),
+      m_section_index (cust->block_line_section ())
   {
   }
 
@@ -327,12 +333,11 @@  struct buildsym_compunit
     (CORE_ADDR end_addr, int expandable, int required);
 
   struct compunit_symtab *end_compunit_symtab_from_static_block
-    (struct block *static_block, int section, int expandable);
+    (struct block *static_block, int expandable);
 
-  struct compunit_symtab *end_compunit_symtab (CORE_ADDR end_addr, int section);
+  struct compunit_symtab *end_compunit_symtab (CORE_ADDR end_addr);
 
-  struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr,
-						 int section);
+  struct compunit_symtab *end_expandable_symtab (CORE_ADDR end_addr);
 
   void augment_type_symtab ();
 
@@ -352,7 +357,7 @@  struct buildsym_compunit
   void watch_main_source_file_lossage ();
 
   struct compunit_symtab *end_compunit_symtab_with_blockvector
-    (struct block *static_block, int section, int expandable);
+    (struct block *static_block, int expandable);
 
   /* The objfile we're reading debug info from.  */
   struct objfile *m_objfile;
@@ -401,6 +406,9 @@  struct buildsym_compunit
      DW_AT_low_pc attribute of a DW_TAG_compile_unit DIE.  */
   CORE_ADDR m_last_source_start_addr;
 
+  /* The section index.  */
+  int m_section_index;
+
   /* Stack of subfile names.  */
   std::vector<const char *> m_subfile_stack;
 
diff --git a/gdb/coffread.c b/gdb/coffread.c
index 4950a7324c8..041960d0939 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -376,7 +376,8 @@  coff_start_compunit_symtab (struct objfile *objfile, const char *name)
      set_last_source_start_addr in coff_end_compunit_symtab.  */
 			 0,
   /* Let buildsym.c deduce the language for this symtab.  */
-			 language_unknown);
+			 language_unknown,
+			 SECT_OFF_TEXT (objfile));
   record_debugformat ("COFF");
 }
 
@@ -404,7 +405,7 @@  coff_end_compunit_symtab (struct objfile *objfile)
 {
   set_last_source_start_addr (current_source_start_addr);
 
-  end_compunit_symtab (current_source_end_addr, SECT_OFF_TEXT (objfile));
+  end_compunit_symtab (current_source_end_addr);
 
   /* Reinitialize for beginning of new file.  */
   set_last_source_file (NULL);
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 97a0df91a53..eca1bef69b3 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -1246,30 +1246,30 @@  get_objfile_text_range (struct objfile *of, int *tsize)
 
 static void
 ctf_start_compunit_symtab (ctf_psymtab *pst,
-			   struct objfile *of, CORE_ADDR text_offset)
+			   struct objfile *of, CORE_ADDR text_offset,
+			   int section_offset)
 {
   struct ctf_context *ccp;
 
   ccp = &pst->context;
   ccp->builder = new buildsym_compunit
 		       (of, pst->filename, nullptr,
-		       language_c, text_offset);
+			language_c, text_offset, section_offset);
   ccp->builder->record_debugformat ("ctf");
 }
 
 /* Finish reading symbol/type definitions in CTF format.
-   END_ADDR is the end address of the file's text.  SECTION is
-   the .text section number.  */
+   END_ADDR is the end address of the file's text.  */
 
 static struct compunit_symtab *
 ctf_end_compunit_symtab (ctf_psymtab *pst,
-			 CORE_ADDR end_addr, int section)
+			 CORE_ADDR end_addr)
 {
   struct ctf_context *ccp;
 
   ccp = &pst->context;
   struct compunit_symtab *result
-    = ccp->builder->end_compunit_symtab (end_addr, section);
+    = ccp->builder->end_compunit_symtab (end_addr);
   delete ccp->builder;
   ccp->builder = nullptr;
   return result;
@@ -1406,13 +1406,13 @@  ctf_psymtab::read_symtab (struct objfile *objfile)
       int tsize;
 
       offset = get_objfile_text_range (objfile, &tsize);
-      ctf_start_compunit_symtab (this, objfile, offset);
+      ctf_start_compunit_symtab (this, objfile, offset,
+				 SECT_OFF_TEXT (objfile));
       expand_psymtab (objfile);
 
       set_text_low (offset);
       set_text_high (offset + tsize);
-      compunit_symtab = ctf_end_compunit_symtab (this, offset + tsize,
-						 SECT_OFF_TEXT (objfile));
+      compunit_symtab = ctf_end_compunit_symtab (this, offset + tsize);
 
       /* Finish up the debug error message.  */
       if (info_verbose)
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index dc11f0bb6a9..b2ca4a83933 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -2331,8 +2331,7 @@  read_ofile_symtab (struct objfile *objfile, legacy_psymtab *pst)
   if (get_last_source_start_addr () > text_offset)
     set_last_source_start_addr (text_offset);
 
-  pst->compunit_symtab = end_compunit_symtab (text_offset + text_size,
-					      SECT_OFF_TEXT (objfile));
+  pst->compunit_symtab = end_compunit_symtab (text_offset + text_size);
 
   end_stabs ();
 
@@ -2594,7 +2593,7 @@  process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name,
 	      patch_subfile_names (get_current_subfile (), name);
 	      break;		/* Ignore repeated SOs.  */
 	    }
-	  end_compunit_symtab (valu, SECT_OFF_TEXT (objfile));
+	  end_compunit_symtab (valu);
 	  end_stabs ();
 	}
 
@@ -2606,7 +2605,8 @@  process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name,
       function_start_offset = 0;
 
       start_stabs ();
-      start_compunit_symtab (objfile, name, NULL, valu, language);
+      start_compunit_symtab (objfile, name, NULL, valu, language,
+			     SECT_OFF_TEXT (objfile));
       record_debugformat ("stabs");
       break;
 
diff --git a/gdb/dwarf2/cu.c b/gdb/dwarf2/cu.c
index 9c1691c90e9..c4b3d9e8bd1 100644
--- a/gdb/dwarf2/cu.c
+++ b/gdb/dwarf2/cu.c
@@ -78,7 +78,8 @@  dwarf2_cu::start_compunit_symtab (const char *name, const char *comp_dir,
 
   m_builder.reset (new struct buildsym_compunit
 		   (this->per_objfile->objfile,
-		    name, comp_dir, name_for_id, lang (), low_pc));
+		    name, comp_dir, name_for_id, lang (), low_pc,
+		    SECT_OFF_TEXT (this->per_objfile->objfile)));
 
   list_in_scope = get_builder ()->get_file_symbols ();
 
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index 6a7412ce834..612b7299c0f 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -8456,7 +8456,7 @@  process_full_comp_unit (dwarf2_cu *cu, enum language pretend_language)
   dwarf2_record_block_ranges (cu->dies, static_block, baseaddr, cu);
 
   cust = cu->get_builder ()->end_compunit_symtab_from_static_block
-    (static_block, SECT_OFF_TEXT (objfile), 0);
+    (static_block, 0);
 
   if (cust != NULL)
     {
@@ -8507,7 +8507,6 @@  process_full_type_unit (dwarf2_cu *cu,
 			enum language pretend_language)
 {
   dwarf2_per_objfile *per_objfile = cu->per_objfile;
-  struct objfile *objfile = per_objfile->objfile;
   struct compunit_symtab *cust;
   struct signatured_type *sig_type;
 
@@ -8541,7 +8540,7 @@  process_full_type_unit (dwarf2_cu *cu,
   if (tug_unshare->compunit_symtab == NULL)
     {
       buildsym_compunit *builder = cu->get_builder ();
-      cust = builder->end_expandable_symtab (0, SECT_OFF_TEXT (objfile));
+      cust = builder->end_expandable_symtab (0);
       tug_unshare->compunit_symtab = cust;
 
       if (cust != NULL)
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 4feee39035e..609b51727aa 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -3968,7 +3968,7 @@  mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
 		    {
 		      valu += section_offsets[SECT_OFF_TEXT (objfile)];
 		      previous_stab_code = N_SO;
-		      cust = end_compunit_symtab (valu, SECT_OFF_TEXT (objfile));
+		      cust = end_compunit_symtab (valu);
 		      end_stabs ();
 		      last_symtab_ended = 1;
 		    }
@@ -4028,8 +4028,7 @@  mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
 
       if (! last_symtab_ended)
 	{
-	  cust = end_compunit_symtab (pst->raw_text_high (),
-				      SECT_OFF_TEXT (objfile));
+	  cust = end_compunit_symtab (pst->raw_text_high ());
 	  end_stabs ();
 	}
 
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 52ae3aecb97..3b990d660f0 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -958,7 +958,7 @@  read_xcoff_symtab (struct objfile *objfile, legacy_psymtab *pst)
 
   start_stabs ();
   start_compunit_symtab (objfile, filestring, NULL, file_start_addr,
-			 pst_symtab_language);
+			 pst_symtab_language, SECT_OFF_TEXT (objfile));
   record_debugformat (debugfmt);
   symnum = ((struct xcoff_symloc *) pst->read_symtab_private)->first_symnum;
   max_symnum =
@@ -1045,14 +1045,14 @@  read_xcoff_symtab (struct objfile *objfile, legacy_psymtab *pst)
 	{
 	  if (get_last_source_file ())
 	    {
-	      pst->compunit_symtab = end_compunit_symtab
-		(cur_src_end_addr, SECT_OFF_TEXT (objfile));
+	      pst->compunit_symtab = end_compunit_symtab (cur_src_end_addr);
 	      end_stabs ();
 	    }
 
 	  start_stabs ();
 	  start_compunit_symtab (objfile, "_globals_", NULL,
-				 0, pst_symtab_language);
+				 0, pst_symtab_language,
+				 SECT_OFF_TEXT (objfile));
 	  record_debugformat (debugfmt);
 	  cur_src_end_addr = first_object_file_end;
 	  /* Done with all files, everything from here on is globals.  */
@@ -1136,14 +1136,14 @@  read_xcoff_symtab (struct objfile *objfile, legacy_psymtab *pst)
 			{
 			  complete_symtab (filestring, file_start_addr);
 			  cur_src_end_addr = file_end_addr;
-			  end_compunit_symtab (file_end_addr,
-					       SECT_OFF_TEXT (objfile));
+			  end_compunit_symtab (file_end_addr);
 			  end_stabs ();
 			  start_stabs ();
 			  /* Give all csects for this source file the same
 			     name.  */
 			  start_compunit_symtab (objfile, filestring, NULL,
-					0, pst_symtab_language);
+						 0, pst_symtab_language,
+						 SECT_OFF_TEXT (objfile));
 			  record_debugformat (debugfmt);
 			}
 
@@ -1243,7 +1243,7 @@  read_xcoff_symtab (struct objfile *objfile, legacy_psymtab *pst)
 
 	  complete_symtab (filestring, file_start_addr);
 	  cur_src_end_addr = file_end_addr;
-	  end_compunit_symtab (file_end_addr, SECT_OFF_TEXT (objfile));
+	  end_compunit_symtab (file_end_addr);
 	  end_stabs ();
 
 	  /* XCOFF, according to the AIX 3.2 documentation, puts the
@@ -1263,7 +1263,7 @@  read_xcoff_symtab (struct objfile *objfile, legacy_psymtab *pst)
 
 	  start_stabs ();
 	  start_compunit_symtab (objfile, filestring, NULL, 0,
-				 pst_symtab_language);
+				 pst_symtab_language, SECT_OFF_TEXT (objfile));
 	  record_debugformat (debugfmt);
 	  last_csect_name = 0;
 
@@ -1431,7 +1431,7 @@  read_xcoff_symtab (struct objfile *objfile, legacy_psymtab *pst)
 
       complete_symtab (filestring, file_start_addr);
       cur_src_end_addr = file_end_addr;
-      cust = end_compunit_symtab (file_end_addr, SECT_OFF_TEXT (objfile));
+      cust = end_compunit_symtab (file_end_addr);
       /* When reading symbols for the last C_FILE of the objfile, try
 	 to make sure that we set pst->compunit_symtab to the symtab for the
 	 file, not to the _globals_ symtab.  I'm not sure whether this