bf7c0a
diff --git a/gold/i386.cc b/gold/i386.cc
bf7c0a
index bf209fe9a86..31161ff091c 100644
bf7c0a
--- a/gold/i386.cc
bf7c0a
+++ b/gold/i386.cc
bf7c0a
@@ -360,7 +360,11 @@ class Target_i386 : public Sized_target<32, false>
bf7c0a
       got_(NULL), plt_(NULL), got_plt_(NULL), got_irelative_(NULL),
bf7c0a
       got_tlsdesc_(NULL), global_offset_table_(NULL), rel_dyn_(NULL),
bf7c0a
       rel_irelative_(NULL), copy_relocs_(elfcpp::R_386_COPY),
bf7c0a
-      got_mod_index_offset_(-1U), tls_base_symbol_defined_(false)
bf7c0a
+      got_mod_index_offset_(-1U), tls_base_symbol_defined_(false),
bf7c0a
+      isa_1_used_(0), isa_1_needed_(0),
bf7c0a
+      feature_1_(0), feature_2_used_(0), feature_2_needed_(0),
bf7c0a
+      object_isa_1_used_(0), object_feature_1_(0),
bf7c0a
+      object_feature_2_used_(0), seen_first_object_(false)
bf7c0a
   { }
bf7c0a
 
bf7c0a
   // Process the relocations to determine unreferenced sections for
bf7c0a
@@ -859,6 +863,21 @@ class Target_i386 : public Sized_target<32, false>
bf7c0a
 				  this->rel_dyn_section(layout));
bf7c0a
   }
bf7c0a
 
bf7c0a
+  // Record a target-specific program property in the .note.gnu.property
bf7c0a
+  // section.
bf7c0a
+  void
bf7c0a
+  record_gnu_property(unsigned int, unsigned int, size_t,
bf7c0a
+		      const unsigned char*, const Object*);
bf7c0a
+
bf7c0a
+  // Merge the target-specific program properties from the current object.
bf7c0a
+  void
bf7c0a
+  merge_gnu_properties(const Object*);
bf7c0a
+
bf7c0a
+  // Finalize the target-specific program properties and add them back to
bf7c0a
+  // the layout.
bf7c0a
+  void
bf7c0a
+  do_finalize_gnu_properties(Layout*) const;
bf7c0a
+
bf7c0a
   // Information about this specific target which we pass to the
bf7c0a
   // general Target structure.
bf7c0a
   static const Target::Target_info i386_info;
bf7c0a
@@ -898,6 +917,26 @@ class Target_i386 : public Sized_target<32, false>
bf7c0a
   unsigned int got_mod_index_offset_;
bf7c0a
   // True if the _TLS_MODULE_BASE_ symbol has been defined.
bf7c0a
   bool tls_base_symbol_defined_;
bf7c0a
+
bf7c0a
+  // Target-specific program properties, from .note.gnu.property section.
bf7c0a
+  // Each bit represents a specific feature.
bf7c0a
+  uint32_t isa_1_used_;
bf7c0a
+  uint32_t isa_1_needed_;
bf7c0a
+  uint32_t feature_1_;
bf7c0a
+  uint32_t feature_2_used_;
bf7c0a
+  uint32_t feature_2_needed_;
bf7c0a
+  // Target-specific properties from the current object.
bf7c0a
+  // These bits get ORed into ISA_1_USED_ after all properties for the object
bf7c0a
+  // have been processed. But if either is all zeroes (as when the property
bf7c0a
+  // is absent from an object), the result should be all zeroes.
bf7c0a
+  // (See PR ld/23486.)
bf7c0a
+  uint32_t object_isa_1_used_;
bf7c0a
+  // These bits get ANDed into FEATURE_1_ after all properties for the object
bf7c0a
+  // have been processed.
bf7c0a
+  uint32_t object_feature_1_;
bf7c0a
+  uint32_t object_feature_2_used_;
bf7c0a
+  // Whether we have seen our first object, for use in initializing FEATURE_1_.
bf7c0a
+  bool seen_first_object_;
bf7c0a
 };
