This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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][PPC] add attribute for small structure return convention


The patch below adds bits for recognizing a new GNU attribute for the
PowerPC platform: the small structure return convention.  While the ABI
for a platform determines how small structures are returned (in r3/r4 or
in memory), GCC provides an option to explicitly override this
(-m{no-}aix-struct-return).  Ensuring that people don't shoot themselves
in the foot is a good thing.

GCC does not yet generate this attribute; that patch is forthcoming
after this one is approved.  Tested on powerpc-linux-gnu.  OK to commit?

-Nathan

include/elf/
	* ppc.h: Add Tag_GNU_Power_ABI_Struct_Return.

bfd/
	* elf32-ppc.c (ppc_elf_merge_obj_attributes): Merge
	Tag_GNU_Power_ABI_Struct_Return.

binutils/
	* readelf.c (display_power_gnu_attribute): Decode
	Tag_GNU_Power_ABI_Struct_Return.

ld/testsuite/
	* ld-powerpc/gnu-attr-12-1.s: New file.
	* ld-powerpc/gnu-attr-12-2.s: New file.
	* ld-powerpc/gnu-attr-12-11.d: New file.
	* ld-powerpc/gnu-attr-12-21.d: New file.
	* ld-powerpc/powerpc.exp: Run new dump tests.

--- bfd/elf32-ppc.c	(revision 223942)
+++ bfd/elf32-ppc.c	(local)
@@ -3964,6 +3964,33 @@ ppc_elf_merge_obj_attributes (bfd *ibfd,
 	   ibfd, obfd, in_abi, out_abi);
     }
 
+  /* Check for conflicting Tag_GNU_Power_ABI_Struct_Return attributes
+     and merge non-conflicting ones.  */
+  in_attr = &in_attrs[Tag_GNU_Power_ABI_Struct_Return];
+  out_attr = &out_attrs[Tag_GNU_Power_ABI_Struct_Return];
+  if (in_attr->i != out_attr->i)
+    {
+      out_attr->type = 1;
+      if (out_attr->i == 0)
+	out_attr->i = in_attr->i;
+      else if (in_attr->i == 0)
+	;
+      else if (out_attr->i == 1 && in_attr->i == 2)
+	_bfd_error_handler
+	  (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), obfd, ibfd);
+      else if (out_attr->i == 2 && in_attr->i == 1)
+	_bfd_error_handler
+	  (_("Warning: %B uses r3/r4 for small structure returns, %B uses memory"), ibfd, obfd);
+      else if (in_attr->i > 2)
+	_bfd_error_handler
+	  (_("Warning: %B uses unknown small structure return convention %d"), ibfd,
+	   in_attr->i);
+      else
+	_bfd_error_handler
+	  (_("Warning: %B uses unknown small structure return convention %d"), obfd,
+	   out_attr->i);
+    }
+
   /* Merge Tag_compatibility attributes and any common GNU ones.  */
   _bfd_elf_merge_object_attributes (ibfd, obfd);
 
--- binutils/readelf.c	(revision 223942)
+++ binutils/readelf.c	(local)
@@ -9062,6 +9062,29 @@ display_power_gnu_attribute (unsigned ch
       return p;
    }
 
+  if (tag == Tag_GNU_Power_ABI_Struct_Return)
+    {
+      val = read_uleb128 (p, &len);
+      p += len;
+      printf ("  Tag_GNU_Power_ABI_Struct_Return: ");
+      switch (val)
+	{
+	case 0:
+	  printf ("Any\n");
+	  break;
+	case 1:
+	  printf ("r3/r4\n");
+	  break;
+	case 2:
+	  printf ("Memory\n");
+	  break;
+	default:
+	  printf ("??? (%d)\n", val);
+	  break;
+	}
+      return p;
+    }
+
   if (tag & 1)
     type = 1; /* String.  */
   else
--- include/elf/ppc.h	(revision 223942)
+++ include/elf/ppc.h	(local)
@@ -186,6 +186,11 @@ enum
      registers, 3 for SPE registers; 0 for not tagged or not using any
      ABIs affected by the differences.  */
   Tag_GNU_Power_ABI_Vector = 8,
+
+  /* Value 1 for ABIs using r3/r4 for returning structures <= 8 bytes,
+     2 for ABIs using memory; 0 for not tagged or not using any ABIs
+     affected by the differences.  */
+  Tag_GNU_Power_ABI_Struct_Return = 12
 };
 
 #endif /* _ELF_PPC_H */
--- ld/testsuite/ld-powerpc/powerpc.exp	(revision 223942)
+++ ld/testsuite/ld-powerpc/powerpc.exp	(local)
@@ -177,3 +177,6 @@ run_dump_test "attr-gnu-4-41"
 run_dump_test "attr-gnu-8-11"
 run_dump_test "attr-gnu-8-23"
 run_dump_test "attr-gnu-8-31"
+
+run_dump_test "attr-gnu-12-11"
+run_dump_test "attr-gnu-12-21"
--- ld/testsuite/ld-powerpc/attr-gnu-12-1.s	(revision 223942)
+++ ld/testsuite/ld-powerpc/attr-gnu-12-1.s	(local)
@@ -0,0 +1 @@
+.gnu_attribute 12,1
--- ld/testsuite/ld-powerpc/attr-gnu-12-11.d	(revision 223942)
+++ ld/testsuite/ld-powerpc/attr-gnu-12-11.d	(local)
@@ -0,0 +1,10 @@
+#source: attr-gnu-12-1.s
+#source: attr-gnu-12-1.s
+#as: -a32
+#ld: -r -melf32ppc
+#readelf: -A
+#target: powerpc*-*-*
+
+Attribute Section: gnu
+File Attributes
+  Tag_GNU_Power_ABI_Struct_Return: r3/r4
--- ld/testsuite/ld-powerpc/attr-gnu-12-2.s	(revision 223942)
+++ ld/testsuite/ld-powerpc/attr-gnu-12-2.s	(local)
@@ -0,0 +1 @@
+.gnu_attribute 12,2
--- ld/testsuite/ld-powerpc/attr-gnu-12-21.d	(revision 223942)
+++ ld/testsuite/ld-powerpc/attr-gnu-12-21.d	(local)
@@ -0,0 +1,6 @@
+#source: attr-gnu-12-2.s
+#source: attr-gnu-12-1.s
+#as: -a32
+#ld: -r -melf32ppc
+#warning: Warning: .* uses r3/r4 for small structure returns, .* uses memory
+#target: powerpc*-*-*


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