diff --git a/gdb/gcore.c b/gdb/gcore.c
index 24810a7dee..401f2aaa82 100644
--- a/gdb/gcore.c
+++ b/gdb/gcore.c
@@ -424,34 +424,34 @@ gcore_create_callback (CORE_ADDR vaddr, unsigned long size, int read,
     {
       /* See if this region of memory lies inside a known file on disk.
 	 If so, we can avoid copying its contents by clearing SEC_LOAD.  */
-      struct objfile *objfile;
       struct obj_section *objsec;
 
-      ALL_OBJSECTIONS (objfile, objsec)
-	{
-	  bfd *abfd = objfile->obfd;
-	  asection *asec = objsec->the_bfd_section;
-	  bfd_vma align = (bfd_vma) 1 << bfd_get_section_alignment (abfd,
-								    asec);
-	  bfd_vma start = obj_section_addr (objsec) & -align;
-	  bfd_vma end = (obj_section_endaddr (objsec) + align - 1) & -align;
-
-	  /* Match if either the entire memory region lies inside the
-	     section (i.e. a mapping covering some pages of a large
-	     segment) or the entire section lies inside the memory region
-	     (i.e. a mapping covering multiple small sections).
-
-	     This BFD was synthesized from reading target memory,
-	     we don't want to omit that.  */
-	  if (objfile->separate_debug_objfile_backlink == NULL
-	      && ((vaddr >= start && vaddr + size <= end)
-	          || (start >= vaddr && end <= vaddr + size))
-	      && !(bfd_get_file_flags (abfd) & BFD_IN_MEMORY))
-	    {
-	      flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
-	      goto keep;	/* Break out of two nested for loops.  */
-	    }
-	}
+      for (struct objfile *objfile : all_objfiles (current_program_space))
+	ALL_OBJFILE_OSECTIONS (objfile, objsec)
+	  {
+	    bfd *abfd = objfile->obfd;
+	    asection *asec = objsec->the_bfd_section;
+	    bfd_vma align = (bfd_vma) 1 << bfd_get_section_alignment (abfd,
+								      asec);
+	    bfd_vma start = obj_section_addr (objsec) & -align;
+	    bfd_vma end = (obj_section_endaddr (objsec) + align - 1) & -align;
+
+	    /* Match if either the entire memory region lies inside the
+	       section (i.e. a mapping covering some pages of a large
+	       segment) or the entire section lies inside the memory region
+	       (i.e. a mapping covering multiple small sections).
+
+	       This BFD was synthesized from reading target memory,
+	       we don't want to omit that.  */
+	    if (objfile->separate_debug_objfile_backlink == NULL
+		&& ((vaddr >= start && vaddr + size <= end)
+		    || (start >= vaddr && end <= vaddr + size))
+		&& !(bfd_get_file_flags (abfd) & BFD_IN_MEMORY))
+	      {
+		flags &= ~(SEC_LOAD | SEC_HAS_CONTENTS);
+		goto keep;	/* Break out of two nested for loops.  */
+	      }
+	  }
 
     keep:;
     }
@@ -489,36 +489,36 @@ objfile_find_memory_regions (struct target_ops *self,
 			     find_memory_region_ftype func, void *obfd)
 {
   /* Use objfile data to create memory sections.  */
-  struct objfile *objfile;
   struct obj_section *objsec;
   bfd_vma temp_bottom, temp_top;
 
   /* Call callback function for each objfile section.  */
-  ALL_OBJSECTIONS (objfile, objsec)
-    {
-      bfd *ibfd = objfile->obfd;
-      asection *isec = objsec->the_bfd_section;
-      flagword flags = bfd_get_section_flags (ibfd, isec);
-
-      /* Separate debug info files are irrelevant for gcore.  */
-      if (objfile->separate_debug_objfile_backlink != NULL)
-	continue;
-
-      if ((flags & SEC_ALLOC) || (flags & SEC_LOAD))
-	{
-	  int size = bfd_section_size (ibfd, isec);
-	  int ret;
-
-	  ret = (*func) (obj_section_addr (objsec), size, 
-			 1, /* All sections will be readable.  */
-			 (flags & SEC_READONLY) == 0, /* Writable.  */
-			 (flags & SEC_CODE) != 0, /* Executable.  */
-			 1, /* MODIFIED is unknown, pass it as true.  */
-			 obfd);
-	  if (ret != 0)
-	    return ret;
-	}
-    }
+  for (struct objfile *objfile : all_objfiles (current_program_space))
+    ALL_OBJFILE_OSECTIONS (objfile, objsec)
+      {
+	bfd *ibfd = objfile->obfd;
+	asection *isec = objsec->the_bfd_section;
+	flagword flags = bfd_get_section_flags (ibfd, isec);
+
+	/* Separate debug info files are irrelevant for gcore.  */
+	if (objfile->separate_debug_objfile_backlink != NULL)
+	  continue;
+
+	if ((flags & SEC_ALLOC) || (flags & SEC_LOAD))
+	  {
+	    int size = bfd_section_size (ibfd, isec);
+	    int ret;
+
+	    ret = (*func) (obj_section_addr (objsec), size, 
+			   1, /* All sections will be readable.  */
+			   (flags & SEC_READONLY) == 0, /* Writable.  */
+			   (flags & SEC_CODE) != 0, /* Executable.  */
+			   1, /* MODIFIED is unknown, pass it as true.  */
+			   obfd);
+	    if (ret != 0)
+	      return ret;
+	  }
+      }
 
   /* Make a stack segment.  */
   if (derive_stack_segment (&temp_bottom, &temp_top))
diff --git a/gdb/maint.c b/gdb/maint.c
index df4bf444ff..0867f62e89 100644
--- a/gdb/maint.c
+++ b/gdb/maint.c
@@ -430,7 +430,6 @@ maintenance_translate_address (const char *arg, int from_tty)
   struct obj_section *sect;
   const char *p;
   struct bound_minimal_symbol sym;
-  struct objfile *objfile;
 
   if (arg == NULL || *arg == 0)
     error (_("requires argument (address or section + address)"));
@@ -448,14 +447,15 @@ maintenance_translate_address (const char *arg, int from_tty)
       int arg_len = p - arg;
       p = skip_spaces (p + 1);
 
-      ALL_OBJSECTIONS (objfile, sect)
-      {
-	if (strncmp (sect->the_bfd_section->name, arg, arg_len) == 0)
-	  break;
-      }
+      for (struct objfile *objfile : all_objfiles (current_program_space))
+	ALL_OBJFILE_OSECTIONS (objfile, sect)
+	  {
+	    if (strncmp (sect->the_bfd_section->name, arg, arg_len) == 0)
+	      goto found;
+	  }
 
-      if (!objfile)
-	error (_("Unknown section %s."), arg);
+      error (_("Unknown section %s."), arg);
+    found: ;
     }
 
   address = parse_and_eval_address (p);
diff --git a/gdb/objfiles.h b/gdb/objfiles.h
index 9d00a55ce5..5e704177eb 100644
--- a/gdb/objfiles.h
+++ b/gdb/objfiles.h
@@ -705,42 +705,6 @@ private:
       }									\
     else
 
