[1/8,PowerPC] Consolidate linux target description selection

Message ID 87wow3uynr.fsf@linux.vnet.ibm.com
State New, archived
Headers

Commit Message

pedromfc May 16, 2018, 8:35 p.m. UTC
  Ulrich Weigand <uweigand@de.ibm.com> writes:

>> +/* Base value for ppc_linux_features variables.  */
>> +const struct ppc_linux_features ppc_linux_no_features = {
>> +  4,
>> +  false,
>> +  false,
>> +  false,
>> +  false,
>> +};
>
> I'm not sure it makes much sense to declare "4" the default wordsize
> -- there's not really a default between 4 and 8.  Maybe it would be
> clearer to just force all users to explicitly set the wordsize.

Is something like this a good style, or should I just initialize
wordsize to 0 and let the previous assert in ppc_match_description
ensure that the wordsize is either 4 or 8?

+/* Features used to determine the target description.  */
+class ppc_linux_features
+{
+public:
+  ppc_linux_features (int _wordsize)
+    : wordsize (_wordsize), altivec (false), vsx (false),
+      isa205 (false), cell (false)
+  {
+    gdb_assert (wordsize == 4 || wordsize == 8);
+  }
+
+  unsigned int wordsize;
+  bool altivec;
+  bool vsx;
+  bool isa205;
+  bool cell;
+};

I still have to rebase the other patches on this.

-- >8 --
Subject: [PATCH] [PowerPC] Consolidate linux target description selection

Share target description declarations and selection among ppc linux
native targets, core files, gdbserver and IPA.

To avoid complicated define guards, gdbserver and IPA now have
declarations for all descriptions, including 64-bit generated
descriptions when compiled in 32-bit mode. These have always been
linked into the gdbserver and IPA binaries. Because they might be
uninitialized, the selection function checks that the selected
description is initialized.

gdb/ChangeLog:
yyyy-mm-dd  Pedro Franco de Carvalho  <pedromfc@linux.vnet.ibm.com>

	* arch/ppc-linux-common.c: New file.
	* arch/ppc-linux-common.h: New file.
	* arch/ppc-linux-tdesc.h: New file.
	* configure.tgt (powerpc*-*-linux*): Add arch/ppc-linux-common.o.
	* Makefile.in (ALL_TARGET_OBS): Add arch/ppc-linux-common.o.
	(HFILES_NO_SRCDIR): Add arch/ppc-linux-common.h and
	arch/ppc-linux-tdesc.h.
	* ppc-linux-nat.c: Include arch/ppc-linux-common.h and
	arch/ppc-linux-tdesc.h.
	(ppc_linux_nat_target::read_description): Remove target
	description matching code. Fill a ppc_linux_features struct and
	call ppc_linux_match_description with it. Move comment about ISA
	2.05 to ppc-linux-common.c.
	* ppc-linux-tdep.c: Include arch/ppc-linux-common.h and
	arch/ppc-linux-tdesc.h.
	(ppc_linux_core_read_description): Remove target description
	matching code. Fill a ppc_linux_features struct and call
	ppc_linux_match_description with it.
	* ppc-linux-tdep.h (tdesc_powerpc_32l, tdesc_powerpc_64l)
	(tdesc_powerpc_altivec32l, tdesc_powerpc_altivec64l)
	(tdesc_powerpc_cell32l, tdesc_powerpc_cell64l)
	(tdesc_powerpc_vsx32l, tdesc_powerpc_vsx64l)
	(tdesc_powerpc_isa205_32l, tdesc_powerpc_isa205_64l)
	(tdesc_powerpc_isa205_altivec32l, tdesc_powerpc_isa205_altivec64l)
	(tdesc_powerpc_isa205_vsx32l, tdesc_powerpc_isa205_vsx64l)
	(tdesc_powerpc_e500l): Remove.

