[PATCH] x86: Don't remove empty GNU_PROPERTY_X86_UINT32_OR_AND properties

H.J. Lu hjl.tools@gmail.com
Tue Dec 4 13:46:00 GMT 2018


For GNU_PROPERTY_X86_COMPAT_ISA_1_USED and GNU_PROPERTY_X86_UINT32_OR_AND
properties, a bit in the output pr_data field is set if it is set in any
relocatable input pr_data fields and this property is present in all
relocatable input files.  A missing property implies that its bits have
unknown values.  When all bits in the the output pr_data field are zero,
this property should not be removed from output to indicate it has zero
in all bits.

bfd/

	PR ld/23372
	* elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Don't remove
	empty properties for GNU_PROPERTY_X86_COMPAT_ISA_1_USED and
	GNU_PROPERTY_X86_UINT32_OR_AND.
	(_bfd_x86_elf_link_fixup_gnu_properties): Likewise.

ld/

	PR ld/23372
	* testsuite/ld-i386/pr23372a.d: Updated.
	* testsuite/ld-i386/pr23372c.d: Likewise.
	* testsuite/ld-x86-64/pr23372a-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23372a.d: Likewise.
	* testsuite/ld-x86-64/pr23372c-x32.d: Likewise.
	* testsuite/ld-x86-64/pr23372c.d: Likewise.
---
 bfd/elfxx-x86.c                       | 17 +++++++++++++----
 ld/testsuite/ld-i386/pr23372a.d       |  5 +++++
 ld/testsuite/ld-i386/pr23372c.d       |  5 +++++
 ld/testsuite/ld-x86-64/pr23372a-x32.d |  5 +++++
 ld/testsuite/ld-x86-64/pr23372a.d     |  5 +++++
 ld/testsuite/ld-x86-64/pr23372c-x32.d |  5 +++++
 ld/testsuite/ld-x86-64/pr23372c.d     |  5 +++++
 7 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index 05f5c6a2f9..bf205d6d3b 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -2414,9 +2414,14 @@ _bfd_x86_elf_merge_gnu_properties (struct bfd_link_info *info,
 	      aprop->pr_kind = property_remove;
 	      updated = TRUE;
 	    }
-	  return updated;
 	}
