diff --git a/gdb/symfile.c b/gdb/symfile.c
index aa53415..ce37390 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -2587,6 +2587,9 @@ reread_symbols (void)
 	  /* Free the obstacks for non-reusable objfiles.  */
 	  psymbol_bcache_free (objfile->psymbol_cache);
 	  objfile->psymbol_cache = psymbol_bcache_init ();
+
+	  /* NB: after this call to obstack_free, objfiles_changed
+	     will need to be called (see discussion below).  */
 	  obstack_free (&objfile->objfile_obstack, 0);
 	  objfile->sections = NULL;
 	  objfile->compunit_symtabs = NULL;
@@ -2639,6 +2642,23 @@ reread_symbols (void)
 	  clear_complaints (&symfile_complaints, 1, 1);
 
 	  objfile->flags &= ~OBJF_PSYMTABS_READ;
+
+	  /* We are about to read new symbols and potentially also
+	     DWARF information.  Some targets may want to pass addresses
+	     read from DWARF DIE's through an adjustment function before
+	     saving them, like MIPS, which may call into
+	     "find_pc_section".  When called, that function will make
+	     use of per-objfile program space data.
+
+	     Since we discarded our section information above, we have
+	     dangling pointers in the per-objfile program space data
+	     structure.  Force GDB to update the section mapping
+	     information by letting it know the objfile has changed,
+	     making the dangling pointers point to correct data
+	     again.  */
+	     
+	  objfiles_changed ();
+
 	  read_symbols (objfile, 0);
 
 	  if (!objfile_has_symbols (objfile))
@@ -2671,9 +2691,6 @@ reread_symbols (void)
 
   if (!new_objfiles.empty ())
     {
-      /* Notify objfiles that we've modified objfile sections.  */
-      objfiles_changed ();
-
       clear_symtab_users (0);
 
       /* clear_objfile_data for each objfile was called before freeing it and
diff --git a/gdb/testsuite/gdb.base/reread-readsym.c b/gdb/testsuite/gdb.base/reread-readsym.c
new file mode 100644
index 0000000..2fee696
--- /dev/null
+++ b/gdb/testsuite/gdb.base/reread-readsym.c
@@ -0,0 +1,22 @@
+/* This testcase is part of GDB, the GNU debugger.
+
+   Copyright 2017 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+int
+main (void)
+{
+  return 0;
+}
diff --git a/gdb/testsuite/gdb.base/reread-readsym.exp b/gdb/testsuite/gdb.base/reread-readsym.exp
new file mode 100644
index 0000000..b69eaad
--- /dev/null
+++ b/gdb/testsuite/gdb.base/reread-readsym.exp
@@ -0,0 +1,61 @@
+#   Copyright 2017 Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+standard_testfile
+
+set gdbfile [standard_output_file ${testfile}.gdb]
+
+# Test rereading executable.  See PR gdb/21337.
+
+proc generate_cmd_file {gdbfile binfile} {
+    set ofd [open $gdbfile w]
+
+    puts $ofd "file ${binfile}"
+    puts $ofd "shell sleep 1; touch ${binfile}"
+    puts $ofd "run"
+    puts $ofd "file"
+    puts $ofd "file ${binfile}"
+    puts $ofd "shell sleep 1; touch ${binfile}"
+    puts $ofd "run"
+    puts $ofd "file"
+    puts $ofd "file ${binfile}"
+    puts $ofd "shell sleep 1; touch ${binfile}"
+    puts $ofd "run"
+    puts $ofd "file"
+    puts $ofd "p \"source-command-completed\""
+    close $ofd
+}
+
+if [use_gdb_stub] {
+    return 0
+}
+
+if {[prepare_for_testing "failed to prepare" $testfile $srcfile debug]} {
+    return -1
+}
+
+# Start with a fresh gdb.
+clean_restart ${testfile}
+
+# Using the source command to read commands from a file is important,
+# otherwise section data is freed and reallocated using the same
+# memory locations and the bug is not exposed.
+generate_cmd_file $gdbfile $binfile
+
+gdb_test "source $gdbfile" ".*source-command-completed.*" \
+    "source $testfile.gdb 1"
+# Sometimes the failure only occurs on the second invocation.
+gdb_test "source $gdbfile" ".*source-command-completed.*" \
+    "source $testfile.gdb 2"
