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

bfd/
	* elf-attrs.c (is_default_attr): Substitute magic numbers with macros.
	(obj_attr_size): Likewise.
	(write_obj_attribute): Likewise.
	(_bfd_elf_copy_obj_attributes): Likewise.
	(_bfd_elf_parse_attributes): Likewise.
	* elf-bfd.h (ATTR_TYPE_FLAG_INT_VAL): New define.
	(ATTR_TYPE_FLAG_STR_VAL, ATTR_TYPE_FLAG_NO_DEFAULT): New defines.
	(ATTR_TYPE_HAS_INT_VAL, ATTR_TYPE_HAS_STR_VAL): New defines.
	(ATTR_TYPE_HAS_NO_DEFAULT): New define.
	* elf32-arm.c (elf32_arm_obj_attrs_arg_type): Replace magic numbers
	with macros.
This commit is contained in:
Andrew Stubbs
2009-01-19 11:55:35 +00:00
parent 2d0bb7614b
commit 3483fe2e0b
4 changed files with 46 additions and 25 deletions

View File

@ -1,3 +1,17 @@
2009-01-19 Andrew Stubbs <ams@codesourcery.com>
* elf-attrs.c (is_default_attr): Substitute magic numbers with macros.
(obj_attr_size): Likewise.
(write_obj_attribute): Likewise.
(_bfd_elf_copy_obj_attributes): Likewise.
(_bfd_elf_parse_attributes): Likewise.
* elf-bfd.h (ATTR_TYPE_FLAG_INT_VAL): New define.
(ATTR_TYPE_FLAG_STR_VAL, ATTR_TYPE_FLAG_NO_DEFAULT): New defines.
(ATTR_TYPE_HAS_INT_VAL, ATTR_TYPE_HAS_STR_VAL): New defines.
(ATTR_TYPE_HAS_NO_DEFAULT): New define.
* elf32-arm.c (elf32_arm_obj_attrs_arg_type): Replace magic numbers
with macros.
2009-01-19 Andrew Stubbs <ams@codesourcery.com> 2009-01-19 Andrew Stubbs <ams@codesourcery.com>
* elf-attrs.c (is_default_attr): Support defaultless attributes. * elf-attrs.c (is_default_attr): Support defaultless attributes.

View File