bf7c0a
 
bf7c0a
 const Target::Target_info Target_i386::i386_info =
bf7c0a
@@ -1042,6 +1081,126 @@ Target_i386::rel_irelative_section(Layout* layout)
bf7c0a
   return this->rel_irelative_;
bf7c0a
 }
bf7c0a
 
bf7c0a
+// Record a target-specific program property from the .note.gnu.property
bf7c0a
+// section.
bf7c0a
+void
bf7c0a
+Target_i386::record_gnu_property(
bf7c0a
+    unsigned int, unsigned int pr_type,
bf7c0a
+    size_t pr_datasz, const unsigned char* pr_data,
bf7c0a
+    const Object* object)
bf7c0a
+{
bf7c0a
+  uint32_t val = 0;
bf7c0a
+
bf7c0a
+  switch (pr_type)
bf7c0a
+    {
bf7c0a
+    case elfcpp::GNU_PROPERTY_X86_COMPAT_ISA_1_USED:
bf7c0a
+    case elfcpp::GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED:
bf7c0a
+    case elfcpp::GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED:
bf7c0a
+    case elfcpp::GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED:
bf7c0a
+    case elfcpp::GNU_PROPERTY_X86_ISA_1_USED:
bf7c0a
+    case elfcpp::GNU_PROPERTY_X86_ISA_1_NEEDED:
bf7c0a
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_1_AND:
bf7c0a
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_2_USED:
bf7c0a
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_2_NEEDED:
bf7c0a
+      if (pr_datasz != 4)
bf7c0a
+	{
bf7c0a
+	  gold_warning(_("%s: corrupt .note.gnu.property section "
bf7c0a
+			 "(pr_datasz for property %d is not 4)"),
bf7c0a
+		       object->name().c_str(), pr_type);
bf7c0a
+	  return;
bf7c0a
+	}
bf7c0a
+      val = elfcpp::Swap<32, false>::readval(pr_data);
bf7c0a
+      break;
bf7c0a
+    default:
bf7c0a
+      gold_warning(_("%s: unknown program property type 0x%x "
bf7c0a
+		     "in .note.gnu.property section"),
bf7c0a
+		   object->name().c_str(), pr_type);
bf7c0a
+      break;
bf7c0a
+    }
bf7c0a
+
bf7c0a
+  switch (pr_type)
bf7c0a
+    {
bf7c0a
+    case elfcpp::GNU_PROPERTY_X86_ISA_1_USED:
bf7c0a
+      this->object_isa_1_used_ |= val;
bf7c0a
+      break;
bf7c0a
+    case elfcpp::GNU_PROPERTY_X86_ISA_1_NEEDED:
bf7c0a
+      this->isa_1_needed_ |= val;
bf7c0a
+      break;
bf7c0a
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_1_AND:
bf7c0a
+      // If we see multiple feature props in one object, OR them together.
bf7c0a
+      this->object_feature_1_ |= val;
bf7c0a
+      break;
bf7c0a
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_2_USED:
bf7c0a
+      this->object_feature_2_used_ |= val;
bf7c0a
+      break;
bf7c0a
+    case elfcpp::GNU_PROPERTY_X86_FEATURE_2_NEEDED:
bf7c0a
+      this->feature_2_needed_ |= val;
bf7c0a
+      break;
bf7c0a
+    }
bf7c0a
+}
bf7c0a
+
bf7c0a
+// Merge the target-specific program properties from the current object.
bf7c0a
+void
bf7c0a
+Target_i386::merge_gnu_properties(const Object*)
bf7c0a
+{
bf7c0a
+  if (this->seen_first_object_)
bf7c0a
+    {
bf7c0a
+      // If any object is missing the ISA_1_USED property, we must omit
bf7c0a
+      // it from the output file.
bf7c0a
+      if (this->object_isa_1_used_ == 0)
bf7c0a
+	this->isa_1_used_ = 0;
bf7c0a
+      else if (this->isa_1_used_ != 0)
bf7c0a
+	this->isa_1_used_ |= this->object_isa_1_used_;
bf7c0a
+      this->feature_1_ &= this->object_feature_1_;
bf7c0a
+      // If any object is missing the FEATURE_2_USED property, we must
bf7c0a
+      // omit it from the output file.
bf7c0a
+      if (this->object_feature_2_used_ == 0)
bf7c0a
+	this->feature_2_used_ = 0;
bf7c0a
+      else if (this->feature_2_used_ != 0)
bf7c0a
+	this->feature_2_used_ |= this->object_feature_2_used_;
bf7c0a
+    }
bf7c0a
+  else
bf7c0a
+    {
bf7c0a
+      this->isa_1_used_ = this->object_isa_1_used_;
bf7c0a
+      this->feature_1_ = this->object_feature_1_;
bf7c0a
+      this->feature_2_used_ = this->object_feature_2_used_;
bf7c0a
+      this->seen_first_object_ = true;
bf7c0a
+    }
bf7c0a
+  this->object_isa_1_used_ = 0;
bf7c0a
+  this->object_feature_1_ = 0;
bf7c0a
+  this->object_feature_2_used_ = 0;
bf7c0a
+}
bf7c0a
+
bf7c0a
+static inline void
bf7c0a
+add_property(Layout* layout, unsigned int pr_type, uint32_t val)
bf7c0a
+{
bf7c0a
+  unsigned char buf[4];
bf7c0a
+  elfcpp::Swap<32, false>::writeval(buf, val);
bf7c0a
+  layout->add_gnu_property(elfcpp::NT_GNU_PROPERTY_TYPE_0, pr_type, 4, buf);
bf7c0a
+}
bf7c0a
+
bf7c0a
+// Finalize the target-specific program properties and add them back to
bf7c0a
+// the layout.
bf7c0a
+void
bf7c0a
+Target_i386::do_finalize_gnu_properties(Layout* layout) const
bf7c0a
+{
bf7c0a
+  if (this->isa_1_used_ != 0)
bf7c0a
+    add_property(layout, elfcpp::GNU_PROPERTY_X86_ISA_1_USED,
bf7c0a
+		 this->isa_1_used_);
bf7c0a
+  if (this->isa_1_needed_ != 0)
bf7c0a
+    add_property(layout, elfcpp::GNU_PROPERTY_X86_ISA_1_NEEDED,
bf7c0a
+		 this->isa_1_needed_);
bf7c0a
+  if (this->feature_1_ != 0)
bf7c0a
+    add_property(layout, elfcpp::GNU_PROPERTY_X86_FEATURE_1_AND,
bf7c0a
+		 this->feature_1_);
bf7c0a
+  if (this->feature_2_used_ != 0)
bf7c0a
+    add_property(layout, elfcpp::GNU_PROPERTY_X86_FEATURE_2_USED,
bf7c0a
+		 this->feature_2_used_);
bf7c0a
+  if (this->feature_2_needed_ != 0)
bf7c0a
+    add_property(layout, elfcpp::GNU_PROPERTY_X86_FEATURE_2_NEEDED,
bf7c0a
+		 this->feature_2_needed_);
bf7c0a
+}
bf7c0a
+
bf7c0a
 // Write the first three reserved words of the .got.plt section.