-/* Traverse all obj_sections in all objfiles in the current program
-   space.
-
-   Note that this detects a "break" in the inner loop, and exits
-   immediately from the outer loop as well, thus, client code doesn't
-   need to know that this is implemented with a double for.  The extra
-   hair is to make sure that a "break;" stops the outer loop iterating
-   as well, and both OBJFILE and OSECT are left unmodified:
-
-    - The outer loop learns about the inner loop's end condition, and
-      stops iterating if it detects the inner loop didn't reach its
-      end.  In other words, the outer loop keeps going only if the
-      inner loop reached its end cleanly [(osect) ==
-      (objfile)->sections_end].
-
-    - OSECT is initialized in the outer loop initialization
-      expressions, such as if the inner loop has reached its end, so
-      the check mentioned above succeeds the first time.
-
-    - The trick to not clearing OBJFILE on a "break;" is, in the outer
-      loop's loop expression, advance OBJFILE, but iff the inner loop
-      reached its end.  If not, there was a "break;", so leave OBJFILE
-      as is; the outer loop's conditional will break immediately as
-      well (as OSECT will be different from OBJFILE->sections_end).  */
-
-#define ALL_OBJSECTIONS(objfile, osect)					\
-  for ((objfile) = current_program_space->objfiles,			\
-	 (objfile) != NULL ? ((osect) = (objfile)->sections_end) : 0;	\
-       (objfile) != NULL						\
-	 && (osect) == (objfile)->sections_end;				\
-       ((osect) == (objfile)->sections_end				\
-	? ((objfile) = (objfile)->next,					\
-	   (objfile) != NULL ? (osect) = (objfile)->sections_end : 0)	\
-	: 0))								\
-    ALL_OBJFILE_OSECTIONS (objfile, osect)
-
 #define SECT_OFF_DATA(objfile) \
      ((objfile->sect_index_data == -1) \
       ? (internal_error (__FILE__, __LINE__, \
diff --git a/gdb/printcmd.c b/gdb/printcmd.c
index 8c999188d7..130c64c3e8 100644
--- a/gdb/printcmd.c
+++ b/gdb/printcmd.c
@@ -1271,7 +1271,6 @@ static void
 info_symbol_command (const char *arg, int from_tty)
 {
   struct minimal_symbol *msymbol;
-  struct objfile *objfile;
   struct obj_section *osect;
   CORE_ADDR addr, sect_addr;
   int matches = 0;
@@ -1281,78 +1280,81 @@ info_symbol_command (const char *arg, int from_tty)
     error_no_arg (_("address"));
 
   addr = parse_and_eval_address (arg);
-  ALL_OBJSECTIONS (objfile, osect)
-  {
-    /* Only process each object file once, even if there's a separate
-       debug file.  */
-    if (objfile->separate_debug_objfile_backlink)
-      continue;
-
-    sect_addr = overlay_mapped_address (addr, osect);
-
-    if (obj_section_addr (osect) <= sect_addr
-	&& sect_addr < obj_section_endaddr (osect)
-	&& (msymbol
-	    = lookup_minimal_symbol_by_pc_section (sect_addr, osect).minsym))
+  for (struct objfile *objfile : all_objfiles (current_program_space))
+    ALL_OBJFILE_OSECTIONS (objfile, osect)
       {
-	const char *obj_name, *mapped, *sec_name, *msym_name;
-	const char *loc_string;
-
-	matches = 1;
-	offset = sect_addr - MSYMBOL_VALUE_ADDRESS (objfile, msymbol);
-	mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped");
-	sec_name = osect->the_bfd_section->name;
-	msym_name = MSYMBOL_PRINT_NAME (msymbol);
-
-	/* Don't print the offset if it is zero.
-	   We assume there's no need to handle i18n of "sym + offset".  */
-	std::string string_holder;
-	if (offset)
+	/* Only process each object file once, even if there's a separate
+	   debug file.  */
+	if (objfile->separate_debug_objfile_backlink)
+	  continue;
+
+	sect_addr = overlay_mapped_address (addr, osect);
+
+	if (obj_section_addr (osect) <= sect_addr
+	    && sect_addr < obj_section_endaddr (osect)
+	    && (msymbol
+		= lookup_minimal_symbol_by_pc_section (sect_addr,
+						       osect).minsym))
 	  {
-	    string_holder = string_printf ("%s + %u", msym_name, offset);
-	    loc_string = string_holder.c_str ();
-	  }
-	else
-	  loc_string = msym_name;
-
-	gdb_assert (osect->objfile && objfile_name (osect->objfile));
-	obj_name = objfile_name (osect->objfile);
-
-	if (MULTI_OBJFILE_P ())
-	  if (pc_in_unmapped_range (addr, osect))
-	    if (section_is_overlay (osect))
-	      printf_filtered (_("%s in load address range of "
-				 "%s overlay section %s of %s\n"),
-			       loc_string, mapped, sec_name, obj_name);
-	    else
-	      printf_filtered (_("%s in load address range of "
-				 "section %s of %s\n"),
-			       loc_string, sec_name, obj_name);
-	  else
-	    if (section_is_overlay (osect))
-	      printf_filtered (_("%s in %s overlay section %s of %s\n"),
-			       loc_string, mapped, sec_name, obj_name);
-	    else
-	      printf_filtered (_("%s in section %s of %s\n"),
-			       loc_string, sec_name, obj_name);
-	else
-	  if (pc_in_unmapped_range (addr, osect))
-	    if (section_is_overlay (osect))
-	      printf_filtered (_("%s in load address range of %s overlay "
-				 "section %s\n"),
-			       loc_string, mapped, sec_name);
+	    const char *obj_name, *mapped, *sec_name, *msym_name;
+	    const char *loc_string;
+
+	    matches = 1;
+	    offset = sect_addr - MSYMBOL_VALUE_ADDRESS (objfile, msymbol);
+	    mapped = section_is_mapped (osect) ? _("mapped") : _("unmapped");
+	    sec_name = osect->the_bfd_section->name;
+	    msym_name = MSYMBOL_PRINT_NAME (msymbol);
+
+	    /* Don't print the offset if it is zero.
+	       We assume there's no need to handle i18n of "sym + offset".  */
+	    std::string string_holder;
+	    if (offset)
+	      {
+		string_holder = string_printf ("%s + %u", msym_name, offset);
+		loc_string = string_holder.c_str ();
+	      }
 	    else
-	      printf_filtered (_("%s in load address range of section %s\n"),
-			       loc_string, sec_name);
-	  else
-	    if (section_is_overlay (osect))
-	      printf_filtered (_("%s in %s overlay section %s\n"),
-			       loc_string, mapped, sec_name);
+	      loc_string = msym_name;
+
+	    gdb_assert (osect->objfile && objfile_name (osect->objfile));
+	    obj_name = objfile_name (osect->objfile);
+
+	    if (MULTI_OBJFILE_P ())
+	      if (pc_in_unmapped_range (addr, osect))
+		if (section_is_overlay (osect))
+		  printf_filtered (_("%s in load address range of "
+				     "%s overlay section %s of %s\n"),
+				   loc_string, mapped, sec_name, obj_name);
+		else
+		  printf_filtered (_("%s in load address range of "
+				     "section %s of %s\n"),
+				   loc_string, sec_name, obj_name);
+	      else
+		if (section_is_overlay (osect))
+		  printf_filtered (_("%s in %s overlay section %s of %s\n"),
+				   loc_string, mapped, sec_name, obj_name);
+		else
+		  printf_filtered (_("%s in section %s of %s\n"),
+				   loc_string, sec_name, obj_name);
 	    else
-	      printf_filtered (_("%s in section %s\n"),
-			       loc_string, sec_name);
+	      if (pc_in_unmapped_range (addr, osect))
+		if (section_is_overlay (osect))
+		  printf_filtered (_("%s in load address range of %s overlay "
+				     "section %s\n"),
+				   loc_string, mapped, sec_name);
+		else
+		  printf_filtered
+		    (_("%s in load address range of section %s\n"),
+		     loc_string, sec_name);
+	      else
+		if (section_is_overlay (osect))
+		  printf_filtered (_("%s in %s overlay section %s\n"),
+				   loc_string, mapped, sec_name);
+		else
+		  printf_filtered (_("%s in section %s\n"),
+				   loc_string, sec_name);
+	  }
       }
-  }
   if (matches == 0)
     printf_filtered (_("No symbol matches %s.\n"), arg);
 }
diff --git a/gdb/spu-tdep.c b/gdb/spu-tdep.c
index 57dd4f1ed0..830d4d4404 100644
--- a/gdb/spu-tdep.c
+++ b/gdb/spu-tdep.c
@@ -1883,11 +1883,10 @@ spu_overlay_update (struct obj_section *osect)
   /* All sections.  */
   else
     {
-      struct objfile *objfile;
-
-      ALL_OBJSECTIONS (objfile, osect)
-	if (section_is_overlay (osect))
-	  spu_overlay_update_osect (osect);
+      for (struct objfile *objfile : all_objfiles (current_program_space))
+	ALL_OBJFILE_OSECTIONS (objfile, osect)
+	  if (section_is_overlay (osect))
+	    spu_overlay_update_osect (osect);
     }
 }
 
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 55756c9da2..b89e1575ad 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2950,12 +2950,12 @@ section_is_overlay (struct obj_section *section)
 static void
 overlay_invalidate_all (void)
 {
-  struct objfile *objfile;
   struct obj_section *sect;
 
-  ALL_OBJSECTIONS (objfile, sect)
-    if (section_is_overlay (sect))
-      sect->ovly_mapped = -1;
+  for (struct objfile *objfile : all_objfiles (current_program_space))
+    ALL_OBJFILE_OSECTIONS (objfile, sect)
+      if (section_is_overlay (sect))
+	sect->ovly_mapped = -1;
 }
 
 /* Function: section_is_mapped (SECTION)
@@ -3126,24 +3126,24 @@ symbol_overlayed_address (CORE_ADDR address, struct obj_section *section)
 struct obj_section *
 find_pc_overlay (CORE_ADDR pc)
 {
-  struct objfile *objfile;
   struct obj_section *osect, *best_match = NULL;
 
   if (overlay_debugging)
     {
-      ALL_OBJSECTIONS (objfile, osect)
-	if (section_is_overlay (osect))
-	  {
-	    if (pc_in_mapped_range (pc, osect))
-	      {
-		if (section_is_mapped (osect))
-		  return osect;
-		else
-		  best_match = osect;
-	      }
-	    else if (pc_in_unmapped_range (pc, osect))
-	      best_match = osect;
-	  }
+      for (struct objfile *objfile : all_objfiles (current_program_space))
+	ALL_OBJFILE_OSECTIONS (objfile, osect)
+	  if (section_is_overlay (osect))
+	    {
+	      if (pc_in_mapped_range (pc, osect))
+		{
+		  if (section_is_mapped (osect))
+		    return osect;
+		  else
+		    best_match = osect;
+		}
+	      else if (pc_in_unmapped_range (pc, osect))
+		best_match = osect;
+	    }
     }
   return best_match;
 }
@@ -3155,14 +3155,14 @@ find_pc_overlay (CORE_ADDR pc)
 struct obj_section *
 find_pc_mapped_section (CORE_ADDR pc)
 {
-  struct objfile *objfile;
   struct obj_section *osect;
 
   if (overlay_debugging)
     {
-      ALL_OBJSECTIONS (objfile, osect)
-	if (pc_in_mapped_range (pc, osect) && section_is_mapped (osect))
-	  return osect;
+      for (struct objfile *objfile : all_objfiles (current_program_space))
+	ALL_OBJFILE_OSECTIONS (objfile, osect)
+	  if (pc_in_mapped_range (pc, osect) && section_is_mapped (osect))
+	    return osect;
     }
 
   return NULL;
@@ -3175,36 +3175,36 @@ static void
 list_overlays_command (const char *args, int from_tty)
 {
   int nmapped = 0;
-  struct objfile *objfile;
   struct obj_section *osect;
 
   if (overlay_debugging)
     {
-      ALL_OBJSECTIONS (objfile, osect)
-      if (section_is_mapped (osect))
-	{
-	  struct gdbarch *gdbarch = get_objfile_arch (objfile);
-	  const char *name;
-	  bfd_vma lma, vma;
-	  int size;
-
-	  vma = bfd_section_vma (objfile->obfd, osect->the_bfd_section);
-	  lma = bfd_section_lma (objfile->obfd, osect->the_bfd_section);
-	  size = bfd_get_section_size (osect->the_bfd_section);
-	  name = bfd_section_name (objfile->obfd, osect->the_bfd_section);
-
-	  printf_filtered ("Section %s, loaded at ", name);
-	  fputs_filtered (paddress (gdbarch, lma), gdb_stdout);
-	  puts_filtered (" - ");
-	  fputs_filtered (paddress (gdbarch, lma + size), gdb_stdout);
-	  printf_filtered (", mapped at ");
-	  fputs_filtered (paddress (gdbarch, vma), gdb_stdout);
-	  puts_filtered (" - ");
-	  fputs_filtered (paddress (gdbarch, vma + size), gdb_stdout);
-	  puts_filtered ("\n");
-
-	  nmapped++;
-	}
+      for (struct objfile *objfile : all_objfiles (current_program_space))
+	ALL_OBJFILE_OSECTIONS (objfile, osect)
+	  if (section_is_mapped (osect))
+	    {
+	      struct gdbarch *gdbarch = get_objfile_arch (objfile);
+	      const char *name;
+	      bfd_vma lma, vma;
+	      int size;
+
+	      vma = bfd_section_vma (objfile->obfd, osect->the_bfd_section);
+	      lma = bfd_section_lma (objfile->obfd, osect->the_bfd_section);
+	      size = bfd_get_section_size (osect->the_bfd_section);
+	      name = bfd_section_name (objfile->obfd, osect->the_bfd_section);
+
+	      printf_filtered ("Section %s, loaded at ", name);
+	      fputs_filtered (paddress (gdbarch, lma), gdb_stdout);
+	      puts_filtered (" - ");
+	      fputs_filtered (paddress (gdbarch, lma + size), gdb_stdout);
+	      printf_filtered (", mapped at ");
+	      fputs_filtered (paddress (gdbarch, vma), gdb_stdout);
+	      puts_filtered (" - ");
+	      fputs_filtered (paddress (gdbarch, vma + size), gdb_stdout);
+	      puts_filtered ("\n");
+
+	      nmapped++;
+	    }
     }
   if (nmapped == 0)
     printf_filtered (_("No sections are mapped.\n"));
@@ -3216,7 +3216,6 @@ list_overlays_command (const char *args, int from_tty)
 static void
 map_overlay_command (const char *args, int from_tty)
 {
-  struct objfile *objfile, *objfile2;
   struct obj_section *sec, *sec2;
 
   if (!overlay_debugging)
@@ -3228,29 +3227,31 @@ map_overlay_command (const char *args, int from_tty)
     error (_("Argument required: name of an overlay section"));
 
   /* First, find a section matching the user supplied argument.  */
-  ALL_OBJSECTIONS (objfile, sec)
-    if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args))
-    {
-      /* Now, check to see if the section is an overlay.  */
-      if (!section_is_overlay (sec))
-	continue;		/* not an overlay section */
-
-      /* Mark the overlay as "mapped".  */
-      sec->ovly_mapped = 1;
-
-      /* Next, make a pass and unmap any sections that are
-         overlapped by this new section: */
-      ALL_OBJSECTIONS (objfile2, sec2)
-	if (sec2->ovly_mapped && sec != sec2 && sections_overlap (sec, sec2))
+  for (struct objfile *objfile : all_objfiles (current_program_space))
+    ALL_OBJFILE_OSECTIONS (objfile, sec)
+      if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args))
 	{
-	  if (info_verbose)
-	    printf_unfiltered (_("Note: section %s unmapped by overlap\n"),
-			     bfd_section_name (objfile->obfd,
-					       sec2->the_bfd_section));
-	  sec2->ovly_mapped = 0;	/* sec2 overlaps sec: unmap sec2.  */
+	  /* Now, check to see if the section is an overlay.  */
+	  if (!section_is_overlay (sec))
+	    continue;		/* not an overlay section */
+
+	  /* Mark the overlay as "mapped".  */
+	  sec->ovly_mapped = 1;
+
+	  /* Next, make a pass and unmap any sections that are
+	     overlapped by this new section: */
+	  for (struct objfile *objfile2 : all_objfiles (current_program_space))
+	    ALL_OBJFILE_OSECTIONS (objfile2, sec2)
+	      if (sec2->ovly_mapped && sec != sec2 && sections_overlap (sec, sec2))
+		{
+		  if (info_verbose)
+		    printf_unfiltered (_("Note: section %s unmapped by overlap\n"),
+				       bfd_section_name (objfile->obfd,
+							 sec2->the_bfd_section));
+		  sec2->ovly_mapped = 0;	/* sec2 overlaps sec: unmap sec2.  */
+		}
+	  return;
 	}
