Fix wrong source file name of cross-arm-binutils.
[platform/upstream/binutils.git] / ld / ldmisc.c
index d5001d1..5e18013 100644 (file)
@@ -1,7 +1,5 @@
 /* ldmisc.c
-   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
-   2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010, 2011
-   Free Software Foundation, Inc.
+   Copyright (C) 1991-2014 Free Software Foundation, Inc.
    Written by Steve Chamberlain of Cygnus Support.
 
    This file is part of the GNU Binutils.
  %E current bfd error or errno
  %F error is fatal
  %G like %D, but only function name
+ %H like %C but in addition emit section+offset
  %I filename from a lang_input_statement_type
  %P print program name
  %R info about a relent
- %S print script file and linenumber
+ %S print script file and linenumber from etree_type.
  %T symbol name
  %V hex bfd_vma
  %W hex bfd_vma with 0x with no leading zeros taking up 8 spaces
@@ -71,11 +70,14 @@ vfinfo (FILE *fp, const char *fmt, va_list arg, bfd_boolean is_warning)
 
   while (*fmt != '\0')
     {
+      const char *str = fmt;
       while (*fmt != '%' && *fmt != '\0')
-       {
-         putc (*fmt, fp);
-         fmt++;
-       }
+       fmt++;
+      if (fmt != str)
+       if (fwrite (str, 1, fmt - str, fp))
+         {
+           /* Ignore.  */
+         }
 
       if (*fmt == '%')
        {
@@ -239,12 +241,19 @@ vfinfo (FILE *fp, const char *fmt, va_list arg, bfd_boolean is_warning)
 
            case 'S':
              /* Print script file and linenumber.  */
-             if (parsing_defsym)
-               fprintf (fp, "--defsym %s", lex_string);
-             else if (ldfile_input_filename != NULL)
-               fprintf (fp, "%s:%u", ldfile_input_filename, lineno);
-             else
-               fprintf (fp, _("built in linker script:%u"), lineno);
+             {
+               etree_type node;
+               etree_type *tp = va_arg (arg, etree_type *);
+
+               if (tp == NULL)
+                 {
+                   tp = &node;
+                   tp->type.filename = ldlex_filename ();
+                   tp->type.lineno = lineno;
+                 }
+               if (tp->type.filename != NULL)
+                 fprintf (fp, "%s:%u", tp->type.filename, tp->type.lineno);
+             }
              break;
 
            case 'R':
@@ -262,6 +271,7 @@ vfinfo (FILE *fp, const char *fmt, va_list arg, bfd_boolean is_warning)
            case 'C':
            case 'D':
            case 'G':
+           case 'H':
              /* Clever filename:linenumber with function name if possible.
                 The arguments are a BFD, a section, and an offset.  */
              {
@@ -276,6 +286,7 @@ vfinfo (FILE *fp, const char *fmt, va_list arg, bfd_boolean is_warning)
                const char *functionname;
                unsigned int linenumber;
                bfd_boolean discard_last;
+               bfd_boolean done;
 
                abfd = va_arg (arg, bfd *);
                section = va_arg (arg, asection *);
@@ -291,19 +302,20 @@ vfinfo (FILE *fp, const char *fmt, va_list arg, bfd_boolean is_warning)
 
                /* 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.  */
+                  offset instead.  */
                discard_last = TRUE;
                if (abfd != NULL
                    && bfd_find_nearest_line (abfd, section, asymbols, offset,
                                              &filename, &functionname,
                                              &linenumber))
                  {
-                   if (functionname != NULL && fmt[-1] == 'C')
+                   if (functionname != NULL
+                       && (fmt[-1] == 'C' || fmt[-1] == 'H'))
                      {
                        /* Detect the case where we are printing out a
                           message for the same function as the last
@@ -343,15 +355,21 @@ vfinfo (FILE *fp, const char *fmt, va_list arg, bfd_boolean is_warning)
                    if (filename != NULL)
                      fprintf (fp, "%s:", filename);
 
+                   done = fmt[-1] != 'H';
                    if (functionname != NULL && fmt[-1] == 'G')
                      lfinfo (fp, "%T", functionname);
                    else if (filename != NULL && linenumber != 0)
-                     fprintf (fp, "%u", linenumber);
+                     fprintf (fp, "%u%s", linenumber, done ? "" : ":");
                    else
-                     lfinfo (fp, "(%A+0x%v)", section, offset);
+                     done = FALSE;
                  }
                else
-                 lfinfo (fp, "%B:(%A+0x%v)", abfd, section, offset);
+                 {
+                   lfinfo (fp, "%B:", abfd);
+                   done = FALSE;
+                 }
+               if (!done)
+                 lfinfo (fp, "(%A+0x%v)", section, offset);
 
                if (discard_last)
                  {
@@ -464,7 +482,22 @@ minfo (const char *fmt, ...)
       va_list arg;
 
       va_start (arg, fmt);
-      vfinfo (config.map_file, fmt, arg, FALSE);
+      if (fmt[0] == '%' && fmt[1] == '!' && fmt[2] == 0)
+       {
+         /* Stash info about --as-needed shared libraries.  Print
+            later so they don't appear intermingled with archive
+            library info.  */
+         struct asneeded_minfo *m = xmalloc (sizeof *m);
+
+         m->next = NULL;
+         m->soname = va_arg (arg, const char *);
+         m->ref = va_arg (arg, bfd *);
+         m->name = va_arg (arg, const char *);
+         *asneeded_list_tail = m;
+         asneeded_list_tail = &m->next;
+       }
+      else
+       vfinfo (config.map_file, fmt, arg, FALSE);
       va_end (arg);
     }
 }