13ae24
# Do not enable IBT when an object file contains code but no GNU Property notes.  (#1687774)
13ae24
13ae24
diff -rup binutils.orig/bfd/elfxx-x86.c binutils-2.30/bfd/elfxx-x86.c
13ae24
--- binutils.orig/bfd/elfxx-x86.c	2019-03-13 10:19:07.715406452 +0000
13ae24
+++ binutils-2.30/bfd/elfxx-x86.c	2019-03-13 10:20:01.255975385 +0000
13ae24
@@ -2377,6 +2377,9 @@ _bfd_x86_elf_merge_gnu_properties (struc
13ae24
 	}
13ae24
       else
13ae24
 	{
13ae24
+	  /* There should be no AND properties since some input doesn't
13ae24
+	     have them.  Set IBT and SHSTK properties for -z ibt and -z
13ae24
+	     shstk if needed.  */
13ae24
 	  features = 0;
13ae24
 	  if (info->ibt)
13ae24
 	    features = GNU_PROPERTY_X86_FEATURE_1_IBT;
13ae24
@@ -2384,18 +2387,15 @@ _bfd_x86_elf_merge_gnu_properties (struc
13ae24
 	    features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
13ae24
 	  if (features)
13ae24
 	    {
13ae24
-	      /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
13ae24
-		 GNU_PROPERTY_X86_FEATURE_1_SHSTK.  */
13ae24
 	      if (aprop != NULL)
13ae24
 		{
13ae24
-		  number = aprop->u.number;
13ae24
-		  aprop->u.number = number | features;
13ae24
-		  updated = number != (unsigned int) aprop->u.number;
13ae24
+		  updated = features != (unsigned int) aprop->u.number;
13ae24
+		  aprop->u.number = features;
13ae24
 		}
13ae24
 	      else
13ae24
 		{
13ae24
-		  bprop->u.number |= features;
13ae24
 		  updated = TRUE;
13ae24
+		  bprop->u.number = features;
13ae24
 		}
13ae24
 	    }
13ae24
 	  else if (aprop != NULL)
13ae24
diff -rup binutils.orig/ld/testsuite/ld-i386/i386.exp binutils-2.30/ld/testsuite/ld-i386/i386.exp
13ae24
--- binutils.orig/ld/testsuite/ld-i386/i386.exp	2019-03-13 10:19:07.258410131 +0000
13ae24
+++ binutils-2.30/ld/testsuite/ld-i386/i386.exp	2019-03-13 10:20:32.995719837 +0000
13ae24
@@ -473,6 +473,8 @@ run_dump_test "pr18815"
13ae24
 run_dump_test "pr19939a"
13ae24
 run_dump_test "pr19939b"
13ae24
 run_dump_test "tlsdesc2"
13ae24
+run_dump_test "pr24322a"
13ae24
+run_dump_test "pr24322b"
13ae24
 
13ae24
 proc undefined_weak {cflags ldflags} {
13ae24
     set testname "Undefined weak symbol"
13ae24
diff -rup binutils.orig/ld/testsuite/ld-x86-64/x86-64.exp binutils-2.30/ld/testsuite/ld-x86-64/x86-64.exp
13ae24
--- binutils.orig/ld/testsuite/ld-x86-64/x86-64.exp	2019-03-13 10:19:07.323409608 +0000
13ae24
+++ binutils-2.30/ld/testsuite/ld-x86-64/x86-64.exp	2019-03-13 10:21:11.938406302 +0000
13ae24
@@ -593,6 +593,10 @@ run_dump_test "pr20253-5a"
13ae24
 run_dump_test "pr20253-5b"
13ae24
 run_dump_test "tlsdesc2"
13ae24
 run_dump_test "pr22048"
13ae24
+run_dump_test "pr24322a"
13ae24
+run_dump_test "pr24322a-x32"
13ae24
+run_dump_test "pr24322b"
13ae24
+run_dump_test "pr24322b-x32"
13ae24
 
13ae24
 proc undefined_weak {cflags ldflags} {
13ae24
     set testname "Undefined weak symbol"
13ae24
--- /dev/null	2019-03-13 08:01:41.976955507 +0000
13ae24
+++ binutils-2.30/ld/testsuite/ld-i386/pr24322a.d	2019-03-13 11:05:58.557068529 +0000
13ae24
@@ -0,0 +1,11 @@
13ae24
+#source: ../ld-x86-64/pr24322a.s
13ae24
+#source: ../ld-x86-64/pr24322b.s
13ae24
+#as: --32 
13ae24
+#ld: -z shstk -m elf_i386
13ae24
+#readelf: -n
13ae24
+
13ae24
+Displaying notes found in: .note.gnu.property
13ae24
+  Owner                 Data size	Description
13ae24
+  GNU                  0x000000..	NT_GNU_PROPERTY_TYPE_0
13ae24
+      Properties: x86 feature: SHSTK
13ae24
+
13ae24
--- /dev/null	2019-03-13 08:01:41.976955507 +0000
13ae24
+++ binutils-2.30/ld/testsuite/ld-i386/pr24322b.d	2019-03-13 11:07:19.837414751 +0000
13ae24
@@ -0,0 +1,11 @@
13ae24
+#source: ../ld-x86-64/pr24322c.s
13ae24
+#source: ../ld-x86-64/pr24322b.s
13ae24
+#as: --32 
13ae24
+#ld: -z shstk -m elf_i386
13ae24
+#readelf: -n
13ae24
+
13ae24
+Displaying notes found in: .note.gnu.property
13ae24
+  Owner                 Data size	Description
13ae24
+  GNU                  0x000000..	NT_GNU_PROPERTY_TYPE_0
13ae24
+      Properties: x86 feature: SHSTK
13ae24
+
13ae24
--- /dev/null	2019-03-13 08:01:41.976955507 +0000
13ae24
+++ binutils-2.30/ld/testsuite/ld-x86-64/pr24322a.s	2019-03-13 10:20:01.256975377 +0000
13ae24
@@ -0,0 +1,27 @@
13ae24
+	.section ".note.gnu.property", "a"
13ae24
+.ifdef __64_bit__
13ae24
+	.p2align 3
13ae24
+.else
13ae24
+	.p2align 2
13ae24
+.endif
13ae24
+	.long 1f - 0f		/* name length */
13ae24
+	.long 5f - 2f		/* data length */
13ae24
+	.long 5			/* note type */
13ae24
+0:	.asciz "GNU"		/* vendor name */
13ae24
+1:
13ae24
+.ifdef __64_bit__
13ae24
+	.p2align 3
13ae24
+.else
13ae24
+	.p2align 2
13ae24
+.endif
13ae24
+2:	.long 0xc0000002	/* pr_type.  */
13ae24
+	.long 4f - 3f		/* pr_datasz.  */
13ae24
+3:
13ae24
+	.long 0x3
13ae24
+4:
13ae24
+.ifdef __64_bit__
13ae24
+	.p2align 3
13ae24
+.else
13ae24
+	.p2align 2
13ae24
+.endif
13ae24
+5:
13ae24
--- /dev/null	2019-03-13 08:01:41.976955507 +0000
13ae24
+++ binutils-2.30/ld/testsuite/ld-x86-64/pr24322a.d	2019-03-13 11:07:47.228194433 +0000
13ae24
@@ -0,0 +1,10 @@
13ae24
+#source: pr24322a.s
13ae24
+#source: pr24322b.s
13ae24
+#as: --64 -defsym __64_bit__=1
13ae24
+#ld: -z shstk -melf_x86_64
13ae24
+#readelf: -n
13ae24
+
13ae24
+Displaying notes found in: .note.gnu.property
13ae24
+  Owner                 Data size	Description
13ae24
+  GNU                  0x000000..	NT_GNU_PROPERTY_TYPE_0
13ae24
+      Properties: x86 feature: SHSTK
13ae24
--- /dev/null	2019-03-13 08:01:41.976955507 +0000
13ae24
+++ binutils-2.30/ld/testsuite/ld-x86-64/pr24322a-x32.d	2019-03-13 11:10:46.635235620 +0000
13ae24
@@ -0,0 +1,10 @@
13ae24
+#source: pr24322a.s
13ae24
+#source: pr24322b.s
13ae24
+#as: --x32
13ae24
+#ld: -z shstk -m elf32_x86_64
13ae24
+#readelf: -n
13ae24
+
13ae24
+Displaying notes found in: .note.gnu.property
13ae24
+  Owner                 Data size	Description
13ae24
+  GNU                  0x000000..	NT_GNU_PROPERTY_TYPE_0
13ae24
+      Properties: x86 feature: SHSTK
13ae24
--- /dev/null	2019-03-13 08:01:41.976955507 +0000
13ae24
+++ binutils-2.30/ld/testsuite/ld-x86-64/pr24322b.s	2019-03-13 10:20:01.257975369 +0000
13ae24
@@ -0,0 +1,4 @@
13ae24
+	.text
13ae24
+	.global _start
13ae24
+_start:
13ae24
+	ret
13ae24
--- /dev/null	2019-03-13 08:01:41.976955507 +0000
13ae24
+++ binutils-2.30/ld/testsuite/ld-x86-64/pr24322b.d	2019-03-13 11:08:03.948059948 +0000
13ae24
@@ -0,0 +1,10 @@
13ae24
+#source: pr24322c.s
13ae24
+#source: pr24322b.s
13ae24
+#as: --64 -defsym __64_bit__=1
13ae24
+#ld: -z shstk -melf_x86_64
13ae24
+#readelf: -n
13ae24
+
13ae24
+Displaying notes found in: .note.gnu.property
13ae24
+  Owner                 Data size	Description
13ae24
+  GNU                  0x000000..	NT_GNU_PROPERTY_TYPE_0
13ae24
+      Properties: x86 feature: SHSTK
13ae24
--- /dev/null	2019-03-13 08:01:41.976955507 +0000
13ae24
+++ binutils-2.30/ld/testsuite/ld-x86-64/pr24322b-x32.d	2019-03-13 11:13:13.626524410 +0000
13ae24
@@ -0,0 +1,10 @@
13ae24
+#source: pr24322c.s
13ae24
+#source: pr24322b.s
13ae24
+#as: --x32
13ae24
+#ld: -z shstk -m elf32_x86_64
13ae24
+#readelf: -n
13ae24
+
13ae24
+Displaying notes found in: .note.gnu.property
13ae24
+  Owner                 Data size	Description
13ae24
+  GNU                  0x000000..	NT_GNU_PROPERTY_TYPE_0
13ae24
+      Properties: x86 feature: SHSTK
13ae24
--- /dev/null	2019-03-13 08:01:41.976955507 +0000
13ae24
+++ binutils-2.30/ld/testsuite/ld-x86-64/pr24322c.s	2019-03-13 10:20:01.257975369 +0000
13ae24
@@ -0,0 +1,27 @@
13ae24
+	.section ".note.gnu.property", "a"
13ae24
+.ifdef __64_bit__
13ae24
+	.p2align 3
13ae24
+.else
13ae24
+	.p2align 2
13ae24
+.endif
13ae24
+	.long 1f - 0f		/* name length */
13ae24
+	.long 5f - 2f		/* data length */
13ae24
+	.long 5			/* note type */
13ae24
+0:	.asciz "GNU"		/* vendor name */
13ae24
+1:
13ae24
+.ifdef __64_bit__
13ae24
+	.p2align 3
13ae24
+.else
13ae24
+	.p2align 2
13ae24
+.endif
13ae24
+2:	.long 0xc0000002	/* pr_type.  */
13ae24
+	.long 4f - 3f		/* pr_datasz.  */
13ae24
+3:
13ae24
+	.long 0x0
13ae24
+4:
13ae24
+.ifdef __64_bit__
13ae24
+	.p2align 3
13ae24
+.else
13ae24
+	.p2align 2
13ae24
+.endif
13ae24
+5: