[PATCH][GOLD] Attributes section part 1

Doug Kwan (關振德) dougkwan@google.com
Fri Dec 4 10:03:00 GMT 2009


Hi,

    This is the first one of a series of patches for support the ARM
attributes section.  This one adds a number of enums used in
Tag_CPU_arch EABI attribute and two new fields in Target_info.

-Doug

2009-12-04  Doug Kwan  <dougkwan@google.com>

elfcpp/ChangeLog:

        * arm.h: Define enums for Tag_CPU_arch EABI attribute.

gold/ChangeLog:
        * arm.cc (Target_arm::arm_info): Initialize new fields
        attributes_section and attributes_vendor.
        * i386.cc (Target_i386::i386_info): Same.
        * object.cc (Sized_relobj::do_layout): Skip attribute section.
        * gold/powerpc.cc (Target_powerpc::powerpc_info): Initialize new
        fields attributes_section and attributes_vendor.
        * sparc.cc (Target_sparc::sparc_info): Same.
        * target.h (Target::attributes_section, Target::attributes_vendor,
        Target::is_attributes_section, Target::attribute_arg_type,
        Target::attributes_order): New method definitions.
        (Target::Target_info::attributes_section,
        Target::Target_info::attributes_vendor): New fields.
        (Target::do_attribute_arg_type, Target::do_attributes_order): New
        virtual method definitions.
        * x86_64.cc (Target_x86_64::x86_64_info): Initialize new fields
        attributes_section and attributes_vendor.
        * testsuite/testfile.cc (Target_test::test_target_info): Same.
-------------- next part --------------
Index: elfcpp/arm.h
===================================================================
RCS file: /cvs/src/src/elfcpp/arm.h,v
retrieving revision 1.2
diff -u -p -r1.2 arm.h
--- elfcpp/arm.h	30 Oct 2009 18:49:59 -0000	1.2
+++ elfcpp/arm.h	4 Dec 2009 09:28:55 -0000
@@ -222,6 +222,29 @@ inline Elf_Word
 arm_eabi_version(Elf_Word flags)
 { return flags & EF_ARM_EABIMASK; }
 
+// Values for the Tag_CPU_arch EABI attribute.
+enum
+{
+  TAG_CPU_ARCH_PRE_V4,
+  TAG_CPU_ARCH_V4,
+  TAG_CPU_ARCH_V4T,
+  TAG_CPU_ARCH_V5T,
+  TAG_CPU_ARCH_V5TE,
+  TAG_CPU_ARCH_V5TEJ,
+  TAG_CPU_ARCH_V6,
+  TAG_CPU_ARCH_V6KZ,
+  TAG_CPU_ARCH_V6T2,
+  TAG_CPU_ARCH_V6K,
+  TAG_CPU_ARCH_V7,
+  TAG_CPU_ARCH_V6_M,
+  TAG_CPU_ARCH_V6S_M,
+  TAG_CPU_ARCH_V7E_M,
+  MAX_TAG_CPU_ARCH = TAG_CPU_ARCH_V7E_M,
+  // Pseudo-architecture to allow objects to be compatible with the subset of
+  // armv4t and armv6-m.  This value should never be stored in object files.
+  TAG_CPU_ARCH_V4T_PLUS_V6_M = (MAX_TAG_CPU_ARCH + 1)
+};
+
 } // End namespace elfcpp.
 
 #endif // !defined(ELFCPP_ARM_H)
Index: gold/arm.cc
===================================================================
RCS file: /cvs/src/src/gold/arm.cc,v
retrieving revision 1.37
diff -u -p -r1.37 arm.cc
--- gold/arm.cc	3 Dec 2009 23:13:55 -0000	1.37
+++ gold/arm.cc	4 Dec 2009 09:28:57 -0000
@@ -1656,7 +1656,9 @@ const Target::Target_info Target_arm<big
   elfcpp::SHN_UNDEF,	// small_common_shndx
   elfcpp::SHN_UNDEF,	// large_common_shndx
   0,			// small_common_section_flags
-  0			// large_common_section_flags
+  0,			// large_common_section_flags
+  ".ARM.attributes",	// attributes_section
+  "aeabi"		// attributes_vendor
 };
 
 // Arm relocate functions class
Index: gold/i386.cc
===================================================================
RCS file: /cvs/src/src/gold/i386.cc,v
retrieving revision 1.101
diff -u -p -r1.101 i386.cc
--- gold/i386.cc	3 Dec 2009 23:13:55 -0000	1.101
+++ gold/i386.cc	4 Dec 2009 09:28:57 -0000
@@ -441,7 +441,9 @@ const Target::Target_info Target_i386::i
   elfcpp::SHN_UNDEF,	// small_common_shndx
   elfcpp::SHN_UNDEF,	// large_common_shndx
   0,			// small_common_section_flags