gdb/gdbserver/ChangeLog:
yyyy-mm-dd  Pedro Franco de Carvalho  <pedromfc@linux.vnet.ibm.com>

	* configure.srv (srv_tgtobj): Add arch/ppc-linux-common.o.
	* Makefile.in (SFILES): Add arch/ppc-linux-common.c.
	* linux-ppc-tdesc.h: Rename to linux-ppc-tdesc-init.h.
	* linux-ppc-tdesc-init.h (tdesc_powerpc_32l, tdesc_powerpc_64l)
	(tdesc_powerpc_altivec32l, tdesc_powerpc_altivec64l)
	(tdesc_powerpc_cell32l, tdesc_powerpc_cell64l)
	(tdesc_powerpc_vsx32l, tdesc_powerpc_vsx64l)
	(tdesc_powerpc_isa205_32l, tdesc_powerpc_isa205_64l)
	(tdesc_powerpc_isa205_altivec32l, tdesc_powerpc_isa205_altivec64l)
	(tdesc_powerpc_isa205_vsx32l, tdesc_powerpc_isa205_vsx64l)
	(tdesc_powerpc_e500l): Remove.
	* linux-ppc-ipa.c: Include arch/ppc-linux-tdesc.h and
	linux-ppc-tdesc-init.h. Don't include linux-ppc-tdesc.h.
	* linux-ppc-low.c: Include arch/ppc-linux-common.h,
	arch/ppc-linux-tdesc.h, and linux-ppc-tdesc-init.h. Don't include
	linux-ppc-tdesc.h.
	(ppc_arch_setup): Remove target description matching code. Fill a
	ppc_linux_features struct and call ppc_linux_match_description
	with it.
---
 gdb/Makefile.in                                    |  3 +
 gdb/arch/ppc-linux-common.c                        | 84 ++++++++++++++++++++++
 gdb/arch/ppc-linux-common.h                        | 50 +++++++++++++
 gdb/arch/ppc-linux-tdesc.h                         | 42 +++++++++++
 gdb/configure.tgt                                  |  3 +-
 gdb/gdbserver/Makefile.in                          |  1 +
 gdb/gdbserver/configure.srv                        |  1 +
 gdb/gdbserver/linux-ppc-ipa.c                      |  3 +-
 gdb/gdbserver/linux-ppc-low.c                      | 75 ++++++++-----------
 .../{linux-ppc-tdesc.h => linux-ppc-tdesc-init.h}  | 15 ----
 gdb/ppc-linux-nat.c                                | 54 ++++----------
 gdb/ppc-linux-tdep.c                               | 39 +++++-----
 gdb/ppc-linux-tdep.h                               | 17 -----
 13 files changed, 249 insertions(+), 138 deletions(-)
 create mode 100644 gdb/arch/ppc-linux-common.c
 create mode 100644 gdb/arch/ppc-linux-common.h
 create mode 100644 gdb/arch/ppc-linux-tdesc.h
 rename gdb/gdbserver/{linux-ppc-tdesc.h => linux-ppc-tdesc-init.h} (76%)
  

Patch

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 87d74a7703..8109c0c6ba 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -678,6 +678,7 @@  ALL_TARGET_OBS = \
 	arch/arm-get-next-pcs.o \
 	arch/arm-linux.o \
 	arch/i386.o \
+	arch/ppc-linux-common.o \
 	arm-bsd-tdep.o \
 	arm-fbsd-tdep.o \
 	arm-linux-tdep.o \
@@ -1411,6 +1412,8 @@  HFILES_NO_SRCDIR = \
 	arch/aarch64-insn.h \
 	arch/arm.h \
 	arch/i386.h \
+	arch/ppc-linux-common.h \
+	arch/ppc-linux-tdesc.h \
 	cli/cli-cmds.h \
 	cli/cli-decode.h \
 	cli/cli-script.h \
