]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
bfd/
authorH.J. Lu <hjl.tools@gmail.com>
Mon, 5 May 2003 05:46:53 +0000 (05:46 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Mon, 5 May 2003 05:46:53 +0000 (05:46 +0000)
2003-05-04  H.J. Lu <hjl@gnu.org>

* elf32-i386.c (allocate_dynrelocs): Don't allocate dynamic
relocation entries for weak undefined symbols with non-default
visibility.
(elf_i386_relocate_section): Initialize the GOT entries and
skip R_386_32/R_386_PC32 for weak undefined symbols with
non-default visibility.

* elfxx-ia64.c (allocate_fptr): Don't allocate function
descriptors for weak undefined symbols with non-default
visibility.
(allocate_dynrel_entries): Don't allocate relocation entries
for symbols resolved to 0.
(set_got_entry): Don't install dynamic relocation for weak
undefined symbols with non-default visibility.
(set_pltoff_entry): Likewise.

* elflink.h (elf_fix_symbol_flags): Hide weak undefined symbols
with non-default visibility.
(elf_link_output_extsym): Don't make weak undefined symbols
with non-default visibility dynamic.

ld/testsuite/

2003-05-04  H.J. Lu <hjl@gnu.org>

* ld-elfvsb/main.c: Updated.
* ld-elfvsb/sh1.c: Likewise.

bfd/ChangeLog
bfd/elf32-i386.c
bfd/elflink.h
bfd/elfxx-ia64.c
ld/testsuite/ChangeLog
ld/testsuite/ld-elfvsb/main.c
ld/testsuite/ld-elfvsb/sh1.c

index dfbc26d863da5b7897dcf8611201cb9955c0bcbe..e209e3dc332b721baa7cd1cf47bfdbee9a660194 100644 (file)
@@ -1,3 +1,26 @@
+2003-05-04  H.J. Lu <hjl@gnu.org>
+
+       * elf32-i386.c (allocate_dynrelocs): Don't allocate dynamic
+       relocation entries for weak undefined symbols with non-default
+       visibility.
+       (elf_i386_relocate_section): Initialize the GOT entries and
+       skip R_386_32/R_386_PC32 for weak undefined symbols with
+       non-default visibility.
+       * elfxx-ia64.c (allocate_fptr): Don't allocate function
+       descriptors for weak undefined symbols with non-default
+       visibility.
+       (allocate_dynrel_entries): Don't allocate relocation entries
+       for symbols resolved to 0.
+       (set_got_entry): Don't install dynamic relocation for weak
+       undefined symbols with non-default visibility.
+       (set_pltoff_entry): Likewise.
+
+       * elflink.h (elf_fix_symbol_flags): Hide weak undefined symbols
+       with non-default visibility.
+       (elf_link_output_extsym): Don't make weak undefined symbols
+       with non-default visibility dynamic.
+
 2003-05-04  H.J. Lu <hjl@gnu.org>
 
        * elflink.h (elf_merge_symbol): Correctly handle weak definiton.
index 060d66c20cebb9b149f923eabaac5e1009b5506a..ac292a1a9e0307239e93e0198bb50abcf1c9398a 100644 (file)
@@ -1569,8 +1569,10 @@ allocate_dynrelocs (h, inf)
            return FALSE;
        }
 
-      if (info->shared
-         || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h))
+      if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+          || h->root.type != bfd_link_hash_undefweak)
+         && (info->shared
+             || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)))
        {
          asection *s = htab->splt;
 
@@ -1656,8 +1658,10 @@ allocate_dynrelocs (h, inf)
        htab->srelgot->_raw_size += sizeof (Elf32_External_Rel);
       else if (tls_type == GOT_TLS_GD)
        htab->srelgot->_raw_size += 2 * sizeof (Elf32_External_Rel);
-      else if (info->shared
-              || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))
+      else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+               || h->root.type != bfd_link_hash_undefweak)
+              && (info->shared
+                  || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h)))
        htab->srelgot->_raw_size += sizeof (Elf32_External_Rel);
     }
   else
@@ -2298,7 +2302,9 @@ elf_i386_relocate_section (output_bfd, info, input_bfd, input_section,
                      && (info->symbolic
                          || h->dynindx == -1
                          || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL))
