1 /* messages.c - error reporter -
2 Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001,
3 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
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 3, 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
24 static void identify (char *);
25 static void as_show_where (void);
26 static void as_warn_internal (char *, unsigned int, char *);
27 static void as_bad_internal (char *, unsigned int, char *);
29 /* Despite the rest of the comments in this file, (FIXME-SOON),
30 here is the current scheme for error messages etc:
32 as_fatal() is used when gas is quite confused and
33 continuing the assembly is pointless. In this case we
34 exit immediately with error status.
36 as_bad() is used to mark errors that result in what we
37 presume to be a useless object file. Say, we ignored
38 something that might have been vital. If we see any of
39 these, assembly will continue to the end of the source,
40 no object file will be produced, and we will terminate
41 with error status. The new option, -Z, tells us to
42 produce an object file anyway but we still exit with
43 error status. The assumption here is that you don't want
44 this object file but we could be wrong.
46 as_warn() is used when we have an error from which we
47 have a plausible error recovery. eg, masking the top
48 bits of a constant that is longer than will fit in the
49 destination. In this case we will continue to assemble
50 the source, although we may have made a bad assumption,
51 and we will produce an object file and return normal exit
52 status (ie, no error). The new option -X tells us to
53 treat all as_warn() errors as as_bad() errors. That is,
54 no object file will be produced and we will exit with
55 error status. The idea here is that we don't kill an
56 entire make because of an error that we knew how to
57 correct. On the other hand, sometimes you might want to
58 stop the make at these points.
60 as_tsktsk() is used when we see a minor error for which
61 our error recovery action is almost certainly correct.
62 In this case, we print a message and then assembly
63 continues as though no error occurred. */
68 static int identified;
81 fprintf (stderr, "%s: ", file);
82 fprintf (stderr, _("Assembler messages:\n"));
85 /* The number of warnings issued. */
86 static int warning_count;
94 /* Nonzero if we've hit a 'bad error', and should not write an obj file,
95 and exit with a nonzero error code. */
97 static int error_count;
105 /* Print the current location to stderr. */
113 as_where (&file, &line);
118 fprintf (stderr, "%s:%u: ", file, line);
120 fprintf (stderr, "%s: ", file);
124 /* Send to stderr a string as a warning, and locate warning
126 Please only use this for when we have some recovery action.
127 Please explain in string (which may have '\n's) what recovery was
131 as_tsktsk (const char *format, ...)
136 va_start (args, format);
137 vfprintf (stderr, format, args);
139 (void) putc ('\n', stderr);
142 /* The common portion of as_warn and as_warn_where. */
145 as_warn_internal (char *file, unsigned int line, char *buffer)
150 as_where (&file, &line);
156 fprintf (stderr, "%s:%u: ", file, line);
158 fprintf (stderr, "%s: ", file);
160 fprintf (stderr, _("Warning: "));
161 fputs (buffer, stderr);
162 (void) putc ('\n', stderr);
164 listing_warning (buffer);
168 /* Send to stderr a string as a warning, and locate warning
170 Please only use this for when we have some recovery action.
171 Please explain in string (which may have '\n's) what recovery was
175 as_warn (const char *format, ...)
180 if (!flag_no_warnings)
182 va_start (args, format);
183 vsnprintf (buffer, sizeof (buffer), format, args);
185 as_warn_internal ((char *) NULL, 0, buffer);
189 /* Like as_bad but the file name and line number are passed in.
190 Unfortunately, we have to repeat the function in order to handle
191 the varargs correctly and portably. */
194 as_warn_where (char *file, unsigned int line, const char *format, ...)
199 if (!flag_no_warnings)
201 va_start (args, format);
202 vsnprintf (buffer, sizeof (buffer), format, args);
204 as_warn_internal (file, line, buffer);
208 /* The common portion of as_bad and as_bad_where. */
211 as_bad_internal (char *file, unsigned int line, char *buffer)
216 as_where (&file, &line);
222 fprintf (stderr, "%s:%u: ", file, line);
224 fprintf (stderr, "%s: ", file);
226 fprintf (stderr, _("Error: "));
227 fputs (buffer, stderr);
228 (void) putc ('\n', stderr);
230 listing_error (buffer);
234 /* Send to stderr a string as a warning, and locate warning in input
235 file(s). Please us when there is no recovery, but we want to
236 continue processing but not produce an object file.
237 Please explain in string (which may have '\n's) what recovery was
241 as_bad (const char *format, ...)
246 va_start (args, format);
247 vsnprintf (buffer, sizeof (buffer), format, args);
250 as_bad_internal ((char *) NULL, 0, buffer);
253 /* Like as_bad but the file name and line number are passed in.
254 Unfortunately, we have to repeat the function in order to handle
255 the varargs correctly and portably. */
258 as_bad_where (char *file, unsigned int line, const char *format, ...)
263 va_start (args, format);
264 vsnprintf (buffer, sizeof (buffer), format, args);
267 as_bad_internal (file, line, buffer);
270 /* Send to stderr a string as a fatal message, and print location of
271 error in input file(s).
272 Please only use this for when we DON'T have some recovery action.
273 It xexit()s with a warning status. */
276 as_fatal (const char *format, ...)
281 va_start (args, format);
282 fprintf (stderr, _("Fatal error: "));
283 vfprintf (stderr, format, args);
284 (void) putc ('\n', stderr);
286 /* Delete the output file, if it exists. This will prevent make from
287 thinking that a file was created and hence does not need rebuilding. */
288 if (out_file_name != NULL)
289 unlink_if_ordinary (out_file_name);
290 xexit (EXIT_FAILURE);
293 /* Indicate assertion failure.
294 Arguments: Filename, line number, optional function name. */
297 as_assert (const char *file, int line, const char *fn)
300 fprintf (stderr, _("Internal error!\n"));
302 fprintf (stderr, _("Assertion failure in %s at %s line %d.\n"),
305 fprintf (stderr, _("Assertion failure at %s line %d.\n"), file, line);
306 fprintf (stderr, _("Please report this bug.\n"));
307 xexit (EXIT_FAILURE);
310 /* as_abort: Print a friendly message saying how totally hosed we are,
311 and exit without producing a core file. */
314 as_abort (const char *file, int line, const char *fn)
318 fprintf (stderr, _("Internal error, aborting at %s line %d in %s\n"),
321 fprintf (stderr, _("Internal error, aborting at %s line %d\n"),
323 fprintf (stderr, _("Please report this bug.\n"));
324 xexit (EXIT_FAILURE);
327 /* Support routines. */
330 sprint_value (char *buf, valueT val)
332 if (sizeof (val) <= sizeof (long))
334 sprintf (buf, "%ld", (long) val);
337 if (sizeof (val) <= sizeof (bfd_vma))
339 sprintf_vma (buf, val);
345 #define HEX_MAX_THRESHOLD 1024
346 #define HEX_MIN_THRESHOLD -(HEX_MAX_THRESHOLD)
349 as_internal_value_out_of_range (char * prefix,
362 if (val >= min && val <= max)
364 addressT right = max & -max;
369 /* xgettext:c-format */
370 err = _("%s out of domain (%d is not a multiple of %d)");
372 as_bad_where (file, line, err,
373 prefix, (int) val, (int) right);
375 as_warn_where (file, line, err,
376 prefix, (int) val, (int) right);
380 if ( val < HEX_MAX_THRESHOLD
381 && min < HEX_MAX_THRESHOLD
382 && max < HEX_MAX_THRESHOLD
383 && val > HEX_MIN_THRESHOLD
384 && min > HEX_MIN_THRESHOLD
385 && max > HEX_MIN_THRESHOLD)
387 /* xgettext:c-format */
388 err = _("%s out of range (%d is not between %d and %d)");
391 as_bad_where (file, line, err,
392 prefix, (int) val, (int) min, (int) max);
394 as_warn_where (file, line, err,
395 prefix, (int) val, (int) min, (int) max);
399 char val_buf [sizeof (val) * 3 + 2];
400 char min_buf [sizeof (val) * 3 + 2];
401 char max_buf [sizeof (val) * 3 + 2];
403 if (sizeof (val) > sizeof (bfd_vma))
406 sprintf_vma (val_buf, (bfd_vma) val);
407 sprintf_vma (min_buf, (bfd_vma) min);
408 sprintf_vma (max_buf, (bfd_vma) max);
410 /* xgettext:c-format. */
411 err = _("%s out of range (0x%s is not between 0x%s and 0x%s)");
414 as_bad_where (file, line, err, prefix, val_buf, min_buf, max_buf);
416 as_warn_where (file, line, err, prefix, val_buf, min_buf, max_buf);
421 as_warn_value_out_of_range (char * prefix,
428 as_internal_value_out_of_range (prefix, value, min, max, file, line, 0);
432 as_bad_value_out_of_range (char * prefix,
439 as_internal_value_out_of_range (prefix, value, min, max, file, line, 1);