binutils/
[deliverable/binutils-gdb.git] / ld / ldmain.c
index bf3c0e6ded2d158575bc789c8a39f85175ab81e5..08679ecbb50b27a4e4fae662590325c567521985 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, 2006, 2007, 2008
+   2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
    Free Software Foundation, Inc.
    Written by Steve Chamberlain steve@cygnus.com
 
@@ -93,13 +93,14 @@ bfd_boolean version_printed;
 /* Nonzero means link in every member of an archive.  */
 bfd_boolean whole_archive;
 
-/* Nonzero means create DT_NEEDED entries only if a dynamic library
-   actually satisfies some reference in a regular object.  */
-bfd_boolean as_needed;
+/* True means only create DT_NEEDED entries for dynamic libraries
+   if they actually satisfy some reference in a regular object.  */
+bfd_boolean add_DT_NEEDED_for_regular;
 
-/* Nonzero means never create DT_NEEDED entries for dynamic libraries
-   in DT_NEEDED tags.  */
-bfd_boolean add_needed = TRUE;
+/* True means create DT_NEEDED entries for dynamic libraries that
+   are DT_NEEDED by dynamic libraries specifically mentioned on
+   the command line.  */
+bfd_boolean add_DT_NEEDED_for_dynamic = TRUE;
 
 /* TRUE if we should demangle symbol names.  */
 bfd_boolean demangling;
@@ -251,7 +252,8 @@ main (int argc, char **argv)
 
   command_line.warn_mismatch = TRUE;
   command_line.warn_search_mismatch = TRUE;
-  command_line.check_section_addresses = TRUE;
+  command_line.check_section_addresses = -1;
+  command_line.disable_target_specific_optimizations = -1;
 
   /* We initialize DEMANGLING based on the environment variable
      COLLECT_NO_DEMANGLE.  The gcc collect2 program will demangle the
@@ -280,6 +282,8 @@ main (int argc, char **argv)
   emulation = get_emulation (argc, argv);
   ldemul_choose_mode (emulation);
   default_target = ldemul_choose_target (argc, argv);
+  config.maxpagesize = bfd_emul_get_maxpagesize (default_target);
+  config.commonpagesize = bfd_emul_get_commonpagesize (default_target);
   lang_init ();
   ldemul_before_parse ();
   lang_has_input_file = FALSE;
@@ -292,8 +296,8 @@ main (int argc, char **argv)
 
   if (link_info.relocatable)
     {
-      if (command_line.relax)
-       einfo (_("%P%F: --relax and -r may not be used together\n"));
+      if (command_line.check_section_addresses < 0)
+       command_line.check_section_addresses = 0;
       if (link_info.shared)
        einfo (_("%P%F: -r and -shared may not be used together\n"));
     }
@@ -374,7 +378,7 @@ main (int argc, char **argv)
       char *s = ldemul_get_script (&isfile);
 
       if (isfile)
-       ldfile_open_command_file (s);
+       ldfile_open_default_command_file (s);
       else
        {
          lex_string = s;
@@ -397,7 +401,7 @@ main (int argc, char **argv)
        {
          static const int ld_bufsz = 8193;
          size_t n;
-         char *buf = xmalloc (ld_bufsz);
+         char *buf = (char *) xmalloc (ld_bufsz);
 
          rewind (saved_script_handle);
          while ((n = fread (buf, 1, ld_bufsz - 1, saved_script_handle)) > 0)
@@ -501,9 +505,9 @@ main (int argc, char **argv)
              FILE *src;
              FILE *dst;
              const int bsize = 4096;
-             char *buf = xmalloc (bsize);
+             char *buf = (char *) xmalloc (bsize);
              int l;
-             char *dst_name = xmalloc (len + 5);
+             char *dst_name = (char *) xmalloc (len + 5);
 
              strcpy (dst_name, output_filename);
              strcat (dst_name, ".exe");
@@ -538,7 +542,7 @@ main (int argc, char **argv)
   if (config.stats)
     {
 #ifdef HAVE_SBRK
-      char *lim = sbrk (0);
+      char *lim = (char *) sbrk (0);
 #endif
       long run_time = get_run_time () - start_time;
 
@@ -670,7 +674,8 @@ add_ysym (const char *name)
 {
   if (link_info.notice_hash == NULL)
     {
-      link_info.notice_hash = xmalloc (sizeof (struct bfd_hash_table));
+      link_info.notice_hash =
+          (struct bfd_hash_table *) xmalloc (sizeof (struct bfd_hash_table));
       if (!bfd_hash_table_init_n (link_info.notice_hash,
                                  bfd_hash_newfunc,
                                  sizeof (struct bfd_hash_entry),
@@ -689,7 +694,8 @@ add_wrap (const char *name)
 {
   if (link_info.wrap_hash == NULL)
     {
-      link_info.wrap_hash = xmalloc (sizeof (struct bfd_hash_table));
+      link_info.wrap_hash =
+          (struct bfd_hash_table *) xmalloc (sizeof (struct bfd_hash_table));
       if (!bfd_hash_table_init_n (link_info.wrap_hash,
                                  bfd_hash_newfunc,
                                  sizeof (struct bfd_hash_entry),
@@ -722,13 +728,14 @@ add_keepsyms_file (const char *filename)
       return;
     }
 
-  link_info.keep_hash = xmalloc (sizeof (struct bfd_hash_table));
+  link_info.keep_hash = (struct bfd_hash_table *)
+      xmalloc (sizeof (struct bfd_hash_table));
   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;
-  buf = xmalloc (bufsize);
+  buf = (char *) xmalloc (bufsize);
 
   c = getc (file);
   while (c != EOF)
@@ -747,7 +754,7 @@ add_keepsyms_file (const char *filename)
              if (len >= bufsize)
                {
                  bufsize *= 2;
-                 buf = xrealloc (buf, bufsize);
+                 buf = (char *) xrealloc (buf, bufsize);
                }
              c = getc (file);
            }
@@ -778,21 +785,11 @@ add_archive_element (struct bfd_link_info *info,
 {
   lang_input_statement_type *input;
 
-  input = xmalloc (sizeof (lang_input_statement_type));
+  input = (lang_input_statement_type *)
+      xcalloc (1, sizeof (lang_input_statement_type));
   input->filename = abfd->filename;
   input->local_sym_name = abfd->filename;
   input->the_bfd = abfd;
-  input->asymbols = NULL;
-  input->next = NULL;
-  input->just_syms_flag = FALSE;
-  input->loaded = FALSE;
-  input->search_dirs_flag = FALSE;
-
-  /* FIXME: The following fields are not set: header.next,
-     header.type, closed, passive_position, symbol_count,
-     next_real_file, is_archive, target, real.  This bit of code is
-     from the old decode_library_subfile function.  I don't know
-     whether any of those fields matters.  */
 
   ldlang_add_file (input);
 