-  0			// large_common_section_flags
+  0,			// large_common_section_flags
+  NULL,			// attributes_section
+  NULL			// attributes_vendor
 };
 
 // Get the GOT section, creating it if necessary.
Index: gold/object.cc
===================================================================
RCS file: /cvs/src/src/gold/object.cc,v
retrieving revision 1.106
diff -u -p -r1.106 object.cc
--- gold/object.cc	9 Nov 2009 23:07:30 -0000	1.106
+++ gold/object.cc	4 Dec 2009 09:28:57 -0000
@@ -250,6 +250,9 @@ Object::handle_split_stack_section(const
   return false;
 }
 
+// Read the attributes section.  This is code common to Sized_relobj
+// and Sized_dynobj, so we put it into Object.
+
 // Class Relobj
 
 // To copy the symbols data read from the file to a local data structure.
@@ -1138,6 +1141,12 @@ Sized_relobj<size, big_endian>::do_layou
 		omit[i] = true;
 	    }
 
+	  // Skip attributes section.
+	  if (parameters->target().is_attributes_section(name))
+	    {
+	      omit[i] = true;
+	    }
+
           bool discard = omit[i];
           if (!discard)
             {
Index: gold/object.h
===================================================================
RCS file: /cvs/src/src/gold/object.h,v
retrieving revision 1.85
diff -u -p -r1.85 object.h
--- gold/object.h	5 Nov 2009 06:24:39 -0000	1.85
+++ gold/object.h	4 Dec 2009 09:28:57 -0000
@@ -587,6 +587,11 @@ class Object
   bool
   handle_split_stack_section(const char* name);
 
+  // If NAME is the name of an attributes section, return ture.
+  // Otherwise return false.
+  bool
+  handle_attributes_section(const char* name);
+
  private:
   // This class may not be copied.
   Object(const Object&);
Index: gold/powerpc.cc
===================================================================
RCS file: /cvs/src/src/gold/powerpc.cc,v
retrieving revision 1.21
diff -u -p -r1.21 powerpc.cc
--- gold/powerpc.cc	3 Dec 2009 23:13:55 -0000	1.21
+++ gold/powerpc.cc	4 Dec 2009 09:28:57 -0000
@@ -342,7 +342,9 @@ Target::Target_info Target_powerpc<32, t
   elfcpp::SHN_UNDEF,	// small_common_shndx
   elfcpp::SHN_UNDEF,	// large_common_shndx
   0,			// small_common_section_flags
-  0			// large_common_section_flags
+  0,			// large_common_section_flags
+  NULL,			// attributes_section
+  NULL			// attributes_vendor
 };
 
 template<>
@@ -363,7 +365,9 @@ Target::Target_info Target_powerpc<32, f
   elfcpp::SHN_UNDEF,	// small_common_shndx
   elfcpp::SHN_UNDEF,	// large_common_shndx
   0,			// small_common_section_flags
-  0			// large_common_section_flags
+  0,			// large_common_section_flags
+  NULL,			// attributes_section
+  NULL			// attributes_vendor
 };
 
 template<>
@@ -384,7 +388,9 @@ Target::Target_info Target_powerpc<64, t
   elfcpp::SHN_UNDEF,	// small_common_shndx
   elfcpp::SHN_UNDEF,	// large_common_shndx
   0,			// small_common_section_flags
-  0			// large_common_section_flags
+  0,			// large_common_section_flags
+  NULL,			// attributes_section
+  NULL			// attributes_vendor
 };
 
 template<>
@@ -405,7 +411,9 @@ Target::Target_info Target_powerpc<64, f
   elfcpp::SHN_UNDEF,	// small_common_shndx
   elfcpp::SHN_UNDEF,	// large_common_shndx
   0,			// small_common_section_flags
-  0			// large_common_section_flags
+  0,			// large_common_section_flags
+  NULL,			// attributes_section
+  NULL			// attributes_vendor
 };
 
 template<int size, bool big_endian>
Index: gold/sparc.cc
===================================================================
RCS file: /cvs/src/src/gold/sparc.cc,v
retrieving revision 1.25
diff -u -p -r1.25 sparc.cc
--- gold/sparc.cc	3 Dec 2009 23:13:55 -0000	1.25
+++ gold/sparc.cc	4 Dec 2009 09:28:57 -0000
@@ -361,7 +361,9 @@ Target::Target_info Target_sparc<32, tru
   elfcpp::SHN_UNDEF,	// small_common_shndx
   elfcpp::SHN_UNDEF,	// large_common_shndx
   0,			// small_common_section_flags
-  0			// large_common_section_flags
+  0,			// large_common_section_flags
+  NULL,			// attributes_section
+  NULL			// attributes_vendor
 };
 
 template<>
