]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blobdiff - gdb/dwarf2/read.c
Remove reference to dwarf2_per_cu_data::dwarf2_per_objfile in queue_and_load_all_dwo_tus
[thirdparty/binutils-gdb.git] / gdb / dwarf2 / read.c
index da1638d3a197bc4216b1e31febeed00582e4759f..4b63b8e8b9bc0000878877e46eb3f51a39ceee73 100644 (file)
@@ -912,12 +912,14 @@ class cutu_reader : public die_reader_specs
 {
 public:
 
-  cutu_reader (struct dwarf2_per_cu_data *this_cu,
+  cutu_reader (dwarf2_per_cu_data *this_cu,
+              dwarf2_per_objfile *per_objfile,
               struct abbrev_table *abbrev_table,
               int use_existing_cu,
               bool skip_partial);
 
   explicit cutu_reader (struct dwarf2_per_cu_data *this_cu,
+                       dwarf2_per_objfile *per_objfile,
                        struct dwarf2_cu *parent_cu = nullptr,
                        struct dwo_file *dwo_file = nullptr);
 
@@ -1202,7 +1204,8 @@ static void dwarf2_find_base_address (struct die_info *die,
                                      struct dwarf2_cu *cu);
 
 static dwarf2_psymtab *create_partial_symtab
-  (struct dwarf2_per_cu_data *per_cu, const char *name);
+  (dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile,
+   const char *name);
 
 static void build_type_psymtabs_reader (const struct die_reader_specs *reader,
                                        const gdb_byte *info_ptr,
@@ -1510,9 +1513,11 @@ static struct type *get_DW_AT_signature_type (struct die_info *,
                                              const struct attribute *,
                                              struct dwarf2_cu *);
 
-static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu);
+static void load_full_type_unit (dwarf2_per_cu_data *per_cu,
+                                dwarf2_per_objfile *per_objfile);
 
-static void read_signatured_type (struct signatured_type *);
+static void read_signatured_type (signatured_type *sig_type,
+                                 dwarf2_per_objfile *per_objfile);
 
 static int attr_to_dynamic_prop (const struct attribute *attr,
                                 struct die_info *die, struct dwarf2_cu *cu,
@@ -1562,14 +1567,18 @@ static void create_all_comp_units (struct dwarf2_per_objfile *dwarf2_per_objfile
 
 static int create_all_type_units (struct dwarf2_per_objfile *dwarf2_per_objfile);
 
-static void load_full_comp_unit (struct dwarf2_per_cu_data *, bool,
-                                enum language);
+static void load_full_comp_unit (dwarf2_per_cu_data *per_cu,
+                                dwarf2_per_objfile *per_objfile,
+                                bool skip_partial,
+                                enum language pretend_language);
 
-static void process_full_comp_unit (struct dwarf2_per_cu_data *,
-                                   enum language);
+static void process_full_comp_unit (dwarf2_per_cu_data *per_cu,
+                                   dwarf2_per_objfile *per_objfile,
+                                   enum language pretend_language);
 
-static void process_full_type_unit (struct dwarf2_per_cu_data *,
-                                   enum language);
+static void process_full_type_unit (dwarf2_per_cu_data *per_cu,
+                                   dwarf2_per_objfile *per_objfile,
+                                   enum language pretend_language);
 
 static void dwarf2_add_dependence (struct dwarf2_cu *,
                                   struct dwarf2_per_cu_data *);
@@ -1663,10 +1672,11 @@ static struct dwp_file *get_dwp_file
   (struct dwarf2_per_objfile *dwarf2_per_objfile);
 
 static struct dwo_unit *lookup_dwo_comp_unit
-  (struct dwarf2_per_cu_data *, const char *, const char *, ULONGEST);
+  (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
+   ULONGEST signature);
 
 static struct dwo_unit *lookup_dwo_type_unit
-  (struct signatured_type *, const char *, const char *);
+  (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir);
 
 static void queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data *);
 
@@ -1752,7 +1762,8 @@ line_header_eq_voidp (const void *item_lhs, const void *item_rhs)
 
 dwarf2_per_bfd::dwarf2_per_bfd (bfd *obfd, const dwarf2_debug_sections *names,
                                bool can_copy_)
-  : can_copy (can_copy_)
+  : obfd (obfd),
+    can_copy (can_copy_)
 {
   if (names == NULL)
     names = &dwarf2_elf_names;
@@ -2112,19 +2123,19 @@ locate_dwz_sections (bfd *abfd, asection *sectp, void *arg)
 /* See dwarf2read.h.  */
 
 struct dwz_file *
-dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
+dwarf2_get_dwz_file (dwarf2_per_bfd *per_bfd)
 {
   const char *filename;
   bfd_size_type buildid_len_arg;
   size_t buildid_len;
   bfd_byte *buildid;
 
-  if (dwarf2_per_objfile->per_bfd->dwz_file != NULL)
-    return dwarf2_per_objfile->per_bfd->dwz_file.get ();
+  if (per_bfd->dwz_file != NULL)
+    return per_bfd->dwz_file.get ();
 
   bfd_set_error (bfd_error_no_error);
   gdb::unique_xmalloc_ptr<char> data
-    (bfd_get_alt_debug_link_info (dwarf2_per_objfile->objfile->obfd,
+    (bfd_get_alt_debug_link_info (per_bfd->obfd,
                                  &buildid_len_arg, &buildid));
   if (data == NULL)
     {
@@ -2144,7 +2155,7 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
   if (!IS_ABSOLUTE_PATH (filename))
     {
       gdb::unique_xmalloc_ptr<char> abs
-       = gdb_realpath (objfile_name (dwarf2_per_objfile->objfile));
+       = gdb_realpath (bfd_get_filename (per_bfd->obfd));
 
       abs_storage = ldirname (abs.get ()) + SLASH_STRING + filename;
       filename = abs_storage.c_str ();
@@ -2165,7 +2176,7 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
   if (dwz_bfd == nullptr)
     {
       gdb::unique_xmalloc_ptr<char> alt_filename;
-      const char *origname = dwarf2_per_objfile->objfile->original_name;
+      const char *origname = bfd_get_filename (per_bfd->obfd);
 
       scoped_fd fd (debuginfod_debuginfo_query (buildid,
                                                buildid_len,
@@ -2187,7 +2198,7 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
 
   if (dwz_bfd == NULL)
     error (_("could not find '.gnu_debugaltlink' file for %s"),
-          objfile_name (dwarf2_per_objfile->objfile));
+          bfd_get_filename (per_bfd->obfd));
 
   std::unique_ptr<struct dwz_file> result
     (new struct dwz_file (std::move (dwz_bfd)));
@@ -2195,10 +2206,9 @@ dwarf2_get_dwz_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
   bfd_map_over_sections (result->dwz_bfd.get (), locate_dwz_sections,
                         result.get ());
 
-  gdb_bfd_record_inclusion (dwarf2_per_objfile->objfile->obfd,
-                           result->dwz_bfd.get ());
-  dwarf2_per_objfile->per_bfd->dwz_file = std::move (result);
-  return dwarf2_per_objfile->per_bfd->dwz_file.get ();
+  gdb_bfd_record_inclusion (per_bfd->obfd, result->dwz_bfd.get ());
+  per_bfd->dwz_file = std::move (result);
+  return per_bfd->dwz_file.get ();
 }
 \f
 /* DWARF quick_symbols_functions support.  */
@@ -2323,17 +2333,18 @@ create_quick_file_names_table (unsigned int nr_initial_entries)
                                     delete_file_name_entry, xcalloc, xfree));
 }
 
-/* Read in PER_CU->CU.  This function is unrelated to symtabs, symtab would
-   have to be created afterwards.  You should call age_cached_comp_units after
-   processing PER_CU->CU.  dw2_setup must have been already called.  */
+/* Read in CU (dwarf2_cu object) for PER_CU in the context of PER_OBJFILE.  This
+   function is unrelated to symtabs, symtab would have to be created afterwards.
+   You should call age_cached_comp_units after processing the CU.  */
 
 static void
-load_cu (struct dwarf2_per_cu_data *per_cu, bool skip_partial)
+load_cu (dwarf2_per_cu_data *per_cu, dwarf2_per_objfile *per_objfile,
+        bool skip_partial)
 {
   if (per_cu->is_debug_types)
-    load_full_type_unit (per_cu);
+    load_full_type_unit (per_cu, per_objfile);
   else
-    load_full_comp_unit (per_cu, skip_partial, language_minimal);
+    load_full_comp_unit (per_cu, per_objfile, skip_partial, language_minimal);
 
   if (per_cu->cu == NULL)
     return;  /* Dummy CU.  */
@@ -2361,7 +2372,7 @@ dw2_do_instantiate_symtab (dwarf2_per_cu_data *per_cu,
   if (!dwarf2_per_objfile->symtab_set_p (per_cu))
     {
       queue_comp_unit (per_cu, language_minimal);
-      load_cu (per_cu, skip_partial);
+      load_cu (per_cu, dwarf2_per_objfile, skip_partial);
 
       /* If we just loaded a CU from a DWO, and we're working with an index
         that may badly handle TUs, load all the TUs in that DWO as well.
@@ -2526,7 +2537,7 @@ create_cus_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
   if (dwz_elements == 0)
     return;
 
-  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
   create_cus_from_index_list (dwarf2_per_objfile, dwz_list, dwz_elements,
                              &dwz->info, 1);
 }
@@ -3073,7 +3084,7 @@ dwarf2_read_gdb_index
 
   /* If there is a .dwz file, read it so we can get its CU list as
      well.  */
-  dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+  dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
   if (dwz != NULL)
     {
       struct mapped_index dwz_map;
@@ -3212,7 +3223,8 @@ dw2_get_file_names_reader (const struct die_reader_specs *reader,
    table for THIS_CU.  */
 
 static struct quick_file_names *
-dw2_get_file_names (struct dwarf2_per_cu_data *this_cu)
+dw2_get_file_names (dwarf2_per_cu_data *this_cu,
+                   dwarf2_per_objfile *per_objfile)
 {
   /* This should never be called for TUs.  */
   gdb_assert (! this_cu->is_debug_types);
@@ -3225,7 +3237,7 @@ dw2_get_file_names (struct dwarf2_per_cu_data *this_cu)
   if (this_cu->v.quick->no_file_data)
     return NULL;
 
-  cutu_reader reader (this_cu);
+  cutu_reader reader (this_cu, per_objfile);
   if (!reader.dummy_p)
     dw2_get_file_names_reader (&reader, reader.info_ptr, reader.comp_unit_die);
 
@@ -3341,7 +3353,8 @@ dw2_map_symtabs_matching_filename
       if (dwarf2_per_objfile->symtab_set_p (per_cu))
        continue;
 
-      quick_file_names *file_data = dw2_get_file_names (per_cu);
+      quick_file_names *file_data
+       = dw2_get_file_names (per_cu, dwarf2_per_objfile);
       if (file_data == NULL)
        continue;
 
@@ -3682,7 +3695,8 @@ dw2_expand_symtabs_with_fullname (struct objfile *objfile,
       if (dwarf2_per_objfile->symtab_set_p (per_cu))
        continue;
 
-      quick_file_names *file_data = dw2_get_file_names (per_cu);
+      quick_file_names *file_data
+       = dw2_get_file_names (per_cu, dwarf2_per_objfile);
       if (file_data == NULL)
        continue;
 
@@ -4671,7 +4685,8 @@ dw_expand_symtabs_matching_file_matcher
       if (dwarf2_per_objfile->symtab_set_p (per_cu))
        continue;
 
-      quick_file_names *file_data = dw2_get_file_names (per_cu);
+      quick_file_names *file_data
+       = dw2_get_file_names (per_cu, dwarf2_per_objfile);
       if (file_data == NULL)
        continue;
 
@@ -4855,7 +4870,8 @@ dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun,
          if (dwarf2_per_objfile->symtab_set_p (per_cu))
            continue;
 
-         quick_file_names *file_data = dw2_get_file_names (per_cu);
+         quick_file_names *file_data
+           = dw2_get_file_names (per_cu, dwarf2_per_objfile);
          if (file_data == NULL)
            continue;
 
@@ -5173,7 +5189,7 @@ create_cus_from_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile,
   if (dwz_map.cu_count == 0)
     return;
 
-  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
   create_cus_from_debug_names_list (dwarf2_per_objfile, dwz_map, dwz->info,
                                    true /* is_dwz */);
 }
@@ -5200,7 +5216,7 @@ dwarf2_read_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile)
 
   /* If there is a .dwz file, read it so we can get its CU list as
      well.  */
-  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
   if (dwz != NULL)
     {
       if (!read_debug_names_from_section (objfile,
@@ -6032,12 +6048,12 @@ static struct dwarf2_section_info *
 get_abbrev_section_for_cu (struct dwarf2_per_cu_data *this_cu)
 {
   struct dwarf2_section_info *abbrev;
-  struct dwarf2_per_objfile *dwarf2_per_objfile = this_cu->dwarf2_per_objfile;
+  dwarf2_per_bfd *per_bfd = this_cu->per_bfd;
 
   if (this_cu->is_dwz)
-    abbrev = &dwarf2_get_dwz_file (dwarf2_per_objfile)->abbrev;
+    abbrev = &dwarf2_get_dwz_file (per_bfd)->abbrev;
   else
-    abbrev = &dwarf2_per_objfile->per_bfd->abbrev;
+    abbrev = &per_bfd->abbrev;
 
   return abbrev;
 }
@@ -6673,7 +6689,7 @@ init_cu_die_reader (struct die_reader_specs *reader,
    The result is non-zero if a valid (non-dummy) DIE was found.  */
 
 static int
-read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
+read_cutu_die_from_dwo (dwarf2_cu *cu,
                        struct dwo_unit *dwo_unit,
                        struct die_info *stub_comp_unit_die,
                        const char *stub_comp_dir,
@@ -6682,9 +6698,9 @@ read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
                        struct die_info **result_comp_unit_die,
                        abbrev_table_up *result_dwo_abbrev_table)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = this_cu->dwarf2_per_objfile;
+  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
+  dwarf2_per_cu_data *per_cu = cu->per_cu;
   struct objfile *objfile = dwarf2_per_objfile->objfile;
-  struct dwarf2_cu *cu = this_cu->cu;
   bfd *abfd;
   const gdb_byte *begin_info_ptr, *info_ptr;
   struct attribute *comp_dir, *stmt_list, *low_pc, *high_pc, *ranges;
@@ -6713,7 +6729,7 @@ read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
     {
       /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the
         DWO file.  */
-      if (! this_cu->is_debug_types)
+      if (!per_cu->is_debug_types)
        stmt_list = dwarf2_attr (stub_comp_unit_die, DW_AT_stmt_list, cu);
       low_pc = dwarf2_attr (stub_comp_unit_die, DW_AT_low_pc, cu);
       high_pc = dwarf2_attr (stub_comp_unit_die, DW_AT_high_pc, cu);
@@ -6746,9 +6762,9 @@ read_cutu_die_from_dwo (struct dwarf2_per_cu_data *this_cu,
                               + to_underlying (dwo_unit->sect_off));
   dwo_abbrev_section = &dwo_unit->dwo_file->sections.abbrev;
 
-  if (this_cu->is_debug_types)
+  if (per_cu->is_debug_types)
     {
-      struct signatured_type *sig_type = (struct signatured_type *) this_cu;
+      signatured_type *sig_type = (struct signatured_type *) per_cu;
 
       info_ptr = read_and_check_comp_unit_head (dwarf2_per_objfile,
                                                &cu->header, section,
@@ -6859,11 +6875,9 @@ lookup_dwo_id (struct dwarf2_cu *cu, struct die_info* comp_unit_die)
    Returns NULL if the specified DWO unit cannot be found.  */
 
 static struct dwo_unit *
-lookup_dwo_unit (struct dwarf2_per_cu_data *this_cu,
-                struct die_info *comp_unit_die,
-                const char *dwo_name)
+lookup_dwo_unit (dwarf2_cu *cu, die_info *comp_unit_die, const char *dwo_name)
 {
-  struct dwarf2_cu *cu = this_cu->cu;
+  dwarf2_per_cu_data *per_cu = cu->per_cu;
   struct dwo_unit *dwo_unit;
   const char *comp_dir;
 
@@ -6873,24 +6887,18 @@ lookup_dwo_unit (struct dwarf2_per_cu_data *this_cu,
   dwo_name = dwarf2_dwo_name (comp_unit_die, cu);
   comp_dir = dwarf2_string_attr (comp_unit_die, DW_AT_comp_dir, cu);
 
-  if (this_cu->is_debug_types)
-    {
-      struct signatured_type *sig_type;
-
-      /* Since this_cu is the first member of struct signatured_type,
-        we can go from a pointer to one to a pointer to the other.  */
-      sig_type = (struct signatured_type *) this_cu;
-      dwo_unit = lookup_dwo_type_unit (sig_type, dwo_name, comp_dir);
-    }
+  if (per_cu->is_debug_types)
+    dwo_unit = lookup_dwo_type_unit (cu, dwo_name, comp_dir);
   else
     {
       gdb::optional<ULONGEST> signature = lookup_dwo_id (cu, comp_unit_die);
+
       if (!signature.has_value ())
        error (_("Dwarf Error: missing dwo_id for dwo_name %s"
                 " [in module %s]"),
-              dwo_name, objfile_name (this_cu->dwarf2_per_objfile->objfile));
-      dwo_unit = lookup_dwo_comp_unit (this_cu, dwo_name, comp_dir,
-                                      *signature);
+              dwo_name, bfd_get_filename (per_cu->per_bfd->obfd));
+
+      dwo_unit = lookup_dwo_comp_unit (cu, dwo_name, comp_dir, *signature);
     }
 
   return dwo_unit;
@@ -6930,7 +6938,7 @@ cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data *this_cu,
      abbrev table.  When reading DWOs with skeletonless TUs, all the TUs
      could share abbrev tables.  */
 
-  if (read_cutu_die_from_dwo (this_cu, sig_type->dwo_unit,
+  if (read_cutu_die_from_dwo (this_cu->cu, sig_type->dwo_unit,
                              NULL /* stub_comp_unit_die */,
                              sig_type->dwo_unit->dwo_file->comp_dir,
                              this, &info_ptr,
@@ -6952,14 +6960,14 @@ cutu_reader::init_tu_and_read_dwo_dies (dwarf2_per_cu_data *this_cu,
    If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it.
    Otherwise, a new CU is allocated with xmalloc.  */
 
-cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
+cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu,
+                         dwarf2_per_objfile *dwarf2_per_objfile,
                          struct abbrev_table *abbrev_table,
                          int use_existing_cu,
                          bool skip_partial)
   : die_reader_specs {},
     m_this_cu (this_cu)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = this_cu->dwarf2_per_objfile;
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   struct dwarf2_section_info *section = this_cu->section;
   bfd *abfd = section->get_bfd_owner ();
@@ -7117,10 +7125,10 @@ cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
                     sect_offset_str (this_cu->sect_off),
                     bfd_get_filename (abfd));
        }
-      dwo_unit = lookup_dwo_unit (this_cu, comp_unit_die, dwo_name);
+      dwo_unit = lookup_dwo_unit (cu, comp_unit_die, dwo_name);
       if (dwo_unit != NULL)
        {
-         if (read_cutu_die_from_dwo (this_cu, dwo_unit,
+         if (read_cutu_die_from_dwo (cu, dwo_unit,
                                      comp_unit_die, NULL,
                                      this, &info_ptr,
                                      &dwo_comp_unit_die,
@@ -7150,8 +7158,11 @@ cutu_reader::keep ()
   gdb_assert (!dummy_p);
   if (m_new_cu != NULL)
     {
-      struct dwarf2_per_objfile *dwarf2_per_objfile
-       = m_this_cu->dwarf2_per_objfile;
+      /* We know that m_this_cu->cu is set, since we are in the process of
+         parsing the CU.  */
+      gdb_assert (m_this_cu->cu != nullptr);
+      dwarf2_per_objfile *dwarf2_per_objfile = m_this_cu->cu->per_objfile;
+
       /* Link this CU into read_in_chain.  */
       m_this_cu->cu->read_in_chain = dwarf2_per_objfile->per_bfd->read_in_chain;
       dwarf2_per_objfile->per_bfd->read_in_chain = m_this_cu;
@@ -7176,13 +7187,13 @@ cutu_reader::keep ()
    When parent_cu is passed, it is used to provide a default value for
    str_offsets_base and addr_base from the parent.  */
 
-cutu_reader::cutu_reader (struct dwarf2_per_cu_data *this_cu,
+cutu_reader::cutu_reader (dwarf2_per_cu_data *this_cu,
+                         dwarf2_per_objfile *dwarf2_per_objfile,
                          struct dwarf2_cu *parent_cu,
                          struct dwo_file *dwo_file)
   : die_reader_specs {},
     m_this_cu (this_cu)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = this_cu->dwarf2_per_objfile;
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   struct dwarf2_section_info *section = this_cu->section;
   bfd *abfd = section->get_bfd_owner ();
@@ -7316,7 +7327,7 @@ create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct)
       else
        name = string_printf ("<type_units_at_0x%x>", line_offset);
 
-      pst = create_partial_symtab (per_cu, name.c_str ());
+      pst = create_partial_symtab (per_cu, dwarf2_per_objfile, name.c_str ());
       pst->anonymous = true;
     }
 
@@ -7390,9 +7401,11 @@ get_type_unit_group (struct dwarf2_cu *cu, const struct attribute *stmt_list)
    dirname, textlow, texthigh.  */
 
 static dwarf2_psymtab *
-create_partial_symtab (struct dwarf2_per_cu_data *per_cu, const char *name)
+create_partial_symtab (dwarf2_per_cu_data *per_cu,
+                      dwarf2_per_objfile *per_objfile,
+                      const char *name)
 {
-  struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
+  struct objfile *objfile = per_objfile->objfile;
   dwarf2_psymtab *pst;
 
   pst = new dwarf2_psymtab (name, objfile, per_cu);
@@ -7414,7 +7427,8 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
                                  enum language pretend_language)
 {
   struct dwarf2_cu *cu = reader->cu;
-  struct objfile *objfile = cu->per_objfile->objfile;
+  dwarf2_per_objfile *per_objfile = cu->per_objfile;
+  struct objfile *objfile = per_objfile->objfile;
   struct gdbarch *gdbarch = objfile->arch ();
   struct dwarf2_per_cu_data *per_cu = cu->per_cu;
   CORE_ADDR baseaddr;
@@ -7441,7 +7455,7 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
       filename = debug_filename.get ();
     }
 
-  pst = create_partial_symtab (per_cu, filename);
+  pst = create_partial_symtab (per_cu, per_objfile, filename);
 
   /* This must be done before calling dwarf2_build_include_psymtabs.  */
   pst->dirname = dwarf2_string_attr (comp_unit_die, DW_AT_comp_dir, cu);
@@ -7544,7 +7558,8 @@ process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
    Process compilation unit THIS_CU for a psymtab.  */
 
 static void
-process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu,
+process_psymtab_comp_unit (dwarf2_per_cu_data *this_cu,
+                          dwarf2_per_objfile *per_objfile,
                           bool want_partial_unit,
                           enum language pretend_language)
 {
@@ -7556,7 +7571,7 @@ process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu,
   if (this_cu->cu != NULL)
     free_one_cached_comp_unit (this_cu);
 
-  cutu_reader reader (this_cu, NULL, 0, false);
+  cutu_reader reader (this_cu, per_objfile, NULL, 0, false);
 
   switch (reader.comp_unit_die->tag)
     {
@@ -7621,7 +7636,7 @@ build_type_psymtabs_reader (const struct die_reader_specs *reader,
   tu_group->tus->push_back (sig_type);
 
   prepare_one_comp_unit (cu, type_unit_die, language_minimal);
-  pst = create_partial_symtab (per_cu, "");
+  pst = create_partial_symtab (per_cu, dwarf2_per_objfile, "");
   pst->anonymous = true;
 
   first_die = load_partial_dies (reader, info_ptr, 1);
@@ -7737,8 +7752,8 @@ build_type_psymtabs_1 (struct dwarf2_per_objfile *dwarf2_per_objfile)
          ++tu_stats->nr_uniq_abbrev_tables;
        }
 
-      cutu_reader reader (&tu.sig_type->per_cu, abbrev_table.get (),
-                         0, false);
+      cutu_reader reader (&tu.sig_type->per_cu, dwarf2_per_objfile,
+                         abbrev_table.get (), 0, false);
       if (!reader.dummy_p)
        build_type_psymtabs_reader (&reader, reader.info_ptr,
                                    reader.comp_unit_die);
@@ -7843,7 +7858,7 @@ process_skeletonless_type_unit (void **slot, void *info)
   *slot = entry;
 
   /* This does the job that build_type_psymtabs_1 would have done.  */
-  cutu_reader reader (&entry->per_cu, NULL, 0, false);
+  cutu_reader reader (&entry->per_cu, dwarf2_per_objfile, NULL, 0, false);
   if (!reader.dummy_p)
     build_type_psymtabs_reader (&reader, reader.info_ptr,
                                reader.comp_unit_die);
@@ -7944,7 +7959,8 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
       if (per_cu->v.psymtab != NULL)
        /* In case a forward DW_TAG_imported_unit has read the CU already.  */
        continue;
-      process_psymtab_comp_unit (per_cu, false, language_minimal);
+      process_psymtab_comp_unit (per_cu, dwarf2_per_objfile, false,
+                                language_minimal);
     }
 
   /* This has to wait until we read the CUs, we need the list of DWOs.  */
@@ -7977,9 +7993,10 @@ dwarf2_build_psymtabs_hard (struct dwarf2_per_objfile *dwarf2_per_objfile)
    This is also used when rereading a primary CU with load_all_dies.  */
 
 static void
-load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu)
+load_partial_comp_unit (dwarf2_per_cu_data *this_cu,
+                       dwarf2_per_objfile *per_objfile)
 {
-  cutu_reader reader (this_cu, NULL, 1, false);
+  cutu_reader reader (this_cu, per_objfile, NULL, 1, false);
 
   if (!reader.dummy_p)
     {
@@ -8058,7 +8075,7 @@ create_all_comp_units (struct dwarf2_per_objfile *dwarf2_per_objfile)
   read_comp_units_from_section (dwarf2_per_objfile, &dwarf2_per_objfile->per_bfd->info,
                                &dwarf2_per_objfile->per_bfd->abbrev, 0);
 
-  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+  dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
   if (dwz != NULL)
     read_comp_units_from_section (dwarf2_per_objfile, &dwz->info, &dwz->abbrev,
                                  1);
@@ -8158,7 +8175,8 @@ scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc,
 
                /* Go read the partial unit, if needed.  */
                if (per_cu->v.psymtab == NULL)
-                 process_psymtab_comp_unit (per_cu, true, cu->language);
+                 process_psymtab_comp_unit (per_cu, cu->per_objfile, true,
+                                            cu->language);
 
                cu->per_cu->imported_symtabs_push (per_cu);
              }
@@ -9012,9 +9030,11 @@ process_queue (struct dwarf2_per_objfile *dwarf2_per_objfile)
            fprintf_unfiltered (gdb_stdlog, "Expanding symtab of %s\n", buf);
 
          if (per_cu->is_debug_types)
-           process_full_type_unit (per_cu, item.pretend_language);
+           process_full_type_unit (per_cu, dwarf2_per_objfile,
+                                   item.pretend_language);
          else
-           process_full_comp_unit (per_cu, item.pretend_language);
+           process_full_comp_unit (per_cu, dwarf2_per_objfile,
+                                   item.pretend_language);
 
          if (dwarf_read_debug >= debug_print_threshold)
            fprintf_unfiltered (gdb_stdlog, "Done expanding %s\n", buf);
@@ -9089,13 +9109,14 @@ die_eq (const void *item_lhs, const void *item_rhs)
 /* Load the DIEs associated with PER_CU into memory.  */
 
 static void
-load_full_comp_unit (struct dwarf2_per_cu_data *this_cu,
+load_full_comp_unit (dwarf2_per_cu_data *this_cu,
+                    dwarf2_per_objfile *per_objfile,
                     bool skip_partial,
                     enum language pretend_language)
 {
   gdb_assert (! this_cu->is_debug_types);
 
-  cutu_reader reader (this_cu, NULL, 1, skip_partial);
+  cutu_reader reader (this_cu, per_objfile, NULL, 1, skip_partial);
   if (reader.dummy_p)
     return;
 
@@ -9605,7 +9626,8 @@ rust_union_quirks (struct dwarf2_cu *cu)
 static void
 recursively_compute_inclusions (std::vector<compunit_symtab *> *result,
                                htab_t all_children, htab_t all_type_symtabs,
-                               struct dwarf2_per_cu_data *per_cu,
+                               dwarf2_per_cu_data *per_cu,
+                               dwarf2_per_objfile *per_objfile,
                                struct compunit_symtab *immediate_parent)
 {
   void **slot = htab_find_slot (all_children, per_cu, INSERT);
@@ -9618,7 +9640,7 @@ recursively_compute_inclusions (std::vector<compunit_symtab *> *result,
   *slot = per_cu;
 
   /* Only add a CU if it has a symbol table.  */
-  compunit_symtab *cust = per_cu->dwarf2_per_objfile->get_symtab (per_cu);
+  compunit_symtab *cust = per_objfile->get_symtab (per_cu);
   if (cust != NULL)
     {
       /* If this is a type unit only add its symbol table if we haven't
@@ -9646,7 +9668,8 @@ recursively_compute_inclusions (std::vector<compunit_symtab *> *result,
     for (dwarf2_per_cu_data *ptr : *per_cu->imported_symtabs)
       {
        recursively_compute_inclusions (result, all_children,
-                                       all_type_symtabs, ptr, cust);
+                                       all_type_symtabs, ptr, per_objfile,
+                                       cust);
       }
 }
 
@@ -9654,7 +9677,8 @@ recursively_compute_inclusions (std::vector<compunit_symtab *> *result,
    PER_CU.  */
 
 static void
-compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu)
+compute_compunit_symtab_includes (dwarf2_per_cu_data *per_cu,
+                                 dwarf2_per_objfile *per_objfile)
 {
   gdb_assert (! per_cu->is_debug_types);
 
@@ -9663,7 +9687,7 @@ compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu)
       int len;
       std::vector<compunit_symtab *> result_symtabs;
       htab_t all_children, all_type_symtabs;
-      compunit_symtab *cust = per_cu->dwarf2_per_objfile->get_symtab (per_cu);
+      compunit_symtab *cust = per_objfile->get_symtab (per_cu);
 
       /* If we don't have a symtab, we can just skip this case.  */
       if (cust == NULL)
@@ -9677,7 +9701,8 @@ compute_compunit_symtab_includes (struct dwarf2_per_cu_data *per_cu)
       for (dwarf2_per_cu_data *ptr : *per_cu->imported_symtabs)
        {
          recursively_compute_inclusions (&result_symtabs, all_children,
-                                         all_type_symtabs, ptr, cust);
+                                         all_type_symtabs, ptr, per_objfile,
+                                         cust);
        }
 
       /* Now we have a transitive closure of all the included symtabs.  */
@@ -9703,7 +9728,7 @@ process_cu_includes (struct dwarf2_per_objfile *dwarf2_per_objfile)
   for (dwarf2_per_cu_data *iter : dwarf2_per_objfile->per_bfd->just_read_cus)
     {
       if (! iter->is_debug_types)
-       compute_compunit_symtab_includes (iter);
+       compute_compunit_symtab_includes (iter, dwarf2_per_objfile);
     }
 
   dwarf2_per_objfile->per_bfd->just_read_cus.clear ();
@@ -9713,11 +9738,11 @@ process_cu_includes (struct dwarf2_per_objfile *dwarf2_per_objfile)
    already been loaded into memory.  */
 
 static void
-process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
+process_full_comp_unit (dwarf2_per_cu_data *per_cu,
+                       dwarf2_per_objfile *dwarf2_per_objfile,
                        enum language pretend_language)
 {
   struct dwarf2_cu *cu = per_cu->cu;
-  struct dwarf2_per_objfile *dwarf2_per_objfile = per_cu->dwarf2_per_objfile;
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   struct gdbarch *gdbarch = objfile->arch ();
   CORE_ADDR lowpc, highpc;
@@ -9813,11 +9838,11 @@ process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
    already been loaded into memory.  */
 
 static void
-process_full_type_unit (struct dwarf2_per_cu_data *per_cu,
+process_full_type_unit (dwarf2_per_cu_data *per_cu,
+                       dwarf2_per_objfile *dwarf2_per_objfile,
                        enum language pretend_language)
 {
   struct dwarf2_cu *cu = per_cu->cu;
-  struct dwarf2_per_objfile *dwarf2_per_objfile = per_cu->dwarf2_per_objfile;
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   struct compunit_symtab *cust;
   struct signatured_type *sig_type;
@@ -9899,8 +9924,9 @@ process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu)
     {
       sect_offset sect_off = attr->get_ref_die_offset ();
       bool is_dwz = (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz);
+      dwarf2_per_objfile *per_objfile = cu->per_objfile;
       dwarf2_per_cu_data *per_cu
-       = dwarf2_find_containing_comp_unit (sect_off, is_dwz, cu->per_objfile);
+       = dwarf2_find_containing_comp_unit (sect_off, is_dwz, per_objfile);
 
       /* We're importing a C++ compilation unit with tag DW_TAG_compile_unit
         into another compilation unit, at root level.  Regard this as a hint,
@@ -9912,7 +9938,7 @@ process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu)
 
       /* If necessary, add it to the queue and load its DIEs.  */
       if (maybe_queue_comp_unit (cu, per_cu, cu->language))
-       load_full_comp_unit (per_cu, false, cu->language);
+       load_full_comp_unit (per_cu, per_objfile, false, cu->language);
 
       cu->per_cu->imported_symtabs_push (per_cu);
     }
@@ -11313,7 +11339,7 @@ create_cus_hash_table (struct dwarf2_per_objfile *dwarf2_per_objfile,
       per_cu.sect_off = sect_offset (info_ptr - section.buffer);
       per_cu.section = &section;
 
-      cutu_reader reader (&per_cu, cu, &dwo_file);
+      cutu_reader reader (&per_cu, dwarf2_per_objfile, cu, &dwo_file);
       if (!reader.dummy_p)
        create_dwo_cu_reader (&reader, reader.info_ptr, reader.comp_unit_die,
                              &dwo_file, &read_unit);
@@ -12330,10 +12356,10 @@ dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp, void *dwo_sections_ptr)
    The result is NULL if DWO_NAME can't be found.  */
 
 static struct dwo_file *
-open_and_init_dwo_file (struct dwarf2_per_cu_data *per_cu,
-                       const char *dwo_name, const char *comp_dir)
+open_and_init_dwo_file (dwarf2_cu *cu, const char *dwo_name,
+                       const char *comp_dir)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = per_cu->dwarf2_per_objfile;
+  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
 
   gdb_bfd_ref_ptr dbfd = open_dwo_file (dwarf2_per_objfile, dwo_name, comp_dir);
   if (dbfd == NULL)
@@ -12351,7 +12377,7 @@ open_and_init_dwo_file (struct dwarf2_per_cu_data *per_cu,
   bfd_map_over_sections (dwo_file->dbfd.get (), dwarf2_locate_dwo_sections,
                         &dwo_file->sections);
 
-  create_cus_hash_table (dwarf2_per_objfile, per_cu->cu, *dwo_file,
+  create_cus_hash_table (dwarf2_per_objfile, cu, *dwo_file,
                         dwo_file->sections.info, dwo_file->cus);
 
   create_debug_types_hash_table (dwarf2_per_objfile, dwo_file.get (),
@@ -12662,11 +12688,10 @@ get_dwp_file (struct dwarf2_per_objfile *dwarf2_per_objfile)
    (dwo_id mismatch or couldn't find the DWO/DWP file).  */
 
 static struct dwo_unit *
-lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit,
-                const char *dwo_name, const char *comp_dir,
+lookup_dwo_cutu (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
                 ULONGEST signature, int is_debug_types)
 {
-  struct dwarf2_per_objfile *dwarf2_per_objfile = this_unit->dwarf2_per_objfile;
+  struct dwarf2_per_objfile *dwarf2_per_objfile = cu->per_objfile;
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   const char *kind = is_debug_types ? "TU" : "CU";
   void **dwo_file_slot;
@@ -12712,7 +12737,7 @@ lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit,
       if (*dwo_file_slot == NULL)
        {
          /* Read in the file and build a table of the CUs/TUs it contains.  */
-         *dwo_file_slot = open_and_init_dwo_file (this_unit, dwo_name, comp_dir);
+         *dwo_file_slot = open_and_init_dwo_file (cu, dwo_name, comp_dir);
        }
       /* NOTE: This will be NULL if unable to open the file.  */
       dwo_file = (struct dwo_file *) *dwo_file_slot;
@@ -12777,10 +12802,8 @@ lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit,
 
     warning (_("Could not find DWO %s %s(%s)%s referenced by %s at offset %s"
               " [in module %s]"),
-            kind, dwo_name, hex_string (signature),
-            dwp_text.c_str (),
-            this_unit->is_debug_types ? "TU" : "CU",
-            sect_offset_str (this_unit->sect_off), objfile_name (objfile));
+            kind, dwo_name, hex_string (signature), dwp_text.c_str (), kind,
+            sect_offset_str (cu->per_cu->sect_off), objfile_name (objfile));
   }
   return NULL;
 }
@@ -12789,21 +12812,25 @@ lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit,
    See lookup_dwo_cutu_unit for details.  */
 
 static struct dwo_unit *
-lookup_dwo_comp_unit (struct dwarf2_per_cu_data *this_cu,
-                     const char *dwo_name, const char *comp_dir,
+lookup_dwo_comp_unit (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir,
                      ULONGEST signature)
 {
-  return lookup_dwo_cutu (this_cu, dwo_name, comp_dir, signature, 0);
+  gdb_assert (!cu->per_cu->is_debug_types);
+
+  return lookup_dwo_cutu (cu, dwo_name, comp_dir, signature, 0);
 }
 
 /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU.
    See lookup_dwo_cutu_unit for details.  */
 
 static struct dwo_unit *
-lookup_dwo_type_unit (struct signatured_type *this_tu,
-                     const char *dwo_name, const char *comp_dir)
+lookup_dwo_type_unit (dwarf2_cu *cu, const char *dwo_name, const char *comp_dir)
 {
-  return lookup_dwo_cutu (&this_tu->per_cu, dwo_name, comp_dir, this_tu->signature, 1);
+  gdb_assert (cu->per_cu->is_debug_types);
+
+  signatured_type *sig_type = (signatured_type *) cu->per_cu;
+
+  return lookup_dwo_cutu (cu, dwo_name, comp_dir, sig_type->signature, 1);
 }
 
 /* Traversal function for queue_and_load_all_dwo_tus.  */
@@ -12812,10 +12839,9 @@ static int
 queue_and_load_dwo_tu (void **slot, void *info)
 {
   struct dwo_unit *dwo_unit = (struct dwo_unit *) *slot;
-  struct dwarf2_per_cu_data *per_cu = (struct dwarf2_per_cu_data *) info;
+  dwarf2_cu *cu = (dwarf2_cu *) info;
   ULONGEST signature = dwo_unit->signature;
-  struct signatured_type *sig_type =
-    lookup_dwo_signatured_type (per_cu->cu, signature);
+  signatured_type *sig_type = lookup_dwo_signatured_type (cu, signature);
 
   if (sig_type != NULL)
     {
@@ -12824,9 +12850,9 @@ queue_and_load_dwo_tu (void **slot, void *info)
       /* We pass NULL for DEPENDENT_CU because we don't yet know if there's
         a real dependency of PER_CU on SIG_TYPE.  That is detected later
         while processing PER_CU.  */
-      if (maybe_queue_comp_unit (NULL, sig_cu, per_cu->cu->language))
-       load_full_type_unit (sig_cu);
-      per_cu->imported_symtabs_push (sig_cu);
+      if (maybe_queue_comp_unit (NULL, sig_cu, cu->language))
+       load_full_type_unit (sig_cu, cu->per_objfile);
+      cu->per_cu->imported_symtabs_push (sig_cu);
     }
 
   return 1;
@@ -12844,8 +12870,8 @@ queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data *per_cu)
   struct dwo_file *dwo_file;
 
   gdb_assert (!per_cu->is_debug_types);
-  gdb_assert (get_dwp_file (per_cu->dwarf2_per_objfile) == NULL);
   gdb_assert (per_cu->cu != NULL);
+  gdb_assert (get_dwp_file (per_cu->cu->per_objfile) == NULL);
 
   dwo_unit = per_cu->cu->dwo_unit;
   gdb_assert (dwo_unit != NULL);
@@ -12853,7 +12879,7 @@ queue_and_load_all_dwo_tus (struct dwarf2_per_cu_data *per_cu)
   dwo_file = dwo_unit->dwo_file;
   if (dwo_file->tus != NULL)
     htab_traverse_noresize (dwo_file->tus.get (), queue_and_load_dwo_tu,
-                           per_cu);
+                           per_cu->cu);
 }
 
 /* Read in various DIEs.  */
@@ -18665,7 +18691,7 @@ find_partial_die (sect_offset sect_off, int offset_in_dwz, struct dwarf2_cu *cu)
                                                 dwarf2_per_objfile);
 
       if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL)
-       load_partial_comp_unit (per_cu);
+       load_partial_comp_unit (per_cu, cu->per_objfile);
 
       per_cu->cu->last_used = 0;
       pd = per_cu->cu->find_partial_die (sect_off);
@@ -18684,7 +18710,7 @@ find_partial_die (sect_offset sect_off, int offset_in_dwz, struct dwarf2_cu *cu)
         DIEs alone (which can still be in use, e.g. in scan_partial_symbols),
         and clobber THIS_CU->cu->partial_dies with the hash table for the new
         set.  */
-      load_partial_comp_unit (per_cu);
+      load_partial_comp_unit (per_cu, cu->per_objfile);
 
       pd = per_cu->cu->find_partial_die (sect_off);
     }
@@ -19103,7 +19129,7 @@ read_attribute_value (const struct die_reader_specs *reader,
       /* FALLTHROUGH */
     case DW_FORM_GNU_strp_alt:
       {
-       struct dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+       dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
        LONGEST str_offset = cu_header->read_offset (abfd, info_ptr,
                                                     &bytes_read);
 
@@ -19400,7 +19426,7 @@ dwarf2_read_addr_index (dwarf2_per_cu_data *per_cu, unsigned int addr_index)
     }
   else
     {
-      cutu_reader reader (per_cu, NULL, 0, false);
+      cutu_reader reader (per_cu, dwarf2_per_objfile, NULL, 0, false);
       addr_base = reader.cu->addr_base;
       addr_size = reader.cu->header.addr_size;
     }
@@ -19698,7 +19724,7 @@ get_debug_line_section (struct dwarf2_cu *cu)
     section = &cu->dwo_unit->dwo_file->sections.line;
   else if (cu->per_cu->is_dwz)
     {
-      struct dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile);
+      dwz_file *dwz = dwarf2_get_dwz_file (dwarf2_per_objfile->per_bfd);
 
       section = &dwz->line;
     }
@@ -22211,7 +22237,7 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz,
 
       /* If necessary, add it to the queue and load its DIEs.  */
       if (maybe_queue_comp_unit (cu, per_cu, cu->language))
-       load_full_comp_unit (per_cu, false, cu->language);
+       load_full_comp_unit (per_cu, dwarf2_per_objfile, false, cu->language);
 
       target_cu = per_cu->cu;
     }
@@ -22219,7 +22245,8 @@ follow_die_offset (sect_offset sect_off, int offset_in_dwz,
     {
       /* We're loading full DIEs during partial symbol reading.  */
       gdb_assert (dwarf2_per_objfile->per_bfd->reading_partial_symbols);
-      load_full_comp_unit (cu->per_cu, false, language_minimal);
+      load_full_comp_unit (cu->per_cu, dwarf2_per_objfile, false,
+                          language_minimal);
     }
 
   *ref_cu = target_cu;
@@ -22274,7 +22301,7 @@ dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
   struct objfile *objfile = dwarf2_per_objfile->objfile;
 
   if (per_cu->cu == NULL)
-    load_cu (per_cu, false);
+    load_cu (per_cu, dwarf2_per_objfile, false);
   cu = per_cu->cu;
   if (cu == NULL)
     {
@@ -22412,7 +22439,7 @@ dwarf2_fetch_constant_bytes (sect_offset sect_off,
   struct objfile *objfile = per_cu->dwarf2_per_objfile->objfile;
 
   if (per_cu->cu == NULL)
-    load_cu (per_cu, false);
+    load_cu (per_cu, per_cu->dwarf2_per_objfile, false);
   cu = per_cu->cu;
   if (cu == NULL)
     {
@@ -22534,7 +22561,7 @@ dwarf2_fetch_die_type_sect_off (sect_offset sect_off,
   struct die_info *die;
 
   if (per_cu->cu == NULL)
-    load_cu (per_cu, false);
+    load_cu (per_cu, per_cu->dwarf2_per_objfile, false);
   cu = per_cu->cu;
   if (!cu)
     return NULL;
@@ -22576,7 +22603,7 @@ follow_die_sig_1 (struct die_info *src_die, struct signatured_type *sig_type,
   /* If necessary, add it to the queue and load its DIEs.  */
 
   if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu, language_minimal))
-    read_signatured_type (sig_type);
+    read_signatured_type (sig_type, (*ref_cu)->per_objfile);
 
   sig_cu = sig_type->per_cu.cu;
   gdb_assert (sig_cu != NULL);
@@ -22739,7 +22766,8 @@ get_DW_AT_signature_type (struct die_info *die, const struct attribute *attr,
 /* Load the DIEs associated with type unit PER_CU into memory.  */
 
 static void
-load_full_type_unit (struct dwarf2_per_cu_data *per_cu)
+load_full_type_unit (dwarf2_per_cu_data *per_cu,
+                    dwarf2_per_objfile *per_objfile)
 {
   struct signatured_type *sig_type;
 
@@ -22753,7 +22781,7 @@ load_full_type_unit (struct dwarf2_per_cu_data *per_cu)
 
   gdb_assert (per_cu->cu == NULL);
 
-  read_signatured_type (sig_type);
+  read_signatured_type (sig_type, per_objfile);
 
   gdb_assert (per_cu->cu != NULL);
 }
@@ -22763,14 +22791,15 @@ load_full_type_unit (struct dwarf2_per_cu_data *per_cu)
    read in the real type from the DWO file as well.  */
 
 static void
-read_signatured_type (struct signatured_type *sig_type)
+read_signatured_type (signatured_type *sig_type,
+                     dwarf2_per_objfile *per_objfile)
 {
   struct dwarf2_per_cu_data *per_cu = &sig_type->per_cu;
 
   gdb_assert (per_cu->is_debug_types);
   gdb_assert (per_cu->cu == NULL);
 
-  cutu_reader reader (per_cu, NULL, 0, false);
+  cutu_reader reader (per_cu, per_objfile, NULL, 0, false);
 
   if (!reader.dummy_p)
     {