@ -43,11 +43,11 @@ uleb128_size (unsigned int i)
static bfd_boolean static bfd_boolean
is_default_attr (obj_attribute *attr) is_default_attr (obj_attribute *attr)
{ {
if ((attr->type & 1) && attr->i != 0) if (ATTR_TYPE_HAS_INT_VAL (attr->type) && attr->i != 0)
return FALSE; return FALSE;
if ((attr->type & 2) && attr->s && *attr->s) if (ATTR_TYPE_HAS_STR_VAL (attr->type) && attr->s && *attr->s)
return FALSE; return FALSE;
if (attr->type & 4) if (ATTR_TYPE_HAS_NO_DEFAULT (attr->type))
return FALSE; return FALSE;
return TRUE; return TRUE;
@ -63,9 +63,9 @@ obj_attr_size (int tag, obj_attribute *attr)
return 0; return 0;
size = uleb128_size (tag); size = uleb128_size (tag);
if (attr->type & 1) if (ATTR_TYPE_HAS_INT_VAL (attr->type))
size += uleb128_size (attr->i); size += uleb128_size (attr->i);
if (attr->type & 2) if (ATTR_TYPE_HAS_STR_VAL (attr->type))
size += strlen ((char *)attr->s) + 1; size += strlen ((char *)attr->s) + 1;
return size; return size;
} }
@ -151,9 +151,9 @@ write_obj_attribute (bfd_byte *p, int tag, obj_attribute *attr)
return p; return p;
p = write_uleb128 (p, tag); p = write_uleb128 (p, tag);
if (attr->type & 1) if (ATTR_TYPE_HAS_INT_VAL (attr->type))
p = write_uleb128 (p, attr->i); p = write_uleb128 (p, attr->i);
if (attr->type & 2) if (ATTR_TYPE_HAS_STR_VAL (attr->type))
{ {
int len; int len;
@ -361,16 +361,16 @@ _bfd_elf_copy_obj_attributes (bfd *ibfd, bfd *obfd)
list = list->next) list = list->next)
{ {
in_attr = &list->attr; in_attr = &list->attr;
switch (in_attr->type) switch (in_attr->type & (ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL))
{ {
case 1: case ATTR_TYPE_FLAG_INT_VAL:
bfd_elf_add_obj_attr_int (obfd, vendor, list->tag, in_attr->i); bfd_elf_add_obj_attr_int (obfd, vendor, list->tag, in_attr->i);
break; break;
case 2: case ATTR_TYPE_FLAG_STR_VAL:
bfd_elf_add_obj_attr_string (obfd, vendor, list->tag, bfd_elf_add_obj_attr_string (obfd, vendor, list->tag,
in_attr->s); in_attr->s);
break; break;
case 3: case ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL:
bfd_elf_add_obj_attr_int_string (obfd, vendor, list->tag, bfd_elf_add_obj_attr_int_string (obfd, vendor, list->tag,
in_attr->i, in_attr->s); in_attr->i, in_attr->s);
break; break;
@ -489,21 +489,21 @@ _bfd_elf_parse_attributes (bfd *abfd, Elf_Internal_Shdr * hdr)
tag = read_unsigned_leb128 (abfd, p, &n); tag = read_unsigned_leb128 (abfd, p, &n);
p += n; p += n;
type = _bfd_elf_obj_attrs_arg_type (abfd, vendor, tag); type = _bfd_elf_obj_attrs_arg_type (abfd, vendor, tag);
switch (type & 3) switch (type & (ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL))
{ {
case 3: case ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL:
val = read_unsigned_leb128 (abfd, p, &n); val = read_unsigned_leb128 (abfd, p, &n);
p += n; p += n;
bfd_elf_add_obj_attr_int_string (abfd, vendor, tag, bfd_elf_add_obj_attr_int_string (abfd, vendor, tag,
val, (char *)p); val, (char *)p);
p += strlen ((char *)p) + 1; p += strlen ((char *)p) + 1;
break; break;
case 2: case ATTR_TYPE_FLAG_STR_VAL:
bfd_elf_add_obj_attr_string (abfd, vendor, tag, bfd_elf_add_obj_attr_string (abfd, vendor, tag,
(char *)p); (char *)p);
p += strlen ((char *)p) + 1; p += strlen ((char *)p) + 1;
break; break;
case 1: case ATTR_TYPE_FLAG_INT_VAL:
val = read_unsigned_leb128 (abfd, p, &n); val = read_unsigned_leb128 (abfd, p, &n);
p += n; p += n;
bfd_elf_add_obj_attr_int (abfd, vendor, tag, val); bfd_elf_add_obj_attr_int (abfd, vendor, tag, val);

View File

@ -1371,13 +1371,20 @@ struct elf_find_verdep_info
/* The maximum number of known object attributes for any target. */ /* The maximum number of known object attributes for any target. */
#define NUM_KNOWN_OBJ_ATTRIBUTES 71 #define NUM_KNOWN_OBJ_ATTRIBUTES 71
/* The value of an object attribute. type & 1 indicates whether there /* The value of an object attribute. The type indicates whether the attribute
is an integer value; type & 2 indicates whether there is a string holds and integer, a string, or both. It can also indicate that there can
value; type & 4 indicates whether the type has a default value be no default (i.e. all values must be written to file, even zero). */
(i.e. is there a value that need not be written to file). */
typedef struct obj_attribute typedef struct obj_attribute
{ {
#define ATTR_TYPE_FLAG_INT_VAL (1 << 0)
#define ATTR_TYPE_FLAG_STR_VAL (1 << 1)
#define ATTR_TYPE_FLAG_NO_DEFAULT (1 << 2)
#define ATTR_TYPE_HAS_INT_VAL(TYPE) ((TYPE) & ATTR_TYPE_FLAG_INT_VAL)
#define ATTR_TYPE_HAS_STR_VAL(TYPE) ((TYPE) & ATTR_TYPE_FLAG_STR_VAL)
#define ATTR_TYPE_HAS_NO_DEFAULT(TYPE) ((TYPE) & ATTR_TYPE_FLAG_NO_DEFAULT)
int type; int type;
unsigned int i; unsigned int i;
char *s; char *s;

View File

@ -8138,15 +8138,15 @@ static int
elf32_arm_obj_attrs_arg_type (int tag) elf32_arm_obj_attrs_arg_type (int tag)
{ {
if (tag == Tag_compatibility) if (tag == Tag_compatibility)
return 3; return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_STR_VAL;
else if (tag == Tag_nodefaults) else if (tag == Tag_nodefaults)
return 5; return ATTR_TYPE_FLAG_INT_VAL | ATTR_TYPE_FLAG_NO_DEFAULT;
else if (tag == 4 || tag == 5) else if (tag == Tag_CPU_raw_name || tag == Tag_CPU_name)
return 2; return ATTR_TYPE_FLAG_STR_VAL;
else if (tag < 32) else if (tag < 32)
return 1; return ATTR_TYPE_FLAG_INT_VAL;
else else
return (tag & 1) != 0 ? 2 : 1; return (tag & 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL : ATTR_TYPE_FLAG_INT_VAL;
} }
/* Read the architecture from the Tag_also_compatible_with attribute, if any. /* Read the architecture from the Tag_also_compatible_with attribute, if any.