@@ -382,7 +384,9 @@ Target::Target_info Target_sparc<64, tru
   elfcpp::SHN_UNDEF,	// small_common_shndx
   elfcpp::SHN_UNDEF,	// large_common_shndx
   0,			// small_common_section_flags
-  0			// large_common_section_flags
+  0,			// large_common_section_flags
+  NULL,			// attributes_section
+  NULL			// attributes_vendor
 };
 
 // We have to take care here, even when operating in little-endian
Index: gold/target.h
===================================================================
RCS file: /cvs/src/src/gold/target.h,v
retrieving revision 1.41
diff -u -p -r1.41 target.h
--- gold/target.h	3 Dec 2009 23:13:55 -0000	1.41
+++ gold/target.h	4 Dec 2009 09:28:57 -0000
@@ -282,6 +282,38 @@ class Target
     return this->do_relax(pass, input_objects, symtab, layout);
   } 
 
+  // Return the target-specific name of attributes section.  This is
+  // NULL if a target does not use attributes section or if it uses
+  // the default section name ".gnu.attributes".
+  const char*
+  attributes_section() const
+  { return this->pti_->attributes_section; }
+
+  // Return the vendor name of vendor attributes.
+  const char*
+  attributes_vendor() const
+  { return this->pti_->attributes_vendor; }
+
+  // Whether a section called NAME is an attribute section.
+  bool
+  is_attributes_section(const char* name) const
+  {
+    return ((this->pti_->attributes_section != NULL
+	     && strcmp(name, this->pti_->attributes_section) == 0)
+	    || strcmp(name, ".gnu.attributes") == 0); 
+  }
+
+  // Determine what arguments an attribute tag takes.
+  int
+  attribute_arg_type(int tag) const
+  { return this->do_attribute_arg_type(tag); }
+
+  // Reorder tags during output.  By default no reordering is done
+  // and this is the identity function.
+  int
+  attributes_order(int num) const
+  { return this->do_attributes_order(num); }
+
  protected:
   // This struct holds the constant information for a child class.  We
   // use a struct to avoid the overhead of virtual function calls for
@@ -323,6 +355,10 @@ class Target
     elfcpp::Elf_Xword small_common_section_flags;
     // Section flags for large common section.
     elfcpp::Elf_Xword large_common_section_flags;
+    // Name of attributes section if it is not ".gnu.attributes".
+    const char* attributes_section;
+    // Vendor name of vendor attributes.
+    const char* attributes_vendor;
   };
 
   Target(const Target_info* pti)
@@ -440,6 +476,17 @@ class Target
   set_view_to_nop(unsigned char* view, section_size_type view_size,
 		  section_offset_type offset, size_t len) const;
 
+  // This must be override by the child class if it has target-specific
+  // attributes subsection in the attribute section. 
+  virtual int
+  do_attribute_arg_type(int) const
+  { gold_unreachable(); }
+
+  // This may be overridden by the child class.
+  virtual int
+  do_attributes_order(int num) const
+  { return num; }
+
  private:
   // The implementations of the four do_make_elf_object virtual functions are
   // almost identical except for their sizes and endianity.  We use a template.
Index: gold/x86_64.cc
===================================================================
RCS file: /cvs/src/src/gold/x86_64.cc,v
retrieving revision 1.94
diff -u -p -r1.94 x86_64.cc
--- gold/x86_64.cc	3 Dec 2009 23:13:55 -0000	1.94
+++ gold/x86_64.cc	4 Dec 2009 09:28:57 -0000
@@ -439,7 +439,9 @@ const Target::Target_info Target_x86_64:
   elfcpp::SHN_UNDEF,	// small_common_shndx
   elfcpp::SHN_X86_64_LCOMMON,	// large_common_shndx
   0,			// small_common_section_flags
-  elfcpp::SHF_X86_64_LARGE	// large_common_section_flags
+  elfcpp::SHF_X86_64_LARGE,	// large_common_section_flags
+  NULL,			// attributes_section
+  NULL			// attributes_vendor
 };
 
 // This is called when a new output section is created.  This is where
Index: gold/testsuite/testfile.cc
===================================================================
RCS file: /cvs/src/src/gold/testsuite/testfile.cc,v
retrieving revision 1.17
diff -u -p -r1.17 testfile.cc
--- gold/testsuite/testfile.cc	29 Oct 2009 05:16:23 -0000	1.17
+++ gold/testsuite/testfile.cc	4 Dec 2009 09:28:57 -0000
@@ -101,7 +101,9 @@ const Target::Target_info Target_test<si
   elfcpp::SHN_UNDEF,			// small_common_shndx
   elfcpp::SHN_UNDEF,			// large_common_shndx
   0,					// small_common_section_flags
-  0					// large_common_section_flags
+  0,					// large_common_section_flags
+  NULL,					// attributes_section
+  NULL					// attributes_vendor
 };
 
 // The test targets.


More information about the Binutils mailing list