* elflink.h (elf_link_input_bfd): Discard local symbols that are
[deliverable/binutils-gdb.git] / bfd / elflink.h
index 8be2f2d6ab7ae596413ed8ca9184748aebc66f59..dd5b4db72637be11cdedeb8c1889fc4d7f7163c9 100644 (file)
@@ -1,5 +1,5 @@
 /* ELF linker support.
-   Copyright 1995, 1996 Free Software Foundation, Inc.
+   Copyright 1995, 1996, 1997 Free Software Foundation, Inc.
 
 This file is part of BFD, the Binary File Descriptor library.
 
@@ -35,7 +35,7 @@ struct elf_info_failed
 {
   boolean failed;
   struct bfd_link_info *info;
-};  
+};
 
 /* Given an ELF BFD, add symbols to the global hash table as
    appropriate.  */
@@ -281,7 +281,7 @@ elf_link_add_object_symbols (abfd, info)
                goto error_return;
 
              if (! (_bfd_generic_link_add_one_symbol
-                    (info, abfd, 
+                    (info, abfd,
                      name + sizeof ".gnu.warning." - 1,
                      BSF_WARNING, s, (bfd_vma) 0, msg, false, collect,
                      (struct bfd_link_hash_entry **) NULL)))
@@ -810,8 +810,7 @@ elf_link_add_object_symbols (abfd, info)
             reference or definition we just found.  Keep a count of
             the number of dynamic symbols we find.  A dynamic symbol
             is one which is referenced or defined by both a regular
-            object and a shared object, or one which is referenced or
-            defined by more than one shared object.  */
+            object and a shared object.  */
          old_flags = h->elf_link_hash_flags;
          dynsym = false;
          if (! dynamic)
@@ -834,8 +833,8 @@ elf_link_add_object_symbols (abfd, info)
              if ((old_flags & (ELF_LINK_HASH_DEF_REGULAR
                                | ELF_LINK_HASH_REF_REGULAR)) != 0
                  || (h->weakdef != NULL
-                     && (old_flags & (ELF_LINK_HASH_DEF_DYNAMIC
-                                      | ELF_LINK_HASH_REF_DYNAMIC)) != 0))
+                     && ! new_weakdef
+                     && h->weakdef->dynindx != -1))
                dynsym = true;
            }
 
@@ -912,6 +911,18 @@ elf_link_add_object_symbols (abfd, info)
                    goto error_return;
                }
 
+             /* If the real definition is in the list of dynamic
+                 symbols, make sure the weak definition is put there
+                 as well.  If we don't do this, then the dynamic
+                 loader might not merge the entries for the real
+                 definition and the weak definition.  */
+             if (h->dynindx != -1
+                 && hlook->dynindx == -1)
+               {
+                 if (! _bfd_elf_link_record_dynamic_symbol (info, hlook))
+                   goto error_return;
+               }
+
              break;
            }
        }
@@ -1040,7 +1051,8 @@ elf_link_create_dynamic_sections (abfd, info)
 
   /* Note that we set the SEC_IN_MEMORY flag for all of these
      sections.  */
-  flags = SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY;
+  flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS
+          | SEC_IN_MEMORY | SEC_LINKER_CREATED);
 
   /* A dynamically linked executable has a .interp section, but a
      shared library does not.  */
