Change get_objfile_arch to a method on objfile

Message ID 20200404221652.14598-1-tom@tromey.com
State New
Headers show
Series
  • Change get_objfile_arch to a method on objfile
Related show

Commit Message

Tom Tromey April 4, 2020, 10:16 p.m.
This changes get_objfile_arch to be a new inline method,
objfile::arch.

To my surprise, this function came up while profiling DWARF psymbol
reading.  Making this change improved performance from 1.986 seconds
to 1.869 seconds.  Both measurements were done by taking the mean of
10 runs on a fixed copy of the gdb executable.

gdb/ChangeLog
2020-04-04  Tom Tromey  <tom@tromey.com>

	* xcoffread.c (enter_line_range, scan_xcoff_symtab): Update.
	* value.c (value_fn_field): Update.
	* valops.c (find_function_in_inferior)
	(value_allocate_space_in_inferior): Update.
	* tui/tui-winsource.c (tui_update_source_windows_with_line):
	Update.
	* tui/tui-source.c (tui_source_window::set_contents): Update.
	* symtab.c (lookup_global_or_static_symbol)
	(find_function_start_sal_1, skip_prologue_sal)
	(print_msymbol_info, find_gnu_ifunc, symbol_arch): Update.
	* symmisc.c (dump_msymbols, dump_symtab_1)
	(maintenance_print_one_line_table): Update.
	* symfile.c (init_entry_point_info, section_is_mapped)
	(list_overlays_command, simple_read_overlay_table)
	(simple_overlay_update_1): Update.
	* stap-probe.c (handle_stap_probe): Update.
	* stabsread.c (dbx_init_float_type, define_symbol)
	(read_one_struct_field, read_enum_type, read_range_type): Update.
	* source.c (info_line_command): Update.
	* python/python.c (gdbpy_source_objfile_script)
	(gdbpy_execute_objfile_script): Update.
	* python/py-type.c (save_objfile_types): Update.
	* python/py-objfile.c (py_free_objfile): Update.
	* python/py-inferior.c (python_new_objfile): Update.
	* psymtab.c (psym_find_pc_sect_compunit_symtab, dump_psymtab)
	(dump_psymtab_addrmap_1, maintenance_info_psymtabs)
	(maintenance_check_psymtabs): Update.
	* printcmd.c (info_address_command): Update.
	* objfiles.h (struct objfile) <arch>: New method, from
	get_objfile_arch.
	(get_objfile_arch): Don't declare.
	* objfiles.c (get_objfile_arch): Remove.
	(filter_overlapping_sections): Update.
	* minsyms.c (msymbol_is_function): Update.
	* mi/mi-symbol-cmds.c (mi_cmd_symbol_list_lines)
	(output_nondebug_symbol): Update.
	* mdebugread.c (parse_symbol, basic_type, parse_partial_symbols)
	(mdebug_expand_psymtab): Update.
	* machoread.c (macho_add_oso_symfile): Update.
	* linux-tdep.c (linux_infcall_mmap, linux_infcall_munmap):
	Update.
	* linux-fork.c (checkpoint_command): Update.
	* linespec.c (convert_linespec_to_sals): Update.
	* jit.c (finalize_symtab): Update.
	* infrun.c (insert_exception_resume_from_probe): Update.
	* ia64-tdep.c (ia64_find_unwind_table): Update.
	* hppa-tdep.c (internalize_unwinds): Update.
	* gdbtypes.c (get_type_arch, init_float_type, objfile_type):
	Update.
	* gcore.c (call_target_sbrk): Update.
	* elfread.c (record_minimal_symbol, elf_symtab_read)
	(elf_rel_plt_read, elf_gnu_ifunc_record_cache)
	(elf_gnu_ifunc_resolve_by_got): Update.
	* dwarf2/read.c (create_addrmap_from_index)
	(create_addrmap_from_aranges, dw2_find_pc_sect_compunit_symtab)
	(read_debug_names_from_section)
	(process_psymtab_comp_unit_reader, add_partial_symbol)
	(add_partial_subprogram, process_full_comp_unit)
	(read_file_scope, read_func_scope, read_lexical_block_scope)
	(read_call_site_scope, dwarf2_ranges_read)
	(dwarf2_record_block_ranges, dwarf2_add_field)
	(mark_common_block_symbol_computed, read_tag_pointer_type)
	(read_tag_string_type, dwarf2_init_float_type)
	(dwarf2_init_complex_target_type, read_base_type)
	(partial_die_info::read, partial_die_info::read)
	(read_attribute_value, dwarf_decode_lines_1, new_symbol)
	(dwarf2_fetch_die_loc_sect_off): Update.
	* dwarf2/loc.c (dwarf2_find_location_expression)
	(class dwarf_evaluate_loc_desc, rw_pieced_value)
	(dwarf2_evaluate_loc_desc_full, dwarf2_locexpr_baton_eval)
	(dwarf2_loc_desc_get_symbol_read_needs)
	(locexpr_describe_location_piece, locexpr_describe_location_1)
	(loclist_describe_location): Update.
	* dwarf2/index-write.c (write_debug_names): Update.
	* dwarf2/frame.c (dwarf2_build_frame_info): Update.
	* dtrace-probe.c (dtrace_process_dof): Update.
	* dbxread.c (read_dbx_symtab, dbx_end_psymtab)
	(process_one_symbol): Update.
	* ctfread.c (ctf_init_float_type, read_base_type): Update.
	* coffread.c (coff_symtab_read, enter_linenos, decode_base_type)
	(coff_read_enum_type): Update.
	* cli/cli-cmds.c (edit_command, list_command): Update.
	* buildsym.c (buildsym_compunit::finish_block_internal): Update.
	* breakpoint.c (create_overlay_event_breakpoint)
	(create_longjmp_master_breakpoint)
	(create_std_terminate_master_breakpoint)
	(create_exception_master_breakpoint, get_sal_arch): Update.
	* block.c (block_gdbarch): Update.
	* annotate.c (annotate_source_line): Update.
---
 gdb/ChangeLog            | 92 ++++++++++++++++++++++++++++++++++++++++
 gdb/annotate.c           |  2 +-
 gdb/block.c              |  2 +-
 gdb/breakpoint.c         | 14 +++---
 gdb/buildsym.c           |  2 +-
 gdb/cli/cli-cmds.c       |  4 +-
 gdb/coffread.c           |  8 ++--
 gdb/ctfread.c            |  4 +-
 gdb/dbxread.c            |  6 +--
 gdb/dtrace-probe.c       |  2 +-
 gdb/dwarf2/frame.c       |  2 +-
 gdb/dwarf2/index-write.c |  2 +-
 gdb/dwarf2/loc.c         | 20 ++++-----
 gdb/dwarf2/read.c        | 62 ++++++++++++++-------------
 gdb/elfread.c            | 10 ++---
 gdb/gcore.c              |  2 +-
 gdb/gdbtypes.c           |  6 +--
 gdb/hppa-tdep.c          |  2 +-
 gdb/ia64-tdep.c          |  2 +-
 gdb/infrun.c             |  2 +-
 gdb/jit.c                |  2 +-
 gdb/linespec.c           |  2 +-
 gdb/linux-fork.c         |  2 +-
 gdb/linux-tdep.c         |  4 +-
 gdb/machoread.c          |  4 +-
 gdb/mdebugread.c         |  8 ++--
 gdb/mi/mi-symbol-cmds.c  |  4 +-
 gdb/minsyms.c            |  2 +-
 gdb/objfiles.c           | 10 +----
 gdb/objfiles.h           |  8 +++-
 gdb/printcmd.c           |  2 +-
 gdb/psymtab.c            | 10 ++---
 gdb/python/py-inferior.c |  2 +-
 gdb/python/py-objfile.c  |  2 +-
 gdb/python/py-type.c     |  2 +-
 gdb/python/python.c      |  4 +-
 gdb/source.c             |  3 +-
 gdb/stabsread.c          | 10 ++---
 gdb/stap-probe.c         |  2 +-
 gdb/symfile.c            | 12 +++---
 gdb/symmisc.c            |  6 +--
 gdb/symtab.c             | 12 +++---
 gdb/tui/tui-source.c     |  2 +-
 gdb/tui/tui-winsource.c  |  2 +-
 gdb/valops.c             |  4 +-
 gdb/value.c              |  2 +-
 gdb/xcoffread.c          |  4 +-
 47 files changed, 231 insertions(+), 142 deletions(-)

-- 
2.17.2

Comments

Tom Tromey April 18, 2020, 2:41 p.m. | #1
>>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:


