From e3c0e327923e27c7d96e6e44e22e10998ff158d7 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sat, 11 Apr 2015 07:34:49 -0700 Subject: Replace SYMBOLIC_BIND with SYMBOL_REFERENCES_LOCAL When checking R_386_GOTOFF/R_X86_64_GOTOFF64 for building shared library, we should check SYMBOL_REFERENCES_LOCAL instead of SYMBOLIC_BIND to cover more cases. bfd/ * elf32-i386.c (elf_i386_relocate_section): Replace SYMBOLIC_BIND with SYMBOL_REFERENCES_LOCAL when checking R_386_GOTOFF against protected data symbol when building shared library. * elf64-x86-64.c (elf_x86_64_relocate_section): Check R_X86_64_GOTOFF64 against undefined symbol and replace SYMBOLIC_BIND with SYMBOL_REFERENCES_LOCAL when checking R_X86_64_GOTOFF64 against protected data symbol when building shared library. ld/testsuite/ * ld-i386/i386.exp: Run protected6a. * ld-i386/protected6.d: Renamed to ... * ld-i386/protected6a.d: This. * ld-x86-64/hidden4.d: New file. * ld-x86-64/hidden4.s: Likewise. * ld-x86-64/hidden5.d: Likewise. * ld-x86-64/hidden5.s: Likewise. * ld-x86-64/protected6.d: Renamed to ... * ld-x86-64/protected6a.d: This. * ld-x86-64/x86-64.exp: Run hidden4, hidden5, protected6a, protected7a and protected7b. --- bfd/ChangeLog | 11 +++++++++++ bfd/elf32-i386.c | 4 ++-- bfd/elf64-x86-64.c | 56 ++++++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 55 insertions(+), 16 deletions(-) (limited to 'bfd') diff --git a/bfd/ChangeLog b/bfd/ChangeLog index ea35435..207884a 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,14 @@ +2015-04-11 H.J. Lu + + * elf32-i386.c (elf_i386_relocate_section): Replace SYMBOLIC_BIND + with SYMBOL_REFERENCES_LOCAL when checking R_386_GOTOFF against + protected data symbol when building shared library. + * elf64-x86-64.c (elf_x86_64_relocate_section): Check + R_X86_64_GOTOFF64 against undefined symbol and replace + SYMBOLIC_BIND with SYMBOL_REFERENCES_LOCAL when checking + R_X86_64_GOTOFF64 against protected data symbol when building + shared library. + 2015-04-10 H.J. Lu PR ld/pr17709 diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c index af16da3..f71bce1 100644 --- a/bfd/elf32-i386.c +++ b/bfd/elf32-i386.c @@ -3717,7 +3717,7 @@ elf_i386_relocate_section (bfd *output_bfd, /* Check to make sure it isn't a protected function or data symbol for shared library since it may not be local when used as function address or with copy relocation. We also - need to make sure that a symbol is defined locally. */ + need to make sure that a symbol is referenced locally. */ if (info->shared && h) { if (!h->def_regular) @@ -3747,7 +3747,7 @@ elf_i386_relocate_section (bfd *output_bfd, return FALSE; } else if (!info->executable - && !SYMBOLIC_BIND (info, h) + && !SYMBOL_REFERENCES_LOCAL (info, h) && (h->type == STT_FUNC || h->type == STT_OBJECT) && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED) diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index 2b37c27..a3604c7 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -3957,22 +3957,50 @@ elf_x86_64_relocate_section (bfd *output_bfd, /* Check to make sure it isn't a protected function or data symbol for shared library since it may not be local when - used as function address or with copy relocation. */ - if (!info->executable - && h - && !SYMBOLIC_BIND (info, h) - && h->def_regular - && (h->type == STT_FUNC - || h->type == STT_OBJECT) - && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED) + used as function address or with copy relocation. We also + need to make sure that a symbol is referenced locally. */ + if (info->shared && h) { - (*_bfd_error_handler) - (_("%B: relocation R_X86_64_GOTOFF64 against protected %s `%s' can not be used when making a shared object"), - input_bfd, - h->type == STT_FUNC ? "function" : "data", - h->root.root.string); - bfd_set_error (bfd_error_bad_value); + if (!h->def_regular) + { + const char *v; + + switch (ELF_ST_VISIBILITY (h->other)) + { + case STV_HIDDEN: + v = _("hidden symbol"); + break; + case STV_INTERNAL: + v = _("internal symbol"); + break; + case STV_PROTECTED: + v = _("protected symbol"); + break; + default: + v = _("symbol"); + break; + } + + (*_bfd_error_handler) + (_("%B: relocation R_X86_64_GOTOFF64 against undefined %s `%s' can not be used when making a shared object"), + input_bfd, v, h->root.root.string); + bfd_set_error (bfd_error_bad_value); + return FALSE; + } + else if (!info->executable + && !SYMBOL_REFERENCES_LOCAL (info, h) + && (h->type == STT_FUNC + || h->type == STT_OBJECT) + && ELF_ST_VISIBILITY (h->other) == STV_PROTECTED) + { + (*_bfd_error_handler) + (_("%B: relocation R_X86_64_GOTOFF64 against protected %s `%s' can not be used when making a shared object"), + input_bfd, + h->type == STT_FUNC ? "function" : "data", + h->root.root.string); + bfd_set_error (bfd_error_bad_value); return FALSE; + } } /* Note that sgot is not involved in this -- cgit v1.1