(_bfd_dwarf2_find_nearest_line): If address length is zero, set it to 8 for
[deliverable/binutils-gdb.git] / bfd / cofflink.c
index e99c470cf482db5504f965f64ccd9b9e6e641e99..eb9388fc71ed5d4ad35adc687968317573715ce7 100644 (file)
@@ -1,5 +1,5 @@
 /* COFF specific linker code.
-   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001
+   Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002
    Free Software Foundation, Inc.
    Written by Ian Lance Taylor, Cygnus Support.
 
@@ -119,13 +119,13 @@ _bfd_coff_link_hash_table_create (abfd)
   struct coff_link_hash_table *ret;
   bfd_size_type amt = sizeof (struct coff_link_hash_table);
 
-  ret = (struct coff_link_hash_table *) bfd_alloc (abfd, amt);
+  ret = (struct coff_link_hash_table *) bfd_malloc (amt);
   if (ret == NULL)
     return NULL;
   if (! _bfd_coff_link_hash_table_init (ret, abfd,
                                        _bfd_coff_link_hash_newfunc))
     {
-      bfd_release (abfd, ret);
+      free (ret);
       return (struct bfd_link_hash_table *) NULL;
     }
   return &ret->root;
@@ -342,12 +342,10 @@ coff_link_add_symbols (abfd, info)
   /* We keep a list of the linker hash table entries that correspond
      to particular symbols.  */
   amt = symcount * sizeof (struct coff_link_hash_entry *);
-  sym_hash = (struct coff_link_hash_entry **) bfd_alloc (abfd, amt);
+  sym_hash = (struct coff_link_hash_entry **) bfd_zalloc (abfd, amt);
   if (sym_hash == NULL && symcount != 0)
     goto error_return;
   obj_coff_sym_hashes (abfd) = sym_hash;
-  memset (sym_hash, 0,
-         (size_t) symcount * sizeof (struct coff_link_hash_entry *));
 
   symesz = bfd_coff_symesz (abfd);
   BFD_ASSERT (symesz == bfd_coff_auxesz (abfd));
@@ -442,7 +440,7 @@ coff_link_add_symbols (abfd, info)
 
          /* The Microsoft Visual C compiler does string pooling by
             hashing the constants to an internal symbol name, and
-            relying on the the linker comdat support to discard
+            relying on the linker comdat support to discard
             duplicate names.  However, if one string is a literal and
             one is a data initializer, one will end up in the .data
             section and one will end up in the .rdata section.  The
@@ -535,7 +533,7 @@ coff_link_add_symbols (abfd, info)
                        (*_bfd_error_handler)
                          (_("Warning: type of symbol `%s' changed from %d to %d in %s"),
                           name, (*sym_hash)->type, sym.n_type,
-                          bfd_get_filename (abfd));
+                          bfd_archive_filename (abfd));
 
                      /* We don't want to change from a meaningful
                         base type to a null one, but if we know
@@ -759,6 +757,10 @@ _bfd_coff_final_link (abfd, info)
          o->flags |= SEC_RELOC;
          o->rel_filepos = rel_filepos;
          rel_filepos += o->reloc_count * relsz;
+         /* In PE COFF, if there are at least 0xffff relocations an
+            extra relocation will be written out to encode the count.  */
+         if (obj_pe (abfd) && o->reloc_count >= 0xffff)
+           rel_filepos += relsz;
        }
 
       if (bfd_coff_long_section_names (abfd)
@@ -1005,7 +1007,8 @@ _bfd_coff_final_link (abfd, info)
   if (info->task_link)
     {
       finfo.failed = false;
-      coff_link_hash_traverse (coff_hash_table (info), _bfd_coff_write_task_globals,
+      coff_link_hash_traverse (coff_hash_table (info),
+                              _bfd_coff_write_task_globals,
                               (PTR) &finfo);
       if (finfo.failed)
        goto error_return;
@@ -1013,7 +1016,8 @@ _bfd_coff_final_link (abfd, info)
 
   /* Write out the global symbols.  */
   finfo.failed = false;
-  coff_link_hash_traverse (coff_hash_table (info), _bfd_coff_write_global_sym,
+  coff_link_hash_traverse (coff_hash_table (info),
+                          _bfd_coff_write_global_sym,
                           (PTR) &finfo);
   if (finfo.failed)
     goto error_return;
@@ -1516,15 +1520,13 @@ _bfd_coff_link_input_bfd (finfo, input_bfd)
 
 #ifndef COFF_WITH_PE
       /* Skip section symbols for sections which are not going to be
-        emitted, or which belong to linkonce sections that are going
-        to be discarded.  */
+        emitted.  */
       if (!skip
          && isym.n_sclass == C_STAT
          && isym.n_type == T_NULL
           && isym.n_numaux > 0)
         {
-          if ((*secpp)->output_section == bfd_abs_section_ptr
-              || (*secpp)->kept_section)
+          if ((*secpp)->output_section == bfd_abs_section_ptr)
             skip = true;
         }
 #endif
@@ -2317,7 +2319,7 @@ _bfd_coff_link_input_bfd (finfo, input_bfd)
            {
              ((*_bfd_error_handler)
               (_("%s: relocs in section `%s', but it has no contents"),
-               bfd_get_filename (input_bfd),
+               bfd_archive_filename (input_bfd),
                bfd_get_section_name (input_bfd, o)));
              bfd_set_error (bfd_error_no_contents);
              return false;
@@ -2499,6 +2501,13 @@ _bfd_coff_write_global_sym (h, data)
 
   output_bfd = finfo->output_bfd;
 
+  if (h->root.type == bfd_link_hash_warning)
+    {
+      h = (struct coff_link_hash_entry *) h->root.u.i.link;
+      if (h->root.type == bfd_link_hash_new)
+       return true;
+    }
+
   if (h->indx >= 0)
     return true;
 
@@ -2514,6 +2523,7 @@ _bfd_coff_write_global_sym (h, data)
     {
     default:
     case bfd_link_hash_new:
+    case bfd_link_hash_warning:
       abort ();
       return false;
 
@@ -2546,7 +2556,6 @@ _bfd_coff_write_global_sym (h, data)
       break;
 
     case bfd_link_hash_indirect:
-    case bfd_link_hash_warning:
       /* Just ignore these.  They can't be handled anyhow.  */
       return true;
     }
@@ -2701,6 +2710,9 @@ _bfd_coff_write_task_globals (h, data)
   boolean rtnval = true;
   boolean save_global_to_static;
 
+  if (h->root.type == bfd_link_hash_warning)
+    h = (struct coff_link_hash_entry *) h->root.u.i.link;
+
   if (h->indx < 0)
     {
       switch (h->root.type)
@@ -2895,7 +2907,7 @@ _bfd_coff_generic_relocate_section (output_bfd, info, input_bfd,
        {
          (*_bfd_error_handler)
            ("%s: illegal symbol index %ld in relocs",
-            bfd_get_filename (input_bfd), symndx);
+            bfd_archive_filename (input_bfd), symndx);
          return false;
        }
       else
@@ -3017,7 +3029,7 @@ _bfd_coff_generic_relocate_section (output_bfd, info, input_bfd,
        case bfd_reloc_outofrange:
          (*_bfd_error_handler)
            (_("%s: bad reloc address 0x%lx in section `%s'"),
-            bfd_get_filename (input_bfd),
+            bfd_archive_filename (input_bfd),
             (unsigned long) rel->r_vaddr,
             bfd_get_section_name (input_bfd, input_section));
          return false;
This page took 0.026388 seconds and 4 git commands to generate.