bfd/
[deliverable/binutils-gdb.git] / ld / ldmain.c
index e89bceab0f350c4fdf17d2d7f8d659ce79e589d8..1784b16c16acb87825b96c336a0a8169e12b7246 100644 (file)
@@ -1,6 +1,6 @@
 /* Main program of GNU linker.
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
-   2002, 2003, 2004, 2005
+   2002, 2003, 2004, 2005, 2006
    Free Software Foundation, Inc.
    Written by Steve Chamberlain steve@cygnus.com
 
@@ -18,8 +18,8 @@
 
    You should have received a copy of the GNU General Public License
    along with GLD; see the file COPYING.  If not, write to the Free
-   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA.  */
+   Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
+   02110-1301, USA.  */
 
 #include "bfd.h"
 #include "sysdep.h"
@@ -50,7 +50,7 @@
 #include <string.h>
 
 #ifdef HAVE_SBRK
-#ifdef NEED_DECLARATION_SBRK
+#if !HAVE_DECL_SBRK
 extern void *sbrk ();
 #endif
 #endif
@@ -160,7 +160,8 @@ static struct bfd_link_callbacks link_callbacks =
   reloc_overflow,
   reloc_dangerous,
   unattached_reloc,
-  notice
+  notice,
+  einfo
 };
 
 struct bfd_link_info link_info;
@@ -197,6 +198,8 @@ main (int argc, char **argv)
 
   START_PROGRESS (program_name, 0);
 
+  expandargv (&argc, &argv);
+
   bfd_init ();
 
   bfd_set_error_program_name (program_name);
@@ -209,7 +212,7 @@ main (int argc, char **argv)
     {
       if (*TARGET_SYSTEM_ROOT == 0)
        {
-         einfo ("%P%F: this linker was not configured to use sysroots");
+         einfo ("%P%F: this linker was not configured to use sysroots\n");
          ld_sysroot = "";
        }
       else
@@ -253,7 +256,6 @@ main (int argc, char **argv)
   command_line.warn_mismatch = TRUE;
   command_line.check_section_addresses = TRUE;
   command_line.accept_unknown_input_arch = FALSE;
-  command_line.reduce_memory_overheads = FALSE;
 
   sort_section = none;
 
@@ -301,6 +303,8 @@ main (int argc, char **argv)
   link_info.create_object_symbols_section = NULL;
   link_info.gc_sym_list = NULL;
   link_info.base_file = NULL;
+  link_info.emit_hash = TRUE;
+  link_info.emit_gnu_hash = FALSE;
   /* SVR4 linkers seem to set DT_INIT and DT_FINI based on magic _init
      and _fini symbols.  We are compatible.  */
   link_info.init_function = "_init";
@@ -310,9 +314,15 @@ main (int argc, char **argv)
   link_info.spare_dynamic_tags = 5;
   link_info.flags = 0;
   link_info.flags_1 = 0;
-  link_info.need_relax_finalize = FALSE;
+  link_info.relax_pass = 1;
   link_info.warn_shared_textrel = FALSE;
   link_info.gc_sections = FALSE;
+  link_info.print_gc_sections = FALSE;
+  link_info.dynamic = NULL;
+  link_info.reduce_memory_overheads = FALSE;
+
+  config.maxpagesize = 0;
+  config.commonpagesize = 0;
 
   ldfile_add_arch ("");
 
@@ -332,6 +342,13 @@ main (int argc, char **argv)
   if (config.hash_table_size != 0)
     bfd_hash_set_default_size (config.hash_table_size);
 
+  if (config.maxpagesize != 0)
+    bfd_emul_set_maxpagesize (default_target, config.maxpagesize);
+
+  if (config.commonpagesize != 0)
+    bfd_emul_set_commonpagesize (default_target,
+                                config.commonpagesize);
+
   ldemul_set_symbols ();
 
   if (link_info.relocatable)
@@ -344,9 +361,6 @@ main (int argc, char **argv)
        einfo (_("%P%F: -r and -shared may not be used together\n"));
     }
 