diff --git a/gdb/arch/ppc-linux-common.c b/gdb/arch/ppc-linux-common.c
new file mode 100644
index 0000000000..d7a61f7dfa
--- /dev/null
+++ b/gdb/arch/ppc-linux-common.c
@@ -0,0 +1,84 @@ 
+/* Common target dependent code for GNU/Linux on PPC systems.
+
+   Copyright (C) 2018 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   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/>.  */
+
+#include "common-defs.h"
+#include "arch/ppc-linux-common.h"
+#include "arch/ppc-linux-tdesc.h"
+
+/* Decimal Floating Point bit in AT_HWCAP.
+
+   This file can be used by a host with another architecture, e.g.
+   when debugging core files, which might not provide this constant.  */
+
+#ifndef PPC_FEATURE_HAS_DFP
+#define PPC_FEATURE_HAS_DFP	0x00000400
+#endif
+
+bool
+ppc_linux_has_isa205 (unsigned long hwcap)
+{
+  /* Power ISA 2.05 (implemented by Power 6 and newer processors)
+     increases the FPSCR from 32 bits to 64 bits.  Even though Power 7
+     supports this ISA version, it doesn't have PPC_FEATURE_ARCH_2_05
+     set, only PPC_FEATURE_ARCH_2_06.  Since for now the only bits
+     used in the higher half of the register are for Decimal Floating
+     Point, we check if that feature is available to decide the size
+     of the FPSCR.  */
+  return ((hwcap & PPC_FEATURE_HAS_DFP) != 0);
+}
+
+const struct target_desc *
+ppc_linux_match_description(struct ppc_linux_features features)
+{
+  struct target_desc *tdesc = NULL;
+
+  if (features.wordsize == 8)
+    {
+      if (features.cell)
+	tdesc = tdesc_powerpc_cell64l;
+      else if (features.vsx)
+	tdesc = features.isa205
+	  ? tdesc_powerpc_isa205_vsx64l : tdesc_powerpc_vsx64l;
+      else if (features.altivec)
+	tdesc = features.isa205
+	  ? tdesc_powerpc_isa205_altivec64l : tdesc_powerpc_altivec64l;
+      else
+	tdesc = features.isa205?
+	  tdesc_powerpc_isa205_64l : tdesc_powerpc_64l;
+    }
+  else
+    {
+      if (features.cell)
+	tdesc = tdesc_powerpc_cell32l;
+      else if (features.vsx)
+	tdesc = features.isa205
+	  ? tdesc_powerpc_isa205_vsx32l : tdesc_powerpc_vsx32l;
+      else if (features.altivec)
+	tdesc = features.isa205
+	  ? tdesc_powerpc_isa205_altivec32l : tdesc_powerpc_altivec32l;
+      else
+	tdesc = features.isa205
+	  ? tdesc_powerpc_isa205_32l : tdesc_powerpc_32l;
+    }
+
+  /* Make sure that the selected tdesc was initialized.  */
+  gdb_assert (tdesc != NULL);
+
+  return tdesc;
+}
diff --git a/gdb/arch/ppc-linux-common.h b/gdb/arch/ppc-linux-common.h
new file mode 100644
index 0000000000..8aa6d40703
--- /dev/null
+++ b/gdb/arch/ppc-linux-common.h
@@ -0,0 +1,50 @@ 
+/* Common target dependent code for GNU/Linux on PPC systems.
+
+   Copyright (C) 2018 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   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/>.  */
+
+#ifndef ARCH_PPC_LINUX_COMMON_H
+#define ARCH_PPC_LINUX_COMMON_H
+
+struct target_desc;
+
+/* Check if the hwcap auxv entry indicates that isa205 is supported.  */
+bool ppc_linux_has_isa205 (unsigned long hwcap);
+
+/* Features used to determine the target description.  */
+class ppc_linux_features
+{
+public:
+  ppc_linux_features (int _wordsize)
+    : wordsize (_wordsize), altivec (false), vsx (false),
+      isa205 (false), cell (false)
+  {
+    gdb_assert (wordsize == 4 || wordsize == 8);
+  }
+
+  unsigned int wordsize;
+  bool altivec;
+  bool vsx;
+  bool isa205;
+  bool cell;
+};
+
+/* Return a target description that matches FEATURES.  */
+const struct target_desc * ppc_linux_match_description
+(struct ppc_linux_features features);
+
+#endif /* ARCH_PPC_LINUX_COMMON_H */
diff --git a/gdb/arch/ppc-linux-tdesc.h b/gdb/arch/ppc-linux-tdesc.h
new file mode 100644
index 0000000000..594c7c7c7c
--- /dev/null
+++ b/gdb/arch/ppc-linux-tdesc.h
@@ -0,0 +1,42 @@ 
+/* Target description declarations shared between gdb, gdbserver and IPA.
+
+   Copyright (C) 2018 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   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/>.  */
+
+#ifndef ARCH_PPC_LINUX_TDESC_H
+#define ARCH_PPC_LINUX_TDESC_H
+
+struct target_desc;
+
+extern struct target_desc *tdesc_powerpc_32l;
+extern struct target_desc *tdesc_powerpc_altivec32l;
+extern struct target_desc *tdesc_powerpc_cell32l;
+extern struct target_desc *tdesc_powerpc_vsx32l;
+extern struct target_desc *tdesc_powerpc_isa205_32l;
+extern struct target_desc *tdesc_powerpc_isa205_altivec32l;
+extern struct target_desc *tdesc_powerpc_isa205_vsx32l;
+extern struct target_desc *tdesc_powerpc_e500l;
+
+extern struct target_desc *tdesc_powerpc_64l;
+extern struct target_desc *tdesc_powerpc_altivec64l;
+extern struct target_desc *tdesc_powerpc_cell64l;
+extern struct target_desc *tdesc_powerpc_vsx64l;
+extern struct target_desc *tdesc_powerpc_isa205_64l;
+extern struct target_desc *tdesc_powerpc_isa205_altivec64l;
+extern struct target_desc *tdesc_powerpc_isa205_vsx64l;
+
+#endif /* ARCH_PPC_LINUX_TDESC_H */
diff --git a/gdb/configure.tgt b/gdb/configure.tgt
index e9a2704ebc..b4bc770617 100644
--- a/gdb/configure.tgt
+++ b/gdb/configure.tgt
@@ -492,7 +492,8 @@  powerpc*-*-linux*)
 			spu-multiarch.o \
 			glibc-tdep.o symfile-mem.o linux-tdep.o \
 			ravenscar-thread.o ppc-ravenscar-thread.o \
