a8e309d1622cf2a9977327a362f92a1a3347ff7a
1 /* messages.c - error reporter -
2 Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001,
4 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
37 #if !defined (USE_STDARG) && !defined (USE_VARARGS)
41 typedef int * va_list;
42 #define va_start(ARGS) ARGS = &REST
46 static void identify (char *);
47 static void as_show_where (void);
48 static void as_warn_internal (char *, unsigned int, char *);
49 static void as_bad_internal (char *, unsigned int, char *);
51 /* Despite the rest of the comments in this file, (FIXME-SOON),
52 here is the current scheme for error messages etc:
54 as_fatal() is used when gas is quite confused and
55 continuing the assembly is pointless. In this case we
56 exit immediately with error status.
58 as_bad() is used to mark errors that result in what we
59 presume to be a useless object file. Say, we ignored
60 something that might have been vital. If we see any of
61 these, assembly will continue to the end of the source,
62 no object file will be produced, and we will terminate
63 with error status. The new option, -Z, tells us to
64 produce an object file anyway but we still exit with
65 error status. The assumption here is that you don't want
66 this object file but we could be wrong.
68 as_warn() is used when we have an error from which we
69 have a plausible error recovery. eg, masking the top
70 bits of a constant that is longer than will fit in the
71 destination. In this case we will continue to assemble
72 the source, although we may have made a bad assumption,
73 and we will produce an object file and return normal exit
74 status (ie, no error). The new option -X tells us to
75 treat all as_warn() errors as as_bad() errors. That is,
76 no object file will be produced and we will exit with
77 error status. The idea here is that we don't kill an
78 entire make because of an error that we knew how to
79 correct. On the other hand, sometimes you might want to
80 stop the make at these points.
82 as_tsktsk() is used when we see a minor error for which
83 our error recovery action is almost certainly correct.
84 In this case, we print a message and then assembly
85 continues as though no error occurred. */
90 static int identified
;
103 fprintf (stderr
, "%s: ", file
);
104 fprintf (stderr
, _("Assembler messages:\n"));
107 /* The number of warnings issued. */
108 static int warning_count
;
113 return warning_count
;
116 /* Nonzero if we've hit a 'bad error', and should not write an obj file,
117 and exit with a nonzero error code. */
119 static int error_count
;
127 /* Print the current location to stderr. */
135 as_where (&file
, &line
);
138 fprintf (stderr
, "%s:%u: ", file
, line
);
141 /* Like perror(3), but with more info. */
144 as_perror (const char *gripe
, /* Unpunctuated error theme. */
145 const char *filename
)
148 int saved_errno
= errno
;
151 fprintf (stderr
, gripe
, filename
);
153 errtxt
= bfd_errmsg (bfd_get_error ());
154 fprintf (stderr
, ": %s\n", errtxt
);
156 bfd_set_error (bfd_error_no_error
);
159 /* Send to stderr a string as a warning, and locate warning
161 Please only use this for when we have some recovery action.
162 Please explain in string (which may have '\n's) what recovery was
167 as_tsktsk (const char *format
, ...)
172 va_start (args
, format
);
173 vfprintf (stderr
, format
, args
);
175 (void) putc ('\n', stderr
);
179 as_tsktsk (format
, va_alist
)
187 vfprintf (stderr
, format
, args
);
189 (void) putc ('\n', stderr
);
191 #endif /* not NO_STDARG */
193 /* The common portion of as_warn and as_warn_where. */
196 as_warn_internal (char *file
, unsigned int line
, char *buffer
)
201 as_where (&file
, &line
);
205 fprintf (stderr
, "%s:%u: ", file
, line
);
206 fprintf (stderr
, _("Warning: "));
207 fputs (buffer
, stderr
);
208 (void) putc ('\n', stderr
);
210 listing_warning (buffer
);
214 /* Send to stderr a string as a warning, and locate warning
216 Please only use this for when we have some recovery action.
217 Please explain in string (which may have '\n's) what recovery was
222 as_warn (const char *format
, ...)
227 if (!flag_no_warnings
)
229 va_start (args
, format
);
230 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
232 as_warn_internal ((char *) NULL
, 0, buffer
);
237 as_warn (format
, va_alist
)
244 if (!flag_no_warnings
)
247 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
249 as_warn_internal ((char *) NULL
, 0, buffer
);
252 #endif /* not NO_STDARG */
254 /* Like as_bad but the file name and line number are passed in.
255 Unfortunately, we have to repeat the function in order to handle
256 the varargs correctly and portably. */
260 as_warn_where (char *file
, unsigned int line
, const char *format
, ...)
265 if (!flag_no_warnings
)
267 va_start (args
, format
);
268 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
270 as_warn_internal (file
, line
, buffer
);
275 as_warn_where (file
, line
, format
, va_alist
)
284 if (!flag_no_warnings
)
287 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
289 as_warn_internal (file
, line
, buffer
);
292 #endif /* not NO_STDARG */
294 /* The common portion of as_bad and as_bad_where. */
297 as_bad_internal (char *file
, unsigned int line
, char *buffer
)
302 as_where (&file
, &line
);
306 fprintf (stderr
, "%s:%u: ", file
, line
);
307 fprintf (stderr
, _("Error: "));
308 fputs (buffer
, stderr
);
309 (void) putc ('\n', stderr
);
311 listing_error (buffer
);
315 /* Send to stderr a string as a warning, and locate warning in input
316 file(s). Please us when there is no recovery, but we want to
317 continue processing but not produce an object file.
318 Please explain in string (which may have '\n's) what recovery was
323 as_bad (const char *format
, ...)
328 va_start (args
, format
);
329 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
332 as_bad_internal ((char *) NULL
, 0, buffer
);
337 as_bad (format
, va_alist
)
345 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
348 as_bad_internal ((char *) NULL
, 0, buffer
);
350 #endif /* not NO_STDARG */
352 /* Like as_bad but the file name and line number are passed in.
353 Unfortunately, we have to repeat the function in order to handle
354 the varargs correctly and portably. */
358 as_bad_where (char *file
, unsigned int line
, const char *format
, ...)
363 va_start (args
, format
);
364 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
367 as_bad_internal (file
, line
, buffer
);
372 as_bad_where (file
, line
, format
, va_alist
)
382 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
385 as_bad_internal (file
, line
, buffer
);
387 #endif /* not NO_STDARG */
389 /* Send to stderr a string as a fatal message, and print location of
390 error in input file(s).
391 Please only use this for when we DON'T have some recovery action.
392 It xexit()s with a warning status. */
396 as_fatal (const char *format
, ...)
401 va_start (args
, format
);
402 fprintf (stderr
, _("Fatal error: "));
403 vfprintf (stderr
, format
, args
);
404 (void) putc ('\n', stderr
);
406 /* Delete the output file, if it exists. This will prevent make from
407 thinking that a file was created and hence does not need rebuilding. */
408 if (out_file_name
!= NULL
)
409 unlink_if_ordinary (out_file_name
);
410 xexit (EXIT_FAILURE
);
414 as_fatal (format
, va_alist
)
422 fprintf (stderr
, _("Fatal error: "));
423 vfprintf (stderr
, format
, args
);
424 (void) putc ('\n', stderr
);
426 xexit (EXIT_FAILURE
);
428 #endif /* not NO_STDARG */
430 /* Indicate assertion failure.
431 Arguments: Filename, line number, optional function name. */
434 as_assert (const char *file
, int line
, const char *fn
)
437 fprintf (stderr
, _("Internal error!\n"));
439 fprintf (stderr
, _("Assertion failure in %s at %s line %d.\n"),
442 fprintf (stderr
, _("Assertion failure at %s line %d.\n"), file
, line
);
443 fprintf (stderr
, _("Please report this bug.\n"));
444 xexit (EXIT_FAILURE
);
447 /* as_abort: Print a friendly message saying how totally hosed we are,
448 and exit without producing a core file. */
451 as_abort (const char *file
, int line
, const char *fn
)
455 fprintf (stderr
, _("Internal error, aborting at %s line %d in %s\n"),
458 fprintf (stderr
, _("Internal error, aborting at %s line %d\n"),
460 fprintf (stderr
, _("Please report this bug.\n"));
461 xexit (EXIT_FAILURE
);
464 /* Support routines. */
467 sprint_value (char *buf
, valueT val
)
469 if (sizeof (val
) <= sizeof (long))
471 sprintf (buf
, "%ld", (long) val
);
474 if (sizeof (val
) <= sizeof (bfd_vma
))
476 sprintf_vma (buf
, val
);
482 #define HEX_MAX_THRESHOLD 1024
483 #define HEX_MIN_THRESHOLD -(HEX_MAX_THRESHOLD)
486 as_internal_value_out_of_range (char * prefix
,
499 if ( val
< HEX_MAX_THRESHOLD
500 && min
< HEX_MAX_THRESHOLD
501 && max
< HEX_MAX_THRESHOLD
502 && val
> HEX_MIN_THRESHOLD
503 && min
> HEX_MIN_THRESHOLD
504 && max
> HEX_MIN_THRESHOLD
)
506 /* xgettext:c-format */
507 err
= _("%s out of range (%d is not between %d and %d)");
510 as_bad_where (file
, line
, err
,
511 prefix
, (int) val
, (int) min
, (int) max
);
513 as_warn_where (file
, line
, err
,
514 prefix
, (int) val
, (int) min
, (int) max
);
518 char val_buf
[sizeof (val
) * 3 + 2];
519 char min_buf
[sizeof (val
) * 3 + 2];
520 char max_buf
[sizeof (val
) * 3 + 2];
522 if (sizeof (val
) > sizeof (bfd_vma
))
525 sprintf_vma (val_buf
, val
);
526 sprintf_vma (min_buf
, min
);
527 sprintf_vma (max_buf
, max
);
529 /* xgettext:c-format. */
530 err
= _("%s out of range (0x%s is not between 0x%s and 0x%s)");
533 as_bad_where (file
, line
, err
, prefix
, val_buf
, min_buf
, max_buf
);
535 as_warn_where (file
, line
, err
, prefix
, val_buf
, min_buf
, max_buf
);
540 as_warn_value_out_of_range (char * prefix
,
547 as_internal_value_out_of_range (prefix
, value
, min
, max
, file
, line
, 0);
551 as_bad_value_out_of_range (char * prefix
,
558 as_internal_value_out_of_range (prefix
, value
, min
, max
, file
, line
, 1);