Blame SOURCES/binutils-gold-i386-gnu-property-notes.patch

12f9d8
diff --git a/gold/i386.cc b/gold/i386.cc
12f9d8
index bf209fe9a86..31161ff091c 100644
12f9d8
--- a/gold/i386.cc
12f9d8
+++ b/gold/i386.cc
12f9d8
@@ -360,7 +360,11 @@ class Target_i386 : public Sized_target<32, false>
12f9d8
       got_(NULL), plt_(NULL), got_plt_(NULL), got_irelative_(NULL),
12f9d8
       got_tlsdesc_(NULL), global_offset_table_(NULL), rel_dyn_(NULL),
12f9d8
       rel_irelative_(NULL), copy_relocs_(elfcpp::R_386_COPY),
12f9d8
-      got_mod_index_offset_(-1U), tls_base_symbol_defined_(false)
12f9d8
+      got_mod_index_offset_(-1U), tls_base_symbol_defined_(false),
12f9d8
+      isa_1_used_(0), isa_1_needed_(0),
12f9d8
+      feature_1_(0), feature_2_used_(0), feature_2_needed_(0),
12f9d8
+      object_isa_1_used_(0), object_feature_1_(0),
12f9d8
+      object_feature_2_used_(0), seen_first_object_(false)
12f9d8
   { }
12f9d8
 
12f9d8
   // Process the relocations to determine unreferenced sections for
12f9d8
@@ -859,6 +863,21 @@ class Target_i386 : public Sized_target<32, false>
12f9d8
 				  this->rel_dyn_section(layout));
12f9d8
   }
12f9d8
 
12f9d8
+  // Record a target-specific program property in the .note.gnu.property
12f9d8
+  // section.
12f9d8
+  void
12f9d8
+  record_gnu_property(unsigned int, unsigned int, size_t,
12f9d8
+		      const unsigned char*, const Object*);
12f9d8
+
12f9d8
+  // Merge the target-specific program properties from the current object.
12f9d8
+  void
12f9d8
+  merge_gnu_properties(const Object*);
12f9d8
+
12f9d8
+  // Finalize the target-specific program properties and add them back to
12f9d8
+  // the layout.
12f9d8
+  void
12f9d8
+  do_finalize_gnu_properties(Layout*) const;
12f9d8
+
12f9d8
   // Information about this specific target which we pass to the
12f9d8
   // general Target structure.
12f9d8
   static const Target::Target_info i386_info;
12f9d8
@@ -898,6 +917,26 @@ class Target_i386 : public Sized_target<32, false>
12f9d8
   unsigned int got_mod_index_offset_;
12f9d8
   // True if the _TLS_MODULE_BASE_ symbol has been defined.
12f9d8
   bool tls_base_symbol_defined_;
12f9d8
+
12f9d8
+  // Target-specific program properties, from .note.gnu.property section.
12f9d8
+  // Each bit represents a specific feature.
12f9d8
+  uint32_t isa_1_used_;
12f9d8
+  uint32_t isa_1_needed_;
12f9d8
+  uint32_t feature_1_;
12f9d8
+  uint32_t feature_2_used_;
12f9d8
+  uint32_t feature_2_needed_;
12f9d8
+  // Target-specific properties from the current object.
12f9d8
+  // These bits get ORed into ISA_1_USED_ after all properties for the object
12f9d8
+  // have been processed. But if either is all zeroes (as when the property
12f9d8
+  // is absent from an object), the result should be all zeroes.
12f9d8
+  // (See PR ld/23486.)
12f9d8
+  uint32_t object_isa_1_used_;
12f9d8
+  // These bits get ANDed into FEATURE_1_ after all properties for the object
12f9d8
+  // have been processed.
12f9d8
+  uint32_t object_feature_1_;
12f9d8
+  uint32_t object_feature_2_used_;
12f9d8
+  // Whether we have seen our first object, for use in initializing FEATURE_1_.
12f9d8
+  bool seen_first_object_;
12f9d8
 };
12f9d8
 
12f9d8
 const Target::Target_info Target_i386::i386_info =
12f9d8
@@ -1042,6 +1081,126 @@ Target_i386::rel_irelative_section(Layout* layout)
12f9d8
   return this->rel_irelative_;
12f9d8
 }
12f9d8
 