-			linux-record.o "
+			linux-record.o \
+			arch/ppc-linux-common.o"
 	gdb_sim=../sim/ppc/libsim.a
 	build_gdbserver=yes
 	;;
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index c377378809..675faa4364 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -196,6 +196,7 @@  SFILES = \
 	$(srcdir)/arch/arm.c \
 	$(srcdir)/arch/arm-get-next-pcs.c \
 	$(srcdir)/arch/arm-linux.c \
+	$(srcdir)/arch/ppc-linux-common.c \
 	$(srcdir)/common/btrace-common.c \
 	$(srcdir)/common/buffer.c \
 	$(srcdir)/common/cleanups.c \
diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
index ffeefb9b92..7153ff339d 100644
--- a/gdb/gdbserver/configure.srv
+++ b/gdb/gdbserver/configure.srv
@@ -225,6 +225,7 @@  case "${target}" in
 			srv_regobj="${srv_regobj} powerpc-isa205-altivec64l.o"
 			srv_regobj="${srv_regobj} powerpc-isa205-vsx64l.o"
 			srv_tgtobj="$srv_linux_obj linux-ppc-low.o ppc-linux.o"
+			srv_tgtobj="${srv_tgtobj} arch/ppc-linux-common.o"
 			srv_xmlfiles="rs6000/powerpc-32l.xml"
 			srv_xmlfiles="${srv_xmlfiles} rs6000/powerpc-altivec32l.xml"
 			srv_xmlfiles="${srv_xmlfiles} rs6000/powerpc-cell32l.xml"
diff --git a/gdb/gdbserver/linux-ppc-ipa.c b/gdb/gdbserver/linux-ppc-ipa.c
index c993e76315..f6861f0d98 100644
--- a/gdb/gdbserver/linux-ppc-ipa.c
+++ b/gdb/gdbserver/linux-ppc-ipa.c
@@ -21,7 +21,8 @@ 
 #include "server.h"
 #include <sys/mman.h>
 #include "tracepoint.h"
-#include "linux-ppc-tdesc.h"
+#include "arch/ppc-linux-tdesc.h"
+#include "linux-ppc-tdesc-init.h"
 #include <elf.h>
 #ifdef HAVE_GETAUXVAL
 #include <sys/auxv.h>
diff --git a/gdb/gdbserver/linux-ppc-low.c b/gdb/gdbserver/linux-ppc-low.c
index 36bd373c88..f337ee3d09 100644
--- a/gdb/gdbserver/linux-ppc-low.c
+++ b/gdb/gdbserver/linux-ppc-low.c
@@ -23,8 +23,10 @@ 
 #include <elf.h>
 #include <asm/ptrace.h>
 
