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

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