1 /* messages.c - error reporter -
2 Copyright (C) 1987-2017 Free Software Foundation, Inc.
3 This file is part of GAS, the GNU Assembler.
5 GAS is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3, or (at your option)
10 GAS is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GAS; see the file COPYING. If not, write to the Free
17 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
23 /* If the system doesn't provide strsignal, we get it defined in
24 libiberty but no declaration is supplied. Because, reasons. */
25 #if !defined (HAVE_STRSIGNAL) && !defined (strsignal)
26 extern const char *strsignal (int);
29 static void identify (const char *);
30 static void as_show_where (void);
31 static void as_warn_internal (const char *, unsigned int, char *);
32 static void as_bad_internal (const char *, unsigned int, char *);
33 static void signal_crash (int) ATTRIBUTE_NORETURN
;
35 /* Despite the rest of the comments in this file, (FIXME-SOON),
36 here is the current scheme for error messages etc:
38 as_fatal() is used when gas is quite confused and
39 continuing the assembly is pointless. In this case we
40 exit immediately with error status.
42 as_bad() is used to mark errors that result in what we
43 presume to be a useless object file. Say, we ignored
44 something that might have been vital. If we see any of
45 these, assembly will continue to the end of the source,
46 no object file will be produced, and we will terminate
47 with error status. The new option, -Z, tells us to
48 produce an object file anyway but we still exit with
49 error status. The assumption here is that you don't want
50 this object file but we could be wrong.
52 as_warn() is used when we have an error from which we
53 have a plausible error recovery. eg, masking the top
54 bits of a constant that is longer than will fit in the
55 destination. In this case we will continue to assemble
56 the source, although we may have made a bad assumption,
57 and we will produce an object file and return normal exit
58 status (ie, no error). The new option -X tells us to
59 treat all as_warn() errors as as_bad() errors. That is,
60 no object file will be produced and we will exit with
61 error status. The idea here is that we don't kill an
62 entire make because of an error that we knew how to
63 correct. On the other hand, sometimes you might want to
64 stop the make at these points.
66 as_tsktsk() is used when we see a minor error for which
67 our error recovery action is almost certainly correct.
68 In this case, we print a message and then assembly
69 continues as though no error occurred.
71 as_abort () is used for logic failure (assert or abort, signal).
75 identify (const char *file
)
77 static int identified
;
90 fprintf (stderr
, "%s: ", file
);
91 fprintf (stderr
, _("Assembler messages:\n"));
94 /* The number of warnings issued. */
95 static int warning_count
;
100 return warning_count
;
103 /* Nonzero if we've hit a 'bad error', and should not write an obj file,
104 and exit with a nonzero error code. */
106 static int error_count
;
114 /* Print the current location to stderr. */
122 file
= as_where (&line
);
127 fprintf (stderr
, "%s:%u: ", file
, line
);
129 fprintf (stderr
, "%s: ", file
);
133 /* Send to stderr a string as a warning, and locate warning
135 Please only use this for when we have some recovery action.
136 Please explain in string (which may have '\n's) what recovery was
140 as_tsktsk (const char *format
, ...)
145 va_start (args
, format
);
146 vfprintf (stderr
, format
, args
);
148 (void) putc ('\n', stderr
);
151 /* The common portion of as_warn and as_warn_where. */
154 as_warn_internal (const char *file
, unsigned int line
, char *buffer
)
159 file
= as_where (&line
);
165 fprintf (stderr
, "%s:%u: %s%s\n", file
, line
, _("Warning: "), buffer
);
167 fprintf (stderr
, "%s: %s%s\n", file
, _("Warning: "), buffer
);
170 fprintf (stderr
, "%s%s\n", _("Warning: "), buffer
);
172 listing_warning (buffer
);
176 /* Send to stderr a string as a warning, and locate warning
178 Please only use this for when we have some recovery action.
179 Please explain in string (which may have '\n's) what recovery was
183 as_warn (const char *format
, ...)
188 if (!flag_no_warnings
)
190 va_start (args
, format
);
191 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
193 as_warn_internal ((char *) NULL
, 0, buffer
);
197 /* Like as_bad but the file name and line number are passed in.
198 Unfortunately, we have to repeat the function in order to handle
199 the varargs correctly and portably. */
202 as_warn_where (const char *file
, unsigned int line
, const char *format
, ...)
207 if (!flag_no_warnings
)
209 va_start (args
, format
);
210 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
212 as_warn_internal (file
, line
, buffer
);
216 /* The common portion of as_bad and as_bad_where. */
219 as_bad_internal (const char *file
, unsigned int line
, char *buffer
)
224 file
= as_where (&line
);
230 fprintf (stderr
, "%s:%u: %s%s\n", file
, line
, _("Error: "), buffer
);
232 fprintf (stderr
, "%s: %s%s\n", file
, _("Error: "), buffer
);
235 fprintf (stderr
, "%s%s\n", _("Error: "), buffer
);
237 listing_error (buffer
);
241 /* Send to stderr a string as a warning, and locate warning in input
242 file(s). Please use when there is no recovery, but we want to
243 continue processing but not produce an object file.
244 Please explain in string (which may have '\n's) what recovery was
248 as_bad (const char *format
, ...)
253 va_start (args
, format
);
254 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
257 as_bad_internal ((char *) NULL
, 0, buffer
);
260 /* Like as_bad but the file name and line number are passed in.
261 Unfortunately, we have to repeat the function in order to handle
262 the varargs correctly and portably. */
265 as_bad_where (const char *file
, unsigned int line
, const char *format
, ...)
270 va_start (args
, format
);
271 vsnprintf (buffer
, sizeof (buffer
), format
, args
);
274 as_bad_internal (file
, line
, buffer
);
277 /* Send to stderr a string as a fatal message, and print location of
278 error in input file(s).
279 Please only use this for when we DON'T have some recovery action.
280 It xexit()s with a warning status. */
283 as_fatal (const char *format
, ...)
288 va_start (args
, format
);
289 fprintf (stderr
, _("Fatal error: "));
290 vfprintf (stderr
, format
, args
);
291 (void) putc ('\n', stderr
);
293 /* Delete the output file, if it exists. This will prevent make from
294 thinking that a file was created and hence does not need rebuilding. */
295 if (out_file_name
!= NULL
)
296 unlink_if_ordinary (out_file_name
);
297 xexit (EXIT_FAILURE
);
300 /* Indicate internal constency error.
301 Arguments: Filename, line number, optional function name.
302 FILENAME may be NULL, which we use for crash-via-signal. */
305 as_abort (const char *file
, int line
, const char *fn
)
310 fprintf (stderr
, _("Internal error (%s).\n"), fn
? fn
: "unknown");
312 fprintf (stderr
, _("Internal error in %s at %s:%d.\n"), fn
, file
, line
);
314 fprintf (stderr
, _("Internal error at %s:%d.\n"), file
, line
);
316 fprintf (stderr
, _("Please report this bug.\n"));
318 xexit (EXIT_FAILURE
);
321 /* Handler for fatal signals, such as SIGSEGV. */
324 signal_crash (int signo
)
326 /* Reset, to prevent unbounded recursion. */
327 signal (signo
, SIG_DFL
);
329 as_abort (NULL
, 0, strsignal (signo
));
332 /* Register signal handlers, for less abrubt crashes. */
338 signal (SIGSEGV
, signal_crash
);
341 signal (SIGILL
, signal_crash
);
344 signal (SIGBUS
, signal_crash
);
347 signal (SIGABRT
, signal_crash
);
349 #if defined SIGIOT && (!defined SIGABRT || SIGABRT != SIGIOT)
350 signal (SIGIOT
, signal_crash
);
353 signal (SIGFPE
, signal_crash
);
357 /* Support routines. */
360 sprint_value (char *buf
, valueT val
)
362 if (sizeof (val
) <= sizeof (long))
364 sprintf (buf
, "%ld", (long) val
);
367 if (sizeof (val
) <= sizeof (bfd_vma
))
369 sprintf_vma (buf
, val
);
375 #define HEX_MAX_THRESHOLD 1024
376 #define HEX_MIN_THRESHOLD -(HEX_MAX_THRESHOLD)
379 as_internal_value_out_of_range (const char *prefix
,
392 if (val
>= min
&& val
<= max
)
394 addressT right
= max
& -max
;
399 /* xgettext:c-format */
400 err
= _("%s out of domain (%d is not a multiple of %d)");
402 as_bad_where (file
, line
, err
,
403 prefix
, (int) val
, (int) right
);
405 as_warn_where (file
, line
, err
,
406 prefix
, (int) val
, (int) right
);
410 if ( val
< HEX_MAX_THRESHOLD
411 && min
< HEX_MAX_THRESHOLD
412 && max
< HEX_MAX_THRESHOLD
413 && val
> HEX_MIN_THRESHOLD
414 && min
> HEX_MIN_THRESHOLD
415 && max
> HEX_MIN_THRESHOLD
)
417 /* xgettext:c-format */
418 err
= _("%s out of range (%d is not between %d and %d)");
421 as_bad_where (file
, line
, err
,
422 prefix
, (int) val
, (int) min
, (int) max
);
424 as_warn_where (file
, line
, err
,
425 prefix
, (int) val
, (int) min
, (int) max
);
429 char val_buf
[sizeof (val
) * 3 + 2];
430 char min_buf
[sizeof (val
) * 3 + 2];
431 char max_buf
[sizeof (val
) * 3 + 2];
433 if (sizeof (val
) > sizeof (bfd_vma
))
436 sprintf_vma (val_buf
, (bfd_vma
) val
);
437 sprintf_vma (min_buf
, (bfd_vma
) min
);
438 sprintf_vma (max_buf
, (bfd_vma
) max
);
440 /* xgettext:c-format. */
441 err
= _("%s out of range (0x%s is not between 0x%s and 0x%s)");
444 as_bad_where (file
, line
, err
, prefix
, val_buf
, min_buf
, max_buf
);
446 as_warn_where (file
, line
, err
, prefix
, val_buf
, min_buf
, max_buf
);
451 as_warn_value_out_of_range (const char *prefix
,
458 as_internal_value_out_of_range (prefix
, value
, min
, max
, file
, line
, 0);
462 as_bad_value_out_of_range (const char *prefix
,
469 as_internal_value_out_of_range (prefix
, value
, min
, max
, file
, line
, 1);
This page took 0.038625 seconds and 4 git commands to generate.