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] Record whether an object attribute is actually set


Attached is a patch to explicitly record whether an ELF object
attribute has been set. This functionality will be used in the
MIPS port to determine the difference between a default value
and a user explicitly setting the default value.

OK to commit?

Tested with mips-linux-gnu and arm-linuxgnueabi as examples of
ports that use attributes albeit that they will not use the new
function. The feature has also been tested by using it in the
O32 FPXX patch.

Regards,
Matthew

2014-05-12  Matthew Fortune <matthew.fortune@imgtec.com>

bfd/
	* elf-attrs.c (bfd_elf_is_obj_attr_set): New function.
	(bfd_elf_add_obj_attr_int): Set is_set.
	(bfd_elf_add_obj_attr_string): Likewise.
	(bfd_elf_add_obj_attr_int_string): Likewise.
	(_bfd_elf_copy_obj_attributes): Likewise.
	* elf-bfd.h (obj_attribute): Add is_set field.
	(bfd_elf_is_obj_attr_set): New prototype.
---
 bfd/elf-attrs.c |   36 ++++++++++++++++++++++++++++++++++++
 bfd/elf-bfd.h   |    2 ++
 2 files changed, 38 insertions(+), 0 deletions(-)

diff --git a/bfd/elf-attrs.c b/bfd/elf-attrs.c
index cd0cbca..ad7d51f 100644
--- a/bfd/elf-attrs.c
+++ b/bfd/elf-attrs.c
@@ -263,6 +263,38 @@ elf_new_obj_attr (bfd *abfd, int vendor, int tag)
   return attr;
 }
 
+/* Determine if an attribute is set.  */
+bfd_boolean
+bfd_elf_is_obj_attr_set (bfd *abfd, int vendor, int tag)
+{
+  obj_attribute_list *p;
+  obj_attribute *attr = NULL;
+
+  if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
+    {
+      /* Known tags are preallocated.  */
+      attr = &elf_known_obj_attributes (abfd)[vendor][tag];
+    }
+  else
+    {
+      for (p = elf_other_obj_attributes (abfd)[vendor];
+	   p;
+	   p = p->next)
+	{
+	  if (tag == p->tag)
+	    {
+	      attr = &p->attr;
+	      break;
+	    }
+	  if (tag < p->tag)
+	    break;
+	}
+    }
+  return attr != NULL
+	 && (!is_default_attr (attr)
+	     || attr->is_set);
+}
+
 /* Return the value of an integer object attribute.  */
 int
 bfd_elf_get_obj_attr_int (bfd *abfd, int vendor, int tag)
@@ -298,6 +330,7 @@ bfd_elf_add_obj_attr_int (bfd *abfd, int vendor, int tag, unsigned int i)
   attr = elf_new_obj_attr (abfd, vendor, tag);
   attr->type = _bfd_elf_obj_attrs_arg_type (abfd, vendor, tag);
   attr->i = i;
+  attr->is_set = TRUE;
 }
 
 /* Duplicate an object attribute string value.  */
@@ -321,6 +354,7 @@ bfd_elf_add_obj_attr_string (bfd *abfd, int vendor, int tag, const char *s)
   attr = elf_new_obj_attr (abfd, vendor, tag);
   attr->type = _bfd_elf_obj_attrs_arg_type (abfd, vendor, tag);
   attr->s = _bfd_elf_attr_strdup (abfd, s);
+  attr->is_set = TRUE;
 }
 
 /* Add a int+string object attribute.  */
@@ -334,6 +368,7 @@ bfd_elf_add_obj_attr_int_string (bfd *abfd, int vendor, int tag,
   attr->type = _bfd_elf_obj_attrs_arg_type (abfd, vendor, tag);
   attr->i = i;
   attr->s = _bfd_elf_attr_strdup (abfd, s);
+  attr->is_set = TRUE;
 }
 
 /* Copy the object attributes from IBFD to OBFD.  */
@@ -360,6 +395,7 @@ _bfd_elf_copy_obj_attributes (bfd *ibfd, bfd *obfd)
 	{
 	  out_attr->type = in_attr->type;
 	  out_attr->i = in_attr->i;
+	  out_attr->is_set = TRUE;
 	  if (in_attr->s && *in_attr->s)
 	    out_attr->s = _bfd_elf_attr_strdup (obfd, in_attr->s);
 	  in_attr++;
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 2c02135..3ec0ced 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -1472,6 +1472,7 @@ typedef struct obj_attribute
   int type;
   unsigned int i;
   char *s;
+  bfd_boolean is_set;
 } obj_attribute;
 
 typedef struct obj_attribute_list
@@ -2355,6 +2356,7 @@ extern void bfd_elf_add_obj_attr_int_string (bfd *, int, int, unsigned int,
 #define bfd_elf_add_proc_attr_int_string(BFD, TAG, INTVAL, STRVAL) \
   bfd_elf_add_obj_attr_int_string ((BFD), OBJ_ATTR_PROC, (TAG), \
 				   (INTVAL), (STRVAL))
+extern bfd_boolean bfd_elf_is_obj_attr_set (bfd *, int, int);
 
 extern char *_bfd_elf_attr_strdup (bfd *, const char *);
 extern void _bfd_elf_copy_obj_attributes (bfd *, bfd *);
-- 
1.7.1


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