diff --git a/gdb/gdbserver/linux-amd64-ipa.c b/gdb/gdbserver/linux-amd64-ipa.c
index 67f36c2..c96e93c 100644
--- a/gdb/gdbserver/linux-amd64-ipa.c
+++ b/gdb/gdbserver/linux-amd64-ipa.c
@@ -168,50 +168,6 @@ supply_static_tracepoint_registers (struct regcache *regcache,
 
 #endif /* HAVE_UST */
 
-/* Return target_desc to use for IPA, given the tdesc index passed by
-   gdbserver.  */
-
-const struct target_desc *
-get_ipa_tdesc (int idx)
-{
-#if defined __ILP32__
-  switch (idx)
-    {
-    case X86_TDESC_SSE:
-      return tdesc_x32_linux;
-    case X86_TDESC_AVX:
-      return tdesc_x32_avx_linux;
-    case X86_TDESC_AVX512:
-      return tdesc_x32_avx512_linux;
-    default:
-      break;
-    }
-#else
-  switch (idx)
-    {
-    case X86_TDESC_SSE:
-      return tdesc_amd64_linux;
-    case X86_TDESC_AVX:
-      return tdesc_amd64_avx_linux;
-    case X86_TDESC_MPX:
-      return tdesc_amd64_mpx_linux;
-    case X86_TDESC_AVX_MPX:
-      return tdesc_amd64_avx_mpx_linux;
-    case X86_TDESC_AVX_MPX_AVX512_PKU:
-      return tdesc_amd64_avx_mpx_avx512_pku_linux;
-    case X86_TDESC_AVX_AVX512:
-      return tdesc_amd64_avx_avx512_linux;
-    default:
-      internal_error (__FILE__, __LINE__,
-		      "unknown ipa tdesc index: %d", idx);
-      return tdesc_amd64_linux;
-    }
-#endif
-
-  internal_error (__FILE__, __LINE__,
-		  "unknown ipa tdesc index: %d", idx);
-}
-
 /* Allocate buffer for the jump pads.  The branch instruction has a
    reach of +/- 31-bit, and the executable is loaded at low addresses.
 
@@ -276,16 +232,4 @@ alloc_jump_pad_buffer (size_t size)
 void
 initialize_low_tracepoint (void)
 {
-#if defined __ILP32__
-  init_registers_x32_linux ();
-  init_registers_x32_avx_linux ();
-  init_registers_x32_avx512_linux ();
-#else
-  init_registers_amd64_linux ();
-  init_registers_amd64_avx_linux ();
-  init_registers_amd64_mpx_linux ();
-  init_registers_amd64_avx_mpx_linux ();
-  init_registers_amd64_avx_avx512_linux ();
-  init_registers_amd64_avx_mpx_avx512_pku_linux ();
-#endif
 }
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index 7744d3b..fceaba2 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -824,26 +824,28 @@ x86_linux_read_description (void)
 	      switch (xcr0 & X86_XSTATE_ALL_MASK)
 	        {
 		case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
-		  return tdesc_amd64_avx_mpx_avx512_pku_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_AVX_MPX_AVX512_PKU,
+					      !is_elf64);
 
 		case X86_XSTATE_AVX_AVX512_MASK:
-		  return tdesc_amd64_avx_avx512_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_AVX_AVX512,
+					      !is_elf64);
 
 		case X86_XSTATE_AVX_MPX_MASK:
-		  return tdesc_amd64_avx_mpx_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_AVX_MPX, !is_elf64);
 
 		case X86_XSTATE_MPX_MASK:
-		  return tdesc_amd64_mpx_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_MPX, !is_elf64);
 
 		case X86_XSTATE_AVX_MASK:
-		  return tdesc_amd64_avx_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_AVX, !is_elf64);
 
 		default:
-		  return tdesc_amd64_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_SSE, !is_elf64);
 		}
 	    }
 	  else
-	    return tdesc_amd64_linux;
+	    return amd64_get_ipa_tdesc (X86_TDESC_SSE, !is_elf64);
 	}
       else
 	{
@@ -853,21 +855,23 @@ x86_linux_read_description (void)
 	        {
 		case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
 		  /* No x32 MPX and PKU, fall back to avx_avx512.  */
-		  return tdesc_x32_avx_avx512_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_AVX_AVX512,
+					      !is_elf64);
 
 		case X86_XSTATE_AVX_AVX512_MASK:
