This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] x86: Properly set IBT and SHSTK properties for -z ibt/shstk


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=44b27f959abf267fc9ec228f4131c932597b01d4

commit 44b27f959abf267fc9ec228f4131c932597b01d4
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Mar 13 14:38:15 2019 +0800

    x86: Properly set IBT and SHSTK properties for -z ibt/shstk
    
    There should be no AND properties if some input doesn't have them.  We
    should set IBT and SHSTK properties for -z ibt and -z shstk if needed.
    
    bfd/
    
    	PR ld/24322
    	* elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Properly
    	merge GNU_PROPERTY_X86_FEATURE_1_[IBT|SHSTK].
    
    ld/
    
    	PR ld/24322
    	* testsuite/ld-i386/i386.exp: Run PR ld/24322 tests.
    	* testsuite/ld-x86-64/x86-64.exp: Likewise.
    	* testsuite/ld-i386/pr24322a.d: New file.
    	* testsuite/ld-i386/pr24322b.d: Likewise.
    	* testsuite/ld-x86-64/pr24322a-x32.d: Likewise.
    	* testsuite/ld-x86-64/pr24322a.d: Likewise.
    	* testsuite/ld-x86-64/pr24322b-x32.d: Likewise.
    	* testsuite/ld-x86-64/pr24322b.d: Likewise.
    	* testsuite/ld-x86-64/pr24322a.s: Likewise.
    	* testsuite/ld-x86-64/pr24322b.s: Likewise.
    	* testsuite/ld-x86-64/pr24322c.s: Likewise.

Diff:
---
 bfd/ChangeLog                         |  6 ++++++
 bfd/elfxx-x86.c                       | 12 ++++++------
 ld/ChangeLog                          | 15 +++++++++++++++
 ld/testsuite/ld-i386/i386.exp         |  2 ++
 ld/testsuite/ld-i386/pr24322a.d       | 12 ++++++++++++
 ld/testsuite/ld-i386/pr24322b.d       | 12 ++++++++++++
 ld/testsuite/ld-x86-64/pr24322a-x32.d | 12 ++++++++++++
 ld/testsuite/ld-x86-64/pr24322a.d     | 12 ++++++++++++
 ld/testsuite/ld-x86-64/pr24322a.s     | 27 +++++++++++++++++++++++++++
 ld/testsuite/ld-x86-64/pr24322b-x32.d | 12 ++++++++++++
 ld/testsuite/ld-x86-64/pr24322b.d     | 12 ++++++++++++
 ld/testsuite/ld-x86-64/pr24322b.s     |  4 ++++
 ld/testsuite/ld-x86-64/pr24322c.s     | 27 +++++++++++++++++++++++++++
 ld/testsuite/ld-x86-64/x86-64.exp     |  4 ++++
 14 files changed, 163 insertions(+), 6 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 3e7d683..39b5500 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2019-03-13  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/24322