Tom> This changes get_objfile_arch to be a new inline method,
Tom> objfile::arch.

Tom> To my surprise, this function came up while profiling DWARF psymbol
Tom> reading.  Making this change improved performance from 1.986 seconds
Tom> to 1.869 seconds.  Both measurements were done by taking the mean of
Tom> 10 runs on a fixed copy of the gdb executable.

I'm checking this in now.

Tom

Patch

diff --git a/gdb/annotate.c b/gdb/annotate.c
index cf9e88cee51..6daa0c57017 100644
--- a/gdb/annotate.c
+++ b/gdb/annotate.c
@@ -450,7 +450,7 @@  annotate_source_line (struct symtab *s, int line, int mid_statement,
 	return;
 
       annotate_source (s->fullname, line, (int) (*offsets)[line - 1],
-		       mid_statement, get_objfile_arch (SYMTAB_OBJFILE (s)),
+		       mid_statement, SYMTAB_OBJFILE (s)->arch (),
 		       pc);
     }
 }
diff --git a/gdb/block.c b/gdb/block.c
index 46c24ec96d5..9b582433e48 100644
--- a/gdb/block.c
+++ b/gdb/block.c
@@ -62,7 +62,7 @@  block_gdbarch (const struct block *block)
   if (BLOCK_FUNCTION (block) != NULL)
     return symbol_arch (BLOCK_FUNCTION (block));
 
-  return get_objfile_arch (block_objfile (block));
+  return block_objfile (block)->arch ();
 }
 
 /* See block.h.  */
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index e49025461ba..4a87c1c5c1c 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3201,7 +3201,7 @@  create_overlay_event_breakpoint (void)
 	}
 
       addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym);
-      b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
+      b = create_internal_breakpoint (objfile->arch (), addr,
                                       bp_overlay_event,
 				      &internal_breakpoint_ops);
       initialize_explicit_location (&explicit_loc);
@@ -3238,7 +3238,7 @@  create_longjmp_master_breakpoint (void)
 	struct gdbarch *gdbarch;
 	struct breakpoint_objfile_data *bp_objfile_data;
 
-	gdbarch = get_objfile_arch (objfile);
+	gdbarch = objfile->arch ();
 
 	bp_objfile_data = get_breakpoint_objfile_data (objfile);
 
@@ -3362,7 +3362,7 @@  create_std_terminate_master_breakpoint (void)
 	  }
 
 	addr = BMSYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym);