-		  return tdesc_x32_avx_avx512_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_AVX_AVX512,
+					      !is_elf64);
 
 		case X86_XSTATE_MPX_MASK: /* No MPX on x32.  */
 		case X86_XSTATE_AVX_MASK:
-		  return tdesc_x32_avx_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_AVX, !is_elf64);
 
 		default:
-		  return tdesc_x32_linux;
+		  return amd64_get_ipa_tdesc (X86_TDESC_SSE, !is_elf64);
 		}
 	    }
 	  else
-	    return tdesc_x32_linux;
+	    return amd64_get_ipa_tdesc (X86_TDESC_SSE, !is_elf64);;
 	}
 #endif
     }
@@ -2897,19 +2901,7 @@ x86_get_ipa_tdesc_idx (void)
   const struct target_desc *tdesc = regcache->tdesc;
 
 #ifdef __x86_64__
-  if (tdesc == tdesc_amd64_linux || tdesc == tdesc_amd64_linux_no_xml
-      || tdesc == tdesc_x32_linux)
-    return X86_TDESC_SSE;
-  if (tdesc == tdesc_amd64_avx_linux || tdesc == tdesc_x32_avx_linux)
-    return X86_TDESC_AVX;
-  if (tdesc == tdesc_amd64_mpx_linux)
-    return X86_TDESC_MPX;
-  if (tdesc == tdesc_amd64_avx_mpx_linux)
-    return X86_TDESC_AVX_MPX;
-  if (tdesc == tdesc_amd64_avx_mpx_avx512_pku_linux || tdesc == tdesc_x32_avx_avx512_linux)
-    return X86_TDESC_AVX_MPX_AVX512_PKU;
-  if (tdesc == tdesc_amd64_avx_avx512_linux)
-    return X86_TDESC_AVX_AVX512;
+  return amd64_get_ipa_tdesc_idx (tdesc);
 #endif
 
   if (tdesc == tdesc_i386_linux_no_xml)