-      return;
-    }
   error (_("No overlay section called %s"), args);
 }
 
@@ -3261,7 +3262,6 @@ map_overlay_command (const char *args, int from_tty)
 static void
 unmap_overlay_command (const char *args, int from_tty)
 {
-  struct objfile *objfile;
   struct obj_section *sec = NULL;
 
   if (!overlay_debugging)
@@ -3273,14 +3273,15 @@ unmap_overlay_command (const char *args, int from_tty)
     error (_("Argument required: name of an overlay section"));
 
   /* First, find a section matching the user supplied argument.  */
-  ALL_OBJSECTIONS (objfile, sec)
-    if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args))
-    {
-      if (!sec->ovly_mapped)
-	error (_("Section %s is not mapped"), args);
-      sec->ovly_mapped = 0;
-      return;
-    }
+  for (struct objfile *objfile : all_objfiles (current_program_space))
+    ALL_OBJFILE_OSECTIONS (objfile, sec)
+      if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args))
+	{
+	  if (!sec->ovly_mapped)
+	    error (_("Section %s is not mapped"), args);
+	  sec->ovly_mapped = 0;
+	  return;
+	}
   error (_("No overlay section called %s"), args);
 }
 
@@ -3512,8 +3513,6 @@ simple_overlay_update_1 (struct obj_section *osect)
 void
 simple_overlay_update (struct obj_section *osect)
 {
-  struct objfile *objfile;
-
   /* Were we given an osect to look up?  NULL means do all of them.  */
   if (osect)
     /* Have we got a cached copy of the target's overlay table?  */
@@ -3545,20 +3544,21 @@ simple_overlay_update (struct obj_section *osect)
     return;
 
   /* Now may as well update all sections, even if only one was requested.  */
-  ALL_OBJSECTIONS (objfile, osect)
-    if (section_is_overlay (osect))
-    {
-      int i;
-      asection *bsect = osect->the_bfd_section;
-
-      for (i = 0; i < cache_novlys; i++)
-	if (cache_ovly_table[i][VMA] == bfd_section_vma (obfd, bsect)
-	    && cache_ovly_table[i][LMA] == bfd_section_lma (obfd, bsect))
-	  { /* obj_section matches i'th entry in ovly_table.  */
-	    osect->ovly_mapped = cache_ovly_table[i][MAPPED];
-	    break;		/* finished with inner for loop: break out.  */
-	  }
-    }
+  for (struct objfile *objfile : all_objfiles (current_program_space))
+    ALL_OBJFILE_OSECTIONS (objfile, osect)
+      if (section_is_overlay (osect))
+	{
+	  int i;
+	  asection *bsect = osect->the_bfd_section;
+
+	  for (i = 0; i < cache_novlys; i++)
+	    if (cache_ovly_table[i][VMA] == bfd_section_vma (obfd, bsect)
+		&& cache_ovly_table[i][LMA] == bfd_section_lma (obfd, bsect))
+	      { /* obj_section matches i'th entry in ovly_table.  */
+		osect->ovly_mapped = cache_ovly_table[i][MAPPED];
+		break;		/* finished with inner for loop: break out.  */
+	      }
+	}
 }
 
 /* Set the output sections and output offsets for section SECTP in