+#include "arch/ppc-linux-common.h"
+#include "arch/ppc-linux-tdesc.h"
 #include "nat/ppc-linux.h"
-#include "linux-ppc-tdesc.h"
+#include "linux-ppc-tdesc-init.h"
 #include "ax.h"
 #include "tracepoint.h"
 
@@ -617,6 +619,8 @@  static void
 ppc_arch_setup (void)
 {
   const struct target_desc *tdesc;
+  int wordsize = 4;
+
 #ifdef __powerpc64__
   long msr;
   struct regcache *regcache;
@@ -634,58 +638,36 @@  ppc_arch_setup (void)
   free_register_cache (regcache);
   if (ppc64_64bit_inferior_p (msr))
     {
-      ppc_get_auxv (AT_HWCAP, &ppc_hwcap);
-      if (ppc_hwcap & PPC_FEATURE_CELL)
-	tdesc = tdesc_powerpc_cell64l;
-      else if (ppc_hwcap & PPC_FEATURE_HAS_VSX)
-	{
-	  /* Power ISA 2.05 (implemented by Power 6 and newer processors)
-	     increases the FPSCR from 32 bits to 64 bits. Even though Power 7
-	     supports this ISA version, it doesn't have PPC_FEATURE_ARCH_2_05
-	     set, only PPC_FEATURE_ARCH_2_06.  Since for now the only bits
-	     used in the higher half of the register are for Decimal Floating
-	     Point, we check if that feature is available to decide the size
-	     of the FPSCR.  */
-	  if (ppc_hwcap & PPC_FEATURE_HAS_DFP)
-	    tdesc = tdesc_powerpc_isa205_vsx64l;
-	  else
-	    tdesc = tdesc_powerpc_vsx64l;
-	}
-      else if (ppc_hwcap & PPC_FEATURE_HAS_ALTIVEC)
-	{
-	  if (ppc_hwcap & PPC_FEATURE_HAS_DFP)
-	    tdesc = tdesc_powerpc_isa205_altivec64l;
-	  else
-	    tdesc = tdesc_powerpc_altivec64l;
-	}
-
-      current_process ()->tdesc = tdesc;
-      return;
+      wordsize = 8;
     }
 #endif
 
-  /* OK, we have a 32-bit inferior.  */
-  tdesc = tdesc_powerpc_32l;
-  current_process ()->tdesc = tdesc;
+  ppc_linux_features features (wordsize);
 
-  ppc_get_auxv (AT_HWCAP, &ppc_hwcap);
-  if (ppc_hwcap & PPC_FEATURE_CELL)
-    tdesc = tdesc_powerpc_cell32l;
-  else if (ppc_hwcap & PPC_FEATURE_HAS_VSX)
+  if (features.wordsize == 4)
     {
-      if (ppc_hwcap & PPC_FEATURE_HAS_DFP)
-	tdesc = tdesc_powerpc_isa205_vsx32l;
-      else
-	tdesc = tdesc_powerpc_vsx32l;
-    }
-  else if (ppc_hwcap & PPC_FEATURE_HAS_ALTIVEC)
-    {
-      if (ppc_hwcap & PPC_FEATURE_HAS_DFP)
-	tdesc = tdesc_powerpc_isa205_altivec32l;
-      else
-	tdesc = tdesc_powerpc_altivec32l;
+      /* OK, we have a 32-bit inferior.  */
+      tdesc = tdesc_powerpc_32l;
+      current_process ()->tdesc = tdesc;
     }
 
+  /* The value of current_process ()->tdesc needs to be set for this
+     call.  */
+  ppc_get_auxv (AT_HWCAP, &ppc_hwcap);
+
+  features.isa205 = ppc_linux_has_isa205 (ppc_hwcap);
+
+  if (ppc_hwcap & PPC_FEATURE_HAS_VSX)
+    features.vsx = true;
+
+  if (ppc_hwcap & PPC_FEATURE_HAS_ALTIVEC)
+    features.altivec = true;
+
+  if (ppc_hwcap & PPC_FEATURE_CELL)
+    features.cell = true;
+
+  tdesc = ppc_linux_match_description (features);
+
   /* On 32-bit machines, check for SPE registers.
      Set the low target's regmap field as appropriately.  */
 #ifndef __powerpc64__
@@ -707,6 +689,7 @@  ppc_arch_setup (void)
       ppc_regmap_adjusted = 1;
    }
 #endif
