diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 9d07ac0d974..b6caa2c220b 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -812,6 +812,7 @@ LOADLIBES = @LOADLIBES@
 MH_CFLAGS = @MH_CFLAGS@
 XM_CLIBS = @XM_CLIBS@
 NAT_GENERATED_FILES = @NAT_GENERATED_FILES@
+NM_H = @NM_H@
 HAVE_NATIVE_GCORE_HOST = @HAVE_NATIVE_GCORE_HOST@
 
 # Native-target dependent makefile fragment comes in here.
@@ -1617,9 +1618,9 @@ DISTSTUFF = $(YYFILES)
 generated_files = \
 	ada-lex.c \
 	config.h \
-	gcore \
 	jit-reader.h \
-	$(NAT_GENERATED_FILES)
+	$(NAT_GENERATED_FILES) \
+	$(NM_H)
 
 # Flags needed to compile Python code
 PYTHON_CFLAGS = @PYTHON_CFLAGS@
@@ -2021,6 +2022,10 @@ config.h: stamp-h ; @true
 stamp-h: $(srcdir)/config.in config.status
 	$(SHELL) config.status config.h
 
+nm.h: stamp-nmh ; @true
+stamp-nmh: config.status
+	$(SHELL) config.status nm.h
+
 config.status: $(srcdir)/configure configure.nat configure.tgt configure.host ../bfd/development.sh
 	$(SHELL) config.status --recheck
 
diff --git a/gdb/configure b/gdb/configure
index 70ce52fa1e8..737b426058c 100755
--- a/gdb/configure
+++ b/gdb/configure
@@ -626,6 +626,7 @@ LIBOBJS
 GCORE_TRANSFORM_NAME
 GDB_TRANSFORM_NAME
 XSLTPROC
+NM_H
 GDB_NM_FILE
 LTLIBBABELTRACE
 LIBBABELTRACE
@@ -17556,28 +17557,25 @@ $as_echo "$as_me: WARNING: babeltrace is missing or unusable; GDB is unable to r
   fi
 fi
 
-# If nativefile (NAT_FILE) is not set in configure.nat, we link to an
-# empty version.
-
-files=
-links=
-
+NM_H=
 rm -f nm.h
 if test "${nativefile}" != ""; then
     case "${nativefile}" in
       nm-*.h ) GDB_NM_FILE="config/${gdb_host_cpu}/${nativefile}" ;;
       * ) GDB_NM_FILE="${nativefile}"
     esac
-    files="${files} ${GDB_NM_FILE}"
-    links="${links} nm.h"
+    ac_config_links="$ac_config_links nm.h:$GDB_NM_FILE"
+
 
 cat >>confdefs.h <<_ACEOF
 #define GDB_NM_FILE "${GDB_NM_FILE}"
 _ACEOF
 
+    NM_H=nm.h
 fi
 
 
+
 for ac_prog in xsltproc
 do
   # Extract the first word of "$ac_prog", so it can be a program name with args.
@@ -17631,16 +17629,6 @@ if test "x$USE_MAINTAINER_MODE" = xyes; then
 fi
 
 
-ac_sources="$files"
-ac_dests="$links"
-while test -n "$ac_sources"; do
-  set $ac_dests; ac_dest=$1; shift; ac_dests=$*
-  set $ac_sources; ac_source=$1; shift; ac_sources=$*
-  ac_config_links_1="$ac_config_links_1 $ac_dest:$ac_source"
-done
-ac_config_links="$ac_config_links $ac_config_links_1"
-
-
 
 
 
@@ -18406,6 +18394,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
 # INIT-COMMANDS
 #
 ac_aux_dir=$ac_aux_dir DEPDIR=$DEPDIR
+GDB_NM_FILE=$GDB_NM_FILE
 
 _ACEOF
 
@@ -18418,7 +18407,7 @@ do
     "config.h") CONFIG_HEADERS="$CONFIG_HEADERS config.h:config.in" ;;
     "depdir") CONFIG_COMMANDS="$CONFIG_COMMANDS depdir" ;;
     "jit-reader.h") CONFIG_FILES="$CONFIG_FILES jit-reader.h:jit-reader.in" ;;
-    "$ac_config_links_1") CONFIG_LINKS="$CONFIG_LINKS $ac_config_links_1" ;;
+    "nm.h") CONFIG_LINKS="$CONFIG_LINKS nm.h:$GDB_NM_FILE" ;;
     "gcore") CONFIG_FILES="$CONFIG_FILES gcore" ;;
     "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
     "gdb-gdb.gdb") CONFIG_FILES="$CONFIG_FILES gdb-gdb.gdb" ;;
@@ -19053,6 +19042,7 @@ $as_echo "$as_me: executing $ac_file commands" >&6;}
   case $ac_file$ac_mode in
     "config.h":H) echo > stamp-h ;;
     "depdir":C) $SHELL $ac_aux_dir/mkinstalldirs $DEPDIR ;;
+    "nm.h":L) echo > stamp-nmh ;;
     "gcore":F) chmod +x gcore ;;
 
   esac
diff --git a/gdb/configure.ac b/gdb/configure.ac
index c4e0dbf9952..dbe01509b91 100644
--- a/gdb/configure.ac
+++ b/gdb/configure.ac
@@ -2217,23 +2217,20 @@ else
   fi
 fi
 
-# If nativefile (NAT_FILE) is not set in configure.nat, we link to an
-# empty version.
-
-files=
-links=
-
+NM_H=
 rm -f nm.h
 if test "${nativefile}" != ""; then
     case "${nativefile}" in
       nm-*.h ) GDB_NM_FILE="config/${gdb_host_cpu}/${nativefile}" ;;
       * ) GDB_NM_FILE="${nativefile}"
     esac
-    files="${files} ${GDB_NM_FILE}"
-    links="${links} nm.h"
+    AC_CONFIG_LINKS([nm.h:$GDB_NM_FILE], [echo > stamp-nmh],
+                    [GDB_NM_FILE=$GDB_NM_FILE])
     AC_DEFINE_UNQUOTED(GDB_NM_FILE, "${GDB_NM_FILE}", [nativefile])
+    NM_H=nm.h
 fi
 AC_SUBST(GDB_NM_FILE)
+AC_SUBST(NM_H)
 
 dnl Add dependency for xsltproc if building with maintainer-mode enabled.
 AC_PATH_PROGS(XSLTPROC, xsltproc, missing)
@@ -2244,8 +2241,6 @@ if test "x$USE_MAINTAINER_MODE" = xyes; then
 fi
 AC_SUBST(XSLTPROC)
 
-AC_LINK_FILES($files, $links)
-
 dnl Check for exe extension set on certain hosts (e.g. Win32)
 AC_EXEEXT
 
