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]

Support object attributes numbers below 4


The object attributes support in BFD currently assumes that no object
attribute has a number smaller than 4.  This is indeed true for ARM
EABI attributes - the numbers within subsections were probably
deliberately chosen not to overlap with those indicating whether a
subsection applies to a whole file, a section or a symbol - and for
GNU attributes.  However, I am now implementing TI C6X attributes, and
those use number 2 for Tag_C6XABI_Tag_CPU_arch (there is no actual
ambiguity between attributes within subsections and those at the start
of a subsection).

This patch allows the possibility of attributes numbered below 4,
removing the hardcoded 4s that were commented on in
<http://sourceware.org/ml/binutils/2007-07/msg00398.html> and
replacing them with LEAST_KNOWN_OBJ_ATTRIBUTE.  In this patch that
macro remains defined as 4; the C6X attributes patch will change it to
2.  If any target requires a value of 0, some further changes will be
needed because of code such as:

      /* Use the Tag_null value to indicate the attributes have been
         initialized.  */
      out_attr[0].i = 1;

Tested with no regressions with cross to arm-eabi; I also tested the
variant with value 2 for LEAST_KNOWN_OBJ_ATTRIBUTE to make sure that
didn't break ARM.  OK to commit?

2010-06-15  Joseph Myers  <joseph@codesourcery.com>

	* elf-bfd.h (LEAST_KNOWN_OBJ_ATTRIBUTE): Define.
	(struct elf_backend_data): Update comment on obj_attrs_order.
	* elf-attrs.c (vendor_obj_attr_size, vendor_set_obj_attr_contents,
	_bfd_elf_copy_obj_attributes): Use LEAST_KNOWN_OBJ_ATTRIBUTE
	instead of hardcoded 4.
	* elf32-arm.c (elf32_arm_obj_attrs_order): Use
	LEAST_KNOWN_OBJ_ATTRIBUTE and LEAST_KNOWN_OBJ_ATTRIBUTE + 1
	instead of hardcoded 4 and 5.
	(elf32_arm_merge_eabi_attributes): Use LEAST_KNOWN_OBJ_ATTRIBUTE
	instead of hardcoded 4.

Index: elf-attrs.c
===================================================================
RCS file: /cvs/src/src/bfd/elf-attrs.c,v
retrieving revision 1.11
diff -u -p -r1.11 elf-attrs.c
--- elf-attrs.c	28 Dec 2009 18:37:30 -0000	1.11
+++ elf-attrs.c	15 Jun 2010 16:20:23 -0000
@@ -1,5 +1,5 @@
 /* ELF attributes support (based on ARM EABI attributes).
-   Copyright 2005, 2006, 2007, 2009
+   Copyright 2005, 2006, 2007, 2009, 2010
    Free Software Foundation, Inc.
 
    This file is part of BFD, the Binary File Descriptor library.
@@ -96,7 +96,7 @@ vendor_obj_attr_size (bfd *abfd, int ven
 
   attr = elf_known_obj_attributes (abfd)[vendor];
   size = 0;
-  for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
+  for (i = LEAST_KNOWN_OBJ_ATTRIBUTE; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
     size += obj_attr_size (i, &attr[i]);
 
   for (list = elf_other_obj_attributes (abfd)[vendor];
@@ -188,7 +188,7 @@ vendor_set_obj_attr_contents (bfd *abfd,
   p += 4;
 
   attr = elf_known_obj_attributes (abfd)[vendor];
-  for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
+  for (i = LEAST_KNOWN_OBJ_ATTRIBUTE; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
     {
       int tag = i;
       if (get_elf_backend_data (abfd)->obj_attrs_order)
@@ -349,9 +349,11 @@ _bfd_elf_copy_obj_attributes (bfd *ibfd,
 
   for (vendor = OBJ_ATTR_FIRST; vendor <= OBJ_ATTR_LAST; vendor++)
     {
-      in_attr = &elf_known_obj_attributes (ibfd)[vendor][4];
-      out_attr = &elf_known_obj_attributes (obfd)[vendor][4];
-      for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
+      in_attr
+	= &elf_known_obj_attributes (ibfd)[vendor][LEAST_KNOWN_OBJ_ATTRIBUTE];
+      out_attr
+	= &elf_known_obj_attributes (obfd)[vendor][LEAST_KNOWN_OBJ_ATTRIBUTE];
+      for (i = LEAST_KNOWN_OBJ_ATTRIBUTE; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
 	{
 	  out_attr->type = in_attr->type;
 	  out_attr->i = in_attr->i;
Index: elf-bfd.h
===================================================================
RCS file: /cvs/src/src/bfd/elf-bfd.h,v
retrieving revision 1.304
diff -u -p -r1.304 elf-bfd.h
--- elf-bfd.h	30 Apr 2010 18:27:29 -0000	1.304
+++ elf-bfd.h	15 Jun 2010 16:20:24 -0000
@@ -1245,10 +1245,11 @@ struct elf_backend_data
   /* The section type to use for an attributes section.  */
   unsigned int obj_attrs_section_type;
 
-  /* This function determines the order in which any attributes are written.
-     It must be defined for input in the range 4..NUM_KNOWN_OBJ_ATTRIBUTES-1
-     (this range is used in order to make unity easy).  The returned value is
-     the actual tag number to place in the input position.  */
+  /* This function determines the order in which any attributes are
+     written.  It must be defined for input in the range
+     LEAST_KNOWN_OBJ_ATTRIBUTE..NUM_KNOWN_OBJ_ATTRIBUTES-1 (this range
+     is used in order to make unity easy).  The returned value is the
+     actual tag number to place in the input position.  */
   int (*obj_attrs_order) (int);
 
   /* This is TRUE if the linker should act like collect and gather
@@ -1412,6 +1413,12 @@ struct bfd_elf_section_data
 #define get_elf_backend_data(abfd) \
    xvec_get_elf_backend_data ((abfd)->xvec)
 
+/* The least object attributes (within an attributes subsection) known
+   for any target.  Some code assumes that the value 0 is not used and
+   the field for that attribute can instead be used as a marker to
+   indicate that attributes have been initialized.  */
+#define LEAST_KNOWN_OBJ_ATTRIBUTE 4
+
 /* The maximum number of known object attributes for any target.  */
 #define NUM_KNOWN_OBJ_ATTRIBUTES 71
 
Index: elf32-arm.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-arm.c,v
retrieving revision 1.235
diff -u -p -r1.235 elf32-arm.c
--- elf32-arm.c	11 May 2010 17:36:27 -0000	1.235
+++ elf32-arm.c	15 Jun 2010 16:20:25 -0000
@@ -9624,9 +9624,9 @@ elf32_arm_obj_attrs_arg_type (int tag)
 static int
 elf32_arm_obj_attrs_order (int num)
 {
-  if (num == 4)
+  if (num == LEAST_KNOWN_OBJ_ATTRIBUTE)
     return Tag_conformance;
-  if (num == 5)
+  if (num == LEAST_KNOWN_OBJ_ATTRIBUTE + 1)
     return Tag_nodefaults;
   if ((num - 2) < Tag_nodefaults)
     return num - 2;
@@ -9932,7 +9932,7 @@ elf32_arm_merge_eabi_attributes (bfd *ib
 	}
     }
 
-  for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
+  for (i = LEAST_KNOWN_OBJ_ATTRIBUTE; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++)
     {
       /* Merge this attribute with existing attributes.  */
       switch (i)

-- 
Joseph S. Myers
joseph@codesourcery.com


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