12f9d8
+// Record a target-specific program property from the .note.gnu.property
12f9d8
+// section.
12f9d8
+void
12f9d8
+Target_i386::record_gnu_property(
12f9d8
+    unsigned int, unsigned int pr_type,
12f9d8
+    size_t pr_datasz, const unsigned char* pr_data,
12f9d8
+    const Object* object)
12f9d8
+{
12f9d8
+  uint32_t val = 0;
12f9d8
+
12f9d8
+  switch (pr_type)
12f9d8
+    {
12f9d8
+    case elfcpp::GNU_PROPERTY_X86_COMPAT_ISA_1_USED:
12f9d8
+    case elfcpp::GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED:
12f9d8
+    case elfcpp::GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED:
12f9d8
+    case elfcpp::GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED:
12f9d8
+    case elfcpp::GNU_PROPERTY_X86_ISA_1_USED:
12f9d8
+    case elfcpp::GNU_PROPERTY_X86_ISA_1_NEEDED:
12f9d8
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_1_AND:
12f9d8
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_2_USED:
12f9d8
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_2_NEEDED:
12f9d8
+      if (pr_datasz != 4)
12f9d8
+	{
12f9d8
+	  gold_warning(_("%s: corrupt .note.gnu.property section "
12f9d8
+			 "(pr_datasz for property %d is not 4)"),
12f9d8
+		       object->name().c_str(), pr_type);
12f9d8
+	  return;
12f9d8
+	}
12f9d8
+      val = elfcpp::Swap<32, false>::readval(pr_data);
12f9d8
+      break;
12f9d8
+    default:
12f9d8
+      gold_warning(_("%s: unknown program property type 0x%x "
12f9d8
+		     "in .note.gnu.property section"),
12f9d8
+		   object->name().c_str(), pr_type);
12f9d8
+      break;
12f9d8
+    }
12f9d8
+
12f9d8
+  switch (pr_type)
12f9d8
+    {
12f9d8
+    case elfcpp::GNU_PROPERTY_X86_ISA_1_USED:
12f9d8
+      this->object_isa_1_used_ |= val;
12f9d8
+      break;
12f9d8
+    case elfcpp::GNU_PROPERTY_X86_ISA_1_NEEDED:
12f9d8
+      this->isa_1_needed_ |= val;
12f9d8
+      break;
12f9d8
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_1_AND:
12f9d8
+      // If we see multiple feature props in one object, OR them together.
12f9d8
+      this->object_feature_1_ |= val;
12f9d8
+      break;
12f9d8
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_2_USED:
12f9d8
+      this->object_feature_2_used_ |= val;
12f9d8
+      break;
12f9d8
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_2_NEEDED:
12f9d8
+      this->feature_2_needed_ |= val;
12f9d8
+      break;
12f9d8
+    }
12f9d8
+}
12f9d8
+
12f9d8
+// Merge the target-specific program properties from the current object.
12f9d8
+void
12f9d8
+Target_i386::merge_gnu_properties(const Object*)
12f9d8
+{
12f9d8
+  if (this->seen_first_object_)
12f9d8
+    {
12f9d8
+      // If any object is missing the ISA_1_USED property, we must omit
12f9d8
+      // it from the output file.
12f9d8
+      if (this->object_isa_1_used_ == 0)
12f9d8
+	this->isa_1_used_ = 0;
12f9d8
+      else if (this->isa_1_used_ != 0)
12f9d8
+	this->isa_1_used_ |= this->object_isa_1_used_;
12f9d8
+      this->feature_1_ &= this->object_feature_1_;
12f9d8
+      // If any object is missing the FEATURE_2_USED property, we must
12f9d8
+      // omit it from the output file.
12f9d8
+      if (this->object_feature_2_used_ == 0)
12f9d8
+	this->feature_2_used_ = 0;
12f9d8
+      else if (this->feature_2_used_ != 0)
12f9d8
+	this->feature_2_used_ |= this->object_feature_2_used_;
12f9d8
+    }
12f9d8
+  else
12f9d8
+    {
12f9d8
+      this->isa_1_used_ = this->object_isa_1_used_;
12f9d8
+      this->feature_1_ = this->object_feature_1_;
12f9d8
+      this->feature_2_used_ = this->object_feature_2_used_;
12f9d8
+      this->seen_first_object_ = true;
12f9d8
+    }
12f9d8
+  this->object_isa_1_used_ = 0;
12f9d8
+  this->object_feature_1_ = 0;
12f9d8
+  this->object_feature_2_used_ = 0;
12f9d8
+}
12f9d8
+
12f9d8
+static inline void
12f9d8
+add_property(Layout* layout, unsigned int pr_type, uint32_t val)
12f9d8
+{
12f9d8
+  unsigned char buf[4];
12f9d8
+  elfcpp::Swap<32, false>::writeval(buf, val);
12f9d8
+  layout->add_gnu_property(elfcpp::NT_GNU_PROPERTY_TYPE_0, pr_type, 4, buf);
12f9d8
+}
12f9d8
+
12f9d8
+// Finalize the target-specific program properties and add them back to
12f9d8
+// the layout.
12f9d8
+void
12f9d8
+Target_i386::do_finalize_gnu_properties(Layout* layout) const
12f9d8
+{
12f9d8
+  if (this->isa_1_used_ != 0)
12f9d8
+    add_property(layout, elfcpp::GNU_PROPERTY_X86_ISA_1_USED,
12f9d8
+		 this->isa_1_used_);
12f9d8
+  if (this->isa_1_needed_ != 0)
12f9d8
+    add_property(layout, elfcpp::GNU_PROPERTY_X86_ISA_1_NEEDED,
12f9d8
+		 this->isa_1_needed_);
12f9d8
+  if (this->feature_1_ != 0)
12f9d8
+    add_property(layout, elfcpp::GNU_PROPERTY_X86_FEATURE_1_AND,
12f9d8
+		 this->feature_1_);
12f9d8
+  if (this->feature_2_used_ != 0)
12f9d8
+    add_property(layout, elfcpp::GNU_PROPERTY_X86_FEATURE_2_USED,
12f9d8
+		 this->feature_2_used_);
12f9d8
+  if (this->feature_2_needed_ != 0)
12f9d8
+    add_property(layout, elfcpp::GNU_PROPERTY_X86_FEATURE_2_NEEDED,
12f9d8
+		 this->feature_2_needed_);
12f9d8
+}
12f9d8
+
12f9d8
 // Write the first three reserved words of the .got.plt section.
12f9d8
 // The remainder of the section is written while writing the PLT
12f9d8
 // in Output_data_plt_i386::do_write.