@@ -2969,19 +2961,9 @@ initialize_low_arch (void)
 {
   /* Initialize the Linux target descriptions.  */
 #ifdef __x86_64__
-  init_registers_amd64_linux ();
-  init_registers_amd64_avx_linux ();
-  init_registers_amd64_mpx_linux ();
-  init_registers_amd64_avx_mpx_linux ();
-  init_registers_amd64_avx_avx512_linux ();
-  init_registers_amd64_avx_mpx_avx512_pku_linux ();
-
-  init_registers_x32_linux ();
-  init_registers_x32_avx_linux ();
-  init_registers_x32_avx_avx512_linux ();
-
   tdesc_amd64_linux_no_xml = XNEW (struct target_desc);
-  copy_target_description (tdesc_amd64_linux_no_xml, tdesc_amd64_linux);
+  copy_target_description (tdesc_amd64_linux_no_xml,
+			   amd64_get_ipa_tdesc (X86_TDESC_SSE, false));
   tdesc_amd64_linux_no_xml->xmltarget = xmltarget_amd64_linux_no_xml;
 #endif
 
diff --git a/gdb/gdbserver/linux-x86-tdesc-selftest.c b/gdb/gdbserver/linux-x86-tdesc-selftest.c
index 31f5240..2b61d86 100644
--- a/gdb/gdbserver/linux-x86-tdesc-selftest.c
+++ b/gdb/gdbserver/linux-x86-tdesc-selftest.c
@@ -48,6 +48,46 @@ extern const struct target_desc *tdesc_i386_avx_mpx_avx512_pku_linux;
 void init_registers_i386_mpx_linux (void);
 extern const struct target_desc *tdesc_i386_mpx_linux;
 
+#ifdef __x86_64__
+
+/* Defined in auto-generated file amd64-linux.c.  */
+void init_registers_amd64_linux (void);
+extern const struct target_desc *tdesc_amd64_linux;
+
+/* Defined in auto-generated file amd64-avx-linux.c.  */
+void init_registers_amd64_avx_linux (void);
+extern const struct target_desc *tdesc_amd64_avx_linux;
+
+/* Defined in auto-generated file amd64-avx-avx512-linux.c.  */
+void init_registers_amd64_avx_avx512_linux (void);
+extern const struct target_desc *tdesc_amd64_avx_avx512_linux;
+
+/* Defined in auto-generated file amd64-avx-mpx-avx512-pku-linux.c.  */
+void init_registers_amd64_avx_mpx_avx512_pku_linux (void);
+extern const struct target_desc *tdesc_amd64_avx_mpx_avx512_pku_linux;
+
+/* Defined in auto-generated file amd64-avx-mpx-linux.c.  */
+void init_registers_amd64_avx_mpx_linux (void);
+extern const struct target_desc *tdesc_amd64_avx_mpx_linux;
+
+/* Defined in auto-generated file amd64-mpx-linux.c.  */
+void init_registers_amd64_mpx_linux (void);
+extern const struct target_desc *tdesc_amd64_mpx_linux;
+
+/* Defined in auto-generated file x32-linux.c.  */
+void init_registers_x32_linux (void);
+extern const struct target_desc *tdesc_x32_linux;
+
+/* Defined in auto-generated file x32-avx-linux.c.  */
+void init_registers_x32_avx_linux (void);
+extern const struct target_desc *tdesc_x32_avx_linux;
+
+/* Defined in auto-generated file x32-avx-avx512-linux.c.  */
+void init_registers_x32_avx_avx512_linux (void);
+extern const struct target_desc *tdesc_x32_avx_avx512_linux;
+
+#endif
+
 namespace selftests {
 namespace gdbserver {
 static void
@@ -82,6 +122,51 @@ i386_tdesc_test ()
   SELF_CHECK (*tdesc == *tdesc_i386_avx_mpx_avx512_pku_linux);
   delete tdesc;
 }
+
+#ifdef __x86_64__
+
+static void
+amd64_tdesc_test ()
+{
+  const struct target_desc *tdesc = amd64_get_ipa_tdesc (X86_TDESC_SSE, false);
+
+  SELF_CHECK (*tdesc == *tdesc_amd64_linux);
+  delete tdesc;
+
+  tdesc = amd64_get_ipa_tdesc (X86_TDESC_AVX, false);
+  SELF_CHECK (*tdesc == *tdesc_amd64_avx_linux);
+  delete tdesc;
+
+  tdesc = amd64_get_ipa_tdesc (X86_TDESC_AVX_AVX512, false);
+  SELF_CHECK (*tdesc == *tdesc_amd64_avx_avx512_linux);
+  delete tdesc;
+
+  tdesc = amd64_get_ipa_tdesc (X86_TDESC_MPX, false);
+  SELF_CHECK (*tdesc == *tdesc_amd64_mpx_linux);
+  delete tdesc;
+
+  tdesc = amd64_get_ipa_tdesc (X86_TDESC_AVX_MPX, false);
+  SELF_CHECK (*tdesc == *tdesc_amd64_avx_mpx_linux);
+  delete tdesc;
+
+  tdesc = amd64_get_ipa_tdesc (X86_TDESC_AVX_MPX_AVX512_PKU, false);
+  SELF_CHECK (*tdesc == *tdesc_amd64_avx_mpx_avx512_pku_linux);
+  delete tdesc;
+
+  tdesc = amd64_get_ipa_tdesc (X86_TDESC_SSE, true);
+  SELF_CHECK (*tdesc == *tdesc_x32_linux);
+  delete tdesc;
+
+  tdesc = amd64_get_ipa_tdesc (X86_TDESC_AVX, true);
+  SELF_CHECK (*tdesc == *tdesc_x32_avx_linux);
+  delete tdesc;
+
+  tdesc = amd64_get_ipa_tdesc (X86_TDESC_AVX_AVX512, true);
+  SELF_CHECK (*tdesc == *tdesc_x32_avx_avx512_linux);
+  delete tdesc;
+}
+
+#endif
 }
 } // namespace selftests
 
@@ -97,4 +182,19 @@ initialize_low_tdesc ()
   init_registers_i386_avx_mpx_avx512_pku_linux ();
 
   register_self_test (selftests::gdbserver::i386_tdesc_test);
+
+#ifdef __x86_64__
+  init_registers_x32_linux ();
+  init_registers_x32_avx_linux ();
+  init_registers_x32_avx_avx512_linux ();
+
+  init_registers_amd64_linux ();
+  init_registers_amd64_avx_linux ();
+  init_registers_amd64_mpx_linux ();
+  init_registers_amd64_avx_mpx_linux ();
+  init_registers_amd64_avx_avx512_linux ();
+  init_registers_amd64_avx_mpx_avx512_pku_linux ();
+
+  register_self_test (selftests::gdbserver::amd64_tdesc_test);
+#endif
 }