-   if (!config.dynamic_link && link_info.shared)
-     einfo (_("%P%F: -static and -shared may not be used together\n"));
-
   if (! link_info.shared)
     {
       if (command_line.filter_shlib)
@@ -474,6 +488,8 @@ main (int argc, char **argv)
   if (nocrossref_list != NULL)
     check_nocrossrefs ();
 
+  lang_finish ();
+
   /* Even if we're producing relocatable output, some non-fatal errors should
      be reported in the exit status.  (What non-fatal errors, if any, do we
      want to ignore for relocatable output?)  */
@@ -592,7 +608,7 @@ get_sysroot (int argc, char **argv)
   const char *path;
 
   for (i = 1; i < argc; i++)
-    if (strncmp (argv[i], "--sysroot=", strlen ("--sysroot=")) == 0)
+    if (CONST_STRNEQ (argv[i], "--sysroot="))
       return argv[i] + strlen ("--sysroot=");
 
   path = get_relative_sysroot (BINDIR);
@@ -621,7 +637,7 @@ get_emulation (int argc, char **argv)
 
   for (i = 1; i < argc; i++)
     {
-      if (!strncmp (argv[i], "-m", 2))
+      if (CONST_STRNEQ (argv[i], "-m"))
        {
          if (argv[i][2] == '\0')
            {
@@ -775,9 +791,10 @@ add_ysym (const char *name)
   if (link_info.notice_hash == NULL)
     {
       link_info.notice_hash = xmalloc (sizeof (struct bfd_hash_table));
-      if (! bfd_hash_table_init_n (link_info.notice_hash,
-                                  bfd_hash_newfunc,
-                                  61))
+      if (!bfd_hash_table_init_n (link_info.notice_hash,
+                                 bfd_hash_newfunc,
+                                 sizeof (struct bfd_hash_entry),
+                                 61))
        einfo (_("%P%F: bfd_hash_table_init failed: %E\n"));
     }
 
@@ -793,9 +810,10 @@ add_wrap (const char *name)
   if (link_info.wrap_hash == NULL)
     {
       link_info.wrap_hash = xmalloc (sizeof (struct bfd_hash_table));
-      if (! bfd_hash_table_init_n (link_info.wrap_hash,
-                                  bfd_hash_newfunc,
-                                  61))
+      if (!bfd_hash_table_init_n (link_info.wrap_hash,
+                                 bfd_hash_newfunc,
+                                 sizeof (struct bfd_hash_entry),
+                                 61))
        einfo (_("%P%F: bfd_hash_table_init failed: %E\n"));
     }
 
@@ -825,7 +843,8 @@ add_keepsyms_file (const char *filename)
     }
 
   link_info.keep_hash = xmalloc (sizeof (struct bfd_hash_table));
-  if (! bfd_hash_table_init (link_info.keep_hash, bfd_hash_newfunc))
+  if (!bfd_hash_table_init (link_info.keep_hash, bfd_hash_newfunc,
+                           sizeof (struct bfd_hash_entry)))
     einfo (_("%P%F: bfd_hash_table_init failed: %E\n"));
 
   bufsize = 100;
@@ -873,7 +892,7 @@ add_keepsyms_file (const char *filename)
    a link.  */
 
 static bfd_boolean
-add_archive_element (struct bfd_link_info *info ATTRIBUTE_UNUSED,
+add_archive_element (struct bfd_link_info *info,
                     bfd *abfd,
                     const char *name)
 {
@@ -904,7 +923,7 @@ add_archive_element (struct bfd_link_info *info ATTRIBUTE_UNUSED,
       bfd *from;
       int len;
 
-      h = bfd_link_hash_lookup (link_info.hash, name, FALSE, FALSE, TRUE);
+      h = bfd_link_hash_lookup (info->hash, name, FALSE, FALSE, TRUE);
 
       if (h == NULL)
        from = NULL;
@@ -1145,7 +1164,7 @@ constructor_callback (struct bfd_link_info *info,
   /* Ensure that BFD_RELOC_CTOR exists now, so that we can give a
      useful error message.  */
   if (bfd_reloc_type_lookup (output_bfd, BFD_RELOC_CTOR) == NULL
-      && (link_info.relocatable
+      && (info->relocatable
          || bfd_reloc_type_lookup (abfd, BFD_RELOC_CTOR) == NULL))
     einfo (_("%P%F: BFD backend error: BFD_RELOC_CTOR unsupported\n"));
 
@@ -1324,7 +1343,8 @@ undefined_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
       if (hash == NULL)
        {
          hash = xmalloc (sizeof (struct bfd_hash_table));
-         if (! bfd_hash_table_init (hash, bfd_hash_newfunc))
+         if (!bfd_hash_table_init (hash, bfd_hash_newfunc,
+                                   sizeof (struct bfd_hash_entry)))
            einfo (_("%F%P: bfd_hash_table_init failed: %E\n"));
        }
 
@@ -1422,10 +1442,7 @@ reloc_overflow (struct bfd_link_info *info ATTRIBUTE_UNUSED,
   if (overflow_cutoff_limit == -1)
     return TRUE;
 
-  if (abfd == NULL)
-    einfo (_("%P%X: generated"));
-  else
-    einfo ("%X%C:", abfd, section, address);
+  einfo ("%X%C:", abfd, section, address);
 
   if (overflow_cutoff_limit >= 0
       && overflow_cutoff_limit-- == 0)
@@ -1477,11 +1494,8 @@ reloc_dangerous (struct bfd_link_info *info ATTRIBUTE_UNUSED,
                 asection *section,
                 bfd_vma address)
 {
-  if (abfd == NULL)
-    einfo (_("%P%X: generated"));
-  else
-    einfo ("%X%C:", abfd, section, address);
-  einfo (_("dangerous relocation: %s\n"), message);
+  einfo (_("%X%C: dangerous relocation: %s\n"),
+        abfd, section, address, message);
   return TRUE;
 }
 
@@ -1495,11 +1509,8 @@ unattached_reloc (struct bfd_link_info *info ATTRIBUTE_UNUSED,
                  asection *section,
                  bfd_vma address)
 {
-  if (abfd == NULL)
-    einfo (_("%P%X: generated"));
-  else
-    einfo ("%X%C:", abfd, section, address);
-  einfo (_(" reloc refers to symbol `%T' which is not being output\n"), name);
+  einfo (_("%X%C: reloc refers to symbol `%T' which is not being output\n"),
+        abfd, section, address, name);
   return TRUE;
 }
 
@@ -1514,6 +1525,13 @@ notice (struct bfd_link_info *info,
        asection *section,
        bfd_vma value)
 {
+  if (name == NULL)
+    {
+      if (command_line.cref || nocrossref_list != NULL)
+       return handle_asneeded_cref (abfd, value);
+      return TRUE;
+    }
+
   if (! info->notice_all
       || (info->notice_hash != NULL
          && bfd_hash_lookup (info->notice_hash, name, FALSE, FALSE) != NULL))
This page took 0.027396 seconds and 4 git commands to generate.