Ignore:
Timestamp:
Aug 16, 2003, 6:59:22 PM (22 years ago)
Author:
bird
Message:

binutils v2.14 - offical sources.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/binutils/ld/ldmisc.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r608 r609  
    11/* ldmisc.c
    2    Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000
     2   Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
     3   2000, 2002, 2003
    34   Free Software Foundation, Inc.
    45   Written by Steve Chamberlain of Cygnus Support.
    56
    6 This file is part of GLD, the Gnu Linker.
    7 
    8 GLD is free software; you can redistribute it and/or modify
    9 it under the terms of the GNU General Public License as published by
    10 the Free Software Foundation; either version 2, or (at your option)
    11 any later version.
    12 
    13 GLD is distributed in the hope that it will be useful,
    14 but WITHOUT ANY WARRANTY; without even the implied warranty of
    15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    16 GNU General Public License for more details.
    17 
    18 You should have received a copy of the GNU General Public License
    19 along with GLD; see the file COPYING.  If not, write to the Free
    20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
    21 02111-1307, USA.  */
     7   This file is part of GLD, the Gnu Linker.
     8
     9   GLD is free software; you can redistribute it and/or modify
     10   it under the terms of the GNU General Public License as published by
     11   the Free Software Foundation; either version 2, or (at your option)
     12   any later version.
     13
     14   GLD is distributed in the hope that it will be useful,
     15   but WITHOUT ANY WARRANTY; without even the implied warranty of
     16   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17   GNU General Public License for more details.
     18
     19   You should have received a copy of the GNU General Public License
     20   along with GLD; see the file COPYING.  If not, write to the Free
     21   Software Foundation, 59 Temple Place - Suite 330, Boston, MA
     22   02111-1307, USA.  */
    2223
    2324#include "bfd.h"
     
    2829#ifdef ANSI_PROTOTYPES
    2930#include <stdarg.h>
    30 #define USE_STDARG 1
    3131#else
    3232#include <varargs.h>
    33 #define USE_STDARG 0
    3433#endif
    3534
     
    3837#include "ldexp.h"
    3938#include "ldlang.h"
    40 #include "ldgram.h"
     39#include <ldgram.h>
    4140#include "ldlex.h"
    4241#include "ldmain.h"
     
    6766*/
    6867
    69 char *
    70 demangle (string)
    71      const char *string;
    72 {
    73   char *res;
    74 
    75   if (output_bfd != NULL
    76       && bfd_get_symbol_leading_char (output_bfd) == string[0])
    77     ++string;
    78 
    79   /* This is a hack for better error reporting on XCOFF, or the MS PE
    80      format.  Xcoff has a single '.', while the NT PE for PPC has
    81      '..'.  So we remove all of them.  */
    82   while (string[0] == '.')
    83     ++string;
    84 
    85   res = cplus_demangle (string, DMGL_ANSI | DMGL_PARAMS);
    86   return res ? res : xstrdup (string);
    87 }
    88 
    8968static void
    9069vfinfo (fp, fmt, arg)
     
    9372     va_list arg;
    9473{
    95   boolean fatal = false;
     74  bfd_boolean fatal = FALSE;
    9675
    9776  while (*fmt != '\0')
     
    11998            case 'X':
    12099              /* no object output, fail return */
    121               config.make_executable = false;
     100              config.make_executable = FALSE;
    122101              break;
    123102
     
    204183            case 'F':
    205184              /* Error is fatal.  */
    206               fatal = true;
     185              fatal = TRUE;
    207186              break;
    208187
     
    258237            case 'D':
    259238            case 'G':
    260               /* Clever filename:linenumber with function name if possible,
    261                  or section name as a last resort.  The arguments are a BFD,
    262                  a section, and an offset.  */
     239              /* Clever filename:linenumber with function name if possible.
     240                 The arguments are a BFD, a section, and an offset.  */
    263241              {
    264242                static bfd *last_bfd;
     
    273251                const char *functionname;
    274252                unsigned int linenumber;
    275                 boolean discard_last;
     253                bfd_boolean discard_last;
    276254
    277255                abfd = va_arg (arg, bfd *);
     
    302280                  }
    303281
    304                 discard_last = true;
     282                lfinfo (fp, "%B(%s+0x%v)", abfd, section->name, offset);
     283
     284                discard_last = TRUE;
    305285                if (bfd_find_nearest_line (abfd, section, asymbols, offset,
    306286                                           &filename, &functionname,
    307287                                           &linenumber))
    308288                  {
    309                     if (functionname != NULL && fmt[-1] == 'G')
     289                    bfd_boolean need_colon = TRUE;
     290
     291                    if (functionname != NULL && fmt[-1] == 'C')
    310292                      {
    311                         lfinfo (fp, "%B:", abfd);
    312                         if (filename != NULL
    313                             && strcmp (filename, bfd_get_filename (abfd)) != 0)
    314                           fprintf (fp, "%s:", filename);
    315                         lfinfo (fp, "%T", functionname);
    316                       }
    317                     else if (functionname != NULL && fmt[-1] == 'C')
    318                       {
    319                         if (filename == (char *) NULL)
    320                           filename = abfd->filename;
    321 
    322293                        if (last_bfd == NULL
    323294                            || last_file == NULL
    324295                            || last_function == NULL
    325296                            || last_bfd != abfd
    326                             || strcmp (last_file, filename) != 0
     297                            || (filename != NULL
     298                                && strcmp (last_file, filename) != 0)
    327299                            || strcmp (last_function, functionname) != 0)
    328300                          {
    329                             /* We use abfd->filename in this initial line,
    330                                in case filename is a .h file or something
    331                                similarly unhelpful.  */
    332                             lfinfo (fp, _("%B: In function `%T':\n"),
    333                                     abfd, functionname);
     301                            lfinfo (fp, _(": In function `%T':\n"),
     302                                    functionname);
     303                            need_colon = FALSE;
    334304
    335305                            last_bfd = abfd;
    336306                            if (last_file != NULL)
    337307                              free (last_file);
    338                             last_file = xstrdup (filename);
     308                            last_file = NULL;
     309                            if (filename)
     310                              last_file = xstrdup (filename);
    339311                            if (last_function != NULL)
    340312                              free (last_function);
    341313                            last_function = xstrdup (functionname);
    342314                          }
    343                         discard_last = false;
    344                         if (linenumber != 0)
    345                           fprintf (fp, "%s:%u", filename, linenumber);
    346                         else
    347                           lfinfo (fp, "%s(%s+0x%v)", filename, section->name,
    348                                   offset);
     315                        discard_last = FALSE;
    349316                      }
    350                     else if (filename == NULL
    351                              || strcmp (filename, abfd->filename) == 0)
     317
     318                    if (filename != NULL)
    352319                      {
    353                         lfinfo (fp, "%B(%s+0x%v)", abfd, section->name,
    354                                 offset);
    355                         if (linenumber != 0)
    356                           lfinfo (fp, ":%u", linenumber);
     320                        if (need_colon)
     321                          putc (':', fp);
     322                        fputs (filename, fp);
    357323                      }
    358                     else if (linenumber != 0)
    359                       lfinfo (fp, "%B:%s:%u", abfd, filename, linenumber);
    360                     else
    361                       lfinfo (fp, "%B(%s+0x%v):%s", abfd, section->name,
    362                               offset, filename);
     324
     325                    if (functionname != NULL && fmt[-1] == 'G')
     326                      lfinfo (fp, ":%T", functionname);
     327                    else if (filename != NULL && linenumber != 0)
     328                      fprintf (fp, ":%u", linenumber);
    363329                  }
    364                 else
    365                   lfinfo (fp, "%B(%s+0x%v)", abfd, section->name, offset);
     330
     331                if (asymbols != NULL && entry == NULL)
     332                  free (asymbols);
    366333
    367334                if (discard_last)
     
    400367    }
    401368
    402   if (fatal == true)
     369  if (config.fatal_warnings)
     370    config.make_executable = FALSE;
     371
     372  if (fatal)
    403373    xexit (1);
     374}
     375
     376/* Wrapper around cplus_demangle.  Strips leading underscores and
     377   other such chars that would otherwise confuse the demangler.  */
     378
     379char *
     380demangle (name)
     381     const char *name;
     382{
     383  char *res;
     384  const char *p;
     385
     386  if (output_bfd != NULL
     387      && bfd_get_symbol_leading_char (output_bfd) == name[0])
     388    ++name;
     389
     390  /* This is a hack for better error reporting on XCOFF, PowerPC64-ELF
     391     or the MS PE format.  These formats have a number of leading '.'s
     392     on at least some symbols, so we remove all dots to avoid
     393     confusing the demangler.  */
     394  p = name;
     395  while (*p == '.')
     396    ++p;
     397
     398  res = cplus_demangle (p, DMGL_ANSI | DMGL_PARAMS);
     399  if (res)
     400    {
     401      size_t dots = p - name;
     402
     403      /* Now put back any stripped dots.  */
     404      if (dots != 0)
     405        {
     406          size_t len = strlen (res) + 1;
     407          char *add_dots = xmalloc (len + dots);
     408
     409          memcpy (add_dots, name, dots);
     410          memcpy (add_dots + dots, res, len);
     411          free (res);
     412          res = add_dots;
     413        }
     414      return res;
     415    }
     416  return xstrdup (name);
    404417}
    405418
     
    410423
    411424void
    412 #if USE_STDARG
    413 info_msg (const char *fmt, ...)
    414 #else
    415 info_msg (va_alist)
    416      va_dcl
    417 #endif
    418 {
    419   va_list arg;
    420 
    421 #if ! USE_STDARG
    422   const char *fmt;
    423 
    424   va_start (arg);
    425   fmt = va_arg (arg, const char *);
    426 #else
    427   va_start (arg, fmt);
    428 #endif
     425info_msg VPARAMS ((const char *fmt, ...))
     426{
     427  VA_OPEN (arg, fmt);
     428  VA_FIXEDARG (arg, const char *, fmt);
    429429
    430430  vfinfo (stdout, fmt, arg);
    431   va_end (arg);
     431  VA_CLOSE (arg);
    432432}
    433433
     
    435435
    436436void
    437 #if USE_STDARG
    438 einfo (const char *fmt, ...)
    439 #else
    440 einfo (va_alist)
    441      va_dcl
    442 #endif
    443 {
    444   va_list arg;
    445 
    446 #if ! USE_STDARG
    447   const char *fmt;
    448 
    449   va_start (arg);
    450   fmt = va_arg (arg, const char *);
    451 #else
    452   va_start (arg, fmt);
    453 #endif
     437einfo VPARAMS ((const char *fmt, ...))
     438{
     439  VA_OPEN (arg, fmt);
     440  VA_FIXEDARG (arg, const char *, fmt);
    454441
    455442  vfinfo (stderr, fmt, arg);
    456   va_end (arg);
     443  VA_CLOSE (arg);
    457444}
    458445
     
    468455
    469456void
    470 #if USE_STDARG
    471 minfo (const char *fmt, ...)
    472 #else
    473 minfo (va_alist)
    474      va_dcl
    475 #endif
    476 {
    477   va_list arg;
    478 
    479 #if ! USE_STDARG
    480   const char *fmt;
    481   va_start (arg);
    482   fmt = va_arg (arg, const char *);
    483 #else
    484   va_start (arg, fmt);
    485 #endif
     457minfo VPARAMS ((const char *fmt, ...))
     458{
     459  VA_OPEN (arg, fmt);
     460  VA_FIXEDARG (arg, const char *, fmt);
    486461
    487462  vfinfo (config.map_file, fmt, arg);
    488   va_end (arg);
    489 }
    490 
    491 void
    492 #if USE_STDARG
    493 lfinfo (FILE *file, const char *fmt, ...)
    494 #else
    495 lfinfo (va_alist)
    496      va_dcl
    497 #endif
    498 {
    499   va_list arg;
    500 
    501 #if ! USE_STDARG
    502   FILE *file;
    503   const char *fmt;
    504 
    505   va_start (arg);
    506   file = va_arg (arg, FILE *);
    507   fmt = va_arg (arg, const char *);
    508 #else
    509   va_start (arg, fmt);
    510 #endif
     463  VA_CLOSE (arg);
     464}
     465
     466void
     467lfinfo VPARAMS ((FILE *file, const char *fmt, ...))
     468{
     469  VA_OPEN (arg, fmt);
     470  VA_FIXEDARG (arg, FILE *, file);
     471  VA_FIXEDARG (arg, const char *, fmt);
    511472
    512473  vfinfo (file, fmt, arg);
    513   va_end (arg);
     474  VA_CLOSE (arg);
    514475}
    515476
     
    547508  xexit (1);
    548509}
     510
     511bfd_boolean
     512error_handler VPARAMS ((int id ATTRIBUTE_UNUSED, const char *fmt, ...))
     513{
     514  VA_OPEN (arg, fmt);
     515  VA_FIXEDARG (arg, const char *, fmt);
     516
     517  vfinfo (stderr, fmt, arg);
     518  VA_CLOSE (arg);
     519  return TRUE;
     520}
Note: See TracChangeset for help on using the changeset viewer.