diff --git a/gdb/gdbserver/linux-x86-tdesc.c b/gdb/gdbserver/linux-x86-tdesc.c
index 2e4079a..44faf5d 100644
--- a/gdb/gdbserver/linux-x86-tdesc.c
+++ b/gdb/gdbserver/linux-x86-tdesc.c
@@ -29,6 +29,19 @@
 #include "../features/i386/32bit-mpx.c"
 #include "../features/i386/32bit-pkeys.c"
 
+#ifdef __x86_64__
+#include "../features/i386/64bit-avx.c"
+#include "../features/i386/64bit-avx512.c"
+#include "../features/i386/64bit-core.c"
+#include "../features/i386/64bit-linux.c"
+#include "../features/i386/64bit-mpx.c"
+#include "../features/i386/64bit-pkeys.c"
+#include "../features/i386/64bit-segments.c"
+#include "../features/i386/64bit-sse.c"
+
+#include "../features/i386/x32-core.c"
+#endif
+
 static const struct target_desc *i386_tdescs[X86_TDESC_LAST] = { };
 
 const struct target_desc *
@@ -84,15 +97,91 @@ i386_get_ipa_tdesc (int idx)
   return *tdesc;;
 }
 
+#ifdef __x86_64__
+
+static const struct target_desc *amd64_tdescs[X86_TDESC_LAST] = { };
+static const struct target_desc *x32_tdescs[X86_TDESC_LAST] = { };
+
+const struct target_desc *
+amd64_get_ipa_tdesc (int idx, bool is_x32)
+{
+  if (idx >= X86_TDESC_LAST)
+    internal_error (__FILE__, __LINE__, "unknown ipa tdesc index: %d", idx);
+
+  struct target_desc **tdesc;
+
+  if (is_x32 && idx != X86_TDESC_SSE && idx != X86_TDESC_AVX
+      && idx != X86_TDESC_AVX_AVX512)
+    internal_error (__FILE__, __LINE__, "unknown ipa tdesc index: %d", idx);
+
+  if (is_x32)
+    tdesc = (struct target_desc **) &x32_tdescs[idx];
+  else
+    tdesc = (struct target_desc **) &amd64_tdescs[idx];
+
+  if (*tdesc == NULL)
+    {
+      *tdesc = new target_desc ();
+
+#ifndef IN_PROCESS_AGENT
+      set_tdesc_architecture (*tdesc, is_x32 ? "i386:x64-32" : "i386:x86-64");
+      set_tdesc_osabi (*tdesc, "GNU/Linux");
+#endif
+
+      long regnum = 0;
+
+      if (is_x32)
+	regnum = create_feature_i386_x32_core (*tdesc, regnum);
+      else
+	regnum = create_feature_i386_64bit_core (*tdesc, regnum);
+
+      regnum = create_feature_i386_64bit_sse (*tdesc, regnum);
+      regnum = create_feature_i386_64bit_linux (*tdesc, regnum);
+      regnum = create_feature_i386_64bit_segments (*tdesc, regnum);
+
+      if (idx == X86_TDESC_AVX || idx == X86_TDESC_AVX_MPX
+	  || idx == X86_TDESC_AVX_AVX512
+	  || idx == X86_TDESC_AVX_MPX_AVX512_PKU)
+	regnum = create_feature_i386_64bit_avx (*tdesc, regnum);
+
+      if (idx == X86_TDESC_MPX || idx == X86_TDESC_AVX_MPX
+	  || idx == X86_TDESC_AVX_MPX_AVX512_PKU)
+	regnum = create_feature_i386_64bit_mpx (*tdesc, regnum);
+
+      if (idx == X86_TDESC_AVX_AVX512
+	  || idx == X86_TDESC_AVX_MPX_AVX512_PKU)
+	regnum = create_feature_i386_64bit_avx512 (*tdesc, regnum);
+
+      if (idx == X86_TDESC_AVX_MPX_AVX512_PKU)
+	regnum = create_feature_i386_64bit_pkeys (*tdesc, regnum);
+
+      init_target_desc (*tdesc);
+
+#ifndef IN_PROCESS_AGENT
+      static const char *expedite_regs_amd64[] = { "rbp", "rsp", "rip", NULL };
+      (*tdesc)->expedite_regs = expedite_regs_amd64;
+#endif
+    }
+  return *tdesc;;
+}
+
+#endif
+
 #ifdef IN_PROCESS_AGENT
 
