diff --git a/gdb/symtab.c b/gdb/symtab.c
index d7317a758b1..e5f70f5a699 100644
--- a/gdb/symtab.c
+++ b/gdb/symtab.c
@@ -655,6 +655,12 @@ find_symtab (program_space *pspace, const char *name,
     }
   else
     {
+      if (pspace->solib_ops ()!= nullptr
+	  && pspace->solib_ops ()->supports_namespaces ()
+	  && pspace->solib_ops ()->num_active_namespaces () > 1)
+	objfiles_to_search
+	  = get_objfiles_in_linker_namespace (get_current_linker_namespace (),
+					      pspace);
       for (objfile &objf : pspace->objfiles ())
 	objfiles_to_search.push_back (&objf);
     }
diff --git a/gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c b/gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c
index 35c5124a65e..012decc25e5 100644
--- a/gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c
+++ b/gdb/testsuite/gdb.base/dlmopen-ns-ids-main.c
@@ -52,6 +52,9 @@ main (void)
   fun = dlsym (handle[0], "func_with_other_call");
   fun (0);
 
+  fun = dlsym (handle[2], "func_with_other_call");
+  fun (0);
+
   dlclose (handle[0]); /* TAG: first dlclose */
   dlclose (handle[1]); /* TAG: second dlclose */
   dlclose (handle[2]); /* TAG: third dlclose */
diff --git a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
index 78daed4518e..9c9f97e6887 100644
--- a/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
+++ b/gdb/testsuite/gdb.base/dlmopen-ns-ids.exp
@@ -370,6 +370,15 @@ proc_with_prefix test_print_namespace_symbol {} {
     gdb_test "print ${ns2}::'${::srcfile_lib}'::gdb_dlmopen_glob + '${::srcfile}'::global_main_file" \
 	".* = 1312"
 
+    gdb_continue_to_breakpoint "change_global in namespace 2"
+    # GDB would find symtabs in load order, ignoring the current linker namespace.
+    # This test ensures that we prefer the symtabs in the namespace in the current
+    # point of execution instead.
+    gdb_test "print gdb_dlmopen_glob == '${::srcfile_lib}'::gdb_dlmopen_glob" \
+	".* = 1" "symtab prioritizes the current namespace"
+    gdb_test "print &gdb_dlmopen_glob == &'${::srcfile_lib}'::gdb_dlmopen_glob" \
+	".* = 1" "Double checking with addresses"
+
     # Leave to default namespace.
     gdb_continue_to_breakpoint "TAG: first dlclose"
     # This global doesn't exist in the default namespace.  Rather than
