ld/
[platform/upstream/binutils.git] / ld / ldmisc.c
index 8fe0b43..9b8f44f 100644 (file)
@@ -1,6 +1,6 @@
 /* ldmisc.c
    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2002, 2003, 2004
+   2001, 2002, 2003, 2004, 2005
    Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support.
 
@@ -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 "bfdlink.h"
@@ -61,7 +61,7 @@
 */
 
 static void
-vfinfo (FILE *fp, const char *fmt, va_list arg)
+vfinfo (FILE *fp, const char *fmt, va_list arg, bfd_boolean is_warning)
 {
   bfd_boolean fatal = FALSE;
 
@@ -190,7 +190,7 @@ vfinfo (FILE *fp, const char *fmt, va_list arg)
                bfd *abfd = va_arg (arg, bfd *);
 
                if (abfd == NULL)
-                 fprintf (fp, "<none>");
+                 fprintf (fp, "%s generated", program_name);
                else if (abfd->my_archive)
                  fprintf (fp, "%s(%s)", abfd->my_archive->filename,
                           abfd->filename);
@@ -275,40 +275,62 @@ vfinfo (FILE *fp, const char *fmt, va_list arg)
                section = va_arg (arg, asection *);
                offset = va_arg (arg, bfd_vma);
 
-               entry = (lang_input_statement_type *) abfd->usrdata;
-               if (entry != (lang_input_statement_type *) NULL
-                   && entry->asymbols != (asymbol **) NULL)
-                 asymbols = entry->asymbols;
+               if (abfd == NULL)
+                 {
+                   entry = NULL;
+                   asymbols = NULL;
+                 }
                else
                  {
-                   long symsize;
-                   long symbol_count;
-
-                   symsize = bfd_get_symtab_upper_bound (abfd);
-                   if (symsize < 0)
-                     einfo (_("%B%F: could not read symbols\n"), abfd);
-                   asymbols = xmalloc (symsize);
-                   symbol_count = bfd_canonicalize_symtab (abfd, asymbols);
-                   if (symbol_count < 0)
-                     einfo (_("%B%F: could not read symbols\n"), abfd);
-                   if (entry != (lang_input_statement_type *) NULL)
+                   entry = (lang_input_statement_type *) abfd->usrdata;
+                   if (entry != (lang_input_statement_type *) NULL
+                       && entry->asymbols != (asymbol **) NULL)
+                     asymbols = entry->asymbols;
+                   else
                      {
-                       entry->asymbols = asymbols;
-                       entry->symbol_count = symbol_count;
+                       long symsize;
+                       long sym_count;
+
+                       symsize = bfd_get_symtab_upper_bound (abfd);
+                       if (symsize < 0)
+                         einfo (_("%B%F: could not read symbols\n"), abfd);
+                       asymbols = xmalloc (symsize);
+                       sym_count = bfd_canonicalize_symtab (abfd, asymbols);
+                       if (sym_count < 0)
+                         einfo (_("%B%F: could not read symbols\n"), abfd);
+                       if (entry != (lang_input_statement_type *) NULL)
+                         {
+                           entry->asymbols = asymbols;
+                           entry->symbol_count = sym_count;
+                         }
                      }
                  }
 
-               lfinfo (fp, "%B(%A+0x%v)", abfd, section, offset);
+               /* The GNU Coding Standard requires that error messages
+                  be of the form:
+                  
+                    source-file-name:lineno: message
 
+                  We do not always have a line number available so if
+                  we cannot find them we print out the section name and
+                  offset instread.  */
                discard_last = TRUE;
-               if (bfd_find_nearest_line (abfd, section, asymbols, offset,
-                                          &filename, &functionname,
-                                          &linenumber))
+               if (abfd != NULL
+                   && bfd_find_nearest_line (abfd, section, asymbols, offset,
+                                             &filename, &functionname,
+                                             &linenumber))
                  {
-                   bfd_boolean need_colon = TRUE;
-
                    if (functionname != NULL && fmt[-1] == 'C')
                      {
+                       /* Detect the case where we are printing out a
+                          message for the same function as the last
+                          call to vinfo ("%C").  In this situation do
+                          not print out the ABFD filename or the
+                          function name again.  Note - we do still
+                          print out the source filename, as this will
+                          allow programs that parse the linker's output
+                          (eg emacs) to correctly locate multiple
+                          errors in the same source file.  */
                        if (last_bfd == NULL
                            || last_file == NULL
                            || last_function == NULL
@@ -317,9 +339,8 @@ vfinfo (FILE *fp, const char *fmt, va_list arg)
                                && strcmp (last_file, filename) != 0)
                            || strcmp (last_function, functionname) != 0)
                          {
-                           lfinfo (fp, _(": In function `%T':\n"),
-                                   functionname);
-                           need_colon = FALSE;
+                           lfinfo (fp, _("%B: In function `%T':\n"),
+                                   abfd, functionname);
 
                            last_bfd = abfd;
                            if (last_file != NULL)
@@ -333,19 +354,24 @@ vfinfo (FILE *fp, const char *fmt, va_list arg)
                          }
                        discard_last = FALSE;
                      }
+                   else
+                     lfinfo (fp, "%B:", abfd);
 
                    if (filename != NULL)
-                     {
-                       if (need_colon)
-                         putc (':', fp);
-                       fputs (filename, fp);
-                     }
+                     fprintf (fp, "%s:", filename);
 
                    if (functionname != NULL && fmt[-1] == 'G')
-                     lfinfo (fp, ":%T", functionname);
-                   else if (filename != NULL && linenumber != 0)
-                     fprintf (fp, ":%u", linenumber);
+                     lfinfo (fp, "%T", functionname);
+                   else if (filename != NULL)
+                     {
+                       if (linenumber != 0)
+                         fprintf (fp, "%u", linenumber);
+                       else
+                         lfinfo (fp, "(%A+0x%v)", section, offset);
+                     }
                  }
+               else
+                 lfinfo (fp, "%B:(%A+0x%v)", abfd, section, offset);
 
                if (asymbols != NULL && entry == NULL)
                  free (asymbols);
@@ -385,7 +411,7 @@ vfinfo (FILE *fp, const char *fmt, va_list arg)
        }
     }
 
-  if (config.fatal_warnings)
+  if (is_warning && config.fatal_warnings)
     config.make_executable = FALSE;
 
   if (fatal)
@@ -445,7 +471,7 @@ info_msg (const char *fmt, ...)
   va_list arg;
 
   va_start (arg, fmt);
-  vfinfo (stdout, fmt, arg);
+  vfinfo (stdout, fmt, arg, FALSE);
   va_end (arg);
 }
 
@@ -457,7 +483,7 @@ einfo (const char *fmt, ...)
   va_list arg;
 
   va_start (arg, fmt);
-  vfinfo (stderr, fmt, arg);
+  vfinfo (stderr, fmt, arg, TRUE);
   va_end (arg);
 }
 
@@ -475,7 +501,7 @@ minfo (const char *fmt, ...)
   va_list arg;
 
   va_start (arg, fmt);
-  vfinfo (config.map_file, fmt, arg);
+  vfinfo (config.map_file, fmt, arg, FALSE);
   va_end (arg);
 }
 
@@ -485,7 +511,7 @@ lfinfo (FILE *file, const char *fmt, ...)
   va_list arg;
 
   va_start (arg, fmt);
-  vfinfo (file, fmt, arg);
+  vfinfo (file, fmt, arg, FALSE);
   va_end (arg);
 }
 \f