summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2020-10-06 15:38:23 -0700
committerH.J. Lu <hjl.tools@gmail.com>2020-10-07 06:55:12 -0700
commit5c1bd3f52c69d00f56f9cb71737396c2651e508d (patch)
tree8cece4234256ae9426e2017b820b9a5d74cbb146
parent93b9bf1651a04cb5334435bbb535ff706cf28ffc (diff)
downloadbinutils-gdb-5c1bd3f52c69d00f56f9cb71737396c2651e508d.tar.gz
x86: Properly merge -z ibt and -z shstk
Merge -z ibt and -z shstk only with GNU_PROPERTY_X86_FEATURE_1_AND, not any GNU_PROPERTY_X86_UINT32_AND_XXX properties. bfd/ PR ld/26711 * elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Merge -z ibt and -z shstk only with GNU_PROPERTY_X86_FEATURE_1_AND. ld/ PR ld/26711 * testsuite/ld-i386/i386.exp: Run ld/26711 tests. * testsuite/ld-x86-64/x86-64.exp: Likewise. * testsuite/ld-i386/pr26711-1.d: Likewise. * testsuite/ld-i386/pr26711-2.d: Likewise. * testsuite/ld-i386/pr26711-3.d: Likewise. * testsuite/ld-x86-64/pr26711-1-x32.d: Likewise. * testsuite/ld-x86-64/pr26711-1.d: Likewise. * testsuite/ld-x86-64/pr26711-2-x32.d: Likewise. * testsuite/ld-x86-64/pr26711-2.d: Likewise. * testsuite/ld-x86-64/pr26711-3-x32.d: Likewise. * testsuite/ld-x86-64/pr26711-3.d: Likewise. * testsuite/ld-x86-64/pr26711.s: Likewise. (cherry picked from commit 574df58f5295ef2728526e6a73b5f429b05f2a8c)
-rw-r--r--bfd/ChangeLog6
-rw-r--r--bfd/elfxx-x86.c31
-rw-r--r--ld/ChangeLog16
-rw-r--r--ld/testsuite/ld-i386/i386.exp3
-rw-r--r--ld/testsuite/ld-i386/pr26711-1.d10
-rw-r--r--ld/testsuite/ld-i386/pr26711-2.d10
-rw-r--r--ld/testsuite/ld-i386/pr26711-3.d10
-rw-r--r--ld/testsuite/ld-x86-64/pr26711-1-x32.d10
-rw-r--r--ld/testsuite/ld-x86-64/pr26711-1.d10
-rw-r--r--ld/testsuite/ld-x86-64/pr26711-2-x32.d10
-rw-r--r--ld/testsuite/ld-x86-64/pr26711-2.d10
-rw-r--r--ld/testsuite/ld-x86-64/pr26711-3-x32.d10
-rw-r--r--ld/testsuite/ld-x86-64/pr26711-3.d10
-rw-r--r--ld/testsuite/ld-x86-64/pr26711.s33
-rw-r--r--ld/testsuite/ld-x86-64/x86-64.exp6
15 files changed, 173 insertions, 12 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index d533d05793e..ad6f9346c05 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,9 @@
+2020-10-07 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/26711
+ * elfxx-x86.c (_bfd_x86_elf_merge_gnu_properties): Merge -z ibt
+ and -z shstk only with GNU_PROPERTY_X86_FEATURE_1_AND.
+
2020-09-10 Alan Modra <amodra@gmail.com>
Apply from master
diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c
index fc783b0e988..e79eee64240 100644
--- a/bfd/elfxx-x86.c
+++ b/bfd/elfxx-x86.c
@@ -2488,15 +2488,19 @@ _bfd_x86_elf_merge_gnu_properties (struct bfd_link_info *info,
abort ();
if (aprop != NULL && bprop != NULL)
{
- features = 0;
- if (htab->params->ibt)
- features = GNU_PROPERTY_X86_FEATURE_1_IBT;
- if (htab->params->shstk)
- features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
number = aprop->u.number;
- /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
- GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
- aprop->u.number = (number & bprop->u.number) | features;
+ aprop->u.number = number & bprop->u.number;
+ if (pr_type == GNU_PROPERTY_X86_FEATURE_1_AND)
+ {
+ features = 0;
+ if (htab->params->ibt)
+ features = GNU_PROPERTY_X86_FEATURE_1_IBT;
+ if (htab->params->shstk)
+ features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
+ /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
+ GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
+ aprop->u.number |= features;
+ }
updated = number != (unsigned int) aprop->u.number;
/* Remove the property if all feature bits are cleared. */
if (aprop->u.number == 0)
@@ -2508,10 +2512,13 @@ _bfd_x86_elf_merge_gnu_properties (struct bfd_link_info *info,
have them. Set IBT and SHSTK properties for -z ibt and -z
shstk if needed. */
features = 0;
- if (htab->params->ibt)
- features = GNU_PROPERTY_X86_FEATURE_1_IBT;
- if (htab->params->shstk)
- features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
+ if (pr_type == GNU_PROPERTY_X86_FEATURE_1_AND)
+ {
+ if (htab->params->ibt)
+ features = GNU_PROPERTY_X86_FEATURE_1_IBT;
+ if (htab->params->shstk)
+ features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
+ }
if (features)
{
if (aprop != NULL)
diff --git a/ld/ChangeLog b/ld/ChangeLog
index bb9dddb0c83..5366ddf8301 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,19 @@
+2020-10-07 H.J. Lu <hongjiu.lu@intel.com>
+
+ PR ld/26711
+ * testsuite/ld-i386/i386.exp: Run ld/26711 tests.
+ * testsuite/ld-x86-64/x86-64.exp: Likewise.
+ * testsuite/ld-i386/pr26711-1.d: Likewise.
+ * testsuite/ld-i386/pr26711-2.d: Likewise.
+ * testsuite/ld-i386/pr26711-3.d: Likewise.
+ * testsuite/ld-x86-64/pr26711-1-x32.d: Likewise.
+ * testsuite/ld-x86-64/pr26711-1.d: Likewise.
+ * testsuite/ld-x86-64/pr26711-2-x32.d: Likewise.
+ * testsuite/ld-x86-64/pr26711-2.d: Likewise.
+ * testsuite/ld-x86-64/pr26711-3-x32.d: Likewise.
+ * testsuite/ld-x86-64/pr26711-3.d: Likewise.
+ * testsuite/ld-x86-64/pr26711.s: Likewise.
+
2020-09-10 Alan Modra <amodra@gmail.com>
Apply from master
diff --git a/ld/testsuite/ld-i386/i386.exp b/ld/testsuite/ld-i386/i386.exp
index 7bb3636d3b0..f477156f0b6 100644
--- a/ld/testsuite/ld-i386/i386.exp
+++ b/ld/testsuite/ld-i386/i386.exp
@@ -496,6 +496,9 @@ run_dump_test "pr23930"
run_dump_test "pr24322a"
run_dump_test "pr24322b"
run_dump_test "align-branch-1"
+run_dump_test "pr26711-1"
+run_dump_test "pr26711-2"
+run_dump_test "pr26711-3"
if { !([istarget "i?86-*-linux*"]
|| [istarget "i?86-*-gnu*"]
diff --git a/ld/testsuite/ld-i386/pr26711-1.d b/ld/testsuite/ld-i386/pr26711-1.d
new file mode 100644
index 00000000000..24a8429fbca
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr26711-1.d
@@ -0,0 +1,10 @@
+#source: ../ld-x86-64/pr26711.s
+#source: ../ld-x86-64/start.s
+#as: --32 -mx86-used-note=no
+#ld: -m elf_i386 -z ibt
+#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 feature: IBT
diff --git a/ld/testsuite/ld-i386/pr26711-2.d b/ld/testsuite/ld-i386/pr26711-2.d
new file mode 100644
index 00000000000..e92559fa70f
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr26711-2.d
@@ -0,0 +1,10 @@
+#source: ../ld-x86-64/pr26711.s
+#source: ../ld-x86-64/start.s
+#as: --32 -mx86-used-note=no
+#ld: -m elf_i386 -z shstk
+#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 feature: SHSTK
diff --git a/ld/testsuite/ld-i386/pr26711-3.d b/ld/testsuite/ld-i386/pr26711-3.d
new file mode 100644
index 00000000000..df9bfced540
--- /dev/null
+++ b/ld/testsuite/ld-i386/pr26711-3.d
@@ -0,0 +1,10 @@
+#source: ../ld-x86-64/pr26711.s
+#source: ../ld-x86-64/start.s
+#as: --32 -mx86-used-note=no
+#ld: -m elf_i386 -z ibt -z shstk
+#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 feature: IBT, SHSTK
diff --git a/ld/testsuite/ld-x86-64/pr26711-1-x32.d b/ld/testsuite/ld-x86-64/pr26711-1-x32.d
new file mode 100644
index 00000000000..67013195b2e
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr26711-1-x32.d
@@ -0,0 +1,10 @@
+#source: pr26711.s
+#source: start.s
+#as: --x32 -mx86-used-note=no
+#ld: -m elf32_x86_64 -z ibt
+#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 feature: IBT
diff --git a/ld/testsuite/ld-x86-64/pr26711-1.d b/ld/testsuite/ld-x86-64/pr26711-1.d
new file mode 100644
index 00000000000..d8e3cbf19ba
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr26711-1.d
@@ -0,0 +1,10 @@
+#source: pr26711.s
+#source: start.s
+#as: --64 -defsym __64_bit__=1 -mx86-used-note=no
+#ld: -m elf_x86_64 -z ibt
+#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 feature: IBT
diff --git a/ld/testsuite/ld-x86-64/pr26711-2-x32.d b/ld/testsuite/ld-x86-64/pr26711-2-x32.d
new file mode 100644
index 00000000000..9822f8df4dc
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr26711-2-x32.d
@@ -0,0 +1,10 @@
+#source: pr26711.s
+#source: start.s
+#as: --x32 -mx86-used-note=no
+#ld: -m elf32_x86_64 -z shstk
+#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 feature: SHSTK
diff --git a/ld/testsuite/ld-x86-64/pr26711-2.d b/ld/testsuite/ld-x86-64/pr26711-2.d
new file mode 100644
index 00000000000..e24cfbfc0b0
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr26711-2.d
@@ -0,0 +1,10 @@
+#source: pr26711.s
+#source: start.s
+#as: --64 -defsym __64_bit__=1 -mx86-used-note=no
+#ld: -m elf_x86_64 -z shstk
+#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 feature: SHSTK
diff --git a/ld/testsuite/ld-x86-64/pr26711-3-x32.d b/ld/testsuite/ld-x86-64/pr26711-3-x32.d
new file mode 100644
index 00000000000..0661c7d5236
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr26711-3-x32.d
@@ -0,0 +1,10 @@
+#source: pr26711.s
+#source: start.s
+#as: --x32 -mx86-used-note=no
+#ld: -m elf32_x86_64 -z ibt -z shstk
+#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 feature: IBT, SHSTK
diff --git a/ld/testsuite/ld-x86-64/pr26711-3.d b/ld/testsuite/ld-x86-64/pr26711-3.d
new file mode 100644
index 00000000000..87bc3ccfb05
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr26711-3.d
@@ -0,0 +1,10 @@
+#source: pr26711.s
+#source: start.s
+#as: --64 -defsym __64_bit__=1 -mx86-used-note=no
+#ld: -m elf_x86_64 -z ibt -z shstk
+#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 feature: IBT, SHSTK
diff --git a/ld/testsuite/ld-x86-64/pr26711.s b/ld/testsuite/ld-x86-64/pr26711.s
new file mode 100644
index 00000000000..8fa185d42a7
--- /dev/null
+++ b/ld/testsuite/ld-x86-64/pr26711.s
@@ -0,0 +1,33 @@
+ .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 0xc0001002 /* pr_type. */
+ .long 4f - 3f /* pr_datasz. */
+3:
+ .long 0x30
+4:
+.ifdef __64_bit__
+ .p2align 3
+.else
+ .p2align 2
+.endif
+5:
+
+ .text
+ .globl foo
+ .type foo, @function
+foo:
+ ret
diff --git a/ld/testsuite/ld-x86-64/x86-64.exp b/ld/testsuite/ld-x86-64/x86-64.exp
index 88f75e0e431..625d5dcb229 100644
--- a/ld/testsuite/ld-x86-64/x86-64.exp
+++ b/ld/testsuite/ld-x86-64/x86-64.exp
@@ -461,6 +461,12 @@ run_dump_test "pr24721-x32"
run_dump_test "pr24905"
run_dump_test "pr24905-x32"
run_dump_test "align-branch-1"
+run_dump_test "pr26711-1"
+run_dump_test "pr26711-1-x32"
+run_dump_test "pr26711-2"
+run_dump_test "pr26711-2-x32"
+run_dump_test "pr26711-3"
+run_dump_test "pr26711-3-x32"
if { ![istarget "x86_64-*-linux*"] && ![istarget "x86_64-*-nacl*"]} {
return