From: Alan Modra Date: Fri, 12 Dec 2014 12:23:46 +0000 (+1030) Subject: Copy relocations against protected symbols X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6cabe1ea460c54c17ac877b2541eccf91d6b4b9c;p=binutils-gdb.git Copy relocations against protected symbols Copy relocs are used in a scheme to avoid dynamic text relocations in non-PIC executables that refer to variables defined in shared libraries. The idea is to have the linker define any such variable in the executable, with a copy reloc copying the initial value, then have both the executable and shared library refer to the executable copy. If the shared library defines the variable as protected then we have two copies of the variable being used. PR 15228 * elflink.c (_bfd_elf_adjust_dynamic_copy): Add "info" param. Error on copy relocs against protected symbols. (elf_merge_st_other): Set h->protected_def. * elf-bfd.h (struct elf_link_hash_entry): Add "protected_def". (_bfd_elf_adjust_dynamic_copy): Update prototype. * elf-m10300.c (_bfd_mn10300_elf_adjust_dynamic_symbol): Update _bfd_elf_adjust_dynamic_copy call. * elf32-arm.c (elf32_arm_adjust_dynamic_symbol): Likewise. * elf32-cr16.c (_bfd_cr16_elf_adjust_dynamic_symbol): Likewise. * elf32-cris.c (elf_cris_adjust_dynamic_symbol): Likewise. * elf32-hppa.c (elf32_hppa_adjust_dynamic_symbol): Likewise. * elf32-i370.c (i370_elf_adjust_dynamic_symbol): Likewise. * elf32-i386.c (elf_i386_adjust_dynamic_symbol): Likewise. * elf32-lm32.c (lm32_elf_adjust_dynamic_symbol): Likewise. * elf32-m32r.c (m32r_elf_adjust_dynamic_symbol): Likewise. * elf32-m68k.c (elf_m68k_adjust_dynamic_symbol): Likewise. * elf32-metag.c (elf_metag_adjust_dynamic_symbol): Likewise. * elf32-or1k.c (or1k_elf_adjust_dynamic_symbol): Likewise. * elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Likewise. * elf32-s390.c (elf_s390_adjust_dynamic_symbol): Likewise. * elf32-sh.c (sh_elf_adjust_dynamic_symbol): Likewise. * elf32-tic6x.c (elf32_tic6x_adjust_dynamic_symbol): Likewise. * elf32-tilepro.c (tilepro_elf_adjust_dynamic_symbol): Likewise. * elf32-vax.c (elf_vax_adjust_dynamic_symbol): Likewise. * elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Likewise. * elf64-s390.c (elf_s390_adjust_dynamic_symbol): Likewise. * elf64-sh64.c (sh64_elf64_adjust_dynamic_symbol): Likewise. * elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol): Likewise. * elfnn-aarch64.c (elfNN_aarch64_adjust_dynamic_symbol): Likewise. * elfxx-mips.c (_bfd_mips_elf_adjust_dynamic_symbol): Likewise. * elfxx-sparc.c (_bfd_sparc_elf_adjust_dynamic_symbol): Likewise. * elfxx-tilegx.c (tilegx_elf_adjust_dynamic_symbol): Likewise. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 9443507f243..0db2820ed7b 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,39 @@ +2014-12-12 Alan Modra + + PR 15228 + * elflink.c (_bfd_elf_adjust_dynamic_copy): Add "info" param. + Error on copy relocs against protected symbols. + (elf_merge_st_other): Set h->protected_def. + * elf-bfd.h (struct elf_link_hash_entry): Add "protected_def". + (_bfd_elf_adjust_dynamic_copy): Update prototype. + * elf-m10300.c (_bfd_mn10300_elf_adjust_dynamic_symbol): Update + _bfd_elf_adjust_dynamic_copy call. + * elf32-arm.c (elf32_arm_adjust_dynamic_symbol): Likewise. + * elf32-cr16.c (_bfd_cr16_elf_adjust_dynamic_symbol): Likewise. + * elf32-cris.c (elf_cris_adjust_dynamic_symbol): Likewise. + * elf32-hppa.c (elf32_hppa_adjust_dynamic_symbol): Likewise. + * elf32-i370.c (i370_elf_adjust_dynamic_symbol): Likewise. + * elf32-i386.c (elf_i386_adjust_dynamic_symbol): Likewise. + * elf32-lm32.c (lm32_elf_adjust_dynamic_symbol): Likewise. + * elf32-m32r.c (m32r_elf_adjust_dynamic_symbol): Likewise. + * elf32-m68k.c (elf_m68k_adjust_dynamic_symbol): Likewise. + * elf32-metag.c (elf_metag_adjust_dynamic_symbol): Likewise. + * elf32-or1k.c (or1k_elf_adjust_dynamic_symbol): Likewise. + * elf32-ppc.c (ppc_elf_adjust_dynamic_symbol): Likewise. + * elf32-s390.c (elf_s390_adjust_dynamic_symbol): Likewise. + * elf32-sh.c (sh_elf_adjust_dynamic_symbol): Likewise. + * elf32-tic6x.c (elf32_tic6x_adjust_dynamic_symbol): Likewise. + * elf32-tilepro.c (tilepro_elf_adjust_dynamic_symbol): Likewise. + * elf32-vax.c (elf_vax_adjust_dynamic_symbol): Likewise. + * elf64-ppc.c (ppc64_elf_adjust_dynamic_symbol): Likewise. + * elf64-s390.c (elf_s390_adjust_dynamic_symbol): Likewise. + * elf64-sh64.c (sh64_elf64_adjust_dynamic_symbol): Likewise. + * elf64-x86-64.c (elf_x86_64_adjust_dynamic_symbol): Likewise. + * elfnn-aarch64.c (elfNN_aarch64_adjust_dynamic_symbol): Likewise. + * elfxx-mips.c (_bfd_mips_elf_adjust_dynamic_symbol): Likewise. + * elfxx-sparc.c (_bfd_sparc_elf_adjust_dynamic_symbol): Likewise. + * elfxx-tilegx.c (tilegx_elf_adjust_dynamic_symbol): Likewise. + 2014-12-11 Keith Seitz * elf.c (elf_parse_notes): Define convenience macro diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h index 6ce70bcf8c6..5e53cbab060 100644 --- a/bfd/elf-bfd.h +++ b/bfd/elf-bfd.h @@ -196,6 +196,8 @@ struct elf_link_hash_entry unsigned int pointer_equality_needed : 1; /* Symbol is a unique global symbol. */ unsigned int unique_global : 1; + /* Symbol is defined with non-default visibility. */ + unsigned int protected_def : 1; /* String table index in .dynstr if this is a dynamic symbol. */ unsigned long dynstr_index; @@ -2026,7 +2028,7 @@ extern bfd_boolean _bfd_elf_link_output_relocs struct elf_link_hash_entry **); extern bfd_boolean _bfd_elf_adjust_dynamic_copy - (struct elf_link_hash_entry *, asection *); + (struct bfd_link_info *, struct elf_link_hash_entry *, asection *); extern bfd_boolean _bfd_elf_dynamic_symbol_p (struct elf_link_hash_entry *, struct bfd_link_info *, bfd_boolean); diff --git a/bfd/elf-m10300.c b/bfd/elf-m10300.c index f29025d5d92..1dbb2f9b262 100644 --- a/bfd/elf-m10300.c +++ b/bfd/elf-m10300.c @@ -5024,7 +5024,7 @@ _bfd_mn10300_elf_adjust_dynamic_symbol (struct bfd_link_info * info, h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Set the sizes of the dynamic sections. */ diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c index 1ff562cf772..5b2f66f0f91 100644 --- a/bfd/elf32-arm.c +++ b/bfd/elf32-arm.c @@ -13339,7 +13339,7 @@ elf32_arm_adjust_dynamic_symbol (struct bfd_link_info * info, h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Allocate space in .plt, .got and associated reloc sections for diff --git a/bfd/elf32-cr16.c b/bfd/elf32-cr16.c index f16f1c628a2..6dadcc1d9ea 100644 --- a/bfd/elf32-cr16.c +++ b/bfd/elf32-cr16.c @@ -2437,7 +2437,7 @@ _bfd_cr16_elf_adjust_dynamic_symbol (struct bfd_link_info * info, h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Set the sizes of the dynamic sections. */ diff --git a/bfd/elf32-cris.c b/bfd/elf32-cris.c index 9b2b956c8af..c516b2f26e5 100644 --- a/bfd/elf32-cris.c +++ b/bfd/elf32-cris.c @@ -3054,7 +3054,7 @@ elf_cris_adjust_dynamic_symbol (struct bfd_link_info *info, h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Adjust our "subclass" elements for an indirect symbol. */ diff --git a/bfd/elf32-hppa.c b/bfd/elf32-hppa.c index 0588ebbfcdf..abc712402c3 100644 --- a/bfd/elf32-hppa.c +++ b/bfd/elf32-hppa.c @@ -1915,7 +1915,7 @@ elf32_hppa_adjust_dynamic_symbol (struct bfd_link_info *info, sec = htab->sdynbss; - return _bfd_elf_adjust_dynamic_copy (eh, sec); + return _bfd_elf_adjust_dynamic_copy (info, eh, sec); } /* Allocate space in the .plt for entries that won't have relocations. diff --git a/bfd/elf32-i370.c b/bfd/elf32-i370.c index c9ed6e0260f..e28c2576102 100644 --- a/bfd/elf32-i370.c +++ b/bfd/elf32-i370.c @@ -534,7 +534,7 @@ i370_elf_adjust_dynamic_symbol (struct bfd_link_info *info, h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Increment the index of a dynamic symbol by a given amount. Called diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index 2bd7f43ade7..e0eef28e213 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -2229,7 +2229,7 @@ elf_i386_adjust_dynamic_symbol (struct bfd_link_info *info, s = htab->sdynbss; - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Allocate space in .plt, .got and associated reloc sections for diff --git a/bfd/elf32-lm32.c b/bfd/elf32-lm32.c index e694055a9bd..5f2b6b8f25e 100644 --- a/bfd/elf32-lm32.c +++ b/bfd/elf32-lm32.c @@ -1892,7 +1892,7 @@ lm32_elf_adjust_dynamic_symbol (struct bfd_link_info *info, h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Allocate space in .plt, .got and associated reloc sections for diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c index 8dba9f0a3e5..e6b45ab0907 100644 --- a/bfd/elf32-m32r.c +++ b/bfd/elf32-m32r.c @@ -1919,7 +1919,7 @@ m32r_elf_adjust_dynamic_symbol (struct bfd_link_info *info, h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Allocate space in .plt, .got and associated reloc sections for diff --git a/bfd/elf32-m68k.c b/bfd/elf32-m68k.c index 0058da442df..9a42288db56 100644 --- a/bfd/elf32-m68k.c +++ b/bfd/elf32-m68k.c @@ -3237,7 +3237,7 @@ elf_m68k_adjust_dynamic_symbol (struct bfd_link_info *info, h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Set the sizes of the dynamic sections. */ diff --git a/bfd/elf32-metag.c b/bfd/elf32-metag.c index 47ca5debe83..a68b51cd9b6 100644 --- a/bfd/elf32-metag.c +++ b/bfd/elf32-metag.c @@ -2587,7 +2587,7 @@ elf_metag_adjust_dynamic_symbol (struct bfd_link_info *info, s = htab->sdynbss; - return _bfd_elf_adjust_dynamic_copy (eh, s); + return _bfd_elf_adjust_dynamic_copy (info, eh, s); } /* Allocate space in .plt, .got and associated reloc sections for diff --git a/bfd/elf32-or1k.c b/bfd/elf32-or1k.c index 5cf29e133a9..e5b7bad252f 100644 --- a/bfd/elf32-or1k.c +++ b/bfd/elf32-or1k.c @@ -2187,7 +2187,7 @@ or1k_elf_adjust_dynamic_symbol (struct bfd_link_info *info, h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Allocate space in .plt, .got and associated reloc sections for diff --git a/bfd/elf32-ppc.c b/bfd/elf32-ppc.c index b4d20753cf7..8429e8f95b7 100644 --- a/bfd/elf32-ppc.c +++ b/bfd/elf32-ppc.c @@ -5628,7 +5628,7 @@ ppc_elf_adjust_dynamic_symbol (struct bfd_link_info *info, h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Generate a symbol to mark plt call stubs. For non-PIC code the sym is diff --git a/bfd/elf32-s390.c b/bfd/elf32-s390.c index ebcb028b86b..07e594f2957 100644 --- a/bfd/elf32-s390.c +++ b/bfd/elf32-s390.c @@ -1762,7 +1762,7 @@ elf_s390_adjust_dynamic_symbol (struct bfd_link_info *info, s = htab->sdynbss; - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Allocate space in .plt, .got and associated reloc sections for diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c index 44a3aa7875e..a737044964d 100644 --- a/bfd/elf32-sh.c +++ b/bfd/elf32-sh.c @@ -2919,7 +2919,7 @@ sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info, h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Allocate space in .plt, .got and associated reloc sections for diff --git a/bfd/elf32-tic6x.c b/bfd/elf32-tic6x.c index 8381cfa7643..9f17979554c 100644 --- a/bfd/elf32-tic6x.c +++ b/bfd/elf32-tic6x.c @@ -2168,7 +2168,7 @@ elf32_tic6x_adjust_dynamic_symbol (struct bfd_link_info *info, s = htab->sdynbss; - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } static bfd_boolean diff --git a/bfd/elf32-tilepro.c b/bfd/elf32-tilepro.c index b9a31d5c476..095992429ad 100644 --- a/bfd/elf32-tilepro.c +++ b/bfd/elf32-tilepro.c @@ -2189,7 +2189,7 @@ tilepro_elf_adjust_dynamic_symbol (struct bfd_link_info *info, h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, htab->sdynbss); + return _bfd_elf_adjust_dynamic_copy (info, h, htab->sdynbss); } /* Allocate space in .plt, .got and associated reloc sections for diff --git a/bfd/elf32-vax.c b/bfd/elf32-vax.c index 1f418672424..05e65e97093 100644 --- a/bfd/elf32-vax.c +++ b/bfd/elf32-vax.c @@ -1043,7 +1043,7 @@ elf_vax_adjust_dynamic_symbol (struct bfd_link_info *info, h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* This function is called via elf_link_hash_traverse. It resets GOT diff --git a/bfd/elf64-ppc.c b/bfd/elf64-ppc.c index cb58df18d11..26ae9ed6571 100644 --- a/bfd/elf64-ppc.c +++ b/bfd/elf64-ppc.c @@ -7121,7 +7121,7 @@ ppc64_elf_adjust_dynamic_symbol (struct bfd_link_info *info, s = htab->dynbss; - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* If given a function descriptor symbol, hide both the function code diff --git a/bfd/elf64-s390.c b/bfd/elf64-s390.c index b2f1aa59fd6..9a874f2b749 100644 --- a/bfd/elf64-s390.c +++ b/bfd/elf64-s390.c @@ -1707,7 +1707,7 @@ elf_s390_adjust_dynamic_symbol (struct bfd_link_info *info, s = htab->sdynbss; - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Allocate space in .plt, .got and associated reloc sections for diff --git a/bfd/elf64-sh64.c b/bfd/elf64-sh64.c index 311d7c3e844..74979293169 100644 --- a/bfd/elf64-sh64.c +++ b/bfd/elf64-sh64.c @@ -3381,7 +3381,7 @@ sh64_elf64_adjust_dynamic_symbol (struct bfd_link_info *info, h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* This function is called via sh_elf_link_hash_traverse if we are diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 64b4634fb42..40a2a8767b6 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -2445,7 +2445,7 @@ elf_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info, s = htab->sdynbss; - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Allocate space in .plt, .got and associated reloc sections for diff --git a/bfd/elflink.c b/bfd/elflink.c index b023ec5a5a5..a01daf2fdff 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -873,6 +873,8 @@ elf_merge_st_other (bfd *abfd, struct elf_link_hash_entry *h, if (symvis - 1 < hvis - 1) h->other = symvis | (h->other & ~ELF_ST_VISIBILITY (-1)); } + else if (definition && ELF_ST_VISIBILITY (isym->st_other) != STV_DEFAULT) + h->protected_def = 1; } /* This function is called when we want to merge a new symbol with an @@ -2637,7 +2639,8 @@ _bfd_elf_adjust_dynamic_symbol (struct elf_link_hash_entry *h, void *data) DYNBSS. */ bfd_boolean -_bfd_elf_adjust_dynamic_copy (struct elf_link_hash_entry *h, +_bfd_elf_adjust_dynamic_copy (struct bfd_link_info *info, + struct elf_link_hash_entry *h, asection *dynbss) { unsigned int power_of_two; @@ -2676,6 +2679,14 @@ _bfd_elf_adjust_dynamic_copy (struct elf_link_hash_entry *h, /* Increment the size of DYNBSS to make room for the symbol. */ dynbss->size += h->size; + if (h->protected_def) + { + info->callbacks->einfo + (_("%P: copy reloc against protected `%T' is invalid\n"), + h->root.root.string); + return FALSE; + } + return TRUE; } diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 0879db97be8..4f0e0c630d8 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -5542,7 +5542,7 @@ elfNN_aarch64_adjust_dynamic_symbol (struct bfd_link_info *info, s = htab->sdynbss; - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index 81128491f64..db403b3a00f 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -9215,7 +9215,7 @@ _bfd_mips_elf_adjust_dynamic_symbol (struct bfd_link_info *info, dynamic will now refer to the local copy instead. */ hmips->possibly_dynamic_relocs = 0; - return _bfd_elf_adjust_dynamic_copy (h, htab->sdynbss); + return _bfd_elf_adjust_dynamic_copy (info, h, htab->sdynbss); } /* This function is called after all the input files have been read, diff --git a/bfd/elfxx-sparc.c b/bfd/elfxx-sparc.c index d5f92d46717..a56493f7d66 100644 --- a/bfd/elfxx-sparc.c +++ b/bfd/elfxx-sparc.c @@ -2211,7 +2211,7 @@ _bfd_sparc_elf_adjust_dynamic_symbol (struct bfd_link_info *info, s = htab->sdynbss; - return _bfd_elf_adjust_dynamic_copy (h, s); + return _bfd_elf_adjust_dynamic_copy (info, h, s); } /* Allocate space in .plt, .got and associated reloc sections for diff --git a/bfd/elfxx-tilegx.c b/bfd/elfxx-tilegx.c index e206bc72d6b..90f4395d7ca 100644 --- a/bfd/elfxx-tilegx.c +++ b/bfd/elfxx-tilegx.c @@ -2456,7 +2456,7 @@ tilegx_elf_adjust_dynamic_symbol (struct bfd_link_info *info, h->needs_copy = 1; } - return _bfd_elf_adjust_dynamic_copy (h, htab->sdynbss); + return _bfd_elf_adjust_dynamic_copy (info, h, htab->sdynbss); } /* Allocate space in .plt, .got and associated reloc sections for