+
   current_process ()->tdesc = tdesc;
 }
 
diff --git a/gdb/gdbserver/linux-ppc-tdesc.h b/gdb/gdbserver/linux-ppc-tdesc-init.h
similarity index 76%
rename from gdb/gdbserver/linux-ppc-tdesc.h
rename to gdb/gdbserver/linux-ppc-tdesc-init.h
index 4a561f5e37..422e7bd9c4 100644
--- a/gdb/gdbserver/linux-ppc-tdesc.h
+++ b/gdb/gdbserver/linux-ppc-tdesc-init.h
@@ -36,35 +36,27 @@  enum ppc_linux_tdesc {
 
 /* Defined in auto-generated file powerpc-32l.c.  */
 void init_registers_powerpc_32l (void);
-extern const struct target_desc *tdesc_powerpc_32l;
 
 /* Defined in auto-generated file powerpc-altivec32l.c.  */
 void init_registers_powerpc_altivec32l (void);
-extern const struct target_desc *tdesc_powerpc_altivec32l;
 
 /* Defined in auto-generated file powerpc-cell32l.c.  */
 void init_registers_powerpc_cell32l (void);
-extern const struct target_desc *tdesc_powerpc_cell32l;
 
 /* Defined in auto-generated file powerpc-vsx32l.c.  */
 void init_registers_powerpc_vsx32l (void);
-extern const struct target_desc *tdesc_powerpc_vsx32l;
 
 /* Defined in auto-generated file powerpc-isa205-32l.c.  */
 void init_registers_powerpc_isa205_32l (void);
-extern const struct target_desc *tdesc_powerpc_isa205_32l;
 
 /* Defined in auto-generated file powerpc-isa205-altivec32l.c.  */
 void init_registers_powerpc_isa205_altivec32l (void);
-extern const struct target_desc *tdesc_powerpc_isa205_altivec32l;
 
 /* Defined in auto-generated file powerpc-isa205-vsx32l.c.  */
 void init_registers_powerpc_isa205_vsx32l (void);
-extern const struct target_desc *tdesc_powerpc_isa205_vsx32l;
 
 /* Defined in auto-generated file powerpc-e500l.c.  */
 void init_registers_powerpc_e500l (void);
-extern const struct target_desc *tdesc_powerpc_e500l;
 
 #endif
 
@@ -72,30 +64,23 @@  extern const struct target_desc *tdesc_powerpc_e500l;
 
 /* Defined in auto-generated file powerpc-64l.c.  */
 void init_registers_powerpc_64l (void);
-extern const struct target_desc *tdesc_powerpc_64l;
 
 /* Defined in auto-generated file powerpc-altivec64l.c.  */
 void init_registers_powerpc_altivec64l (void);
-extern const struct target_desc *tdesc_powerpc_altivec64l;
 
 /* Defined in auto-generated file powerpc-cell64l.c.  */
 void init_registers_powerpc_cell64l (void);
-extern const struct target_desc *tdesc_powerpc_cell64l;
 
 /* Defined in auto-generated file powerpc-vsx64l.c.  */
 void init_registers_powerpc_vsx64l (void);
-extern const struct target_desc *tdesc_powerpc_vsx64l;
 
 /* Defined in auto-generated file powerpc-isa205-64l.c.  */
 void init_registers_powerpc_isa205_64l (void);
-extern const struct target_desc *tdesc_powerpc_isa205_64l;
 
 /* Defined in auto-generated file powerpc-isa205-altivec64l.c.  */
 void init_registers_powerpc_isa205_altivec64l (void);
-extern const struct target_desc *tdesc_powerpc_isa205_altivec64l;
 
 /* Defined in auto-generated file powerpc-isa205-vsx64l.c.  */
 void init_registers_powerpc_isa205_vsx64l (void);
-extern const struct target_desc *tdesc_powerpc_isa205_vsx64l;
 
 #endif
diff --git a/gdb/ppc-linux-nat.c b/gdb/ppc-linux-nat.c
index 1423339339..24ab8fde04 100644
--- a/gdb/ppc-linux-nat.c
+++ b/gdb/ppc-linux-nat.c
@@ -45,6 +45,8 @@ 
 #include "elf/common.h"
 #include "auxv.h"
 
+#include "arch/ppc-linux-common.h"
+#include "arch/ppc-linux-tdesc.h"
 #include "nat/ppc-linux.h"
 
 /* Similarly for the hardware watchpoint support.  These requests are used
@@ -2416,11 +2418,6 @@  ppc_linux_nat_target::auxv_parse (gdb_byte **readptr,
 const struct target_desc *
 ppc_linux_nat_target::read_description ()
 {
-  int altivec = 0;
-  int vsx = 0;
-  int isa205 = 0;
-  int cell = 0;
-
   int tid = ptid_get_lwp (inferior_ptid);
   if (tid == 0)
     tid = ptid_get_pid (inferior_ptid);
@@ -2438,13 +2435,17 @@  ppc_linux_nat_target::read_description ()
 	perror_with_name (_("Unable to fetch SPE registers"));
     }
 
+  ppc_linux_features features (ppc_linux_target_wordsize (tid));
+
+  unsigned long hwcap = ppc_linux_get_hwcap ();
+
   if (have_ptrace_getsetvsxregs
-      && (ppc_linux_get_hwcap () & PPC_FEATURE_HAS_VSX))
+      && (hwcap & PPC_FEATURE_HAS_VSX))
     {
       gdb_vsxregset_t vsxregset;
 
       if (ptrace (PTRACE_GETVSXREGS, tid, 0, &vsxregset) >= 0)
-	vsx = 1;
+	features.vsx = true;
 
       /* EIO means that the PTRACE_GETVSXREGS request isn't supported.
 	 Anything else needs to be reported.  */
@@ -2453,12 +2454,12 @@  ppc_linux_nat_target::read_description ()
     }
 
   if (have_ptrace_getvrregs
-      && (ppc_linux_get_hwcap () & PPC_FEATURE_HAS_ALTIVEC))
+      && (hwcap & PPC_FEATURE_HAS_ALTIVEC))
     {
       gdb_vrregset_t vrregset;
 
       if (ptrace (PTRACE_GETVRREGS, tid, 0, &vrregset) >= 0)
-        altivec = 1;
+        features.altivec = true;
 
       /* EIO means that the PTRACE_GETVRREGS request isn't supported.
 	 Anything else needs to be reported.  */
@@ -2466,39 +2467,12 @@  ppc_linux_nat_target::read_description ()
 	perror_with_name (_("Unable to fetch AltiVec registers"));
     }
 
