link_hash_copy_indirect and symbol flags
authorAlan Modra <amodra@gmail.com>
Thu, 29 Dec 2016 12:19:41 +0000 (22:49 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 29 Dec 2016 13:26:54 +0000 (23:56 +1030)
A while ago HJ fixed PR ld/18720 with commit 6e33951ed, which, among
other things, modified _bfd_elf_link_hash_copy_indirect to not copy
ref_dynamic, ref_regular, ref_regular_nonweak, non_got_ref, needs_plt
and pointer_equality_needed when setting up an indirect non-versioned
symbol pointing to a non-default versioned symbol.  I didn't notice at
the time, but the pr18720 testcase fails on hppa-linux with
"internal error, aborting at binutils-gdb-2.28/bfd/elf32-hppa.c:3933
in elf32_hppa_relocate_section".

Now hppa-linux creates entries in the plt even for local functions, if
they are referenced using plabel (function pointer) relocations.   So
needs_plt is set for foo when processing pr18720a.o.  When the aliases
in pr28720b.o are processed, we get an indirection from foo to
foo@FOO, but don't copy needs_plt.  Since foo@FOO is the "real" symbol
that is used after that point, no plt entry is made for foo and we
bomb when relocating the plabel.

As shown by the hppa-linux scenario, needs_plt should be copied even
for non-default versioned symbols.  I believe all of the others ought
to be copied too, with the exception of ref_dynamic.  Not copying
ref_dynamic is right because if a shared lib references "foo" it
should not be satisfied by any non-default version "foo@FOO".

* elflink.c (_bfd_elf_link_hash_copy_indirect): Only omit
copying one flag, ref_dynamic, when versioned_hidden.
* elf64-ppc.c (ppc64_elf_copy_indirect_symbol): Likewise.
* elf32-hppa.c (elf32_hppa_copy_indirect_symbol): Use same
logic for copying weakdef flags.  Copy plabel flag and merge
tls_type.
* elf32-i386.c (elf_i386_copy_indirect_symbol): Use same logic
for copying weakdef flags.
* elf32-ppc.c (ppc_elf_copy_indirect_symbol): Likewise.
* elf32-s390.c (elf_s390_copy_indirect_symbol): Likewise.
* elf32-sh.c (sh_elf_copy_indirect_symbol): Likewise.
* elf64-s390.c (elf_s390_copy_indirect_symbol): Likewise.
* elfnn-ia64.c (elfNN_ia64_hash_copy_indirect): Likewise.
* elf64-x86-64.c (elf_x86_64_copy_indirect_symbol): Likewise.
Simplify.

bfd/ChangeLog
bfd/elf32-hppa.c
bfd/elf32-i386.c
bfd/elf32-ppc.c
bfd/elf32-s390.c
bfd/elf32-sh.c
bfd/elf64-ppc.c
bfd/elf64-s390.c
bfd/elf64-x86-64.c
bfd/elflink.c
bfd/elfnn-ia64.c

index d1b012fe0bc536219402bfe57c39794ed97a4c05..bee5e402221fba4598e33f721ee182355fb2b3e2 100644 (file)
@@ -1,3 +1,21 @@
+2016-12-29  Alan Modra  <amodra@gmail.com>
+
+       * elflink.c (_bfd_elf_link_hash_copy_indirect): Only omit
+       copying one flag, ref_dynamic, when versioned_hidden.
+       * elf64-ppc.c (ppc64_elf_copy_indirect_symbol): Likewise.
+       * elf32-hppa.c (elf32_hppa_copy_indirect_symbol): Use same
+       logic for copying weakdef flags.  Copy plabel flag and merge
+       tls_type.
+       * elf32-i386.c (elf_i386_copy_indirect_symbol): Use same logic
+       for copying weakdef flags.
+       * elf32-ppc.c (ppc_elf_copy_indirect_symbol): Likewise.
+       * elf32-s390.c (elf_s390_copy_indirect_symbol): Likewise.
+       * elf32-sh.c (sh_elf_copy_indirect_symbol): Likewise.
+       * elf64-s390.c (elf_s390_copy_indirect_symbol): Likewise.
+       * elfnn-ia64.c (elfNN_ia64_hash_copy_indirect): Likewise.
+       * elf64-x86-64.c (elf_x86_64_copy_indirect_symbol): Likewise.
+       Simplify.
+
 2016-12-28  Alan Modra  <amodra@gmail.com>
 
        PR ld/20995
index cbe42cfde9f0e7d82b3337b40e0a552a11a42eb6..eab384b7ed7331a21e4be3dd86320fa81a0086b2 100644 (file)
@@ -1056,19 +1056,20 @@ elf32_hppa_copy_indirect_symbol (struct bfd_link_info *info,
       /* If called to transfer flags for a weakdef during processing
         of elf_adjust_dynamic_symbol, don't copy non_got_ref.
         We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
-      eh_dir->ref_dynamic |= eh_ind->ref_dynamic;
+      if (eh_dir->versioned != versioned_hidden)
+       eh_dir->ref_dynamic |= eh_ind->ref_dynamic;
       eh_dir->ref_regular |= eh_ind->ref_regular;
       eh_dir->ref_regular_nonweak |= eh_ind->ref_regular_nonweak;
       eh_dir->needs_plt |= eh_ind->needs_plt;
     }
   else
     {
-      if (eh_ind->root.type == bfd_link_hash_indirect
-          && eh_dir->got.refcount <= 0)
-        {
-          hh_dir->tls_type = hh_ind->tls_type;
-          hh_ind->tls_type = GOT_UNKNOWN;
-        }
+      if (eh_ind->root.type == bfd_link_hash_indirect)
+       {
+         hh_dir->plabel |= hh_ind->plabel;
+         hh_dir->tls_type |= hh_ind->tls_type;
+         hh_ind->tls_type = GOT_UNKNOWN;
+       }
 
       _bfd_elf_link_hash_copy_indirect (info, eh_dir, eh_ind);
     }
index 8f4477d00efba9453c193e4ae7a190cf6508b024..0846cae689a88b66f640db35a5373d0e20c59e3f 100644 (file)
@@ -1168,7 +1168,8 @@ elf_i386_copy_indirect_symbol (struct bfd_link_info *info,
       /* If called to transfer flags for a weakdef during processing
         of elf_adjust_dynamic_symbol, don't copy non_got_ref.
         We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
-      dir->ref_dynamic |= ind->ref_dynamic;
+      if (dir->versioned != versioned_hidden)
+       dir->ref_dynamic |= ind->ref_dynamic;
       dir->ref_regular |= ind->ref_regular;
       dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
       dir->needs_plt |= ind->needs_plt;
index e65ff615a44d7454d33d1f8d7a840eb58405bf1e..05b990952461db76433c5e178304b561a6ce35c4 100644 (file)
@@ -3606,7 +3606,8 @@ ppc_elf_copy_indirect_symbol (struct bfd_link_info *info,
        && edir->elf.dynamic_adjusted))
     edir->elf.non_got_ref |= eind->elf.non_got_ref;
 
-  edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
+  if (edir->elf.versioned != versioned_hidden)
+    edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
   edir->elf.ref_regular |= eind->elf.ref_regular;
   edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
   edir->elf.needs_plt |= eind->elf.needs_plt;
index b52144aaaa1566f68d37951755f4e9419b18babc..ae8b5b969f0875062bb5e04e2f3615d36255cee1 100644 (file)
@@ -873,7 +873,8 @@ elf_s390_copy_indirect_symbol (struct bfd_link_info *info,
       /* If called to transfer flags for a weakdef during processing
         of elf_adjust_dynamic_symbol, don't copy non_got_ref.
         We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
-      dir->ref_dynamic |= ind->ref_dynamic;
+      if (dir->versioned != versioned_hidden)
+       dir->ref_dynamic |= ind->ref_dynamic;
       dir->ref_regular |= ind->ref_regular;
       dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
       dir->needs_plt |= ind->needs_plt;
index 5da1d088f573f6409c14ce461d41955a2cd3e081..9dd1157cf60680d6b63fec208c9a8508f4a032d8 100644 (file)
@@ -5733,7 +5733,8 @@ sh_elf_copy_indirect_symbol (struct bfd_link_info *info,
       /* If called to transfer flags for a weakdef during processing
         of elf_adjust_dynamic_symbol, don't copy non_got_ref.
         We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
-      dir->ref_dynamic |= ind->ref_dynamic;
+      if (dir->versioned != versioned_hidden)
+       dir->ref_dynamic |= ind->ref_dynamic;
       dir->ref_regular |= ind->ref_regular;
       dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
       dir->needs_plt |= ind->needs_plt;
index 9520777f1e0403d90a48b6f6c0a2b69f6421f96a..b838cde0e0d79a8e746a274e8e7defa6be2fee5f 100644 (file)
@@ -4713,22 +4713,20 @@ ppc64_elf_copy_indirect_symbol (struct bfd_link_info *info,
   if (eind->oh != NULL)
     edir->oh = ppc_follow_link (eind->oh);
 
-  if (edir->elf.versioned != versioned_hidden)
-    {
-      /* If called to transfer flags for a weakdef during processing
-        of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF.
-        We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
-      if (!(ELIMINATE_COPY_RELOCS
-           && eind->elf.root.type != bfd_link_hash_indirect
-           && edir->elf.dynamic_adjusted))
-       edir->elf.non_got_ref |= eind->elf.non_got_ref;
+  /* If called to transfer flags for a weakdef during processing
+     of elf_adjust_dynamic_symbol, don't copy NON_GOT_REF.
+     We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
+  if (!(ELIMINATE_COPY_RELOCS
+       && eind->elf.root.type != bfd_link_hash_indirect
+       && edir->elf.dynamic_adjusted))
+    edir->elf.non_got_ref |= eind->elf.non_got_ref;
 
-      edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
-      edir->elf.ref_regular |= eind->elf.ref_regular;
-      edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
-      edir->elf.needs_plt |= eind->elf.needs_plt;
-      edir->elf.pointer_equality_needed |= eind->elf.pointer_equality_needed;
-    }
+  if (edir->elf.versioned != versioned_hidden)
+    edir->elf.ref_dynamic |= eind->elf.ref_dynamic;
+  edir->elf.ref_regular |= eind->elf.ref_regular;
+  edir->elf.ref_regular_nonweak |= eind->elf.ref_regular_nonweak;
+  edir->elf.needs_plt |= eind->elf.needs_plt;
+  edir->elf.pointer_equality_needed |= eind->elf.pointer_equality_needed;
 
   /* If we were called to copy over info for a weak sym, don't copy
      dyn_relocs, plt/got info, or dynindx.  We used to copy dyn_relocs
index 64a74c5dfcdd87bed5636d29d379d5b92425ff45..5dfee1c3cb635e3714b8c616f7d9942470b30633 100644 (file)
@@ -785,7 +785,8 @@ elf_s390_copy_indirect_symbol (struct bfd_link_info *info,
       /* If called to transfer flags for a weakdef during processing
         of elf_adjust_dynamic_symbol, don't copy non_got_ref.
         We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
-      dir->ref_dynamic |= ind->ref_dynamic;
+      if (dir->versioned != versioned_hidden)
+       dir->ref_dynamic |= ind->ref_dynamic;
       dir->ref_regular |= ind->ref_regular;
       dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
       dir->needs_plt |= ind->needs_plt;
index 5b3dd8a09a1a5816622e29a2d16c1408d05246d8..412bd9cca59b473e08785db830141bd2666bd7b9 100644 (file)
@@ -1164,14 +1164,9 @@ elf_x86_64_copy_indirect_symbol (struct bfd_link_info *info,
   edir = (struct elf_x86_64_link_hash_entry *) dir;
   eind = (struct elf_x86_64_link_hash_entry *) ind;
 
-  if (!edir->has_bnd_reloc)
-    edir->has_bnd_reloc = eind->has_bnd_reloc;
-
-  if (!edir->has_got_reloc)
-    edir->has_got_reloc = eind->has_got_reloc;
-
-  if (!edir->has_non_got_reloc)
-    edir->has_non_got_reloc = eind->has_non_got_reloc;
+  edir->has_bnd_reloc |= eind->has_bnd_reloc;
+  edir->has_got_reloc |= eind->has_got_reloc;
+  edir->has_non_got_reloc |= eind->has_non_got_reloc;
 
   if (eind->dyn_relocs != NULL)
     {
@@ -1218,7 +1213,8 @@ elf_x86_64_copy_indirect_symbol (struct bfd_link_info *info,
       /* If called to transfer flags for a weakdef during processing
         of elf_adjust_dynamic_symbol, don't copy non_got_ref.
         We clear it ourselves for ELIMINATE_COPY_RELOCS.  */
-      dir->ref_dynamic |= ind->ref_dynamic;
+      if (dir->versioned != versioned_hidden)
+       dir->ref_dynamic |= ind->ref_dynamic;
       dir->ref_regular |= ind->ref_regular;
       dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
       dir->needs_plt |= ind->needs_plt;
index 2fd8883fd60484974b0ac1c872bddc2fcc81d7b1..81cd236961abadf362c17839ed223003583d53bd 100644 (file)
@@ -7102,18 +7102,15 @@ _bfd_elf_link_hash_copy_indirect (struct bfd_link_info *info,
   struct elf_link_hash_table *htab;
 
   /* Copy down any references that we may have already seen to the
-     symbol which just became indirect if DIR isn't a hidden versioned
-     symbol.  */
+     symbol which just became indirect.  */
 
   if (dir->versioned != versioned_hidden)
-    {
-      dir->ref_dynamic |= ind->ref_dynamic;
-      dir->ref_regular |= ind->ref_regular;
-      dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
-      dir->non_got_ref |= ind->non_got_ref;
-      dir->needs_plt |= ind->needs_plt;
-      dir->pointer_equality_needed |= ind->pointer_equality_needed;
-    }
+    dir->ref_dynamic |= ind->ref_dynamic;
+  dir->ref_regular |= ind->ref_regular;
+  dir->ref_regular_nonweak |= ind->ref_regular_nonweak;
+  dir->non_got_ref |= ind->non_got_ref;
+  dir->needs_plt |= ind->needs_plt;
+  dir->pointer_equality_needed |= ind->pointer_equality_needed;
 
   if (ind->root.type != bfd_link_hash_indirect)
     return;
index 32f94111db7322d4347c4db6373846f49aed24a5..02340420891fadee3a861e95439f4c00a9e38a13 100644 (file)
@@ -1274,7 +1274,8 @@ elfNN_ia64_hash_copy_indirect (struct bfd_link_info *info,
   /* Copy down any references that we may have already seen to the
      symbol which just became indirect.  */
 
-  dir->root.ref_dynamic |= ind->root.ref_dynamic;
+  if (dir->root.versioned != versioned_hidden)
+    dir->root.ref_dynamic |= ind->root.ref_dynamic;
   dir->root.ref_regular |= ind->root.ref_regular;
   dir->root.ref_regular_nonweak |= ind->root.ref_regular_nonweak;
   dir->root.needs_plt |= ind->root.needs_plt;
This page took 0.072652 seconds and 4 git commands to generate.