@@ -910,10 +907,10 @@ multiple_definition (struct bfd_link_info *info ATTRIBUTE_UNUSED,
   if (obfd != NULL)
     einfo (_("%D: first defined here\n"), obfd, osec, oval);
 
-  if (command_line.relax)
+  if (RELAXATION_ENABLED)
     {
       einfo (_("%P: Disabling relaxation: it will not work with multiple definitions\n"));
-      command_line.relax = 0;
+      command_line.disable_target_specific_optimizations = -1;
     }
 
   return TRUE;
@@ -1107,45 +1104,22 @@ warning_callback (struct bfd_link_info *info ATTRIBUTE_UNUSED,
     einfo ("%B: %s%s\n", abfd, _("warning: "), warning);
   else
     {
-      lang_input_statement_type *entry;
-      asymbol **asymbols;
-      struct warning_callback_info info;
+      struct warning_callback_info cinfo;
 
       /* Look through the relocs to see if we can find a plausible
         address.  */
-      entry = (lang_input_statement_type *) abfd->usrdata;
-      if (entry != NULL && entry->asymbols != NULL)
-       asymbols = entry->asymbols;
-      else
-       {
-         long symsize;
-         long symbol_count;
-
-         symsize = bfd_get_symtab_upper_bound (abfd);
-         if (symsize < 0)
-           einfo (_("%B%F: could not read symbols: %E\n"), abfd);
-         asymbols = xmalloc (symsize);
-         symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
-         if (symbol_count < 0)
-           einfo (_("%B%F: could not read symbols: %E\n"), abfd);
-         if (entry != NULL)
-           {
-             entry->asymbols = asymbols;
-             entry->symbol_count = symbol_count;
-           }
-       }
 
-      info.found = FALSE;
-      info.warning = warning;
-      info.symbol = symbol;
-      info.asymbols = asymbols;
-      bfd_map_over_sections (abfd, warning_find_reloc, &info);
+      if (!bfd_generic_link_read_symbols (abfd))
+       einfo (_("%B%F: could not read symbols: %E\n"), abfd);
 
-      if (! info.found)
-       einfo ("%B: %s%s\n", abfd, _("warning: "), warning);
+      cinfo.found = FALSE;
+      cinfo.warning = warning;
+      cinfo.symbol = symbol;
+      cinfo.asymbols = bfd_get_outsymbols (abfd);
+      bfd_map_over_sections (abfd, warning_find_reloc, &cinfo);
 
-      if (entry == NULL)
-       free (asymbols);
+      if (! cinfo.found)
+       einfo ("%B: %s%s\n", abfd, _("warning: "), warning);
     }
 
   return TRUE;
@@ -1159,7 +1133,7 @@ warning_callback (struct bfd_link_info *info ATTRIBUTE_UNUSED,
 static void
 warning_find_reloc (bfd *abfd, asection *sec, void *iarg)
 {
-  struct warning_callback_info *info = iarg;
+  struct warning_callback_info *info = (struct warning_callback_info *) iarg;
   long relsize;
   arelent **relpp;
   long relcount;
@@ -1174,7 +1148,7 @@ warning_find_reloc (bfd *abfd, asection *sec, void *iarg)
   if (relsize == 0)
     return;
 
-  relpp = xmalloc (relsize);
+  relpp = (arelent **) xmalloc (relsize);
   relcount = bfd_canonicalize_reloc (abfd, sec, relpp, info->asymbols);
   if (relcount < 0)
     einfo (_("%B%F: could not read relocs: %E\n"), abfd);
@@ -1222,7 +1196,8 @@ undefined_symbol (struct bfd_link_info *info ATTRIBUTE_UNUSED,
       /* Only warn once about a particular undefined symbol.  */
       if (hash == NULL)
        {
-         hash = xmalloc (sizeof (struct bfd_hash_table));
+         hash = (struct bfd_hash_table *)
+              xmalloc (sizeof (struct bfd_hash_table));
          if (!bfd_hash_table_init (hash, bfd_hash_newfunc,
                                    sizeof (struct bfd_hash_entry)))
            einfo (_("%F%P: bfd_hash_table_init failed: %E\n"));
@@ -1408,7 +1383,7 @@ notice (struct bfd_link_info *info,
   if (name == NULL)
     {
       if (command_line.cref || nocrossref_list != NULL)
-       return handle_asneeded_cref (abfd, value);
+       return handle_asneeded_cref (abfd, (enum notice_asneeded_action) value);
       return TRUE;
     }
 
This page took 0.027047 seconds and 4 git commands to generate.