+	* elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Properly
+	merge GNU_PROPERTY_X86_FEATURE_1_[IBT|SHSTK].
+
 2019-03-12  Alan Modra  <amodra@gmail.com>
 
 	* coffcode.h (buy_and_read): Delete unnecessary forward decl.  Add
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index d6b851c..584a75f 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -2496,6 +2496,9 @@ _bfd_x86_elf_merge_gnu_properties (struct bfd_link_info *info,
 	}
       else
 	{
+	  /* There should be no AND properties since some input doesn't
+	     have them.  Set IBT and SHSTK properties for -z ibt and -z
+	     shstk if needed.  */
 	  features = 0;
 	  if (info->ibt)
 	    features = GNU_PROPERTY_X86_FEATURE_1_IBT;
@@ -2503,18 +2506,15 @@ _bfd_x86_elf_merge_gnu_properties (struct bfd_link_info *info,
 	    features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
 	  if (features)
 	    {
-	      /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
-		 GNU_PROPERTY_X86_FEATURE_1_SHSTK.  */
 	      if (aprop != NULL)
 		{
-		  number = aprop->u.number;
-		  aprop->u.number = number | features;
-		  updated = number != (unsigned int) aprop->u.number;
+		  updated = features != (unsigned int) aprop->u.number;
+		  aprop->u.number = features;
 		}
 	      else
 		{
-		  bprop->u.number |= features;
 		  updated = TRUE;
+		  bprop->u.number = features;
 		}
 	    }
 	  else if (aprop != NULL)
diff --git a/ld/ChangeLog b/ld/ChangeLog
index c2cbe87..3722d4f 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,18 @@
+2019-03-13  H.J. Lu  <hongjiu.lu@intel.com>
+
+	PR ld/24322
+	* testsuite/ld-i386/i386.exp: Run PR ld/24322 tests.
+	* testsuite/ld-x86-64/x86-64.exp: Likewise.
+	* testsuite/ld-i386/pr24322a.d: New file.
+	* testsuite/ld-i386/pr24322b.d: Likewise.
+	* testsuite/ld-x86-64/pr24322a-x32.d: Likewise.
+	* testsuite/ld-x86-64/pr24322a.d: Likewise.
+	* testsuite/ld-x86-64/pr24322b-x32.d: Likewise.
+	* testsuite/ld-x86-64/pr24322b.d: Likewise.
+	* testsuite/ld-x86-64/pr24322a.s: Likewise.
+	* testsuite/ld-x86-64/pr24322b.s: Likewise.
+	* testsuite/ld-x86-64/pr24322c.s: Likewise.
+
 2019-03-06  Nick Bowler  <nbowler@draconx.ca>
 
 	PR 24289
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index e51a4c3..1a1a750 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -483,6 +483,8 @@ run_dump_test "pr23486c"
 run_dump_test "pr23486d"
 run_dump_test "pr23854"
 run_dump_test "pr23930"
+run_dump_test "pr24322a"
+run_dump_test "pr24322b"
 
 if { !([istarget "i?86-*-linux*"]
        || [istarget "i?86-*-gnu*"]
diff --git a/ld/testsuite/ld-i386/pr24322a.d b/ld/testsuite/ld-i386/pr24322a.d
new file mode 100644
index 0000000..a00ace3
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr24322a.d
@@ -0,0 +1,12 @@
+#source: ../ld-x86-64/pr24322a.s
+#source: ../ld-x86-64/pr24322b.s
+#as: --32 -mx86-used-note=yes
+#ld: -z shstk -m elf_i386
+#readelf: -n
+
+Displaying notes found in: .note.gnu.property
+  Owner                 Data size	Description
+  GNU                  0x00000024	NT_GNU_PROPERTY_TYPE_0
+      Properties: x86 feature: SHSTK
+	x86 ISA used: <None>
+	x86 feature used: x86
diff --git a/ld/testsuite/ld-i386/pr24322b.d b/ld/testsuite/ld-i386/pr24322b.d
new file mode 100644
index 0000000..8c66096
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr24322b.d
@@ -0,0 +1,12 @@
+#source: ../ld-x86-64/pr24322c.s
+#source: ../ld-x86-64/pr24322b.s
+#as: --32 -mx86-used-note=yes
+#ld: -z shstk -m elf_i386
+#readelf: -n
+
+Displaying notes found in: .note.gnu.property
+  Owner                 Data size	Description
+  GNU                  0x00000024	NT_GNU_PROPERTY_TYPE_0
+      Properties: x86 feature: SHSTK
+	x86 ISA used: <None>
+	x86 feature used: x86
diff --git a/ld/testsuite/ld-x86-64/pr24322a-x32.d b/ld/testsuite/ld-x86-64/pr24322a-x32.d
new file mode 100644
index 0000000..7f06a65
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr24322a-x32.d
@@ -0,0 +1,12 @@
+#source: pr24322a.s
+#source: pr24322b.s
+#as: --x32 -mx86-used-note=yes
+#ld: -z shstk -m elf32_x86_64
+#readelf: -n
+
+Displaying notes found in: .note.gnu.property
+  Owner                 Data size	Description
+  GNU                  0x00000024	NT_GNU_PROPERTY_TYPE_0
+      Properties: x86 feature: SHSTK
+	x86 ISA used: <None>
+	x86 feature used: x86
diff --git a/ld/testsuite/ld-x86-64/pr24322a.d b/ld/testsuite/ld-x86-64/pr24322a.d
new file mode 100644
index 0000000..4b992b4
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr24322a.d
@@ -0,0 +1,12 @@
+#source: pr24322a.s
+#source: pr24322b.s
+#as: --64 -defsym __64_bit__=1 -mx86-used-note=yes
+#ld: -z shstk -melf_x86_64
+#readelf: -n
+
+Displaying notes found in: .note.gnu.property
+  Owner                 Data size	Description
+  GNU                  0x00000030	NT_GNU_PROPERTY_TYPE_0
+      Properties: x86 feature: SHSTK
+	x86 ISA used: <None>
+	x86 feature used: x86
diff --git a/ld/testsuite/ld-x86-64/pr24322a.s b/ld/testsuite/ld-x86-64/pr24322a.s
new file mode 100644
index 0000000..15989d6
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr24322a.s
@@ -0,0 +1,27 @@
+	.section ".note.gnu.property", "a"
+.ifdef __64_bit__
+	.p2align 3
+.else
+	.p2align 2
+.endif
+	.long 1f - 0f		/* name length */
+	.long 5f - 2f		/* data length */
+	.long 5			/* note type */
+0:	.asciz "GNU"		/* vendor name */
+1:
+.ifdef __64_bit__
+	.p2align 3
+.else
+	.p2align 2
+.endif
+2:	.long 0xc0000002	/* pr_type.  */
+	.long 4f - 3f		/* pr_datasz.  */
+3:
+	.long 0x3
+4:
+.ifdef __64_bit__
+	.p2align 3
+.else
+	.p2align 2
+.endif
+5:
diff --git a/ld/testsuite/ld-x86-64/pr24322b-x32.d b/ld/testsuite/ld-x86-64/pr24322b-x32.d
new file mode 100644
index 0000000..3199cb1
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr24322b-x32.d
@@ -0,0 +1,12 @@
+#source: pr24322c.s
+#source: pr24322b.s
+#as: --x32 -mx86-used-note=yes
+#ld: -z shstk -m elf32_x86_64
+#readelf: -n
+
+Displaying notes found in: .note.gnu.property
+  Owner                 Data size	Description
+  GNU                  0x00000024	NT_GNU_PROPERTY_TYPE_0
+      Properties: x86 feature: SHSTK
+	x86 ISA used: <None>
+	x86 feature used: x86
diff --git a/ld/testsuite/ld-x86-64/pr24322b.d b/ld/testsuite/ld-x86-64/pr24322b.d
new file mode 100644
index 0000000..b391774
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr24322b.d
@@ -0,0 +1,12 @@
+#source: pr24322c.s
+#source: pr24322b.s
+#as: --64 -defsym __64_bit__=1 -mx86-used-note=yes
+#ld: -z shstk -melf_x86_64
+#readelf: -n
+
+Displaying notes found in: .note.gnu.property
+  Owner                 Data size	Description
+  GNU                  0x00000030	NT_GNU_PROPERTY_TYPE_0
+      Properties: x86 feature: SHSTK
+	x86 ISA used: <None>
+	x86 feature used: x86
diff --git a/ld/testsuite/ld-x86-64/pr24322b.s b/ld/testsuite/ld-x86-64/pr24322b.s
new file mode 100644
index 0000000..3681235
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr24322b.s
@@ -0,0 +1,4 @@
+	.text
+	.global _start
+_start:
+	ret
diff --git a/ld/testsuite/ld-x86-64/pr24322c.s b/ld/testsuite/ld-x86-64/pr24322c.s
new file mode 100644
index 0000000..6a6b517
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr24322c.s
@@ -0,0 +1,27 @@
+	.section ".note.gnu.property", "a"
+.ifdef __64_bit__
+	.p2align 3
+.else
+	.p2align 2
+.endif
+	.long 1f - 0f		/* name length */
+	.long 5f - 2f		/* data length */
+	.long 5			/* note type */
+0:	.asciz "GNU"		/* vendor name */
+1:
+.ifdef __64_bit__
+	.p2align 3
+.else
+	.p2align 2
+.endif
+2:	.long 0xc0000002	/* pr_type.  */
+	.long 4f - 3f		/* pr_datasz.  */
+3:
+	.long 0x0
+4:
+.ifdef __64_bit__
+	.p2align 3
+.else
+	.p2align 2
+.endif
+5:
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index b03aace..47d92c9 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -426,6 +426,10 @@ run_dump_test "pr23930"
 run_dump_test "pr23930-x32"
 run_dump_test "pr24151a"
 run_dump_test "pr24151a-x32"
+run_dump_test "pr24322a"
+run_dump_test "pr24322a-x32"
+run_dump_test "pr24322b"
+run_dump_test "pr24322b-x32"
 
 if { ![istarget "x86_64-*-linux*"] && ![istarget "x86_64-*-nacl*"]} {
     return


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]