From 1695f2a1354cec9d5e489d7e7955a8144dbb2546 Mon Sep 17 00:00:00 2001 From: Andrew Stubbs Date: Mon, 19 Jan 2009 12:14:05 +0000 Subject: [PATCH] 2009-01-19 Andrew Stubbs bfd/ * elf-attrs.c (vendor_set_obj_attr_contents): Support tag ordering. * elf-bfd.h (elf_backend_data): Add obj_attrs_order. * elf32-arm.c (elf32_arm_obj_attrs_order): New function. (elf_backend_obj_attrs_order): New define. * elfxx-target.h (elf_backend_obj_attrs_order): New define. (elfNN_bed): Add elf_backend_obj_attrs_order. gas/testsuite/ * gas/arm/attr-order.d: New file. * gas/arm/attr-order.s: New file. --- bfd/ChangeLog | 9 +++++++++ bfd/elf-attrs.c | 7 ++++++- bfd/elf-bfd.h | 6 ++++++ bfd/elf32-arm.c | 19 +++++++++++++++++++ bfd/elfxx-target.h | 4 ++++ gas/testsuite/ChangeLog | 5 +++++ gas/testsuite/gas/arm/attr-order.d | 15 +++++++++++++++ gas/testsuite/gas/arm/attr-order.s | 9 +++++++++ 8 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 gas/testsuite/gas/arm/attr-order.d create mode 100644 gas/testsuite/gas/arm/attr-order.s diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 65300c1e5f..c2cc5e3c47 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,5 +1,14 @@ 2009-01-19 Andrew Stubbs + * elf-attrs.c (vendor_set_obj_attr_contents): Support tag ordering. + * elf-bfd.h (elf_backend_data): Add obj_attrs_order. + * elf32-arm.c (elf32_arm_obj_attrs_order): New function. + (elf_backend_obj_attrs_order): New define. + * elfxx-target.h (elf_backend_obj_attrs_order): New define. + (elfNN_bed): Add elf_backend_obj_attrs_order. + +2009-01-19 Andrew Stubbs + * elf-attrs.c (is_default_attr): Substitute magic numbers with macros. (obj_attr_size): Likewise. (write_obj_attribute): Likewise. diff --git a/bfd/elf-attrs.c b/bfd/elf-attrs.c index 1e8076b743..e60053b872 100644 --- a/bfd/elf-attrs.c +++ b/bfd/elf-attrs.c @@ -189,7 +189,12 @@ vendor_set_obj_attr_contents (bfd *abfd, bfd_byte *contents, bfd_vma size, attr = elf_known_obj_attributes (abfd)[vendor]; for (i = 4; i < NUM_KNOWN_OBJ_ATTRIBUTES; i++) - p = write_obj_attribute (p, i, &attr[i]); + { + int tag = i; + if (get_elf_backend_data (abfd)->obj_attrs_order) + tag = get_elf_backend_data (abfd)->obj_attrs_order (i); + p = write_obj_attribute (p, tag, &attr[tag]); + } for (list = elf_other_obj_attributes (abfd)[vendor]; list; diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index c0d8c8a40e..35dc0180f8 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -1167,6 +1167,12 @@ 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. */ + int (*obj_attrs_order) (int); + /* This is TRUE if the linker should act like collect and gather global constructors and destructors by name. This is TRUE for MIPS ELF because the Irix 5 tools can not handle the .init diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index bf1f06f137..5fdd138230 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -8149,6 +8149,24 @@ elf32_arm_obj_attrs_arg_type (int tag) return (tag & 1) != 0 ? ATTR_TYPE_FLAG_STR_VAL : ATTR_TYPE_FLAG_INT_VAL; } +/* The ABI defines that Tag_conformance should be emitted first, and that + Tag_nodefaults should be second (if either is defined). This sets those + two positions, and bumps up the position of all the remaining tags to + compensate. */ +static int +elf32_arm_obj_attrs_order (int num) +{ + if (num == 4) + return Tag_conformance; + if (num == 5) + return Tag_nodefaults; + if ((num - 2) < Tag_nodefaults) + return num - 2; + if ((num - 1) < Tag_conformance) + return num - 1; + return num; +} + /* Read the architecture from the Tag_also_compatible_with attribute, if any. Returns -1 if no architecture could be read. */ @@ -12292,6 +12310,7 @@ const struct elf_size_info elf32_arm_size_info = #define elf_backend_obj_attrs_arg_type elf32_arm_obj_attrs_arg_type #undef elf_backend_obj_attrs_section_type #define elf_backend_obj_attrs_section_type SHT_ARM_ATTRIBUTES +#define elf_backend_obj_attrs_order elf32_arm_obj_attrs_order #include "elf32-target.h" diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h index 811dbf5533..4aa8dd4b68 100644 --- a/bfd/elfxx-target.h +++ b/bfd/elfxx-target.h @@ -461,6 +461,9 @@ #ifndef elf_backend_obj_attrs_section_type #define elf_backend_obj_attrs_section_type SHT_GNU_ATTRIBUTES #endif +#ifndef elf_backend_obj_attrs_order +#define elf_backend_obj_attrs_order NULL +#endif #ifndef elf_backend_post_process_headers #define elf_backend_post_process_headers NULL #endif @@ -720,6 +723,7 @@ static struct elf_backend_data elfNN_bed = elf_backend_obj_attrs_section, elf_backend_obj_attrs_arg_type, elf_backend_obj_attrs_section_type, + elf_backend_obj_attrs_order, elf_backend_collect, elf_backend_type_change_ok, elf_backend_may_use_rel_p, diff --git a/gas/testsuite/ChangeLog b/gas/testsuite/ChangeLog index b4039ef213..00abbb99ca 100644 --- a/gas/testsuite/ChangeLog +++ b/gas/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2009-01-19 Andrew Stubbs + + * gas/arm/attr-order.d: New file. + * gas/arm/attr-order.s: New file. + 2009-01-16 Andrew Stubbs Daniel Jacobowitz diff --git a/gas/testsuite/gas/arm/attr-order.d b/gas/testsuite/gas/arm/attr-order.d new file mode 100644 index 0000000000..19f0c28f34 --- /dev/null +++ b/gas/testsuite/gas/arm/attr-order.d @@ -0,0 +1,15 @@ +# name: EABI attribute ordering +# source: attr-order.s +# as: +# readelf: -A + +Attribute Section: aeabi +File Attributes + Tag_conformance: "2.07" + Tag_nodefaults: True + Tag_CPU_name: "ARM7TDMI" + Tag_CPU_arch: v4T + Tag_unknown_63: "val" + Tag_also_compatible_with: v6-M + Tag_T2EE_use: Allowed + Tag_Virtualization_use: Allowed diff --git a/gas/testsuite/gas/arm/attr-order.s b/gas/testsuite/gas/arm/attr-order.s new file mode 100644 index 0000000000..10eb3a35eb --- /dev/null +++ b/gas/testsuite/gas/arm/attr-order.s @@ -0,0 +1,9 @@ +@ This test ensures that the following attributes +@ are emitted in the proper order. + .cpu arm7tdmi + .eabi_attribute 63, "val" + .eabi_attribute Tag_nodefaults, 0 + .eabi_attribute Tag_also_compatible_with, "\006\013" + .eabi_attribute Tag_T2EE_use, 1 + .eabi_attribute Tag_conformance, "2.07" + .eabi_attribute Tag_Virtualization_use, 1 -- 2.11.0