From 574df58f5295ef2728526e6a73b5f429b05f2a8c Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Tue, 6 Oct 2020 15:38:23 -0700 Subject: 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. --- bfd/elfxx-x86.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'bfd/elfxx-x86.c') diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c index e58ddc1..143aae4 100644 --- a/bfd/elfxx-x86.c +++ b/bfd/elfxx-x86.c @@ -2417,15 +2417,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) @@ -2437,10 +2441,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) -- cgit v1.1