bf7c0a
 // The remainder of the section is written while writing the PLT
bf7c0a
 // in Output_data_plt_i386::do_write.
bf7c0a
--- binutils.orig/elfcpp/elfcpp.h	2021-06-23 12:31:04.550738064 +0100
bf7c0a
+++ binutils-2.30/elfcpp/elfcpp.h	2021-06-23 12:33:18.068875079 +0100
bf7c0a
@@ -1008,9 +1008,21 @@ enum
bf7c0a
   GNU_PROPERTY_STACK_SIZE = 1,
bf7c0a
   GNU_PROPERTY_NO_COPY_ON_PROTECTED = 2,
bf7c0a
   GNU_PROPERTY_LOPROC = 0xc0000000,
bf7c0a
-  GNU_PROPERTY_X86_ISA_1_USED = 0xc0000000,
bf7c0a
-  GNU_PROPERTY_X86_ISA_1_NEEDED = 0xc0000001,
bf7c0a
-  GNU_PROPERTY_X86_FEATURE_1_AND = 0xc0000002,
bf7c0a
+  GNU_PROPERTY_X86_COMPAT_ISA_1_USED = 0xc0000000,
bf7c0a
+  GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED = 0xc0000001,
bf7c0a
+  GNU_PROPERTY_X86_UINT32_AND_LO = 0xc0000002,
bf7c0a
+  GNU_PROPERTY_X86_UINT32_AND_HI = 0xc0007fff,
bf7c0a
+  GNU_PROPERTY_X86_UINT32_OR_LO = 0xc0008000,
bf7c0a
+  GNU_PROPERTY_X86_UINT32_OR_HI = 0xc000ffff,
bf7c0a
+  GNU_PROPERTY_X86_UINT32_OR_AND_LO = 0xc0010000,
bf7c0a
+  GNU_PROPERTY_X86_UINT32_OR_AND_HI = 0xc0017fff,
bf7c0a
+  GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED = GNU_PROPERTY_X86_UINT32_OR_LO + 0,
bf7c0a
+  GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED = GNU_PROPERTY_X86_UINT32_OR_AND_LO + 0,
bf7c0a
+  GNU_PROPERTY_X86_FEATURE_1_AND = GNU_PROPERTY_X86_UINT32_AND_LO + 0,
bf7c0a
+  GNU_PROPERTY_X86_ISA_1_NEEDED = GNU_PROPERTY_X86_UINT32_OR_LO + 2,
bf7c0a
+  GNU_PROPERTY_X86_FEATURE_2_NEEDED = GNU_PROPERTY_X86_UINT32_OR_LO + 1,
bf7c0a
+  GNU_PROPERTY_X86_ISA_1_USED = GNU_PROPERTY_X86_UINT32_OR_AND_LO + 2,
bf7c0a
+  GNU_PROPERTY_X86_FEATURE_2_USED = GNU_PROPERTY_X86_UINT32_OR_AND_LO + 1,
bf7c0a
   GNU_PROPERTY_HIPROC = 0xdfffffff,
