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