summaryrefslogtreecommitdiff
path: root/bfd/elf-properties.c
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2017-08-26 19:22:26 -0700
committerH.J. Lu <hjl.tools@gmail.com>2017-08-26 19:26:21 -0700
commita5b4ee9451dc9ffb6aa29376fc03943c53c6da0d (patch)
tree74028cae4c8a9f47eab5faa25aff8a47b0c04e77 /bfd/elf-properties.c
parentaecbb010f9d74b574ba89a64f45cde2407e53dab (diff)
Disallow copy relocation against protected data symbol
We shpouldn't generate copy relocation to resolve reference to protected data symbol defined in shared object with the NO_COPY_ON_PROTECTED property. This patch adds a bit to elf_obj_tdata as well as elf_i386_link_hash_entry and elf_x86_64_link_hash_entry to track the bfd with the NO_COPY_ON_PROTECTED property as well as protected symbol defined in shared object. extern_protected_data is set to FALSE if any input relocatable file contains the NO_COPY_ON_PROTECTED property. bfd/ PR ld/21997 * elf-bfd.h (elf_obj_tdata): Use ENUM_BITFIELD on object_id, dyn_lib_class and has_gnu_symbols. Change bad_symtab to bitfield. Add a has_no_copy_on_protected bitfield. (elf_has_no_copy_on_protected): New. * elf-properties.c (_bfd_elf_parse_gnu_properties): Set elf_has_no_copy_on_protected for GNU_PROPERTY_NO_COPY_ON_PROTECTED. (elf_merge_gnu_property_list): Likewise. (_bfd_elf_link_setup_gnu_properties): Set extern_protected_data to FALSE for elf_has_no_copy_on_protected. * elf32-i386.c (SYMBOL_NO_COPYRELOC): New. (elf_i386_link_hash_entry): Add def_protected. (elf_i386_adjust_dynamic_symbol): Also check SYMBOL_NO_COPYRELOC when checking info->nocopyreloc. (elf_i386_link_setup_gnu_properties): Don't set extern_protected_data here. (elf_i386_merge_symbol_attribute): New function. (elf_backend_merge_symbol_attribute): New. * elf64-x86-64.c (SYMBOL_NO_COPYRELOC): New. (elf_x86_64_link_hash_entry): Add def_protected. (elf_x86_64_need_pic): Report protected symbol for def_protected. (elf_x86_64_adjust_dynamic_symbol): Also check SYMBOL_NO_COPYRELOC when checking info->nocopyreloc. (elf_x86_64_relocate_section): Also check for R_X86_64_PC32 relocation run-time overflow and unresolvable R_X86_64_32S relocation against protected data symbol defined in shared object with GNU_PROPERTY_NO_COPY_ON_PROTECTED. (elf_x86_64_link_setup_gnu_properties): Don't set extern_protected_data here. (elf_x86_64_merge_symbol_attribute): New function. (elf_backend_merge_symbol_attribute): New. ld/ PR ld/21997 * testsuite/ld-i386/i386.exp: Run PR ld/21997 tests. * testsuite/ld-x86-64/x86-64.exp: Likewise. * testsuite/ld-i386/pr21997-1a.S: New file. * testsuite/ld-i386/pr21997-1b.c: Likewise. * testsuite/ld-i386/pr21997-1c.S: Likewise. * testsuite/ld-x86-64/pr21997-1a.S: Likewise. * testsuite/ld-x86-64/pr21997-1a.err: Likewise. * testsuite/ld-x86-64/pr21997-1b.c: Likewise. * testsuite/ld-x86-64/pr21997-1b.err: Likewise. * testsuite/ld-x86-64/pr21997-1c.c: Likewise.
Diffstat (limited to 'bfd/elf-properties.c')
-rw-r--r--bfd/elf-properties.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/bfd/elf-properties.c b/bfd/elf-properties.c
index 13d620d9c4..f367aa6941 100644
--- a/bfd/elf-properties.c
+++ b/bfd/elf-properties.c
@@ -168,6 +168,7 @@ bad_size:
return FALSE;
}
prop = _bfd_elf_get_property (abfd, type, datasz);
+ elf_has_no_copy_on_protected (abfd) = TRUE;
prop->pr_kind = property_number;
goto next;
@@ -290,6 +291,9 @@ elf_merge_gnu_property_list (struct bfd_link_info *info, bfd *abfd,
for (p = *listp; p != NULL; p = p->next)
if (elf_merge_gnu_properties (info, abfd, NULL, &p->property))
{
+ if (p->property.pr_type == GNU_PROPERTY_NO_COPY_ON_PROTECTED)
+ elf_has_no_copy_on_protected (abfd) = TRUE;
+
pr = _bfd_elf_get_property (abfd, p->property.pr_type,
p->property.pr_datasz);
/* It must be a new property. */
@@ -489,6 +493,11 @@ _bfd_elf_link_setup_gnu_properties (struct bfd_link_info *info)
/* Cache the section contents for elf_link_input_bfd. */
elf_section_data (sec)->this_hdr.contents = contents;
+
+ /* If GNU_PROPERTY_NO_COPY_ON_PROTECTED is set, protected data
+ symbol is defined in the shared object. */
+ if (elf_has_no_copy_on_protected (first_pbfd))
+ info->extern_protected_data = FALSE;
}
return first_pbfd;