-  /* Power ISA 2.05 (implemented by Power 6 and newer processors) increases
-     the FPSCR from 32 bits to 64 bits.  Even though Power 7 supports this
-     ISA version, it doesn't have PPC_FEATURE_ARCH_2_05 set, only
-     PPC_FEATURE_ARCH_2_06.  Since for now the only bits used in the higher
-     half of the register are for Decimal Floating Point, we check if that
-     feature is available to decide the size of the FPSCR.  */
-  if (ppc_linux_get_hwcap () & PPC_FEATURE_HAS_DFP)
-    isa205 = 1;
-
-  if (ppc_linux_get_hwcap () & PPC_FEATURE_CELL)
-    cell = 1;
-
-  if (ppc_linux_target_wordsize () == 8)
-    {
-      if (cell)
-	return tdesc_powerpc_cell64l;
-      else if (vsx)
-	return isa205? tdesc_powerpc_isa205_vsx64l : tdesc_powerpc_vsx64l;
-      else if (altivec)
-	return isa205
-	  ? tdesc_powerpc_isa205_altivec64l : tdesc_powerpc_altivec64l;
-
-      return isa205? tdesc_powerpc_isa205_64l : tdesc_powerpc_64l;
-    }
+  if (hwcap & PPC_FEATURE_CELL)
+    features.cell = true;
 
