fsf address update, but not in COPYING files
[deliverable/binutils-gdb.git] / ld / ldmain.c
index 5b2e370f8a5bf9b9a366801cdd15150b9564a549..a0f5eb5c157d5702b1955231c5af33ccf08909a2 100644 (file)
@@ -16,13 +16,14 @@ GNU General Public License for more details.
 
 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, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+the Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 
 #include "bfd.h"
 #include "sysdep.h"
 #include <stdio.h>
 #include "libiberty.h"
+#include "progress.h"
 #include "bfdlink.h"
 
 #include "config.h"
@@ -45,6 +46,11 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include <string.h>
 
+/* Use sbrk() except on specific OS types */
+#if !defined(__amigados__) && !defined(WINDOWS_NT)
+#define HAVE_SBRK
+#endif
+
 static char *get_emulation PARAMS ((int, char **));
 static void set_scripts_dir PARAMS ((void));
 
@@ -72,6 +78,9 @@ boolean trace_file_tries;
    instead of complaining if no input files are given.  */
 boolean version_printed;
 
+/* Nonzero means link in every member of an archive.  */
+boolean whole_archive;
+
 args_type command_line;
 
 ld_config_type config;
@@ -152,20 +161,25 @@ main (argc, argv)
   program_name = argv[0];
   xmalloc_set_program_name (program_name);
 
+  START_PROGRESS (program_name, 0);
+
   bfd_init ();
 
   xatexit (remove_output);
 
   /* Initialize the data about options.  */
   trace_files = trace_file_tries = version_printed = false;
+  whole_archive = false;
   config.traditional_format = false;
   config.build_constructors = true;
   config.dynamic_link = false;
   command_line.force_common_definition = false;
   command_line.interpreter = NULL;
+  command_line.rpath = NULL;
 
   link_info.callbacks = &link_callbacks;
   link_info.relocateable = false;
+  link_info.shared = false;
   link_info.strip = strip_none;
   link_info.discard = discard_none;
   link_info.lprefix_len = 1;
@@ -176,6 +190,14 @@ main (argc, argv)
   link_info.hash = NULL;
   link_info.keep_hash = NULL;
   link_info.notice_hash = NULL;
+  link_info.subsystem = console;
+  link_info.stack_heap_parameters.stack_defined = false;
+  link_info.stack_heap_parameters.heap_defined  = false;
+  link_info.stack_heap_parameters.stack_reserve = 0;
+  link_info.stack_heap_parameters.stack_commit  = 0;
+  link_info.stack_heap_parameters.heap_reserve  = 0;
+  link_info.stack_heap_parameters.heap_commit   = 0;
+
 
   ldfile_add_arch ("");
 
@@ -199,8 +221,18 @@ main (argc, argv)
        einfo ("%P%F: -relax and -r may not be used together\n");
       if (config.dynamic_link)
        einfo ("%P%F: -r and -call_shared may not be used together\n");
-      if (link_info.strip == strip_all)
-       einfo ("%P%F: -r and -s may not be used together\n");
+      if (link_info.shared)
+       einfo ("%P%F: -r and -shared may not be used together\n");
+    }
+
+  /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols).  I
+     don't see how else this can be handled, since in this case we
+     must preserve all externally visible symbols.  */
+  if (link_info.relocateable && link_info.strip == strip_all)
+    {
+      link_info.strip = strip_debugger;
+      if (link_info.discard == discard_none)
+       link_info.discard = discard_all;
     }
 
   /* This essentially adds another -L directory so this must be done after
@@ -216,7 +248,16 @@ main (argc, argv)
       if (isfile)
        ldfile_open_command_file (s);
       else
-       lex_redirect (s);
+       {
+         if (trace_file_tries)
+           {
+             info_msg ("using internal linker script:\n");
+             info_msg ("==================================================\n");
+             info_msg (s);
+             info_msg ("\n==================================================\n");
+           }
+         lex_redirect (s);
+       }
       parser_input = input_script;
       yyparse ();
     }
@@ -249,6 +290,7 @@ main (argc, argv)
          config.map_file = fopen (config.map_filename, FOPEN_WT);
          if (config.map_file == (FILE *) NULL)
            {
+             bfd_set_error (bfd_error_system_call);
              einfo ("%P%F: cannot open map file %s: %E\n",
                     config.map_filename);
            }
@@ -304,16 +346,22 @@ main (argc, argv)
        einfo ("%F%B: final close failed: %E\n", output_bfd);
     }
 
+  END_PROGRESS (program_name);
+
   if (config.stats)
     {
       extern char **environ;
+#ifdef HAVE_SBRK
       char *lim = (char *) sbrk (0);
+#endif
       long run_time = get_run_time () - start_time;
 
       fprintf (stderr, "%s: total time in link: %ld.%06ld\n",
               program_name, run_time / 1000000, run_time % 1000000);
+#ifdef HAVE_SBRK
       fprintf (stderr, "%s: data size %ld\n", program_name,
               (long) (lim - (char *) &environ));
+#endif
     }
 
   /* Prevent remove_output from doing anything, after a successful link.  */