bf7c0a
   GNU_PROPERTY_LOUSER = 0xe0000000,
bf7c0a
   GNU_PROPERTY_HIUSER = 0xffffffff
bf7c0a
--- binutils.orig/gold/i386.cc	2021-07-07 14:15:34.369441519 +0100
bf7c0a
+++ binutils-2.30/gold/i386.cc	2021-07-07 14:36:11.932838272 +0100
bf7c0a
@@ -362,9 +362,8 @@ class Target_i386 : public Sized_target<
bf7c0a
       rel_irelative_(NULL), copy_relocs_(elfcpp::R_386_COPY),
bf7c0a
       got_mod_index_offset_(-1U), tls_base_symbol_defined_(false),
bf7c0a
       isa_1_used_(0), isa_1_needed_(0),
bf7c0a
-      feature_1_(0), feature_2_used_(0), feature_2_needed_(0),
bf7c0a
-      object_isa_1_used_(0), object_feature_1_(0),
bf7c0a
-      object_feature_2_used_(0), seen_first_object_(false)
bf7c0a
+      feature_1_(0), object_feature_1_(0),
bf7c0a
+      seen_first_object_(false)
bf7c0a
   { }
bf7c0a
 
bf7c0a
   // Process the relocations to determine unreferenced sections for
bf7c0a
@@ -866,7 +865,7 @@ class Target_i386 : public Sized_target<
bf7c0a
   // Record a target-specific program property in the .note.gnu.property
