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 4/6] ARM attributes: defaultless attributes


The attached patch adds a new flag for the attribute type. This flag
indicates that the attribute does not have a default value.

What this means is that, when the tools write the attributes to the
output, they will not suppress the attribute if it has a zero value.
Since attributes only have a type (and therefore a no-default flag) if
they have been read from somewhere, they are still only written if they
are present.

The only attribute that needs this feature is Tag_nodefaults that is
considered set if it exists, and the value is ignored. (Note that that
"no defaults" in its name is a coincidence, and the important thing here
is that the value can be (should be) zero.)

OK?

Andrew

2009-01-12  Andrew Stubbs  <ams@codesourcery.com>

	bfd/
	* elf-attrs.c (is_default_attr): Support defaultless attributes.
	(bfd_elf_add_obj_attr_int): Get type from _bfd_elf_obj_attrs_arg_type.
	(bfd_elf_add_obj_attr_string): Likewise.
	(bfd_elf_add_obj_attr_int_string): Likewise.
	(_bfd_elf_parse_attributes): Allow for unknown flag bits in type.
	* elf-bfd.h (struct obj_attribute): Document new flag bit.
	* elf32-arm.c (elf32_arm_obj_attrs_arg_type): Specify that
	Tag_nodefaults has no default value.
	(elf32_arm_merge_eabi_attributes): Modify the Tag_nodefaults
	comment to reflect the new state.

	gas/
	* read.c (s_vendor_attribute): Allow for unknown flag bits in type.


---
 bfd/elf-attrs.c |   10 ++++++----
 bfd/elf-bfd.h   |    3 ++-
 bfd/elf32-arm.c |   11 ++++++-----
 gas/read.c      |    4 ++--
 4 files changed, 16 insertions(+), 12 deletions(-)

Index: bfd/elf-attrs.c
===================================================================
--- bfd/elf-attrs.c.orig
+++ bfd/elf-attrs.c
@@ -47,6 +47,8 @@ is_default_attr (obj_attribute *attr)
     return FALSE;
   if ((attr->type & 2) && attr->s && *attr->s)
     return FALSE;
+  if (attr->type & 4)
+    return FALSE;
 
   return TRUE;
 }
@@ -290,7 +292,7 @@ bfd_elf_add_obj_attr_int (bfd *abfd, int
   obj_attribute *attr;
 
   attr = elf_new_obj_attr (abfd, vendor, tag);
-  attr->type = 1;
+  attr->type = _bfd_elf_obj_attrs_arg_type (abfd, vendor, tag);
   attr->i = i;
 }
 
@@ -313,7 +315,7 @@ bfd_elf_add_obj_attr_string (bfd *abfd, 
   obj_attribute *attr;
 
   attr = elf_new_obj_attr (abfd, vendor, tag);
-  attr->type = 2;
+  attr->type = _bfd_elf_obj_attrs_arg_type (abfd, vendor, tag);
   attr->s = _bfd_elf_attr_strdup (abfd, s);
 }
 
@@ -325,7 +327,7 @@ bfd_elf_add_obj_attr_int_string (bfd *ab
   obj_attribute *attr;
 
   attr = elf_new_obj_attr (abfd, vendor, tag);
-  attr->type = 3;
+  attr->type = _bfd_elf_obj_attrs_arg_type (abfd, vendor, tag);
   attr->i = i;
   attr->s = _bfd_elf_attr_strdup (abfd, s);
 }
@@ -487,7 +489,7 @@ _bfd_elf_parse_attributes (bfd *abfd, El
 		      tag = read_unsigned_leb128 (abfd, p, &n);
 		      p += n;
 		      type = _bfd_elf_obj_attrs_arg_type (abfd, vendor, tag);
-		      switch (type)
+		      switch (type & 3)
 			{
 			case 3:
 			  val = read_unsigned_leb128 (abfd, p, &n);
Index: bfd/elf-bfd.h
===================================================================
--- bfd/elf-bfd.h.orig
+++ bfd/elf-bfd.h
@@ -1375,7 +1375,8 @@ struct elf_find_verdep_info
 
 /* The value of an object attribute.  type & 1 indicates whether there
    is an integer value; type & 2 indicates whether there is a string
-   value.  */
+   value; type & 4 indicates whether the type has a default value
+   (i.e. is there a value that need not be written to file).  */
 
 typedef struct obj_attribute
 {
Index: bfd/elf32-arm.c
===================================================================
--- bfd/elf32-arm.c.orig
+++ bfd/elf32-arm.c
@@ -8135,6 +8135,8 @@ elf32_arm_obj_attrs_arg_type (int tag)
 {
   if (tag == Tag_compatibility)
     return 3;
+  else if (tag == Tag_nodefaults)
+    return 5;
   else if (tag == 4 || tag == 5)
     return 2;
   else if (tag < 32)
@@ -8671,11 +8673,10 @@ elf32_arm_merge_eabi_attributes (bfd *ib
 	  break;
 
 	case Tag_nodefaults:
-	  /* This tag is set if it exists, but the value is unused.
-	     Unfortunately, we don't record whether each attribute is zero
-	     initialized, or read from the file, so the information has been
-	     lost.  In any case, we don't write attributes with zero values.
-	     Do nothing. */
+	  /* This tag is set if it exists, but the value is unused (and is
+	     typically zero).  We don't actually need to do anything here -
+	     the merge happens automatically when the type flags are merged
+	     below.  */
 	  break;
 	case Tag_also_compatible_with:
 	  /* Already done in Tag_CPU_arch.  */
Index: gas/read.c
===================================================================
--- gas/read.c.orig
+++ gas/read.c
@@ -2123,7 +2123,7 @@ s_vendor_attribute (int vendor)
 	}
       i = exp.X_add_number;
     }
-  if (type == 3
+  if ((type & 3) == 3
       && skip_past_comma (&input_line_pointer) == -1)
     {
       as_bad (_("expected comma"));
@@ -2140,7 +2140,7 @@ s_vendor_attribute (int vendor)
       s = demand_copy_C_string (&len);
     }
 
-  switch (type)
+  switch (type & 3)
     {
     case 3:
       bfd_elf_add_obj_attr_int_string (stdoutput, vendor, tag, i, s);



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