-#if defined __i386__
 const struct target_desc *
 get_ipa_tdesc (int idx)
 {
-return i386_get_ipa_tdesc (idx);
-}
+#if defined __i386__
+  return i386_get_ipa_tdesc (idx);
+#else
+#if defined __ILP32__
+  return amd64_get_ipa_tdesc (idx, true);
+#else
+  return amd64_get_ipa_tdesc (idx, false);
+#endif
 #endif
+}
 
 #else
 int
@@ -107,4 +196,23 @@ i386_get_ipa_tdesc_idx (const struct target_desc *tdesc)
   return 0;
 }
 
+#if defined __x86_64__
+int
+amd64_get_ipa_tdesc_idx (const struct target_desc *tdesc)
+{
+  for (int i = 0; i < X86_TDESC_LAST; i++)
+    {
+      if (tdesc == amd64_tdescs[i])
+	return i;
+    }
+  for (int i = 0; i < X86_TDESC_LAST; i++)
+    {
+      if (tdesc == x32_tdescs[i])
+	return i;
+    }
+
+  return 0;
+}
+
+#endif
 #endif
diff --git a/gdb/gdbserver/linux-x86-tdesc.h b/gdb/gdbserver/linux-x86-tdesc.h
index 894cf4e..2636efc 100644
--- a/gdb/gdbserver/linux-x86-tdesc.h
+++ b/gdb/gdbserver/linux-x86-tdesc.h
@@ -33,54 +33,18 @@ enum x86_linux_tdesc {
   X86_TDESC_LAST = 7,
 };
 
-#ifdef __x86_64__
-
-#if defined __LP64__  || !defined IN_PROCESS_AGENT
-/* Defined in auto-generated file amd64-linux.c.  */
-void init_registers_amd64_linux (void);
-extern const struct target_desc *tdesc_amd64_linux;
-
-/* Defined in auto-generated file amd64-avx-linux.c.  */
-void init_registers_amd64_avx_linux (void);
-extern const struct target_desc *tdesc_amd64_avx_linux;
-
-/* Defined in auto-generated file amd64-avx-avx512-linux.c.  */
-void init_registers_amd64_avx_avx512_linux (void);
-extern const struct target_desc *tdesc_amd64_avx_avx512_linux;
-
-/* Defined in auto-generated file amd64-avx-mpx-avx512-pku-linux.c.  */
-void init_registers_amd64_avx_mpx_avx512_pku_linux (void);
-extern const struct target_desc *tdesc_amd64_avx_mpx_avx512_pku_linux;
-
-/* Defined in auto-generated file amd64-avx-mpx-linux.c.  */
-void init_registers_amd64_avx_mpx_linux (void);
-extern const struct target_desc *tdesc_amd64_avx_mpx_linux;
-
-/* Defined in auto-generated file amd64-mpx-linux.c.  */
-void init_registers_amd64_mpx_linux (void);
-extern const struct target_desc *tdesc_amd64_mpx_linux;
+#if defined __i386__ || !defined IN_PROCESS_AGENT
+int i386_get_ipa_tdesc_idx (const struct target_desc *tdesc);
 #endif
 
-#if defined __ILP32__ || !defined IN_PROCESS_AGENT
-/* Defined in auto-generated file x32-linux.c.  */
-void init_registers_x32_linux (void);
-extern const struct target_desc *tdesc_x32_linux;
-
-/* Defined in auto-generated file x32-avx-linux.c.  */
-void init_registers_x32_avx_linux (void);
-extern const struct target_desc *tdesc_x32_avx_linux;
-
-/* Defined in auto-generated file x32-avx-avx512-linux.c.  */
-void init_registers_x32_avx_avx512_linux (void);
-extern const struct target_desc *tdesc_x32_avx_avx512_linux;
+#if defined __x86_64__ && !defined IN_PROCESS_AGENT
+int amd64_get_ipa_tdesc_idx (const struct target_desc *tdesc);
 #endif
 
-#endif
+const struct target_desc *i386_get_ipa_tdesc (int idx);
 
-#if defined __i386__ || !defined IN_PROCESS_AGENT
-int i386_get_ipa_tdesc_idx (const struct target_desc *tdesc);
+#ifdef __x86_64__
+const struct target_desc *amd64_get_ipa_tdesc (int idx, bool is_x32);
 #endif
 
-const struct target_desc *i386_get_ipa_tdesc (int idx);
-
 void initialize_low_tdesc ();