-  if (cell)
-    return tdesc_powerpc_cell32l;
-  else if (vsx)
-    return isa205? tdesc_powerpc_isa205_vsx32l : tdesc_powerpc_vsx32l;
-  else if (altivec)
-    return isa205? tdesc_powerpc_isa205_altivec32l : tdesc_powerpc_altivec32l;
+  features.isa205 = ppc_linux_has_isa205 (hwcap);
 
-  return isa205? tdesc_powerpc_isa205_32l : tdesc_powerpc_32l;
+  return ppc_linux_match_description (features);
 }
 
 void
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index 6d3a64c4f0..fd599fb4f5 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -37,6 +37,8 @@ 
 #include "ppc-tdep.h"
 #include "ppc64-tdep.h"
 #include "ppc-linux-tdep.h"
+#include "arch/ppc-linux-common.h"
+#include "arch/ppc-linux-tdesc.h"
 #include "glibc-tdep.h"
 #include "trad-frame.h"
 #include "frame-unwind.h"
@@ -966,38 +968,39 @@  ppc_linux_core_read_description (struct gdbarch *gdbarch,
 				 struct target_ops *target,
 				 bfd *abfd)
 {
+  int wordsize;
   asection *cell = bfd_sections_find_if (abfd, ppc_linux_spu_section, NULL);
   asection *altivec = bfd_get_section_by_name (abfd, ".reg-ppc-vmx");
   asection *vsx = bfd_get_section_by_name (abfd, ".reg-ppc-vsx");
   asection *section = bfd_get_section_by_name (abfd, ".reg");
+
   if (! section)
     return NULL;
 
   switch (bfd_section_size (abfd, section))
     {
     case 48 * 4:
-      if (cell)
-	return tdesc_powerpc_cell32l;
-      else if (vsx)
-	return tdesc_powerpc_vsx32l;
-      else if (altivec)
-	return tdesc_powerpc_altivec32l;
-      else
-	return tdesc_powerpc_32l;
-
+      wordsize = 4;
+      break;
     case 48 * 8:
-      if (cell)
-	return tdesc_powerpc_cell64l;
-      else if (vsx)
-	return tdesc_powerpc_vsx64l;
-      else if (altivec)
-	return tdesc_powerpc_altivec64l;
-      else
-	return tdesc_powerpc_64l;
-
+      wordsize = 8;
+      break;
     default:
       return NULL;
     }
+
+  ppc_linux_features features (wordsize);
+
+  if (cell)
+    features.cell = true;
+
+  if (altivec)
+    features.altivec = true;
+
+  if (vsx)
+    features.vsx = true;
+
+  return ppc_linux_match_description (features);
 }
 
 
diff --git a/gdb/ppc-linux-tdep.h b/gdb/ppc-linux-tdep.h
index 465f9ff932..5e7c4be16b 100644
--- a/gdb/ppc-linux-tdep.h
+++ b/gdb/ppc-linux-tdep.h
@@ -40,21 +40,4 @@  enum {
 /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable.  */
 int ppc_linux_trap_reg_p (struct gdbarch *gdbarch);
 
-/* Linux target descriptions.  */
-extern struct target_desc *tdesc_powerpc_32l;
-extern struct target_desc *tdesc_powerpc_altivec32l;
-extern struct target_desc *tdesc_powerpc_cell32l;
-extern struct target_desc *tdesc_powerpc_vsx32l;
-extern struct target_desc *tdesc_powerpc_isa205_32l;
-extern struct target_desc *tdesc_powerpc_isa205_altivec32l;
-extern struct target_desc *tdesc_powerpc_isa205_vsx32l;
-extern struct target_desc *tdesc_powerpc_e500l;
-extern struct target_desc *tdesc_powerpc_64l;
-extern struct target_desc *tdesc_powerpc_altivec64l;
-extern struct target_desc *tdesc_powerpc_cell64l;
-extern struct target_desc *tdesc_powerpc_vsx64l;
-extern struct target_desc *tdesc_powerpc_isa205_64l;
-extern struct target_desc *tdesc_powerpc_isa205_altivec64l;
-extern struct target_desc *tdesc_powerpc_isa205_vsx64l;
-
 #endif /* PPC_LINUX_TDEP_H */