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

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