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

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