Commit | Line | Data |
---|---|---|
252b5132 | 1 | /* messages.c - error reporter - |
2159ac21 | 2 | Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001, |
0af1713e | 3 | 2003, 2004, 2005, 2006, 2007, 2008 |
252b5132 RH |
4 | Free Software Foundation, Inc. |
5 | This file is part of GAS, the GNU Assembler. | |
6 | ||
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 | |
ec2655a6 | 9 | the Free Software Foundation; either version 3, or (at your option) |
252b5132 RH |
10 | any later version. |
11 | ||
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. | |
16 | ||
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 | |
4b4da160 NC |
19 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
20 | 02110-1301, USA. */ | |
252b5132 RH |
21 | |
22 | #include "as.h" | |
23 | ||
254d758c KH |
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 *); | |
252b5132 | 28 | |
ef99799a | 29 | /* Despite the rest of the comments in this file, (FIXME-SOON), |
5a1964ec NC |
30 | here is the current scheme for error messages etc: |
31 | ||
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. | |
35 | ||
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. | |
45 | ||
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. | |
59 | ||
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. */ | |
252b5132 RH |
64 | |
65 | static void | |
254d758c | 66 | identify (char *file) |
252b5132 RH |
67 | { |
68 | static int identified; | |
5a1964ec | 69 | |
252b5132 RH |
70 | if (identified) |
71 | return; | |
72 | identified++; | |
73 | ||
74 | if (!file) | |
75 | { | |
76 | unsigned int x; | |
77 | as_where (&file, &x); | |
78 | } | |
79 | ||
80 | if (file) | |
81 | fprintf (stderr, "%s: ", file); | |
82 | fprintf (stderr, _("Assembler messages:\n")); | |
83 | } | |
84 | ||
ef99799a KH |
85 | /* The number of warnings issued. */ |
86 | static int warning_count; | |
252b5132 | 87 | |
c488923f | 88 | int |
254d758c | 89 | had_warnings (void) |
252b5132 | 90 | { |
5a1964ec | 91 | return warning_count; |
252b5132 RH |
92 | } |
93 | ||
94 | /* Nonzero if we've hit a 'bad error', and should not write an obj file, | |
ef99799a | 95 | and exit with a nonzero error code. */ |
252b5132 RH |
96 | |
97 | static int error_count; | |
98 | ||
c488923f | 99 | int |
254d758c | 100 | had_errors (void) |
252b5132 | 101 | { |
5a1964ec | 102 | return error_count; |
252b5132 RH |
103 | } |
104 | ||
252b5132 RH |
105 | /* Print the current location to stderr. */ |
106 | ||
107 | static void | |
254d758c | 108 | as_show_where (void) |
252b5132 RH |
109 | { |
110 | char *file; | |
111 | unsigned int line; | |
112 | ||
113 | as_where (&file, &line); | |
114 | identify (file); | |
115 | if (file) | |
116 | fprintf (stderr, "%s:%u: ", file, line); | |
117 | } | |
118 | ||
ef99799a KH |
119 | /* Send to stderr a string as a warning, and locate warning |
120 | in input file(s). | |
121 | Please only use this for when we have some recovery action. | |
122 | Please explain in string (which may have '\n's) what recovery was | |
123 | done. */ | |
252b5132 | 124 | |
c488923f | 125 | void |
ef99799a | 126 | as_tsktsk (const char *format, ...) |
252b5132 RH |
127 | { |
128 | va_list args; | |
129 | ||
130 | as_show_where (); | |
131 | va_start (args, format); | |
132 | vfprintf (stderr, format, args); | |
133 | va_end (args); | |
134 | (void) putc ('\n', stderr); | |
ef99799a | 135 | } |
252b5132 RH |
136 | |
137 | /* The common portion of as_warn and as_warn_where. */ | |
138 | ||
139 | static void | |
254d758c | 140 | as_warn_internal (char *file, unsigned int line, char *buffer) |
252b5132 RH |
141 | { |
142 | ++warning_count; | |
143 | ||
144 | if (file == NULL) | |
145 | as_where (&file, &line); | |
146 | ||
147 | identify (file); | |
148 | if (file) | |
149 | fprintf (stderr, "%s:%u: ", file, line); | |
150 | fprintf (stderr, _("Warning: ")); | |
151 | fputs (buffer, stderr); | |
152 | (void) putc ('\n', stderr); | |
153 | #ifndef NO_LISTING | |
154 | listing_warning (buffer); | |
155 | #endif | |
156 | } | |
157 | ||
ef99799a KH |
158 | /* Send to stderr a string as a warning, and locate warning |
159 | in input file(s). | |
160 | Please only use this for when we have some recovery action. | |
161 | Please explain in string (which may have '\n's) what recovery was | |
162 | done. */ | |
252b5132 | 163 | |
c488923f | 164 | void |
ef99799a | 165 | as_warn (const char *format, ...) |
252b5132 RH |
166 | { |
167 | va_list args; | |
168 | char buffer[2000]; | |
169 | ||
170 | if (!flag_no_warnings) | |
171 | { | |
172 | va_start (args, format); | |
a9bfff94 | 173 | vsnprintf (buffer, sizeof (buffer), format, args); |
252b5132 RH |
174 | va_end (args); |
175 | as_warn_internal ((char *) NULL, 0, buffer); | |
176 | } | |
ef99799a | 177 | } |
252b5132 | 178 | |
ef99799a KH |
179 | /* Like as_bad but the file name and line number are passed in. |
180 | Unfortunately, we have to repeat the function in order to handle | |
181 | the varargs correctly and portably. */ | |
252b5132 | 182 | |
c488923f | 183 | void |
ef99799a | 184 | as_warn_where (char *file, unsigned int line, const char *format, ...) |
252b5132 RH |
185 | { |
186 | va_list args; | |
187 | char buffer[2000]; | |
188 | ||
189 | if (!flag_no_warnings) | |
190 | { | |
191 | va_start (args, format); | |
a9bfff94 | 192 | vsnprintf (buffer, sizeof (buffer), format, args); |
252b5132 RH |
193 | va_end (args); |
194 | as_warn_internal (file, line, buffer); | |
195 | } | |
ef99799a | 196 | } |
252b5132 RH |
197 | |
198 | /* The common portion of as_bad and as_bad_where. */ | |
199 | ||
200 | static void | |
254d758c | 201 | as_bad_internal (char *file, unsigned int line, char *buffer) |
252b5132 RH |
202 | { |
203 | ++error_count; | |
204 | ||
205 | if (file == NULL) | |
206 | as_where (&file, &line); | |
207 | ||
208 | identify (file); | |
209 | if (file) | |
210 | fprintf (stderr, "%s:%u: ", file, line); | |
211 | fprintf (stderr, _("Error: ")); | |
212 | fputs (buffer, stderr); | |
213 | (void) putc ('\n', stderr); | |
214 | #ifndef NO_LISTING | |
215 | listing_error (buffer); | |
216 | #endif | |
217 | } | |
218 | ||
ef99799a KH |
219 | /* Send to stderr a string as a warning, and locate warning in input |
220 | file(s). Please us when there is no recovery, but we want to | |
221 | continue processing but not produce an object file. | |
222 | Please explain in string (which may have '\n's) what recovery was | |
43ad3147 | 223 | done. */ |
252b5132 | 224 | |
c488923f | 225 | void |
ef99799a | 226 | as_bad (const char *format, ...) |
252b5132 RH |
227 | { |
228 | va_list args; | |
229 | char buffer[2000]; | |
230 | ||
231 | va_start (args, format); | |
a9bfff94 | 232 | vsnprintf (buffer, sizeof (buffer), format, args); |
252b5132 RH |
233 | va_end (args); |
234 | ||
235 | as_bad_internal ((char *) NULL, 0, buffer); | |
236 | } | |
237 | ||
ef99799a KH |
238 | /* Like as_bad but the file name and line number are passed in. |
239 | Unfortunately, we have to repeat the function in order to handle | |
240 | the varargs correctly and portably. */ | |
252b5132 | 241 | |
c488923f | 242 | void |
ef99799a | 243 | as_bad_where (char *file, unsigned int line, const char *format, ...) |
252b5132 RH |
244 | { |
245 | va_list args; | |
246 | char buffer[2000]; | |
247 | ||
248 | va_start (args, format); | |
a9bfff94 | 249 | vsnprintf (buffer, sizeof (buffer), format, args); |
252b5132 RH |
250 | va_end (args); |
251 | ||
252 | as_bad_internal (file, line, buffer); | |
253 | } | |
254 | ||
ef99799a KH |
255 | /* Send to stderr a string as a fatal message, and print location of |
256 | error in input file(s). | |
257 | Please only use this for when we DON'T have some recovery action. | |
258 | It xexit()s with a warning status. */ | |
252b5132 | 259 | |
c488923f | 260 | void |
ef99799a | 261 | as_fatal (const char *format, ...) |
252b5132 RH |
262 | { |
263 | va_list args; | |
264 | ||
265 | as_show_where (); | |
266 | va_start (args, format); | |
267 | fprintf (stderr, _("Fatal error: ")); | |
268 | vfprintf (stderr, format, args); | |
269 | (void) putc ('\n', stderr); | |
270 | va_end (args); | |
d4887adc NC |
271 | /* Delete the output file, if it exists. This will prevent make from |
272 | thinking that a file was created and hence does not need rebuilding. */ | |
273 | if (out_file_name != NULL) | |
bb14f524 | 274 | unlink_if_ordinary (out_file_name); |
252b5132 | 275 | xexit (EXIT_FAILURE); |
ef99799a | 276 | } |
252b5132 | 277 | |
ef99799a KH |
278 | /* Indicate assertion failure. |
279 | Arguments: Filename, line number, optional function name. */ | |
252b5132 RH |
280 | |
281 | void | |
254d758c | 282 | as_assert (const char *file, int line, const char *fn) |
252b5132 RH |
283 | { |
284 | as_show_where (); | |
285 | fprintf (stderr, _("Internal error!\n")); | |
286 | if (fn) | |
287 | fprintf (stderr, _("Assertion failure in %s at %s line %d.\n"), | |
288 | fn, file, line); | |
289 | else | |
290 | fprintf (stderr, _("Assertion failure at %s line %d.\n"), file, line); | |
291 | fprintf (stderr, _("Please report this bug.\n")); | |
292 | xexit (EXIT_FAILURE); | |
293 | } | |
294 | ||
295 | /* as_abort: Print a friendly message saying how totally hosed we are, | |
296 | and exit without producing a core file. */ | |
ef99799a | 297 | |
252b5132 | 298 | void |
254d758c | 299 | as_abort (const char *file, int line, const char *fn) |
252b5132 RH |
300 | { |
301 | as_show_where (); | |
302 | if (fn) | |
303 | fprintf (stderr, _("Internal error, aborting at %s line %d in %s\n"), | |
304 | file, line, fn); | |
305 | else | |
306 | fprintf (stderr, _("Internal error, aborting at %s line %d\n"), | |
307 | file, line); | |
308 | fprintf (stderr, _("Please report this bug.\n")); | |
309 | xexit (EXIT_FAILURE); | |
310 | } | |
311 | ||
312 | /* Support routines. */ | |
313 | ||
252b5132 | 314 | void |
254d758c | 315 | sprint_value (char *buf, valueT val) |
252b5132 RH |
316 | { |
317 | if (sizeof (val) <= sizeof (long)) | |
318 | { | |
319 | sprintf (buf, "%ld", (long) val); | |
320 | return; | |
321 | } | |
252b5132 RH |
322 | if (sizeof (val) <= sizeof (bfd_vma)) |
323 | { | |
324 | sprintf_vma (buf, val); | |
325 | return; | |
326 | } | |
252b5132 RH |
327 | abort (); |
328 | } | |
e5976317 NC |
329 | |
330 | #define HEX_MAX_THRESHOLD 1024 | |
331 | #define HEX_MIN_THRESHOLD -(HEX_MAX_THRESHOLD) | |
332 | ||
333 | static void | |
334 | as_internal_value_out_of_range (char * prefix, | |
335 | offsetT val, | |
336 | offsetT min, | |
337 | offsetT max, | |
338 | char * file, | |
339 | unsigned line, | |
340 | int bad) | |
341 | { | |
342 | const char * err; | |
343 | ||
344 | if (prefix == NULL) | |
345 | prefix = ""; | |
346 | ||
b84bf58a AM |
347 | if (val >= min && val <= max) |
348 | { | |
349 | addressT right = max & -max; | |
350 | ||
351 | if (max <= 1) | |
352 | abort (); | |
353 | ||
354 | /* xgettext:c-format */ | |
931774a9 | 355 | err = _("%s out of domain (%d is not a multiple of %d)"); |
b84bf58a AM |
356 | if (bad) |
357 | as_bad_where (file, line, err, | |
358 | prefix, (int) val, (int) right); | |
359 | else | |
360 | as_warn_where (file, line, err, | |
361 | prefix, (int) val, (int) right); | |
931774a9 | 362 | return; |
b84bf58a AM |
363 | } |
364 | ||
e5976317 NC |
365 | if ( val < HEX_MAX_THRESHOLD |
366 | && min < HEX_MAX_THRESHOLD | |
367 | && max < HEX_MAX_THRESHOLD | |
368 | && val > HEX_MIN_THRESHOLD | |
369 | && min > HEX_MIN_THRESHOLD | |
370 | && max > HEX_MIN_THRESHOLD) | |
e5976317 NC |
371 | { |
372 | /* xgettext:c-format */ | |
373 | err = _("%s out of range (%d is not between %d and %d)"); | |
374 | ||
375 | if (bad) | |
2159ac21 AM |
376 | as_bad_where (file, line, err, |
377 | prefix, (int) val, (int) min, (int) max); | |
e5976317 | 378 | else |
2159ac21 AM |
379 | as_warn_where (file, line, err, |
380 | prefix, (int) val, (int) min, (int) max); | |
e5976317 | 381 | } |
e5976317 NC |
382 | else |
383 | { | |
384 | char val_buf [sizeof (val) * 3 + 2]; | |
385 | char min_buf [sizeof (val) * 3 + 2]; | |
386 | char max_buf [sizeof (val) * 3 + 2]; | |
387 | ||
388 | if (sizeof (val) > sizeof (bfd_vma)) | |
389 | abort (); | |
390 | ||
0af1713e AM |
391 | sprintf_vma (val_buf, (bfd_vma) val); |
392 | sprintf_vma (min_buf, (bfd_vma) min); | |
393 | sprintf_vma (max_buf, (bfd_vma) max); | |
e5976317 NC |
394 | |
395 | /* xgettext:c-format. */ | |
396 | err = _("%s out of range (0x%s is not between 0x%s and 0x%s)"); | |
397 | ||
398 | if (bad) | |
399 | as_bad_where (file, line, err, prefix, val_buf, min_buf, max_buf); | |
400 | else | |
401 | as_warn_where (file, line, err, prefix, val_buf, min_buf, max_buf); | |
402 | } | |
e5976317 NC |
403 | } |
404 | ||
405 | void | |
406 | as_warn_value_out_of_range (char * prefix, | |
407 | offsetT value, | |
408 | offsetT min, | |
409 | offsetT max, | |
410 | char * file, | |
411 | unsigned line) | |
412 | { | |
413 | as_internal_value_out_of_range (prefix, value, min, max, file, line, 0); | |
414 | } | |
415 | ||
416 | void | |
417 | as_bad_value_out_of_range (char * prefix, | |
418 | offsetT value, | |
419 | offsetT min, | |
420 | offsetT max, | |
421 | char * file, | |
422 | unsigned line) | |
423 | { | |
424 | as_internal_value_out_of_range (prefix, value, min, max, file, line, 1); | |
425 | } |