@@ -1246,7 +1258,7 @@ NAME(_bfd_elf,link_read_relocs) (abfd, o, external_relocs, internal_relocs,
   /* Cache the results for next time, if we can.  */
   if (keep_memory)
     elf_section_data (o)->relocs = internal_relocs;
-                
+
   if (alloc1 != NULL)
     free (alloc1);
 
@@ -1326,11 +1338,12 @@ NAME(bfd_elf,record_link_assignment) (output_bfd, info, name, provide)
    based on the number of symbols there are.  If there are fewer than
    3 symbols we use 1 bucket, fewer than 17 symbols we use 3 buckets,
    fewer than 37 we use 17 buckets, and so forth.  We never use more
-   than 521 buckets.  */
+   than 32771 buckets.  */
 
 static const size_t elf_buckets[] =
 {
-  1, 3, 17, 37, 67, 97, 131, 197, 263, 521, 0
+  1, 3, 17, 37, 67, 97, 131, 197, 263, 521, 1031, 2053, 4099, 8209,
+  16411, 32771, 0
 };
 
 /* Set up the sizes and contents of the ELF dynamic sections.  This is
@@ -1340,11 +1353,14 @@ static const size_t elf_buckets[] =
 
 boolean
 NAME(bfd_elf,size_dynamic_sections) (output_bfd, soname, rpath,
-                                    export_dynamic, info, sinterpptr)
+                                    export_dynamic, filter_shlib,
+                                    auxiliary_filters, info, sinterpptr)
      bfd *output_bfd;
      const char *soname;
      const char *rpath;
      boolean export_dynamic;
+     const char *filter_shlib;
+     const char * const *auxiliary_filters;
      struct bfd_link_info *info;
      asection **sinterpptr;
 {
@@ -1356,6 +1372,13 @@ NAME(bfd_elf,size_dynamic_sections) (output_bfd, soname, rpath,
   if (info->hash->creator->flavour != bfd_target_elf_flavour)
     return true;
 
+  /* The backend may have to create some sections regardless of whether
+     we're dynamic or not.  */
+  bed = get_elf_backend_data (output_bfd);
+  if (bed->elf_backend_always_size_sections
+      && ! (*bed->elf_backend_always_size_sections) (output_bfd, info))
+    return false;
+
   dynobj = elf_hash_table (info)->dynobj;
 
   /* If there were no dynamic objects in the link, there is nothing to
@@ -1395,7 +1418,7 @@ NAME(bfd_elf,size_dynamic_sections) (output_bfd, soname, rpath,
          if (indx == (bfd_size_type) -1
              || ! elf_add_dynamic_entry (info, DT_SONAME, indx))
            return false;
-       }      
+       }
 
       if (info->symbolic)
        {
@@ -1414,6 +1437,33 @@ NAME(bfd_elf,size_dynamic_sections) (output_bfd, soname, rpath,
            return false;
        }
 
+      if (filter_shlib != NULL)
+       {
+         bfd_size_type indx;
+
+         indx = _bfd_stringtab_add (elf_hash_table (info)->dynstr,
+                                    filter_shlib, true, true);
+         if (indx == (bfd_size_type) -1
+             || ! elf_add_dynamic_entry (info, DT_FILTER, indx))
+           return false;
+       }
+
+      if (auxiliary_filters != NULL)
+       {
+         const char * const *p;
+
+         for (p = auxiliary_filters; *p != NULL; p++)
+           {
+             bfd_size_type indx;
+
+             indx = _bfd_stringtab_add (elf_hash_table (info)->dynstr,
+                                        *p, true, true);
+             if (indx == (bfd_size_type) -1
+                 || ! elf_add_dynamic_entry (info, DT_AUXILIARY, indx))
+               return false;
+           }
+       }
+
       /* Find all symbols which were defined in a dynamic object and make
         the backend pick a reasonable value for them.  */
       eif.failed = false;
@@ -1457,7 +1507,6 @@ NAME(bfd_elf,size_dynamic_sections) (output_bfd, soname, rpath,
 
   /* The backend must work out the sizes of all the other dynamic
      sections.  */
-  bed = get_elf_backend_data (output_bfd);
   if (! (*bed->elf_backend_size_dynamic_sections) (output_bfd, info))
     return false;
 
@@ -1768,7 +1817,7 @@ struct elf_finfo_failed
 {
   boolean failed;
   struct elf_final_link_info *finfo;
-};  
+};
 
 /* Do the final step of an ELF link.  */
 
@@ -2184,7 +2233,7 @@ elf_bfd_final_link (abfd, info)
        {
          if (*rel_hash == NULL)
            continue;
-             
+
          BFD_ASSERT ((*rel_hash)->indx >= 0);
 
          if (rel_hdr->sh_entsize == sizeof (Elf_External_Rel))
@@ -2338,11 +2387,10 @@ elf_bfd_final_link (abfd, info)
          if ((o->flags & SEC_HAS_CONTENTS) == 0
              || o->_raw_size == 0)
            continue;
-         if ((o->flags & SEC_IN_MEMORY) == 0)
+         if ((o->flags & SEC_LINKER_CREATED) == 0)
            {
              /* At this point, we are only interested in sections
-                 created by elf_link_create_dynamic_sections.  FIXME:
-                 This test is fragile.  */
+                 created by elf_link_create_dynamic_sections.  */
              continue;
            }
          if ((elf_section_data (o->output_section)->this_hdr.sh_type
@@ -2833,9 +2881,20 @@ elf_link_input_bfd (finfo, input_bfd)
       if (finfo->info->discard == discard_all)
        continue;
 
+      /* If this symbol is defined in a section which we are
+         discarding, we don't need to keep it.  For the benefit of the
+         MIPS ELF linker, we check SEC_EXCLUDE as well as linker_mark.  */
+      if (isym->st_shndx > 0
+         && isym->st_shndx < SHN_LORESERVE
+         && isec != NULL
+         && (! isec->linker_mark
+             || (! finfo->info->relocateable
+                 && (isec->flags & SEC_EXCLUDE) != 0)))
+       continue;
+
       /* Get the name of the symbol.  */
       name = bfd_elf_string_from_elf_section (input_bfd, symtab_hdr->sh_link,
-                                         isym->st_name);
+                                             isym->st_name);
       if (name == NULL)
        return false;
 
@@ -2890,11 +2949,10 @@ elf_link_input_bfd (finfo, input_bfd)
          || (o->_raw_size == 0 && (o->flags & SEC_RELOC) == 0))
        continue;
 
-      if ((o->flags & SEC_IN_MEMORY) != 0
-         && input_bfd == elf_hash_table (finfo->info)->dynobj)
+      if ((o->flags & SEC_LINKER_CREATED) != 0)
        {
-         /* Section was created by elf_link_create_dynamic_sections.
-             FIXME: This test is fragile.  */
+         /* Section was created by elf_link_create_dynamic_sections
+            or somesuch.  */
          continue;
        }
 
This page took 0.027628 seconds and 4 git commands to generate.