-                     && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)))
+                     && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))
+                 || (ELF_ST_VISIBILITY (h->other)
+                     && h->root.type == bfd_link_hash_undefweak))
                {
                  /* This is actually a static link, or it is a
                     -Bsymbolic link and the symbol is defined
@@ -2422,6 +2428,9 @@ elf_i386_relocate_section (output_bfd, info, input_bfd, input_section,
            break;
 
          if ((info->shared
+              && (h == NULL
+                  || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+                  || h->root.type != bfd_link_hash_undefweak)
               && (r_type != R_386_PC32
                   || (h != NULL
                       && h->dynindx != -1
index dfcce7d2564f3de4131918d16b195884dfcd772c..0f590a4c294e07acd82eaf1a29d9618c0f4e43e7 100644 (file)
@@ -4151,6 +4151,16 @@ elf_fix_symbol_flags (h, eif)
       (*bed->elf_backend_hide_symbol) (eif->info, h, force_local);
     }
 
+  /* If a weak undefined symbol has non-default visibility, we also
+     hide it from the dynamic linker.  */
+  if (ELF_ST_VISIBILITY (h->other)
+      && h->root.type == bfd_link_hash_undefweak)
+    {
+      struct elf_backend_data *bed;
+      bed = get_elf_backend_data (elf_hash_table (eif->info)->dynobj);
+      (*bed->elf_backend_hide_symbol) (eif->info, h, TRUE);
+    }
+
   /* If this is a weak defined symbol in a dynamic object, and we know
      the real definition in the dynamic object, copy interesting flags
      over to the real definition.  */
@@ -6546,7 +6556,9 @@ elf_link_output_extsym (h, data)
      forced local syms when non-shared is due to a historical quirk.  */
   if ((h->dynindx != -1
        || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)
-      && (finfo->info->shared
+      && ((finfo->info->shared
+          && (ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+              || h->root.type != bfd_link_hash_undefweak))
          || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0)
       && elf_hash_table (finfo->info)->dynamic_sections_created)
     {
index 946157fd7bcd870c6130fbc7f573cf670aa293fa..31f05e9606c749fdf0f7ec32f13cd33c9e948290 100644 (file)
@@ -2635,7 +2635,10 @@ allocate_fptr (dyn_i, data)
               || h->root.type == bfd_link_hash_warning)
          h = (struct elf_link_hash_entry *) h->root.u.i.link;
 
-      if (x->info->shared
+      if ((x->info->shared
+          && (!h
+              || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT
+              || h->root.type != bfd_link_hash_undefweak))
          /* AIX needs an FPTR in this case. */
          || (elfNN_ia64_aix_vec (x->info->hash->creator)
              && (!h
@@ -2760,15 +2763,18 @@ allocate_dynrel_entries (dyn_i, data)
   struct elfNN_ia64_allocate_data *x = (struct elfNN_ia64_allocate_data *)data;
   struct elfNN_ia64_link_hash_table *ia64_info;
   struct elfNN_ia64_dyn_reloc_entry *rent;
-  bfd_boolean dynamic_symbol, shared;
+  bfd_boolean dynamic_symbol, shared, resolved_zero;
 
   ia64_info = elfNN_ia64_hash_table (x->info);
   dynamic_symbol = elfNN_ia64_dynamic_symbol_p (dyn_i->h, x->info)
     || (elfNN_ia64_aix_vec (x->info->hash->creator)
        /* Don't allocate an entry for __GLOB_DATA_PTR */
        && (!dyn_i->h || strcmp (dyn_i->h->root.root.string,
-         "__GLOB_DATA_PTR") != 0));
+                                "__GLOB_DATA_PTR") != 0));
   shared = x->info->shared;
+  resolved_zero = (dyn_i->h
+                  && ELF_ST_VISIBILITY (dyn_i->h->other)
+                  && dyn_i->h->root.type == bfd_link_hash_undefweak);
 
   /* Take care of the normal data relocations.  */
 
@@ -2813,8 +2819,12 @@ allocate_dynrel_entries (dyn_i, data)
 
   /* Take care of the GOT and PLT relocations.  */
 
-  if (((dynamic_symbol || shared) && (dyn_i->want_got || dyn_i->want_gotx))
-      || (dyn_i->want_ltoff_fptr && dyn_i->h && dyn_i->h->dynindx != -1))
+  if ((!resolved_zero
+       && (dynamic_symbol || shared)
+       && (dyn_i->want_got || dyn_i->want_gotx))
+      || (dyn_i->want_ltoff_fptr
+         && dyn_i->h
+         && dyn_i->h->dynindx != -1))
     ia64_info->rel_got_sec->_raw_size += sizeof (ElfNN_External_Rela);
   if ((dynamic_symbol || shared) && dyn_i->want_tprel)
     ia64_info->rel_got_sec->_raw_size += sizeof (ElfNN_External_Rela);
@@ -2823,7 +2833,7 @@ allocate_dynrel_entries (dyn_i, data)
   if (dynamic_symbol && dyn_i->want_dtprel)
     ia64_info->rel_got_sec->_raw_size += sizeof (ElfNN_External_Rela);
 
-  if (dyn_i->want_pltoff)
+  if (!resolved_zero && dyn_i->want_pltoff)
     {
       bfd_size_type t = 0;
 
@@ -3431,7 +3441,11 @@ set_got_entry (abfd, info, dyn_i, dynindx, addend, value, dyn_r_type)
       bfd_put_64 (abfd, value, got_sec->contents + got_offset);
 
       /* Install a dynamic relocation if needed.  */
-      if ((info->shared && dyn_r_type != R_IA64_DTPREL64LSB)
+      if ((info->shared
+          && (!dyn_i->h
+              || ELF_ST_VISIBILITY (dyn_i->h->other) == STV_DEFAULT
+              || dyn_i->h->root.type != bfd_link_hash_undefweak)
+          && dyn_r_type != R_IA64_DTPREL64LSB)
           || elfNN_ia64_dynamic_symbol_p (dyn_i->h, info)
          || elfNN_ia64_aix_vec (abfd->xvec)
          || (dynindx != -1 && dyn_r_type == R_IA64_FPTR64LSB))
@@ -3552,7 +3566,11 @@ set_pltoff_entry (abfd, info, dyn_i, value, is_plt)
       bfd_put_64 (abfd, gp, pltoff_sec->contents + dyn_i->pltoff_offset + 8);
 
       /* Install dynamic relocations if needed.  */
-      if (!is_plt && info->shared)
+      if (!is_plt
+         && info->shared
+         && (!dyn_i->h
+             || ELF_ST_VISIBILITY (dyn_i->h->other) == STV_DEFAULT
+             || dyn_i->h->root.type != bfd_link_hash_undefweak))
        {
          unsigned int dyn_r_type;
 
index dcd5724d446cebdac09f9257024279d6decaf75a..10d1dddf4036c66d0e6acdc9d5bfe03e218ed5a5 100644 (file)
@@ -1,3 +1,8 @@
+2003-05-04  H.J. Lu <hjl@gnu.org>
+
+       * ld-elfvsb/main.c: Updated.
+       * ld-elfvsb/sh1.c: Likewise.
+
 2003-05-04  H.J. Lu <hjl@gnu.org>
 
        * ld-elfvers/vers18.dsym: Updated for weak definiton change.
index 6ce97bf4b25045ab970f8ac22908b3cc7f097294..1ce2e3eb3751aba14da3f0f983f90ffaa1c3086b 100644 (file)
@@ -165,6 +165,37 @@ main_visibility_checkweak ()
 {
   return 1;
 }
+#elif defined (HIDDEN_WEAK_TEST)
+int
+main_visibility_checkcom ()
+{
+  return 1;
+}
+
+#pragma weak visibility_undef_var_weak
+extern int visibility_undef_var_weak;
+asm (".hidden visibility_undef_var_weak");
+
+#pragma weak visibility_undef_func_weak
+extern int visibility_undef_func_weak ();
+asm (".hidden visibility_undef_func_weak");
+
+#pragma weak visibility_var_weak
+extern int visibility_var_weak;
+asm (".hidden visibility_var_weak");
+
+#pragma weak visibility_func_weak
+extern int visibility_func_weak ();
+asm (".hidden visibility_func_weak");
+
+int
+main_visibility_checkweak ()
+{
+  return &visibility_undef_var_weak == NULL
+        && &visibility_undef_func_weak == NULL
+        && &visibility_func_weak == NULL
+        && &visibility_var_weak == NULL;
+}
 #elif defined (HIDDEN_UNDEF_TEST)
 extern int visibility_def;
 asm (".hidden visibility_def");
index 2b9b9eeb52308e27ea872bdd6fc6db0582959bb5..8d9fcdbdcb33a9c2b42f6b147ac1b741a7f8567a 100644 (file)
@@ -339,6 +339,37 @@ shlib_visibility_checkweak ()
 {
   return 1;
 }
+#elif defined (HIDDEN_WEAK_TEST)
+#pragma weak shlib_visibility_undef_var_weak
+extern int shlib_visibility_undef_var_weak;
+asm (".hidden shlib_visibility_undef_var_weak");
+
+#pragma weak shlib_visibility_undef_func_weak
+extern int shlib_visibility_undef_func_weak ();
+asm (".hidden shlib_visibility_undef_func_weak");
+
+#pragma weak shlib_visibility_var_weak
+extern int shlib_visibility_var_weak;
+asm (".hidden shlib_visibility_var_weak");
+
+#pragma weak shlib_visibility_func_weak
+extern int shlib_visibility_func_weak ();
+asm (".hidden shlib_visibility_func_weak");
+
+int
+shlib_visibility_checkcom ()
+{
+  return 1;
+}
+
+int
+shlib_visibility_checkweak ()
+{
+  return &shlib_visibility_undef_var_weak == NULL
+        && &shlib_visibility_undef_func_weak == NULL
+        && &shlib_visibility_func_weak == NULL
+        && &shlib_visibility_var_weak == NULL;
+}
 #else
 int
 shlib_visibility_checkcom ()