aboutsummaryrefslogtreecommitdiff
path: root/bfd/elf64-x86-64.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-08-23 10:15:39 -0700
committerH.J. Lu <hjl.tools@gmail.com>2017-08-23 10:15:58 -0700
commit73784fa565bd66f1ac165816c03e5217b7d67bbc (patch)
tree00a650b903a28e8c12a40a7a836c5bf5baf9c92a /bfd/elf64-x86-64.c
parent6e41ddec97d402c6c150701da0f70d40bd6ed5ca (diff)
downloadgdb-73784fa565bd66f1ac165816c03e5217b7d67bbc.zip
gdb-73784fa565bd66f1ac165816c03e5217b7d67bbc.tar.gz
gdb-73784fa565bd66f1ac165816c03e5217b7d67bbc.tar.bz2
x86: Clear extern_protected_data for GNU_PROPERTY_NO_COPY_ON_PROTECTED
When GNU_PROPERTY_NO_COPY_ON_PROTECTED is set, it indicates that there are no copy relocations against protected data symbols. When linker sees GNU_PROPERTY_NO_COPY_ON_PROTECTED on any input relocatable file, it sets extern_protected_data to FALSE. bfd/ * elf32-i386.c (elf_i386_link_setup_gnu_properties): Set extern_protected_data to FALSE if GNU_PROPERTY_NO_COPY_ON_PROTECTED is set on any input relocatable file. * elf64-x86-64.c (elf_x86_64_link_setup_gnu_properties): Likewise. ld/ * testsuite/ld-i386/i386.exp: Run protected7. * testsuite/ld-i386/protected7.d: New file. * testsuite/ld-i386/protected7.s: Likewise. * testsuite/ld-x86-64/protected8.d: Likewise. * testsuite/ld-x86-64/protected8.s: Likewise. * testsuite/ld-x86-64/x86-64.exp: Run protected8.
Diffstat (limited to 'bfd/elf64-x86-64.c')
-rw-r--r--bfd/elf64-x86-64.c114
1 files changed, 67 insertions, 47 deletions
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 8a6bd62..244db80 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -7302,71 +7302,91 @@ elf_x86_64_link_setup_gnu_properties (struct bfd_link_info *info)
unsigned int plt_alignment, features;
struct elf_x86_64_link_hash_table *htab;
bfd *pbfd;
+ bfd *ebfd = NULL;
+ elf_property *prop;
features = 0;
if (info->ibt)
features = GNU_PROPERTY_X86_FEATURE_1_IBT;
if (info->shstk)
features |= GNU_PROPERTY_X86_FEATURE_1_SHSTK;
- if (features)
- {
- /* Turn on GNU_PROPERTY_X86_FEATURE_1_IBT and
- GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
- bfd *ebfd = NULL;
- elf_property *prop;
-
- for (pbfd = info->input_bfds;
- pbfd != NULL;
- pbfd = pbfd->link.next)
- if (bfd_get_flavour (pbfd) == bfd_target_elf_flavour
- && bfd_count_sections (pbfd) != 0)
- {
- ebfd = pbfd;
- if (elf_properties (pbfd) != NULL)
- {
- /* Find a normal input file with GNU property note. */
- prop = _bfd_elf_get_property (pbfd,
- GNU_PROPERTY_X86_FEATURE_1_AND,
- 4);
- /* Add GNU_PROPERTY_X86_FEATURE_1_IBT and
- GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
- prop->u.number |= features;
- prop->pr_kind = property_number;
- break;
- }
- }
+ /* Find a normal input file with GNU property note. */
+ for (pbfd = info->input_bfds;
+ pbfd != NULL;
+ pbfd = pbfd->link.next)
+ if (bfd_get_flavour (pbfd) == bfd_target_elf_flavour
+ && bfd_count_sections (pbfd) != 0)
+ {
+ ebfd = pbfd;
+
+ if (elf_properties (pbfd) != NULL)
+ break;
+ }
- if (pbfd == NULL && ebfd != NULL)
+ if (ebfd != NULL)
+ {
+ if (features)
{
- /* Create GNU_PROPERTY_X86_FEATURE_1_IBT if needed. */
+ /* If features is set, add GNU_PROPERTY_X86_FEATURE_1_IBT and
+ GNU_PROPERTY_X86_FEATURE_1_SHSTK. */
prop = _bfd_elf_get_property (ebfd,
GNU_PROPERTY_X86_FEATURE_1_AND,
4);
- prop->u.number = features;
+ prop->u.number |= features;
prop->pr_kind = property_number;
- sec = bfd_make_section_with_flags (ebfd,
- NOTE_GNU_PROPERTY_SECTION_NAME,
- (SEC_ALLOC
- | SEC_LOAD
- | SEC_IN_MEMORY
- | SEC_READONLY
- | SEC_HAS_CONTENTS
- | SEC_DATA));
- if (sec == NULL)
- info->callbacks->einfo (_("%F: failed to create GNU property section\n"));
-
- if (!bfd_set_section_alignment (ebfd, sec,
- ABI_64_P (ebfd) ? 3 : 2))
+ /* Create the GNU property note section if needed. */
+ if (pbfd == NULL)
{
+ sec = bfd_make_section_with_flags (ebfd,
+ NOTE_GNU_PROPERTY_SECTION_NAME,
+ (SEC_ALLOC
+ | SEC_LOAD
+ | SEC_IN_MEMORY
+ | SEC_READONLY
+ | SEC_HAS_CONTENTS
+ | SEC_DATA));
+ if (sec == NULL)
+ info->callbacks->einfo (_("%F: failed to create GNU property section\n"));
+
+ if (!bfd_set_section_alignment (ebfd, sec,
+ ABI_64_P (ebfd) ? 3 : 2))
+ {
error_alignment:
- info->callbacks->einfo (_("%F%A: failed to align section\n"),
- sec);
- }
+ info->callbacks->einfo (_("%F%A: failed to align section\n"),
+ sec);
+ }
- elf_section_type (sec) = SHT_NOTE;
+ elf_section_type (sec) = SHT_NOTE;
+ }
}
+
+ /* Check GNU_PROPERTY_NO_COPY_ON_PROTECTED. */
+ for (; pbfd != NULL; pbfd = pbfd->link.next)
+ if (bfd_get_flavour (pbfd) == bfd_target_elf_flavour
+ && (pbfd->flags
+ & (DYNAMIC | BFD_LINKER_CREATED | BFD_PLUGIN)) == 0)
+ {
+ elf_property_list *p;
+
+ /* The property list is sorted in order of type. */
+ for (p = elf_properties (pbfd); p != NULL; p = p->next)
+ {
+ if (GNU_PROPERTY_NO_COPY_ON_PROTECTED
+ == p->property.pr_type)
+ {
+ /* Clear extern_protected_data if
+ GNU_PROPERTY_NO_COPY_ON_PROTECTED is
+ set on any input relocatable file. */
+ info->extern_protected_data = FALSE;
+ break;
+ }
+ else if (GNU_PROPERTY_NO_COPY_ON_PROTECTED
+ < p->property.pr_type)
+ break;
+ }
+ }
}
pbfd = _bfd_elf_link_setup_gnu_properties (info);