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

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