-	b = create_internal_breakpoint (get_objfile_arch (objfile), addr,
+	b = create_internal_breakpoint (objfile->arch (), addr,
 					bp_std_terminate_master,
 					&internal_breakpoint_ops);
 	initialize_explicit_location (&explicit_loc);
@@ -3414,7 +3414,7 @@  create_exception_master_breakpoint (void)
 
       if (!bp_objfile_data->exception_probes.empty ())
 	{
-	  gdbarch = get_objfile_arch (objfile);
+	  gdbarch = objfile->arch ();
 
 	  for (probe *p : bp_objfile_data->exception_probes)
 	    {
@@ -3434,7 +3434,7 @@  create_exception_master_breakpoint (void)
       if (msym_not_found_p (bp_objfile_data->exception_msym.minsym))
 	continue;
 
-      gdbarch = get_objfile_arch (objfile);
+      gdbarch = objfile->arch ();
 
       if (bp_objfile_data->exception_msym.minsym == NULL)
 	{
@@ -7116,9 +7116,9 @@  struct gdbarch *
 get_sal_arch (struct symtab_and_line sal)
 {
   if (sal.section)
-    return get_objfile_arch (sal.section->objfile);
+    return sal.section->objfile->arch ();
   if (sal.symtab)
-    return get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
+    return SYMTAB_OBJFILE (sal.symtab)->arch ();
 
   return NULL;
 }
diff --git a/gdb/buildsym.c b/gdb/buildsym.c
index fe071035542..7d709a5b0e8 100644
--- a/gdb/buildsym.c
+++ b/gdb/buildsym.c
@@ -213,7 +213,7 @@  buildsym_compunit::finish_block_internal
      CORE_ADDR start, CORE_ADDR end,
      int is_global, int expandable)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (m_objfile);
+  struct gdbarch *gdbarch = m_objfile->arch ();
   struct pending *next, *next1;
   struct block *block;
   struct pending_block *pblock;
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c
index 6f324410e16..d1e6949e58b 100644
--- a/gdb/cli/cli-cmds.c
+++ b/gdb/cli/cli-cmds.c
@@ -945,7 +945,7 @@  edit_command (const char *arg, int from_tty)
 	    error (_("No source file for address %s."),
 		   paddress (get_current_arch (), sal.pc));
 
-	  gdbarch = get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
+	  gdbarch = SYMTAB_OBJFILE (sal.symtab)->arch ();
           sym = find_pc_function (sal.pc);
           if (sym)
 	    printf_filtered ("%s is in %s (%s:%d).\n",
@@ -1277,7 +1277,7 @@  list_command (const char *arg, int from_tty)
 	error (_("No source file for address %s."),
 	       paddress (get_current_arch (), sal.pc));
 
-      gdbarch = get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
+      gdbarch = SYMTAB_OBJFILE (sal.symtab)->arch ();
       sym = find_pc_function (sal.pc);
       if (sym)
 	printf_filtered ("%s is in %s (%s:%d).\n",
diff --git a/gdb/coffread.c b/gdb/coffread.c
index b682755bbba..7fbdcc4f68f 100644
--- a/gdb/coffread.c
+++ b/gdb/coffread.c
@@ -753,7 +753,7 @@  coff_symtab_read (minimal_symbol_reader &reader,
 		  long symtab_offset, unsigned int nsyms,
 		  struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct context_stack *newobj = nullptr;
   struct coff_symbol coff_symbol;
   struct coff_symbol *cs = &coff_symbol;
@@ -1402,7 +1402,7 @@  static void
 enter_linenos (long file_offset, int first_line,
 	       int last_line, struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   char *rawptr;
   struct internal_lineno lptr;
 
@@ -1834,7 +1834,7 @@  decode_base_type (struct coff_symbol *cs,
 		  union internal_auxent *aux, 
 		  struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct type *type;
 
   switch (c_type)
@@ -2062,7 +2062,7 @@  static struct type *
 coff_read_enum_type (int index, int length, int lastsym,
 		     struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct symbol *sym;
   struct type *type;
   int nsyms = 0;
diff --git a/gdb/ctfread.c b/gdb/ctfread.c
index 7784e9d35d6..8cc7271c075 100644
--- a/gdb/ctfread.c
+++ b/gdb/ctfread.c
@@ -330,7 +330,7 @@  ctf_init_float_type (struct objfile *objfile,
 		     const char *name,
 		     const char *name_hint)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   const struct floatformat **format;
   struct type *type;
 
@@ -521,7 +521,7 @@  read_base_type (struct ctf_context *ccp, ctf_id_t tid)
   if (kind == CTF_K_INTEGER)
     {
       uint32_t issigned, ischar, isbool;
-      struct gdbarch *gdbarch = get_objfile_arch (of);
+      struct gdbarch *gdbarch = of->arch ();
 
       issigned = cet.cte_format & CTF_INT_SIGNED;
       ischar = cet.cte_format & CTF_INT_CHAR;
diff --git a/gdb/dbxread.c b/gdb/dbxread.c
index ac81278e996..c0155593e3b 100644
--- a/gdb/dbxread.c
+++ b/gdb/dbxread.c
@@ -951,7 +951,7 @@  function_outside_compilation_unit_complaint (const char *arg1)
 static void
 read_dbx_symtab (minimal_symbol_reader &reader, struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct external_nlist *bufp = 0;	/* =0 avoids gcc -Wall glitch.  */
   struct internal_nlist nlist;
   CORE_ADDR text_addr;
@@ -1936,7 +1936,7 @@  dbx_end_psymtab (struct objfile *objfile, legacy_psymtab *pst,
 		 int textlow_not_set)
 {
   int i;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
 
   if (capping_symbol_offset != -1)
     LDSYMLEN (pst) = capping_symbol_offset - LDSYMOFF (pst);
@@ -2338,7 +2338,7 @@  process_one_symbol (int type, int desc, CORE_ADDR valu, const char *name,
 		    const section_offsets &section_offsets,
 		    struct objfile *objfile, enum language language)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct context_stack *newobj;
   struct context_stack cstk;
   /* This remembers the address of the start of a function.  It is
diff --git a/gdb/dtrace-probe.c b/gdb/dtrace-probe.c
index daa5dcc1e98..c452ac9b476 100644
--- a/gdb/dtrace-probe.c
+++ b/gdb/dtrace-probe.c
@@ -520,7 +520,7 @@  dtrace_process_dof (asection *sect, struct objfile *objfile,
 		    std::vector<std::unique_ptr<probe>> *probesp,
 		    struct dtrace_dof_hdr *dof)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct dtrace_dof_sect *section;
   int i;
 
diff --git a/gdb/dwarf2/frame.c b/gdb/dwarf2/frame.c
index 74488f9a8aa..f7276d48ce7 100644
--- a/gdb/dwarf2/frame.c
+++ b/gdb/dwarf2/frame.c
@@ -2147,7 +2147,7 @@  dwarf2_build_frame_info (struct objfile *objfile)
   dwarf2_cie_table cie_table;
   dwarf2_fde_table fde_table;
 
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
 
   /* Build a minimal decoding of the DWARF2 compilation unit.  */
   std::unique_ptr<comp_unit> unit (new comp_unit (objfile));
diff --git a/gdb/dwarf2/index-write.c b/gdb/dwarf2/index-write.c
index 8c933dc63b7..855be0e2bb7 100644
--- a/gdb/dwarf2/index-write.c
+++ b/gdb/dwarf2/index-write.c
@@ -1496,7 +1496,7 @@  write_debug_names (struct dwarf2_per_objfile *dwarf2_per_objfile,
   const bool dwarf5_is_dwarf64 = check_dwarf64_offsets (dwarf2_per_objfile);
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   const enum bfd_endian dwarf5_byte_order
-    = gdbarch_byte_order (get_objfile_arch (objfile));
+    = gdbarch_byte_order (objfile->arch ());
 
   /* The CU list is already sorted, so we don't need to do additional
      work here.  Also, the debug_types entries do not appear in
diff --git a/gdb/dwarf2/loc.c b/gdb/dwarf2/loc.c
index fc54e16ffdd..c68bcdb9188 100644
--- a/gdb/dwarf2/loc.c
+++ b/gdb/dwarf2/loc.c
@@ -313,7 +313,7 @@  dwarf2_find_location_expression (struct dwarf2_loclist_baton *baton,
 				 size_t *locexpr_length, CORE_ADDR pc)
 {
   struct objfile *objfile = baton->per_cu->objfile ();
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned int addr_size = baton->per_cu->addr_size ();
   int signed_addr_p = bfd_get_sign_extend_vma (objfile->obfd);
@@ -721,7 +721,7 @@  class dwarf_evaluate_loc_desc : public dwarf_expr_context
 							(CORE_ADDR) 0);
 
     scoped_restore save_arch = make_scoped_restore (&this->gdbarch);
-    this->gdbarch = get_objfile_arch (per_cu->objfile ());
+    this->gdbarch = per_cu->objfile ()->arch ();
     scoped_restore save_addr_size = make_scoped_restore (&this->addr_size);
     this->addr_size = per_cu->addr_size ();
     scoped_restore save_offset = make_scoped_restore (&this->offset);
@@ -1808,7 +1808,7 @@  rw_pieced_value (struct value *v, struct value *from)
 	      }
 
 	    struct objfile *objfile = c->per_cu->objfile ();
-	    struct gdbarch *objfile_gdbarch = get_objfile_arch (objfile);
+	    struct gdbarch *objfile_gdbarch = objfile->arch ();
 	    ULONGEST stack_value_size_bits
 	      = 8 * TYPE_LENGTH (value_type (p->v.value));
 
@@ -2184,7 +2184,7 @@  dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
 
   scoped_value_mark free_values;
 
-  ctx.gdbarch = get_objfile_arch (objfile);
+  ctx.gdbarch = objfile->arch ();
   ctx.addr_size = per_cu->addr_size ();
   ctx.ref_addr_size = per_cu->ref_addr_size ();
   ctx.offset = per_cu->text_offset ();
@@ -2307,7 +2307,7 @@  dwarf2_evaluate_loc_desc_full (struct type *type, struct frame_info *frame,
 	    size_t n = TYPE_LENGTH (value_type (value));
 	    size_t len = TYPE_LENGTH (subobj_type);
 	    size_t max = TYPE_LENGTH (type);
-	    struct gdbarch *objfile_gdbarch = get_objfile_arch (objfile);
+	    struct gdbarch *objfile_gdbarch = objfile->arch ();
 
 	    if (subobj_byte_offset + len > max)
 	      invalid_synthetic_pointer ();
@@ -2401,7 +2401,7 @@  dwarf2_locexpr_baton_eval (const struct dwarf2_locexpr_baton *dlbaton,
 
   objfile = dlbaton->per_cu->objfile ();
 
-  ctx.gdbarch = get_objfile_arch (objfile);
+  ctx.gdbarch = objfile->arch ();
   ctx.addr_size = dlbaton->per_cu->addr_size ();
   ctx.ref_addr_size = dlbaton->per_cu->ref_addr_size ();
   ctx.offset = dlbaton->per_cu->text_offset ();
@@ -2732,7 +2732,7 @@  dwarf2_loc_desc_get_symbol_read_needs (const gdb_byte *data, size_t size,
 
   ctx.needs = SYMBOL_NEEDS_NONE;
   ctx.per_cu = per_cu;
-  ctx.gdbarch = get_objfile_arch (objfile);
+  ctx.gdbarch = objfile->arch ();
   ctx.addr_size = per_cu->addr_size ();
   ctx.ref_addr_size = per_cu->ref_addr_size ();
   ctx.offset = per_cu->text_offset ();
@@ -3630,7 +3630,7 @@  locexpr_describe_location_piece (struct symbol *symbol, struct ui_file *stream,
 				 const gdb_byte *data, const gdb_byte *end,
 				 unsigned int addr_size)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   size_t leb128_size;
 
   if (data[0] >= DW_OP_reg0 && data[0] <= DW_OP_reg31)
@@ -4226,7 +4226,7 @@  locexpr_describe_location_1 (struct symbol *symbol, CORE_ADDR addr,
 	{
 	  fprintf_filtered (stream, _("a complex DWARF expression:\n"));
 	  data = disassemble_dwarf_expression (stream,
-					       get_objfile_arch (objfile),
+					       objfile->arch (),
 					       addr_size, offset_size, data,
 					       data, end, 0,
 					       dwarf_always_disassemble,
@@ -4428,7 +4428,7 @@  loclist_describe_location (struct symbol *symbol, CORE_ADDR addr,
     = (struct dwarf2_loclist_baton *) SYMBOL_LOCATION_BATON (symbol);
   const gdb_byte *loc_ptr, *buf_end;
   struct objfile *objfile = dlbaton->per_cu->objfile ();
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
   unsigned int addr_size = dlbaton->per_cu->addr_size ();
   int offset_size = dlbaton->per_cu->offset_size ();
diff --git a/gdb/dwarf2/read.c b/gdb/dwarf2/read.c
index bcc3116071e..3a23e62a653 100644
--- a/gdb/dwarf2/read.c
+++ b/gdb/dwarf2/read.c
@@ -2531,7 +2531,7 @@  create_addrmap_from_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
 			   struct mapped_index *index)
 {
   struct objfile *objfile = dwarf2_per_objfile->objfile;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   const gdb_byte *iter, *end;
   struct addrmap *mutable_map;
   CORE_ADDR baseaddr;
@@ -2588,7 +2588,7 @@  create_addrmap_from_aranges (struct dwarf2_per_objfile *dwarf2_per_objfile,
 {
   struct objfile *objfile = dwarf2_per_objfile->objfile;
   bfd *abfd = objfile->obfd;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   const CORE_ADDR baseaddr = objfile->text_section_offset ();
 
   auto_obstack temp_obstack;
@@ -4644,7 +4644,7 @@  dw2_find_pc_sect_compunit_symtab (struct objfile *objfile,
 
   if (warn_if_readin && data->v.quick->compunit_symtab)
     warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"),
-	     paddress (get_objfile_arch (objfile), pc));
+	     paddress (objfile->arch (), pc));
 
   result
     = recursively_find_pc_sect_compunit_symtab (dw2_instantiate_symtab (data,
@@ -4774,7 +4774,7 @@  read_debug_names_from_section (struct objfile *objfile,
 
   section->read (objfile);
 
-  map.dwarf5_byte_order = gdbarch_byte_order (get_objfile_arch (objfile));
+  map.dwarf5_byte_order = gdbarch_byte_order (objfile->arch ());
 
   const gdb_byte *addr = section->buffer;
 
@@ -7182,7 +7182,7 @@  process_psymtab_comp_unit_reader (const struct die_reader_specs *reader,
 {
   struct dwarf2_cu *cu = reader->cu;
   struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct dwarf2_per_cu_data *per_cu = cu->per_cu;
   CORE_ADDR baseaddr;
   CORE_ADDR best_lowpc = 0, best_highpc = 0;
@@ -8096,7 +8096,7 @@  add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu)
   struct dwarf2_per_objfile *dwarf2_per_objfile
     = cu->per_cu->dwarf2_per_objfile;
   struct objfile *objfile = dwarf2_per_objfile->objfile;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   CORE_ADDR addr = 0;
   const char *actual_name = NULL;
   CORE_ADDR baseaddr;
@@ -8339,7 +8339,7 @@  add_partial_subprogram (struct partial_die_info *pdi,
 	  if (set_addrmap)
 	    {
 	      struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
-	      struct gdbarch *gdbarch = get_objfile_arch (objfile);
+	      struct gdbarch *gdbarch = objfile->arch ();
 	      CORE_ADDR baseaddr;
 	      CORE_ADDR this_highpc;
 	      CORE_ADDR this_lowpc;
@@ -9475,7 +9475,7 @@  process_full_comp_unit (struct dwarf2_per_cu_data *per_cu,
   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 = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   CORE_ADDR lowpc, highpc;
   struct compunit_symtab *cust;
   CORE_ADDR baseaddr;
@@ -10680,7 +10680,7 @@  read_file_scope (struct die_info *die, struct dwarf2_cu *cu)
   struct dwarf2_per_objfile *dwarf2_per_objfile
     = cu->per_cu->dwarf2_per_objfile;
   struct objfile *objfile = dwarf2_per_objfile->objfile;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   CORE_ADDR lowpc = ((CORE_ADDR) -1);
   CORE_ADDR highpc = ((CORE_ADDR) 0);
   struct attribute *attr;
@@ -12754,7 +12754,7 @@  static void
 read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct context_stack *newobj;
   CORE_ADDR lowpc;
   CORE_ADDR highpc;
@@ -12955,7 +12955,7 @@  static void
 read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   CORE_ADDR lowpc, highpc;
   struct die_info *child_die;
   CORE_ADDR baseaddr;
@@ -13026,7 +13026,7 @@  static void
 read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   CORE_ADDR pc, baseaddr;
   struct attribute *attr;
   struct call_site *call_site, call_site_local;
@@ -13671,7 +13671,7 @@  dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return,
 		    dwarf2_psymtab *ranges_pst)
 {
   struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   const CORE_ADDR baseaddr = objfile->text_section_offset ();
   int low_set = 0;
   CORE_ADDR low = 0;
@@ -13915,7 +13915,7 @@  dwarf2_record_block_ranges (struct die_info *die, struct block *block,
                             CORE_ADDR baseaddr, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct attribute *attr;
   struct attribute *attr_high;
 
@@ -14103,7 +14103,7 @@  dwarf2_add_field (struct field_info *fip, struct die_info *die,
 		  struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct nextfield *new_field;
   struct attribute *attr;
   struct field *fp;
@@ -15869,7 +15869,7 @@  mark_common_block_symbol_computed (struct symbol *sym,
   struct dwarf2_locexpr_baton *baton;
   gdb_byte *ptr;
   unsigned int cu_off;
-  enum bfd_endian byte_order = gdbarch_byte_order (get_objfile_arch (objfile));
+  enum bfd_endian byte_order = gdbarch_byte_order (objfile->arch ());
   LONGEST offset = 0;
 
   gdb_assert (common_loc && member_loc);
@@ -16177,7 +16177,7 @@  static struct type *
 read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct gdbarch *gdbarch
-    = get_objfile_arch (cu->per_cu->dwarf2_per_objfile->objfile);
+    = cu->per_cu->dwarf2_per_objfile->objfile->arch ();
   struct comp_unit_head *cu_header = &cu->header;
   struct type *type;
   struct attribute *attr_byte_size;
@@ -16436,7 +16436,7 @@  static struct type *
 read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu)
 {
   struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct type *type, *range_type, *index_type, *char_type;
   struct attribute *attr;
   struct dynamic_prop prop;
@@ -16754,7 +16754,7 @@  static struct type *
 dwarf2_init_float_type (struct objfile *objfile, int bits, const char *name,
 			const char *name_hint, enum bfd_endian byte_order)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   const struct floatformat **format;
   struct type *type;
 
@@ -16802,7 +16802,7 @@  dwarf2_init_complex_target_type (struct dwarf2_cu *cu,
 				 int bits, const char *name_hint,
 				 enum bfd_endian byte_order)
 {
-  gdbarch *gdbarch = get_objfile_arch (objfile);
+  gdbarch *gdbarch = objfile->arch ();
   struct type *tt = nullptr;
 
   /* Try to find a suitable floating point builtin type of size BITS.
@@ -16875,7 +16875,7 @@  read_base_type (struct die_info *die, struct dwarf2_cu *cu)
   if (!name)
     complaint (_("DW_AT_name missing from DW_TAG_base_type"));
 
-  arch = get_objfile_arch (objfile);
+  arch = objfile->arch ();
   enum bfd_endian byte_order = gdbarch_byte_order (arch);
 
   attr = dwarf2_attr (die, DW_AT_endianity, cu);
@@ -18081,7 +18081,7 @@  partial_die_info::read (const struct die_reader_specs *reader,
       if (lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero)
 	{
 	  struct objfile *objfile = dwarf2_per_objfile->objfile;
-	  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+	  struct gdbarch *gdbarch = objfile->arch ();
 
 	  complaint (_("DW_AT_low_pc %s is zero "
 		       "for DIE at %s [in module %s]"),
@@ -18093,7 +18093,7 @@  partial_die_info::read (const struct die_reader_specs *reader,
       else if (lowpc >= highpc)
 	{
 	  struct objfile *objfile = dwarf2_per_objfile->objfile;
-	  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+	  struct gdbarch *gdbarch = objfile->arch ();
 
 	  complaint (_("DW_AT_low_pc %s is not < DW_AT_high_pc %s "
 		       "for DIE at %s [in module %s]"),
@@ -18379,7 +18379,6 @@  read_attribute_value (const struct die_reader_specs *reader,
   struct dwarf2_per_objfile *dwarf2_per_objfile
     = cu->per_cu->dwarf2_per_objfile;
   struct objfile *objfile = dwarf2_per_objfile->objfile;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
   bfd *abfd = reader->abfd;
   struct comp_unit_head *cu_header = &cu->header;
   unsigned int bytes_read;
@@ -18403,9 +18402,12 @@  read_attribute_value (const struct die_reader_specs *reader,
       info_ptr += bytes_read;
       break;
     case DW_FORM_addr:
-      DW_ADDR (attr) = cu->header.read_address (abfd, info_ptr, &bytes_read);
-      DW_ADDR (attr) = gdbarch_adjust_dwarf2_addr (gdbarch, DW_ADDR (attr));
-      info_ptr += bytes_read;
+      {
+	struct gdbarch *gdbarch = objfile->arch ();
+	DW_ADDR (attr) = cu->header.read_address (abfd, info_ptr, &bytes_read);
+	DW_ADDR (attr) = gdbarch_adjust_dwarf2_addr (gdbarch, DW_ADDR (attr));
+	info_ptr += bytes_read;
+      }
       break;
     case DW_FORM_block2:
       blk = dwarf_alloc_block (cu);
@@ -19610,7 +19612,7 @@  dwarf_decode_lines_1 (struct line_header *lh, struct dwarf2_cu *cu,
   CORE_ADDR baseaddr;
   struct objfile *objfile = cu->per_cu->dwarf2_per_objfile->objfile;
   bfd *abfd = objfile->obfd;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   /* True if we're recording line info (as opposed to building partial
      symtabs and just interested in finding include files mentioned by
      the line number program).  */
@@ -20034,7 +20036,7 @@  new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu,
   struct dwarf2_per_objfile *dwarf2_per_objfile
     = cu->per_cu->dwarf2_per_objfile;
   struct objfile *objfile = dwarf2_per_objfile->objfile;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct symbol *sym = NULL;
   const char *name;
   struct attribute *attr = NULL;
@@ -21681,7 +21683,7 @@  dwarf2_fetch_die_loc_sect_off (sect_offset sect_off,
     {
       CORE_ADDR pc = (*get_frame_pc) (baton);
       CORE_ADDR baseaddr = objfile->text_section_offset ();
-      struct gdbarch *gdbarch = get_objfile_arch (objfile);
+      struct gdbarch *gdbarch = objfile->arch ();
 
       for (const auto &cand_off
 	     : dwarf2_per_objfile->abstract_to_concrete[die->sect_off])
diff --git a/gdb/elfread.c b/gdb/elfread.c
index 42c4e77785f..2f2fef93996 100644
--- a/gdb/elfread.c
+++ b/gdb/elfread.c
@@ -206,7 +206,7 @@  record_minimal_symbol (minimal_symbol_reader &reader,
 		       enum minimal_symbol_type ms_type,
 		       asection *bfd_section, struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
 
   if (ms_type == mst_text || ms_type == mst_file_text
       || ms_type == mst_text_gnu_ifunc)
@@ -251,7 +251,7 @@  elf_symtab_read (minimal_symbol_reader &reader,
 		 long number_of_symbols, asymbol **symbol_table,
 		 bool copy_names)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   asymbol *sym;
   long i;
   CORE_ADDR symaddr;
@@ -559,7 +559,7 @@  elf_rel_plt_read (minimal_symbol_reader &reader,
   const struct elf_backend_data *bed = get_elf_backend_data (obfd);
   asection *relplt, *got_plt;
   bfd_size_type reloc_count, reloc;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
   size_t ptr_size = TYPE_LENGTH (ptr_type);
 
@@ -747,7 +747,7 @@  elf_gnu_ifunc_record_cache (const char *name, CORE_ADDR addr)
     {
       struct elf_gnu_ifunc_cache *entry_found_p
 	= (struct elf_gnu_ifunc_cache *) *slot;
-      struct gdbarch *gdbarch = get_objfile_arch (objfile);
+      struct gdbarch *gdbarch = objfile->arch ();
 
       if (entry_found_p->addr != addr)
 	{
@@ -825,7 +825,7 @@  elf_gnu_ifunc_resolve_by_got (const char *name, CORE_ADDR *addr_p)
   for (objfile *objfile : current_program_space->objfiles ())
     {
       bfd *obfd = objfile->obfd;
-      struct gdbarch *gdbarch = get_objfile_arch (objfile);
+      struct gdbarch *gdbarch = objfile->arch ();
       struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
       size_t ptr_size = TYPE_LENGTH (ptr_type);
       CORE_ADDR pointer_address, addr;
diff --git a/gdb/gcore.c b/gdb/gcore.c
index d12011e9021..7b653fb74e3 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -282,7 +282,7 @@  call_target_sbrk (int sbrk_arg)
   else
     return (bfd_vma) 0;
 
-  gdbarch = get_objfile_arch (sbrk_objf);
+  gdbarch = sbrk_objf->arch ();
   target_sbrk_arg = value_from_longest (builtin_type (gdbarch)->builtin_int, 
 					sbrk_arg);
   gdb_assert (target_sbrk_arg);
diff --git a/gdb/gdbtypes.c b/gdb/gdbtypes.c
index f23def1ff71..157b3c5e614 100644
--- a/gdb/gdbtypes.c
+++ b/gdb/gdbtypes.c
@@ -236,7 +236,7 @@  get_type_arch (const struct type *type)
   struct gdbarch *arch;
 
   if (TYPE_OBJFILE_OWNED (type))
-    arch = get_objfile_arch (TYPE_OWNER (type).objfile);
+    arch = TYPE_OWNER (type).objfile->arch ();
   else
     arch = TYPE_OWNER (type).gdbarch;
 
@@ -3000,7 +3000,7 @@  init_float_type (struct objfile *objfile,
 {
   if (byte_order == BFD_ENDIAN_UNKNOWN)
     {
-      struct gdbarch *gdbarch = get_objfile_arch (objfile);
+      struct gdbarch *gdbarch = objfile->arch ();
       byte_order = gdbarch_byte_order (gdbarch);
     }
   const struct floatformat *fmt = floatformats[byte_order];
@@ -5607,7 +5607,7 @@  objfile_type (struct objfile *objfile)
 				 1, struct objfile_type);
 
   /* Use the objfile architecture to determine basic type properties.  */
-  gdbarch = get_objfile_arch (objfile);
+  gdbarch = objfile->arch ();
 
   /* Basic types.  */
   objfile_type->builtin_void
diff --git a/gdb/hppa-tdep.c b/gdb/hppa-tdep.c
index 3730a73af2a..88abe90c5a8 100644
--- a/gdb/hppa-tdep.c
+++ b/gdb/hppa-tdep.c
@@ -258,7 +258,7 @@  internalize_unwinds (struct objfile *objfile, struct unwind_table_entry *table,
 
   if (size > 0)
     {
-      struct gdbarch *gdbarch = get_objfile_arch (objfile);
+      struct gdbarch *gdbarch = objfile->arch ();
       unsigned long tmp;
       unsigned i;
       char *buf = (char *) alloca (size);
diff --git a/gdb/ia64-tdep.c b/gdb/ia64-tdep.c
index db02882bbe3..5fa0fad2888 100644
--- a/gdb/ia64-tdep.c
+++ b/gdb/ia64-tdep.c
@@ -2764,7 +2764,7 @@  ia64_find_unwind_table (struct objfile *objfile, unw_word_t ip,
 
   dip->start_ip = p_text->p_vaddr + load_base;
   dip->end_ip = dip->start_ip + p_text->p_memsz;
-  dip->gp = ia64_find_global_pointer (get_objfile_arch (objfile), ip);
+  dip->gp = ia64_find_global_pointer (objfile->arch (), ip);
   dip->format = UNW_INFO_FORMAT_REMOTE_TABLE;
   dip->u.rti.name_ptr = (unw_word_t) bfd_get_filename (bfd);
   dip->u.rti.segbase = segbase;
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 8ff34c382d6..53e832eb401 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -7818,7 +7818,7 @@  insert_exception_resume_from_probe (struct thread_info *tp,
   if (debug_infrun)
     fprintf_unfiltered (gdb_stdlog,
 			"infrun: exception resume at %s\n",
-			paddress (get_objfile_arch (probe->objfile),
+			paddress (probe->objfile->arch (),
 				  handler));
 
   bp = set_momentary_breakpoint_at_pc (get_frame_arch (frame),
diff --git a/gdb/jit.c b/gdb/jit.c
index 8eb98f4a38a..07e9ce7ae24 100644
--- a/gdb/jit.c
+++ b/gdb/jit.c
@@ -656,7 +656,7 @@  finalize_symtab (struct gdb_symtab *stab, struct objfile *objfile)
     {
       struct block *new_block = allocate_block (&objfile->objfile_obstack);
       struct symbol *block_name = allocate_symbol (objfile);
-      struct type *block_type = arch_type (get_objfile_arch (objfile),
+      struct type *block_type = arch_type (objfile->arch (),
 					   TYPE_CODE_VOID,
 					   TARGET_CHAR_BIT,
 					   "void");
diff --git a/gdb/linespec.c b/gdb/linespec.c
index d853e02d8f6..4b75700f8b6 100644
--- a/gdb/linespec.c
+++ b/gdb/linespec.c
@@ -2291,7 +2291,7 @@  convert_linespec_to_sals (struct linespec_state *state, linespec_p ls)
 			  if (MSYMBOL_TYPE (elem.minsym) == mst_data_gnu_ifunc)
 			    {
 			      struct gdbarch *gdbarch
-				= get_objfile_arch (elem.objfile);
+				= elem.objfile->arch ();
 			      msym_addr
 				= (gdbarch_convert_from_func_ptr_addr
 				   (gdbarch,
diff --git a/gdb/linux-fork.c b/gdb/linux-fork.c
index 357188685d0..2233d4429ce 100644
--- a/gdb/linux-fork.c
+++ b/gdb/linux-fork.c
@@ -663,7 +663,7 @@  checkpoint_command (const char *args, int from_tty)
   if (!fork_fn)
     error (_("checkpoint: can't find fork function in inferior."));
 
-  gdbarch = get_objfile_arch (fork_objf);
+  gdbarch = fork_objf->arch ();
   ret = value_from_longest (builtin_type (gdbarch)->builtin_int, 0);
 
   /* Tell linux-nat.c that we're checkpointing this inferior.  */
diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c
index e50946ce379..ed84d6ace6b 100644
--- a/gdb/linux-tdep.c
+++ b/gdb/linux-tdep.c
@@ -2326,7 +2326,7 @@  linux_infcall_mmap (CORE_ADDR size, unsigned prot)
      "mmap" uses 64-bit off_t on x86_64 and 32-bit off_t on i386 and x32.  */
   struct value *mmap_val = find_function_in_inferior ("mmap64", &objf);
   struct value *addr_val;
-  struct gdbarch *gdbarch = get_objfile_arch (objf);
+  struct gdbarch *gdbarch = objf->arch ();
   CORE_ADDR retval;
   enum
     {
@@ -2365,7 +2365,7 @@  linux_infcall_munmap (CORE_ADDR addr, CORE_ADDR size)
   struct objfile *objf;
   struct value *munmap_val = find_function_in_inferior ("munmap", &objf);
   struct value *retval_val;
-  struct gdbarch *gdbarch = get_objfile_arch (objf);
+  struct gdbarch *gdbarch = objf->arch ();
   LONGEST retval;
   enum
     {
diff --git a/gdb/machoread.c b/gdb/machoread.c
index 9881298021d..4655b67f118 100644
--- a/gdb/machoread.c
+++ b/gdb/machoread.c
@@ -493,7 +493,7 @@  macho_add_oso_symfile (oso_el *oso, const gdb_bfd_ref_ptr &abfd,
             {
               if (mach_o_debug_level > 4)
                 {
-                  struct gdbarch *arch = get_objfile_arch (main_objfile);
+                  struct gdbarch *arch = main_objfile->arch ();
                   printf_unfiltered
                     (_("Adding symbol %s (addr: %s)\n"),
                      sym->name, paddress (arch, sym->value));
@@ -567,7 +567,7 @@  macho_add_oso_symfile (oso_el *oso, const gdb_bfd_ref_ptr &abfd,
 
                   if (mach_o_debug_level > 3)
                     {
-                      struct gdbarch *arch = get_objfile_arch (main_objfile);
+                      struct gdbarch *arch = main_objfile->arch ();
                       printf_unfiltered
                         (_("resolve sect %s with %s (set to %s)\n"),
                          sec->name, sym->name,
diff --git a/gdb/mdebugread.c b/gdb/mdebugread.c
index 5dfd80de192..5c4158cd6fb 100644
--- a/gdb/mdebugread.c
+++ b/gdb/mdebugread.c
@@ -573,7 +573,7 @@  static int
 parse_symbol (SYMR *sh, union aux_ext *ax, char *ext_sh, int bigend,
 	      const section_offsets &section_offsets, struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
   void (*const swap_sym_in) (bfd *, void *, SYMR *) = debug_swap->swap_sym_in;
   const char *name;
@@ -1357,7 +1357,7 @@  static const struct objfile_key<struct type *,
 static struct type *
 basic_type (int bt, struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct type **map_bt = basic_type_data.get (objfile);
   struct type *tp;
 
@@ -2283,7 +2283,7 @@  static void
 parse_partial_symbols (minimal_symbol_reader &reader,
 		       struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   const bfd_size_type external_sym_size = debug_swap->external_sym_size;
   const bfd_size_type external_rfd_size = debug_swap->external_rfd_size;
   const bfd_size_type external_ext_size = debug_swap->external_ext_size;
@@ -3899,7 +3899,7 @@  mdebug_expand_psymtab (legacy_psymtab *pst, struct objfile *objfile)
 
   if (processing_gcc_compilation != 0)
     {
-      struct gdbarch *gdbarch = get_objfile_arch (objfile);
+      struct gdbarch *gdbarch = objfile->arch ();
 
       /* This symbol table contains stabs-in-ecoff entries.  */
 
diff --git a/gdb/mi/mi-symbol-cmds.c b/gdb/mi/mi-symbol-cmds.c
index a5ce2d179d8..d48d0effe27 100644
--- a/gdb/mi/mi-symbol-cmds.c
+++ b/gdb/mi/mi-symbol-cmds.c
@@ -50,7 +50,7 @@  mi_cmd_symbol_list_lines (const char *command, char **argv, int argc)
      already sorted by increasing values in the symbol table, so no
      need to perform any other sorting.  */
 
-  gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
+  gdbarch = SYMTAB_OBJFILE (s)->arch ();
 
   ui_out_emit_list list_emitter (uiout, "lines");
   if (SYMTAB_LINETABLE (s) != NULL && SYMTAB_LINETABLE (s)->nitems > 0)
@@ -96,7 +96,7 @@  static void
 output_nondebug_symbol (ui_out *uiout,
 			const struct bound_minimal_symbol &msymbol)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (msymbol.objfile);
+  struct gdbarch *gdbarch = msymbol.objfile->arch ();
   ui_out_emit_tuple tuple_emitter (uiout, NULL);
 
   uiout->field_core_addr ("address", gdbarch,
diff --git a/gdb/minsyms.c b/gdb/minsyms.c
index d2ac8172eea..2c1262b0dd6 100644
--- a/gdb/minsyms.c
+++ b/gdb/minsyms.c
@@ -77,7 +77,7 @@  msymbol_is_function (struct objfile *objfile, minimal_symbol *minsym,
     case mst_file_bss:
     case mst_data_gnu_ifunc:
       {
-	struct gdbarch *gdbarch = get_objfile_arch (objfile);
+	struct gdbarch *gdbarch = objfile->arch ();
 	CORE_ADDR pc
 	  = gdbarch_convert_from_func_ptr_addr (gdbarch, msym_addr,
 						current_top_target ());
diff --git a/gdb/objfiles.c b/gdb/objfiles.c
index 3138049e622..d329a953c17 100644
--- a/gdb/objfiles.c
+++ b/gdb/objfiles.c
@@ -374,14 +374,6 @@  objfile::objfile (bfd *abfd, const char *name, objfile_flags flags_)
   per_bfd = get_objfile_bfd_data (this, abfd);
 }
 
-/* Retrieve the gdbarch associated with OBJFILE.  */
-
-struct gdbarch *
-get_objfile_arch (const struct objfile *objfile)
-{
-  return objfile->per_bfd->gdbarch;
-}
-
 /* If there is a valid and known entry point, function fills *ENTRY_P with it
    and returns non-zero; otherwise it returns zero.  */
 
@@ -1132,7 +1124,7 @@  filter_overlapping_sections (struct obj_section **map, int map_size)
 
 	      const CORE_ADDR sect2_endaddr = obj_section_endaddr (sect2);
 
-	      struct gdbarch *const gdbarch = get_objfile_arch (objf1);
+	      struct gdbarch *const gdbarch = objf1->arch ();
 
 	      complaint (_("unexpected overlap between:\n"
 			   " (A) section `%s' from `%s' [%s, %s)\n"
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index a568fa4bcda..77f94e4f21d 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -544,6 +544,12 @@  struct objfile
 							str.size () + 1);
   }
 
+  /* Retrieve the gdbarch associated with this objfile.  */
+  struct gdbarch *arch () const
+  {
+    return per_bfd->gdbarch;
+  }
+
 
   /* The object file's original name as specified by the user,
      made absolute, and tilde-expanded.  However, it is not canonicalized
@@ -709,8 +715,6 @@  typedef std::unique_ptr<objfile, objfile_deleter> objfile_up;
 
 /* Declarations for functions defined in objfiles.c */
 
-extern struct gdbarch *get_objfile_arch (const struct objfile *);
-
 extern int entry_point_address_query (CORE_ADDR *entry_p);
 
 extern CORE_ADDR entry_point_address (void);
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 645ac4da9a4..de6d3d43bb4 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1442,7 +1442,7 @@  info_address_command (const char *exp, int from_tty)
 	{
 	  struct objfile *objfile = msymbol.objfile;
 
-	  gdbarch = get_objfile_arch (objfile);
+	  gdbarch = objfile->arch ();
 	  load_addr = BMSYMBOL_VALUE_ADDRESS (msymbol);
 
 	  printf_filtered ("Symbol \"");
diff --git a/gdb/psymtab.c b/gdb/psymtab.c
index 129eecb0671..7bc3d9a6d04 100644
--- a/gdb/psymtab.c
+++ b/gdb/psymtab.c
@@ -392,7 +392,7 @@  psym_find_pc_sect_compunit_symtab (struct objfile *objfile,
 	   continue, so let's not.  */
 	warning (_("\
 (Internal error: pc %s in read in psymtab, but not in symtab.)\n"),
-		 paddress (get_objfile_arch (objfile), pc));
+		 paddress (objfile->arch (), pc));
       psymtab_to_symtab (objfile, ps);
       return ps->get_compunit_symtab ();
     }
@@ -927,7 +927,7 @@  static void
 dump_psymtab (struct objfile *objfile, struct partial_symtab *psymtab,
 	      struct ui_file *outfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   int i;
 
   if (psymtab->anonymous)
@@ -1779,7 +1779,7 @@  dump_psymtab_addrmap_1 (void *datap, CORE_ADDR start_addr, void *obj)
 {
   struct dump_psymtab_addrmap_data *data
     = (struct dump_psymtab_addrmap_data *) datap;
-  struct gdbarch *gdbarch = get_objfile_arch (data->objfile);
+  struct gdbarch *gdbarch = data->objfile->arch ();
   struct partial_symtab *addrmap_psymtab = (struct partial_symtab *) obj;
   const char *psymtab_address_or_end = NULL;
 
@@ -1999,7 +1999,7 @@  maintenance_info_psymtabs (const char *regexp, int from_tty)
   ALL_PSPACES (pspace)
     for (objfile *objfile : pspace->objfiles ())
       {
-	struct gdbarch *gdbarch = get_objfile_arch (objfile);
+	struct gdbarch *gdbarch = objfile->arch ();
 
 	/* We don't want to print anything for this objfile until we
 	   actually find a symtab whose name matches.  */
@@ -2118,7 +2118,7 @@  maintenance_check_psymtabs (const char *ignore, int from_tty)
   for (objfile *objfile : current_program_space->objfiles ())
     for (partial_symtab *ps : require_partial_symbols (objfile, true))
       {
-	struct gdbarch *gdbarch = get_objfile_arch (objfile);
+	struct gdbarch *gdbarch = objfile->arch ();
 
 	/* We don't call psymtab_to_symtab here because that may cause symtab
 	   expansion.  When debugging a problem it helps if checkers leave
diff --git a/gdb/python/py-inferior.c b/gdb/python/py-inferior.c
index fd7d8a8aa70..b9268c11d43 100644
--- a/gdb/python/py-inferior.c
+++ b/gdb/python/py-inferior.c
@@ -193,7 +193,7 @@  python_new_objfile (struct objfile *objfile)
     return;
 
   gdbpy_enter enter_py (objfile != NULL
-			? get_objfile_arch (objfile)
+			? objfile->arch ()
 			: target_gdbarch (),
 			current_language);
 
diff --git a/gdb/python/py-objfile.c b/gdb/python/py-objfile.c
index 942349d6e66..205da8b649f 100644
--- a/gdb/python/py-objfile.c
+++ b/gdb/python/py-objfile.c
@@ -661,7 +661,7 @@  gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw)
 static void
 py_free_objfile (struct objfile *objfile, void *datum)
 {
-  gdbpy_enter enter_py (get_objfile_arch (objfile), current_language);
+  gdbpy_enter enter_py (objfile->arch (), current_language);
   gdbpy_ref<objfile_object> object ((objfile_object *) datum);
   object->objfile = NULL;
 }
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index b19cad098a4..61720491c7a 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -1049,7 +1049,7 @@  save_objfile_types (struct objfile *objfile, void *datum)
 
   /* This prevents another thread from freeing the objects we're
      operating on.  */
-  gdbpy_enter enter_py (get_objfile_arch (objfile), current_language);
+  gdbpy_enter enter_py (objfile->arch (), current_language);
 
   copied_types = create_copied_types_hash (objfile);
 
diff --git a/gdb/python/python.c b/gdb/python/python.c
index 6e243c1a07b..d17df7dac6f 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1389,7 +1389,7 @@  gdbpy_source_objfile_script (const struct extension_language_defn *extlang,
   if (!gdb_python_initialized)
     return;
 
-  gdbpy_enter enter_py (get_objfile_arch (objfile), current_language);
+  gdbpy_enter enter_py (objfile->arch (), current_language);
   gdbpy_current_objfile = objfile;
 
   python_run_simple_file (file, filename);
@@ -1411,7 +1411,7 @@  gdbpy_execute_objfile_script (const struct extension_language_defn *extlang,
   if (!gdb_python_initialized)
     return;
 
-  gdbpy_enter enter_py (get_objfile_arch (objfile), current_language);
+  gdbpy_enter enter_py (objfile->arch (), current_language);
   gdbpy_current_objfile = objfile;
 
   PyRun_SimpleString (script);
diff --git a/gdb/source.c b/gdb/source.c
index 50de93952bb..7d22bbb5db3 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -1499,8 +1499,7 @@  info_line_command (const char *arg, int from_tty)
       else if (sal.line > 0
 	       && find_line_pc_range (sal, &start_pc, &end_pc))
 	{
-	  struct gdbarch *gdbarch
-	    = get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
+	  struct gdbarch *gdbarch = SYMTAB_OBJFILE (sal.symtab)->arch ();
 
 	  if (start_pc == end_pc)
 	    {
diff --git a/gdb/stabsread.c b/gdb/stabsread.c
index 068ece2ff53..5ef7748a9eb 100644
--- a/gdb/stabsread.c
+++ b/gdb/stabsread.c
@@ -369,7 +369,7 @@  dbx_alloc_type (int typenums[2], struct objfile *objfile)
 static struct type *
 dbx_init_float_type (struct objfile *objfile, int bits)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   const struct floatformat **format;
   struct type *type;
 
@@ -649,7 +649,7 @@  struct symbol *
 define_symbol (CORE_ADDR valu, const char *string, int desc, int type,
 	       struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct symbol *sym;
   const char *p = find_name_end (string);
   int deftype;
@@ -2823,7 +2823,7 @@  read_one_struct_field (struct stab_field_info *fip, const char **pp,
 		       const char *p, struct type *type,
 		       struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
 
   fip->list->field.name
     = obstack_strndup (&objfile->objfile_obstack, *pp, p - *pp);
@@ -3581,7 +3581,7 @@  static struct type *
 read_enum_type (const char **pp, struct type *type,
 		struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   const char *p;
   char *name;
   long n;
@@ -3997,7 +3997,7 @@  static struct type *
 read_range_type (const char **pp, int typenums[2], int type_size,
                  struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   const char *orig_pp = *pp;
   int rangenums[2];
   long n2, n3;
diff --git a/gdb/stap-probe.c b/gdb/stap-probe.c
index 1a5ba5a1b3e..4b1a75f8166 100644
--- a/gdb/stap-probe.c
+++ b/gdb/stap-probe.c
@@ -1517,7 +1517,7 @@  handle_stap_probe (struct objfile *objfile, struct sdt_note *el,
 {
   bfd *abfd = objfile->obfd;
   int size = bfd_get_arch_size (abfd) / 8;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   struct type *ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
 
   /* Provider and the name of the probe.  */
diff --git a/gdb/symfile.c b/gdb/symfile.c
index bd27a1fefef..66376a9b81b 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -852,14 +852,14 @@  init_entry_point_info (struct objfile *objfile)
       /* Make certain that the address points at real code, and not a
 	 function descriptor.  */
       entry_point
-	= gdbarch_convert_from_func_ptr_addr (get_objfile_arch (objfile),
+	= gdbarch_convert_from_func_ptr_addr (objfile->arch (),
 					      entry_point,
 					      current_top_target ());
 
       /* Remove any ISA markers, so that this matches entries in the
 	 symbol table.  */
       ei->entry_point
-	= gdbarch_addr_bits_remove (get_objfile_arch (objfile), entry_point);
+	= gdbarch_addr_bits_remove (objfile->arch (), entry_point);
 
       found = 0;
       ALL_OBJFILE_OSECTIONS (objfile, osect)
@@ -2998,7 +2998,7 @@  section_is_mapped (struct obj_section *osect)
     case ovly_auto:		/* overlay debugging automatic */
       /* Unles there is a gdbarch_overlay_update function,
          there's really nothing useful to do here (can't really go auto).  */
-      gdbarch = get_objfile_arch (osect->objfile);
+      gdbarch = osect->objfile->arch ();
       if (gdbarch_overlay_update_p (gdbarch))
 	{
 	  if (overlay_cache_invalid)
@@ -3197,7 +3197,7 @@  list_overlays_command (const char *args, int from_tty)
 	ALL_OBJFILE_OSECTIONS (objfile, osect)
 	  if (section_is_mapped (osect))
 	    {
-	      struct gdbarch *gdbarch = get_objfile_arch (objfile);
+	      struct gdbarch *gdbarch = objfile->arch ();
 	      const char *name;
 	      bfd_vma lma, vma;
 	      int size;
@@ -3464,7 +3464,7 @@  simple_read_overlay_table (void)
       return 0;
     }
 
-  gdbarch = get_objfile_arch (ovly_table_msym.objfile);
+  gdbarch = ovly_table_msym.objfile->arch ();
   word_size = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
   byte_order = gdbarch_byte_order (gdbarch);
 
@@ -3493,7 +3493,7 @@  simple_overlay_update_1 (struct obj_section *osect)
 {
   int i;
   asection *bsect = osect->the_bfd_section;
-  struct gdbarch *gdbarch = get_objfile_arch (osect->objfile);
+  struct gdbarch *gdbarch = osect->objfile->arch ();
   int word_size = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
   enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
 
diff --git a/gdb/symmisc.c b/gdb/symmisc.c
index bee136ed465..45e69cbe1e8 100644
--- a/gdb/symmisc.c
+++ b/gdb/symmisc.c
@@ -179,7 +179,7 @@  dump_objfile (struct objfile *objfile)
 static void
 dump_msymbols (struct objfile *objfile, struct ui_file *outfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   int index;
   char ms_type;
 
@@ -269,7 +269,7 @@  static void
 dump_symtab_1 (struct symtab *symtab, struct ui_file *outfile)
 {
   struct objfile *objfile = SYMTAB_OBJFILE (symtab);
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   int i;
   struct mdict_iterator miter;
   int len;
@@ -1054,7 +1054,7 @@  maintenance_print_one_line_table (struct symtab *symtab, void *data)
 	    uiout->field_signed ("line", item->line);
 	  else
 	    uiout->field_string ("line", _("END"));
-	  uiout->field_core_addr ("address", get_objfile_arch (objfile),
+	  uiout->field_core_addr ("address", objfile->arch (),
 				  item->pc);
 	  uiout->field_string ("is-stmt", item->is_stmt ? "Y" : "");
 	  uiout->text ("\n");
diff --git a/gdb/symtab.c b/gdb/symtab.c
index 5f07f3cc93e..c6ee23807d6 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -2666,7 +2666,7 @@  lookup_global_or_static_symbol (const char *name,
       lookup_data.block_index = block_index;
       lookup_data.domain = domain;
       gdbarch_iterate_over_objfiles_in_search_order
-	(objfile != NULL ? get_objfile_arch (objfile) : target_gdbarch (),
+	(objfile != NULL ? objfile->arch () : target_gdbarch (),
 	 lookup_symbol_global_or_static_iterator_cb, &lookup_data, objfile);
       result = lookup_data.result;
     }
@@ -3647,7 +3647,7 @@  find_function_start_sal_1 (CORE_ADDR func_addr, obj_section *section,
       && (COMPUNIT_LOCATIONS_VALID (SYMTAB_COMPUNIT (sal.symtab))
 	  || SYMTAB_LANGUAGE (sal.symtab) == language_asm))
     {
-      struct gdbarch *gdbarch = get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
+      struct gdbarch *gdbarch = SYMTAB_OBJFILE (sal.symtab)->arch ();
 
       sal.pc = func_addr;
       if (gdbarch_skip_entrypoint_p (gdbarch))
@@ -3806,7 +3806,7 @@  skip_prologue_sal (struct symtab_and_line *sal)
       name = msymbol.minsym->linkage_name ();
     }
 
-  gdbarch = get_objfile_arch (objfile);
+  gdbarch = objfile->arch ();
 
   /* Process the prologue in two passes.  In the first pass try to skip the
      prologue (SKIP is true) and verify there is a real need for it (indicated
@@ -4928,7 +4928,7 @@  print_symbol_info (enum search_domain kind,
 static void
 print_msymbol_info (struct bound_minimal_symbol msymbol)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (msymbol.objfile);
+  struct gdbarch *gdbarch = msymbol.objfile->arch ();
   char *tmp;
 
   if (gdbarch_addr_bit (gdbarch) <= 32)
@@ -5550,7 +5550,7 @@  find_gnu_ifunc (const symbol *sym)
 	  CORE_ADDR msym_addr = MSYMBOL_VALUE_ADDRESS (objfile, minsym);
 	  if (MSYMBOL_TYPE (minsym) == mst_data_gnu_ifunc)
 	    {
-	      struct gdbarch *gdbarch = get_objfile_arch (objfile);
+	      struct gdbarch *gdbarch = objfile->arch ();
 	      msym_addr
 		= gdbarch_convert_from_func_ptr_addr (gdbarch,
 						      msym_addr,
@@ -6405,7 +6405,7 @@  symbol_arch (const struct symbol *symbol)
 {
   if (!SYMBOL_OBJFILE_OWNED (symbol))
     return symbol->owner.arch;
-  return get_objfile_arch (SYMTAB_OBJFILE (symbol->owner.symtab));
+  return SYMTAB_OBJFILE (symbol->owner.symtab)->arch ();
 }
 
 /* See symtab.h.  */
diff --git a/gdb/tui/tui-source.c b/gdb/tui/tui-source.c
index 7bc1220a876..fd5bd7dd960 100644
--- a/gdb/tui/tui-source.c
+++ b/gdb/tui/tui-source.c
@@ -74,7 +74,7 @@  tui_source_window::set_contents (struct gdbarch *arch,
   m_fullname = make_unique_xstrdup (symtab_to_fullname (s));
 
   cur_line = 0;
-  m_gdbarch = get_objfile_arch (SYMTAB_OBJFILE (s));
+  m_gdbarch = SYMTAB_OBJFILE (s)->arch ();
   m_start_line_or_addr.loa = LOA_LINE;
   cur_line_no = m_start_line_or_addr.u.line_no = line_no;
 
diff --git a/gdb/tui/tui-winsource.c b/gdb/tui/tui-winsource.c
index b5ba59e2f7a..db0add99688 100644
--- a/gdb/tui/tui-winsource.c
+++ b/gdb/tui/tui-winsource.c
@@ -216,7 +216,7 @@  tui_update_source_windows_with_line (struct symtab_and_line sal)
   if (sal.symtab != nullptr)
     {
       find_line_pc (sal.symtab, sal.line, &sal.pc);
-      gdbarch = get_objfile_arch (SYMTAB_OBJFILE (sal.symtab));
+      gdbarch = SYMTAB_OBJFILE (sal.symtab)->arch ();
     }
 
   for (struct tui_source_window_base *win_info : tui_source_windows ())
diff --git a/gdb/valops.c b/gdb/valops.c
index 03c6482ee1e..04cf22cced1 100644
--- a/gdb/valops.c
+++ b/gdb/valops.c
@@ -139,7 +139,7 @@  find_function_in_inferior (const char *name, struct objfile **objf_p)
       if (msymbol.minsym != NULL)
 	{
 	  struct objfile *objfile = msymbol.objfile;
-	  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+	  struct gdbarch *gdbarch = objfile->arch ();
 
 	  struct type *type;
 	  CORE_ADDR maddr;
@@ -175,7 +175,7 @@  value_allocate_space_in_inferior (int len)
 {
   struct objfile *objf;
   struct value *val = find_function_in_inferior ("malloc", &objf);
-  struct gdbarch *gdbarch = get_objfile_arch (objf);
+  struct gdbarch *gdbarch = objf->arch ();
   struct value *blocklen;
 
   blocklen = value_from_longest (builtin_type (gdbarch)->builtin_int, len);
diff --git a/gdb/value.c b/gdb/value.c
index f722c272d8b..6e2a9ba4fcc 100644
--- a/gdb/value.c
+++ b/gdb/value.c
@@ -3068,7 +3068,7 @@  value_fn_field (struct value **arg1p, struct fn_field *f,
       /* The minimal symbol might point to a function descriptor;
 	 resolve it to the actual code address instead.  */
       struct objfile *objfile = msym.objfile;
-      struct gdbarch *gdbarch = get_objfile_arch (objfile);
+      struct gdbarch *gdbarch = objfile->arch ();
 
       set_value_address (v,
 	gdbarch_convert_from_func_ptr_addr
diff --git a/gdb/xcoffread.c b/gdb/xcoffread.c
index 6c118138807..2c19dc8c822 100644
--- a/gdb/xcoffread.c
+++ b/gdb/xcoffread.c
@@ -829,7 +829,7 @@  enter_line_range (struct subfile *subfile, unsigned beginoffset,
 		  CORE_ADDR endaddr, unsigned *firstLine)
 {
   struct objfile *objfile = this_symtab_objfile;
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   unsigned int curoffset;
   CORE_ADDR addr;
   void *ext_lnno;
@@ -2121,7 +2121,7 @@  static void
 scan_xcoff_symtab (minimal_symbol_reader &reader,
 		   struct objfile *objfile)
 {
-  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  struct gdbarch *gdbarch = objfile->arch ();
   CORE_ADDR toc_offset = 0;	/* toc offset value in data section.  */
   const char *filestring = NULL;