bf7c0a
   // section.
bf7c0a
   void
bf7c0a
-  record_gnu_property(unsigned int, unsigned int, size_t,
bf7c0a
+  record_gnu_property(int, int, size_t,
bf7c0a
 		      const unsigned char*, const Object*);
bf7c0a
 
bf7c0a
   // Merge the target-specific program properties from the current object.
bf7c0a
@@ -923,18 +922,10 @@ class Target_i386 : public Sized_target<
bf7c0a
   uint32_t isa_1_used_;
bf7c0a
   uint32_t isa_1_needed_;
bf7c0a
   uint32_t feature_1_;
bf7c0a
-  uint32_t feature_2_used_;
bf7c0a
-  uint32_t feature_2_needed_;
bf7c0a
   // Target-specific properties from the current object.
bf7c0a
-  // These bits get ORed into ISA_1_USED_ after all properties for the object
bf7c0a
-  // have been processed. But if either is all zeroes (as when the property
bf7c0a
-  // is absent from an object), the result should be all zeroes.
bf7c0a
-  // (See PR ld/23486.)
bf7c0a
-  uint32_t object_isa_1_used_;
bf7c0a
   // These bits get ANDed into FEATURE_1_ after all properties for the object
bf7c0a
   // have been processed.
bf7c0a
   uint32_t object_feature_1_;
bf7c0a
-  uint32_t object_feature_2_used_;
bf7c0a
   // Whether we have seen our first object, for use in initializing FEATURE_1_.
bf7c0a
   bool seen_first_object_;
bf7c0a
 };