@@ -601,7 +649,7 @@ multiple_definition (info, name, obfd, osec, oval, nbfd, nsec, nval)
   einfo ("%X%C: multiple definition of `%T'\n",
         nbfd, nsec, nval, name);
   if (obfd != (bfd *) NULL)
-    einfo ("%C: first defined here\n", obfd, osec, oval);
+    einfo ("%D: first defined here\n", obfd, osec, oval);
   return true;
 }
 
@@ -625,19 +673,25 @@ multiple_common (info, name, obfd, otype, osize, nbfd, ntype, nsize)
   if (! config.warn_common)
     return true;
 
-  if (ntype == bfd_link_hash_defined)
+  if (ntype == bfd_link_hash_defined
+      || ntype == bfd_link_hash_defweak
+      || ntype == bfd_link_hash_indirect)
     {
       ASSERT (otype == bfd_link_hash_common);
       einfo ("%B: warning: definition of `%T' overriding common\n",
             nbfd, name);
-      einfo ("%B: warning: common is here\n", obfd);
+      if (obfd != NULL)
+       einfo ("%B: warning: common is here\n", obfd);
     }
-  else if (otype == bfd_link_hash_defined)
+  else if (otype == bfd_link_hash_defined
+          || otype == bfd_link_hash_defweak
+          || otype == bfd_link_hash_indirect)
     {
       ASSERT (ntype == bfd_link_hash_common);
       einfo ("%B: warning: common of `%T' overridden by definition\n",
             nbfd, name);
-      einfo ("%B: warning: defined here\n", obfd);
+      if (obfd != NULL)
+       einfo ("%B: warning: defined here\n", obfd);
     }
   else
     {
@@ -646,18 +700,21 @@ multiple_common (info, name, obfd, otype, osize, nbfd, ntype, nsize)
        {
          einfo ("%B: warning: common of `%T' overridden by larger common\n",
                 nbfd, name);
-         einfo ("%B: warning: larger common is here\n", obfd);
+         if (obfd != NULL)
+           einfo ("%B: warning: larger common is here\n", obfd);
        }
       else if (nsize > osize)
        {
          einfo ("%B: warning: common of `%T' overriding smaller common\n",
                 nbfd, name);
-         einfo ("%B: warning: smaller common is here\n", obfd);
+         if (obfd != NULL)
+           einfo ("%B: warning: smaller common is here\n", obfd);
        }
       else
        {
          einfo ("%B: warning: multiple common of `%T'\n", nbfd, name);
-         einfo ("%B: warning: previous common is here\n", obfd);
+         if (obfd != NULL)
+           einfo ("%B: warning: previous common is here\n", obfd);
        }
     }
 
@@ -778,6 +835,27 @@ undefined_symbol (info, name, abfd, section, address)
 
 #define MAX_ERRORS_IN_A_ROW 5
 
+  if (config.warn_once)
+    {
+      static struct bfd_hash_table *hash;
+
+      /* Only warn once about a particular undefined symbol.  */
+
+      if (hash == NULL)
+       {
+         hash = ((struct bfd_hash_table *)
+                 xmalloc (sizeof (struct bfd_hash_table)));
+         if (! bfd_hash_table_init (hash, bfd_hash_newfunc))
+           einfo ("%F%P: bfd_hash_table_init failed: %E\n");
+       }
+
+      if (bfd_hash_lookup (hash, name, false, false) != NULL)
+       return true;
+
+      if (bfd_hash_lookup (hash, name, true, true) == NULL)
+       einfo ("%F%P: bfd_hash_lookup failed: %E\n");
+    }
+
   /* We never print more than a reasonable number of errors in a row
      for a single symbol.  */
   if (error_name != (char *) NULL
@@ -791,12 +869,24 @@ undefined_symbol (info, name, abfd, section, address)
       error_name = buystring (name);
     }
 
-  if (error_count < MAX_ERRORS_IN_A_ROW)
-    einfo ("%X%C: undefined reference to `%T'\n",
-          abfd, section, address, name);
-  else if (error_count == MAX_ERRORS_IN_A_ROW)
-    einfo ("%C: more undefined references to `%T' follow\n",
-          abfd, section, address, name);
+  if (section != NULL)
+    {
+      if (error_count < MAX_ERRORS_IN_A_ROW)
+       einfo ("%X%C: undefined reference to `%T'\n",
+              abfd, section, address, name);
+      else if (error_count == MAX_ERRORS_IN_A_ROW)
+       einfo ("%D: more undefined references to `%T' follow\n",
+              abfd, section, address, name);
+    }
+  else
+    {
+      if (error_count < MAX_ERRORS_IN_A_ROW)
+       einfo ("%X%B: undefined reference to `%T'\n",
+              abfd, name);
+      else if (error_count == MAX_ERRORS_IN_A_ROW)
+       einfo ("%B: more undefined references to `%T' follow\n",
+              abfd, name);
+    }
 
   return true;
 }
@@ -877,7 +967,7 @@ notice_ysym (info, name, abfd, section, value)
      bfd_vma value;
 {
   einfo ("%B: %s %s\n", abfd,
-        section != &bfd_und_section ? "definition of" : "reference to",
+        bfd_is_und_section (section) ? "reference to" : "definition of",
         name);
   return true;
 }
This page took 0.032229 seconds and 4 git commands to generate.