-      goto or_property;
+      else
+	{
+	  number = aprop->u.number;
+	  aprop->u.number = number | bprop->u.number;
+	  updated = number != (unsigned int) aprop->u.number;
+	}
+      return updated;
     }
   else if (pr_type == GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
 	   || (pr_type >= GNU_PROPERTY_X86_UINT32_OR_LO
@@ -2424,7 +2429,6 @@ _bfd_x86_elf_merge_gnu_properties (struct bfd_link_info *info,
     {
       if (aprop != NULL && bprop != NULL)
 	{
-or_property:
 	  number = aprop->u.number;
 	  aprop->u.number = number | bprop->u.number;
 	  /* Remove the property if all bits are empty.  */
@@ -2941,7 +2945,12 @@ _bfd_x86_elf_link_fixup_gnu_properties (struct bfd_link_info *info,
 	  || (type >= GNU_PROPERTY_X86_UINT32_OR_AND_LO
 	      && type <= GNU_PROPERTY_X86_UINT32_OR_AND_HI))
 	{
-	  if (p->property.u.number == 0)
+	  if (p->property.u.number == 0
+	      && (type == GNU_PROPERTY_X86_COMPAT_ISA_1_NEEDED
+		  || (type >= GNU_PROPERTY_X86_UINT32_AND_LO
+		      && type <= GNU_PROPERTY_X86_UINT32_AND_HI)
+		  || (type >= GNU_PROPERTY_X86_UINT32_OR_LO
+		      && type <= GNU_PROPERTY_X86_UINT32_OR_HI)))
 	    {
 	      /* Remove empty property.  */
 	      *listp = p->next;
diff --git a/ld/testsuite/ld-i386/pr23372a.d b/ld/testsuite/ld-i386/pr23372a.d
index b75523bdc3..7af7efb065 100644
--- a/ld/testsuite/ld-i386/pr23372a.d
+++ b/ld/testsuite/ld-i386/pr23372a.d
@@ -3,3 +3,8 @@
 #as: --32
 #ld: -r -m elf_i386
 #readelf: -n
+
+Displaying notes found in: .note.gnu.property
+  Owner                 Data size	Description
+  GNU                  0x[0-9a-f]+	NT_GNU_PROPERTY_TYPE_0
+      Properties: x86 ISA used: 
diff --git a/ld/testsuite/ld-i386/pr23372c.d b/ld/testsuite/ld-i386/pr23372c.d
index 987ae4cfe5..d5bcc4d7b2 100644
--- a/ld/testsuite/ld-i386/pr23372c.d
+++ b/ld/testsuite/ld-i386/pr23372c.d
@@ -3,3 +3,8 @@
 #as: --32
 #ld: -r -m elf_i386
 #readelf: -n
+
+Displaying notes found in: .note.gnu.property
+  Owner                 Data size	Description
+  GNU                  0x[0-9a-f]+	NT_GNU_PROPERTY_TYPE_0
+      Properties: x86 ISA used: 
diff --git a/ld/testsuite/ld-x86-64/pr23372a-x32.d b/ld/testsuite/ld-x86-64/pr23372a-x32.d
index 9f93642364..84e4602994 100644
--- a/ld/testsuite/ld-x86-64/pr23372a-x32.d
+++ b/ld/testsuite/ld-x86-64/pr23372a-x32.d
@@ -3,3 +3,8 @@
 #as: --x32
 #ld: -r -m elf32_x86_64
 #readelf: -n
+
+Displaying notes found in: .note.gnu.property
+  Owner                 Data size	Description
+  GNU                  0x[0-9a-f]+	NT_GNU_PROPERTY_TYPE_0
+      Properties: x86 ISA used: 
diff --git a/ld/testsuite/ld-x86-64/pr23372a.d b/ld/testsuite/ld-x86-64/pr23372a.d
index ee688fc2e2..d988a6a4cb 100644
--- a/ld/testsuite/ld-x86-64/pr23372a.d
+++ b/ld/testsuite/ld-x86-64/pr23372a.d
@@ -3,3 +3,8 @@
 #as: --64 -defsym __64_bit__=1
 #ld: -r -m elf_x86_64
 #readelf: -n
+
+Displaying notes found in: .note.gnu.property
+  Owner                 Data size	Description
+  GNU                  0x[0-9a-f]+	NT_GNU_PROPERTY_TYPE_0
+      Properties: x86 ISA used: 
diff --git a/ld/testsuite/ld-x86-64/pr23372c-x32.d b/ld/testsuite/ld-x86-64/pr23372c-x32.d
index 863f4b7e44..efd6e84aa2 100644
--- a/ld/testsuite/ld-x86-64/pr23372c-x32.d
+++ b/ld/testsuite/ld-x86-64/pr23372c-x32.d
@@ -3,3 +3,8 @@
 #as: --x32
 #ld: -r -m elf32_x86_64
 #readelf: -n
+
+Displaying notes found in: .note.gnu.property
+  Owner                 Data size	Description
+  GNU                  0x[0-9a-f]+	NT_GNU_PROPERTY_TYPE_0
+      Properties: x86 ISA used: 
diff --git a/ld/testsuite/ld-x86-64/pr23372c.d b/ld/testsuite/ld-x86-64/pr23372c.d
index 23bdaa786a..f56859a014 100644
--- a/ld/testsuite/ld-x86-64/pr23372c.d
+++ b/ld/testsuite/ld-x86-64/pr23372c.d
@@ -3,3 +3,8 @@
 #as: --64 -defsym __64_bit__=1
 #ld: -r -m elf_x86_64
 #readelf: -n
+
+Displaying notes found in: .note.gnu.property
+  Owner                 Data size	Description
+  GNU                  0x[0-9a-f]+	NT_GNU_PROPERTY_TYPE_0
+      Properties: x86 ISA used: 
-- 
2.19.2



More information about the Binutils mailing list