bf7c0a
@@ -1084,7 +1075,7 @@ Target_i386::rel_irelative_section(Layou
bf7c0a
 // section.
bf7c0a
 void
bf7c0a
 Target_i386::record_gnu_property(
bf7c0a
-    unsigned int, unsigned int pr_type,
bf7c0a
+    int, int pr_type,
bf7c0a
     size_t pr_datasz, const unsigned char* pr_data,
bf7c0a
     const Object* object)
bf7c0a
 {
bf7c0a
@@ -1092,15 +1083,9 @@ Target_i386::record_gnu_property(
bf7c0a
 
bf7c0a
   switch (pr_type)
bf7c0a
     {
bf7c0a
-    case elfcpp::GNU_PROPERTY_X86_COMPAT_ISA_1_USED:
bf7c0a
-    case elfcpp::GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED:
bf7c0a
-    case elfcpp::GNU_PROPERTY_X86_COMPAT_2_ISA_1_USED:
bf7c0a
-    case elfcpp::GNU_PROPERTY_X86_COMPAT_2_ISA_1_NEEDED:
bf7c0a
     case elfcpp::GNU_PROPERTY_X86_ISA_1_USED:
bf7c0a
     case elfcpp::GNU_PROPERTY_X86_ISA_1_NEEDED:
bf7c0a
     case elfcpp::GNU_PROPERTY_X86_FEATURE_1_AND:
bf7c0a
-    case elfcpp::GNU_PROPERTY_X86_FEATURE_2_USED:
bf7c0a
-    case elfcpp::GNU_PROPERTY_X86_FEATURE_2_NEEDED:
bf7c0a
       if (pr_datasz != 4)
bf7c0a
 	{
bf7c0a
 	  gold_warning(_("%s: corrupt .note.gnu.property section "
bf7c0a
@@ -1120,7 +1105,7 @@ Target_i386::record_gnu_property(
bf7c0a
   switch (pr_type)
bf7c0a
     {
bf7c0a
     case elfcpp::GNU_PROPERTY_X86_ISA_1_USED:
bf7c0a
-      this->object_isa_1_used_ |= val;
bf7c0a
+      this->isa_1_used_ |= val;
bf7c0a
       break;
bf7c0a
     case elfcpp::GNU_PROPERTY_X86_ISA_1_NEEDED:
bf7c0a
       this->isa_1_needed_ |= val;
bf7c0a
@@ -1129,12 +1114,6 @@ Target_i386::record_gnu_property(
bf7c0a
       // If we see multiple feature props in one object, OR them together.
bf7c0a
       this->object_feature_1_ |= val;
bf7c0a
       break;
bf7c0a
-    case elfcpp::GNU_PROPERTY_X86_FEATURE_2_USED:
bf7c0a
-      this->object_feature_2_used_ |= val;
bf7c0a
-      break;
bf7c0a
-    case elfcpp::GNU_PROPERTY_X86_FEATURE_2_NEEDED:
bf7c0a
-      this->feature_2_needed_ |= val;
bf7c0a
-      break;
bf7c0a
     }
bf7c0a
 }
bf7c0a
 
bf7c0a
@@ -1143,31 +1122,13 @@ void
bf7c0a
 Target_i386::merge_gnu_properties(const Object*)
bf7c0a
 {
bf7c0a
   if (this->seen_first_object_)
bf7c0a
-    {
bf7c0a
-      // If any object is missing the ISA_1_USED property, we must omit
bf7c0a
-      // it from the output file.
bf7c0a
-      if (this->object_isa_1_used_ == 0)
bf7c0a
-	this->isa_1_used_ = 0;
bf7c0a
-      else if (this->isa_1_used_ != 0)
bf7c0a
-	this->isa_1_used_ |= this->object_isa_1_used_;
bf7c0a
-      this->feature_1_ &= this->object_feature_1_;
bf7c0a
-      // If any object is missing the FEATURE_2_USED property, we must
bf7c0a
-      // omit it from the output file.
bf7c0a
-      if (this->object_feature_2_used_ == 0)
bf7c0a
-	this->feature_2_used_ = 0;
bf7c0a
-      else if (this->feature_2_used_ != 0)
bf7c0a
-	this->feature_2_used_ |= this->object_feature_2_used_;
bf7c0a
-    }
bf7c0a
+    this->feature_1_ &= this->object_feature_1_;
bf7c0a
   else
bf7c0a
     {
bf7c0a
-      this->isa_1_used_ = this->object_isa_1_used_;
bf7c0a
       this->feature_1_ = this->object_feature_1_;
bf7c0a
-      this->feature_2_used_ = this->object_feature_2_used_;
bf7c0a
       this->seen_first_object_ = true;
bf7c0a
     }
bf7c0a
-  this->object_isa_1_used_ = 0;
bf7c0a
   this->object_feature_1_ = 0;
bf7c0a
-  this->object_feature_2_used_ = 0;
bf7c0a
 }
bf7c0a
 
bf7c0a
 static inline void
bf7c0a
@@ -1192,12 +1153,6 @@ Target_i386::do_finalize_gnu_properties(
bf7c0a
   if (this->feature_1_ != 0)
bf7c0a
     add_property(layout, elfcpp::GNU_PROPERTY_X86_FEATURE_1_AND,
bf7c0a
 		 this->feature_1_);
bf7c0a
-  if (this->feature_2_used_ != 0)
bf7c0a
-    add_property(layout, elfcpp::GNU_PROPERTY_X86_FEATURE_2_USED,
bf7c0a
-		 this->feature_2_used_);
bf7c0a
-  if (this->feature_2_needed_ != 0)
bf7c0a
-    add_property(layout, elfcpp::GNU_PROPERTY_X86_FEATURE_2_NEEDED,
bf7c0a
-		 this->feature_2_needed_);
bf7c0a
 }
bf7c0a
 
bf7c0a
 // Write the first three reserved words of the .got.plt section.