ELF: Check ELF_COMMON_DEF_P for common symbols

Since common symbols that are turned into definitions don't have the
DEF_REGULAR flag set, we need to check ELF_COMMON_DEF_P for common
symbols.

bfd/

	PR ld/19579
	PR ld/21306
	* elf32-s390.c (elf_s390_finish_dynamic_symbol): Check
	ELF_COMMON_DEF_P for common symbols.
	* elf64-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
	* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
	* elflink.c (_bfd_elf_merge_symbol): Revert commits
	202ac193bbbecc96a4978d1ac3d17148253f9b01 and
	07492f668d2173da7a2bda3707ff0985e0f460b6.

ld/

	PR ld/19579
	PR ld/21306
	* testsuite/ld-elf/pr19579a.c (main): Updated.
This commit is contained in:
H.J. Lu
2017-04-07 07:40:14 -07:00
parent 6670ec1372
commit 8170f7693b
7 changed files with 25 additions and 9 deletions

View File

@ -1,3 +1,15 @@
2017-04-07 H.J. Lu <hongjiu.lu@intel.com>
PR ld/19579
PR ld/21306
* elf32-s390.c (elf_s390_finish_dynamic_symbol): Check
ELF_COMMON_DEF_P for common symbols.
* elf64-s390.c (elf_s390_finish_dynamic_symbol): Likewise.
* elf64-x86-64.c (elf_x86_64_relocate_section): Likewise.
* elflink.c (_bfd_elf_merge_symbol): Revert commits
202ac193bbbecc96a4978d1ac3d17148253f9b01 and
07492f668d2173da7a2bda3707ff0985e0f460b6.
2017-04-07 Pedro Alves <palves@redhat.com> 2017-04-07 Pedro Alves <palves@redhat.com>
* opncls.c (bfd_get_debug_link_info): Rename to... * opncls.c (bfd_get_debug_link_info): Rename to...

View File

@ -3785,7 +3785,7 @@ elf_s390_finish_dynamic_symbol (bfd *output_bfd,
RELATIVE reloc. The entry in the global offset table RELATIVE reloc. The entry in the global offset table
will already have been initialized in the will already have been initialized in the
relocate_section function. */ relocate_section function. */
if (!h->def_regular) if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
return FALSE; return FALSE;
BFD_ASSERT((h->got.offset & 1) != 0); BFD_ASSERT((h->got.offset & 1) != 0);
rela.r_info = ELF32_R_INFO (0, R_390_RELATIVE); rela.r_info = ELF32_R_INFO (0, R_390_RELATIVE);

View File

@ -3582,7 +3582,7 @@ elf_s390_finish_dynamic_symbol (bfd *output_bfd,
RELATIVE reloc. The entry in the global offset table RELATIVE reloc. The entry in the global offset table
will already have been initialized in the will already have been initialized in the
relocate_section function. */ relocate_section function. */
if (!h->def_regular) if (!(h->def_regular || ELF_COMMON_DEF_P (h)))
return FALSE; return FALSE;
BFD_ASSERT((h->got.offset & 1) != 0); BFD_ASSERT((h->got.offset & 1) != 0);
rela.r_info = ELF64_R_INFO (0, R_390_RELATIVE); rela.r_info = ELF64_R_INFO (0, R_390_RELATIVE);

View File

@ -4926,7 +4926,8 @@ do_ifunc_pointer:
{ {
/* Symbol is referenced locally. Make sure it is /* Symbol is referenced locally. Make sure it is
defined locally or for a branch. */ defined locally or for a branch. */
fail = !h->def_regular && !branch; fail = (!(h->def_regular || ELF_COMMON_DEF_P (h))
&& !branch);
} }
else if (!(bfd_link_pie (info) else if (!(bfd_link_pie (info)
&& (h->needs_copy || eh->needs_copy))) && (h->needs_copy || eh->needs_copy)))

View File

@ -1544,16 +1544,13 @@ _bfd_elf_merge_symbol (bfd *abfd,
represent variables; this can cause confusion in principle, but represent variables; this can cause confusion in principle, but
any such confusion would seem to indicate an erroneous program or any such confusion would seem to indicate an erroneous program or
shared library. We also permit a common symbol in a regular shared library. We also permit a common symbol in a regular
object to override a weak symbol in a shared object. A common object to override a weak symbol in a shared object. */
symbol in executable also overrides a symbol in a shared object. */
if (newdyn if (newdyn
&& newdef && newdef
&& (olddef && (olddef
|| (h->root.type == bfd_link_hash_common || (h->root.type == bfd_link_hash_common
&& (newweak && (newweak || newfunc))))
|| newfunc
|| (!olddyn && bfd_link_executable (info))))))
{ {
*override = TRUE; *override = TRUE;
newdef = FALSE; newdef = FALSE;

View File

@ -1,3 +1,9 @@
2017-04-07 H.J. Lu <hongjiu.lu@intel.com>
PR ld/19579
PR ld/21306
* testsuite/ld-elf/pr19579a.c (main): Updated.
2017-04-07 Nick Clifton <nickc@redhat.com> 2017-04-07 Nick Clifton <nickc@redhat.com>
PR 21090 PR 21090

View File

@ -9,7 +9,7 @@ extern int *bar_p (void);
int int
main () main ()
{ {
if (foo[0] == 0 && foo == foo_p () && bar[0] == 0 && bar == bar_p ()) if (foo[0] == 0 && foo == foo_p () && bar[0] == -1 && bar == bar_p ())
printf ("PASS\n"); printf ("PASS\n");
return 0; return 0;
} }