This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] use .gnu.attributes to detect e500 machine type


The patch introduces determining e500 cpu from .gnu.attributes; if gnu attributes section is not present, fall-back to the old way of checking the presence of .PPC.EMB.apuinfo section.

It also introduces a function for "show powerpc vector-abi" to print both ABI being used and if different, global setting (output can be seen below). This could be a separate patch - let me know if you want it separately.

Background of the patch:

Currently, gdb relies on presence .PPC.EMB.apuinfo section. This is not completely correct since apuinfo section can contain information about any APU instructions present, and not only SPE. So we could have a binary with .PPC.EMB.apuinfo section and without SPE APU. Further, .PPC.EMB.apuinfo may not be present at all even if -me500 is specified. This is due to gas emitting this section only if it encounters SPE APU instructions in the assembly.

.gnu.attributes section records user setting, whether there were SPE instructions generated or not. We use gnu object attributes in rs6000 already (for determining vector-abi and float-point abi).

The only problem with .gnu.attribute is that if binary is compiled with pre-4.3 gcc, .gnu.attributes section does not get generated at all. (.gnu_attribute was added in 4.3). This is why we fall-back to .PPC.EMB.apuinfo presence.

Results of the patch:

After starting gdb, no executable:
(gdb) show powerpc vector-abi
The vector ABI in use is "generic". Default setting is "auto".
(gdb) file /mnt/win/ppcspetest_g
Reading symbols from /mnt/win/ppcspetest_g...done.
(gdb) show powerpc vector-abi
The vector ABI in use is "spe". Default setting is "auto".

** If user overrides selected vector-abi, this is the display:
(gdb) set powerpc vector-abi generic
(gdb) show powerpc vector-abi
The vector ABI is "generic"

"show powerpc vector-abi" will now display both selected vector-abi and user setting ("Default setting is ..."). Only if the two concide, it will only say "Target vector ABI is ...").


Aleksandar Ristovski
QNX Software Systems

* rs6000-tdep.c (rs6000_gdbarch_init): Use .gnu.attributes to see
if this is a e500 binary (with SPE APU).
(powerpc_show_vector_abi): New function.
(_initialize_rs6000_tdep): Use powerpc_show_vector_abi.

Index: gdb/rs6000-tdep.c
RCS file: /cvs/src/src/gdb/rs6000-tdep.c,v
retrieving revision 1.328
diff -u -p -r1.328 rs6000-tdep.c
--- gdb/rs6000-tdep.c	22 Feb 2009 01:02:19 -0000	1.328
+++ gdb/rs6000-tdep.c	8 Apr 2009 13:13:12 -0000
@@ -3385,11 +3385,34 @@ rs6000_gdbarch_init (struct gdbarch_info
   if (info.abfd)
-      sect = bfd_get_section_by_name (info.abfd, ".PPC.EMB.apuinfo");
-      if (sect)
+      /* We want to check .gnu.attributes first as it records user's 
+	 setting.  In particular, we want to know if this binary is meant
+	 to be executed on a popwer pc with  SPE APU.  To do that,
+	 we look for tag 8. Failing that, resort to detecting apuinfo 
+	 section.  See 'as.pdf', section 'Object Attributes'.   */
+      int tag8_value; /* Tag_GNU_Power_ABI_Vector */
+      unsigned long m = 0;
+      tag8_value = bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
+					     Tag_GNU_Power_ABI_Vector);
+      /* The vector ABI used by this object file. The value will be:
+	 - 0 for files not affected by the vector ABI.
+	 - 1 for files using general purpose registers to pass vectors.
+	 - 2 for files using AltiVec registers to pass vectors.
+	 - 3 for files using SPE registers to pass vectors.  */
+      if (tag8_value == 3)
+	m = bfd_mach_ppc_e500;
+      else
+	{
+	  sect = bfd_get_section_by_name (info.abfd, ".PPC.EMB.apuinfo");
+	  if (sect)
+	    m = bfd_mach_ppc_e500;
+	}
+      if (m != 0)
+	  mach = m;
 	  arch = info.bfd_arch_info->arch;
-	  mach = bfd_mach_ppc_e500;
 	  bfd_default_set_arch_mach (&abfd, arch, mach);
 	  info.bfd_arch_info = bfd_get_arch_info (&abfd);
@@ -4003,6 +4026,36 @@ powerpc_set_vector_abi (char *args, int 
     internal_error (__FILE__, __LINE__, "could not update architecture");
+static void
+powerpc_show_vector_abi (struct ui_file *file,
+			 int from_tty,
+			 struct cmd_list_element *c,
+			 const char *value)
+  struct gdbarch *gdbarch = current_gdbarch;
+  enum powerpc_vector_abi tdep_vector_abi;
+  int global_msg_only = 0;
+  if (gdbarch == NULL)
+    global_msg_only = 1;
+  else 
+    {
+      tdep_vector_abi = gdbarch_tdep (gdbarch)->vector_abi;
+      if (strcmp (powerpc_vector_abi_string,
+		  powerpc_vector_strings[tdep_vector_abi]) == 0)
+	global_msg_only = 1;
+    }
+  if (global_msg_only)
+    printf_unfiltered ("The vector ABI is \"%s\"\n",
+		       powerpc_vector_abi_string);
+  else
+    printf_unfiltered ("\
+The vector ABI in use is \"%s\". Default setting is \"%s\".\n",
+		       powerpc_vector_strings[tdep_vector_abi],
+		       powerpc_vector_abi_string); 
 /* Initialization code.  */
 extern initialize_file_ftype _initialize_rs6000_tdep; /* -Wmissing-prototypes */
@@ -4056,6 +4109,6 @@ _initialize_rs6000_tdep (void)
 			_("Set the vector ABI."),
 			_("Show the vector ABI."),
-			NULL, powerpc_set_vector_abi, NULL,
+			NULL, powerpc_set_vector_abi, powerpc_show_vector_abi,
 			&setpowerpccmdlist, &showpowerpccmdlist);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]