]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/messages.c
Automatic date update in version.in
[thirdparty/binutils-gdb.git] / gas / messages.c
CommitLineData
252b5132 1/* messages.c - error reporter -
6f2750fe 2 Copyright (C) 1987-2016 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
3b4dbbbf 22static void identify (const char *);
254d758c 23static void as_show_where (void);
3b4dbbbf
TS
24static void as_warn_internal (const char *, unsigned int, char *);
25static void as_bad_internal (const 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
3b4dbbbf 64identify (const 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;
3b4dbbbf 75 file = as_where (&x);
252b5132
RH
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 107{
3b4dbbbf 108 const char *file;
252b5132
RH
109 unsigned int line;
110
3b4dbbbf 111 file = as_where (&line);
252b5132
RH
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
3b4dbbbf 143as_warn_internal (const char *file, unsigned int line, char *buffer)
252b5132
RH
144{
145 ++warning_count;
146
147 if (file == NULL)
3b4dbbbf 148 file = as_where (&line);
252b5132
RH
149
150 identify (file);
151 if (file)
144886fa
AM
152 {
153 if (line != 0)
b52855e7 154 fprintf (stderr, "%s:%u: %s%s\n", file, line, _("Warning: "), buffer);
144886fa 155 else
b52855e7 156 fprintf (stderr, "%s: %s%s\n", file, _("Warning: "), buffer);
144886fa 157 }
39128ec0 158 else
b52855e7 159 fprintf (stderr, "%s%s\n", _("Warning: "), buffer);
252b5132
RH
160#ifndef NO_LISTING
161 listing_warning (buffer);
162#endif
163}
164
ef99799a
KH
165/* Send to stderr a string as a warning, and locate warning
166 in input file(s).
167 Please only use this for when we have some recovery action.
168 Please explain in string (which may have '\n's) what recovery was
169 done. */
252b5132 170
c488923f 171void
ef99799a 172as_warn (const char *format, ...)
252b5132
RH
173{
174 va_list args;
175 char buffer[2000];
176
177 if (!flag_no_warnings)
178 {
179 va_start (args, format);
a9bfff94 180 vsnprintf (buffer, sizeof (buffer), format, args);
252b5132
RH
181 va_end (args);
182 as_warn_internal ((char *) NULL, 0, buffer);
183 }
ef99799a 184}
252b5132 185
ef99799a
KH
186/* Like as_bad but the file name and line number are passed in.
187 Unfortunately, we have to repeat the function in order to handle
188 the varargs correctly and portably. */
252b5132 189
c488923f 190void
3b4dbbbf 191as_warn_where (const char *file, unsigned int line, const char *format, ...)
252b5132
RH
192{
193 va_list args;
194 char buffer[2000];
195
196 if (!flag_no_warnings)
197 {
198 va_start (args, format);
a9bfff94 199 vsnprintf (buffer, sizeof (buffer), format, args);
252b5132
RH
200 va_end (args);
201 as_warn_internal (file, line, buffer);
202 }
ef99799a 203}
252b5132
RH
204
205/* The common portion of as_bad and as_bad_where. */
206
207static void
3b4dbbbf 208as_bad_internal (const char *file, unsigned int line, char *buffer)
252b5132
RH
209{
210 ++error_count;
211
212 if (file == NULL)
3b4dbbbf 213 file = as_where (&line);
252b5132
RH
214
215 identify (file);
216 if (file)
144886fa
AM
217 {
218 if (line != 0)
b52855e7 219 fprintf (stderr, "%s:%u: %s%s\n", file, line, _("Error: "), buffer);
144886fa 220 else
b52855e7 221 fprintf (stderr, "%s: %s%s\n", file, _("Error: "), buffer);
144886fa 222 }
39128ec0 223 else
b52855e7 224 fprintf (stderr, "%s%s\n", _("Error: "), buffer);
252b5132
RH
225#ifndef NO_LISTING
226 listing_error (buffer);
227#endif
228}
229
ef99799a
KH
230/* Send to stderr a string as a warning, and locate warning in input
231 file(s). Please us when there is no recovery, but we want to
232 continue processing but not produce an object file.
233 Please explain in string (which may have '\n's) what recovery was
43ad3147 234 done. */
252b5132 235
c488923f 236void
ef99799a 237as_bad (const char *format, ...)
252b5132
RH
238{
239 va_list args;
240 char buffer[2000];
241
242 va_start (args, format);
a9bfff94 243 vsnprintf (buffer, sizeof (buffer), format, args);
252b5132
RH
244 va_end (args);
245
246 as_bad_internal ((char *) NULL, 0, buffer);
247}
248
ef99799a
KH
249/* Like as_bad but the file name and line number are passed in.
250 Unfortunately, we have to repeat the function in order to handle
251 the varargs correctly and portably. */
252b5132 252
c488923f 253void
3b4dbbbf 254as_bad_where (const char *file, unsigned int line, const char *format, ...)
252b5132
RH
255{
256 va_list args;
257 char buffer[2000];
258
259 va_start (args, format);
a9bfff94 260 vsnprintf (buffer, sizeof (buffer), format, args);
252b5132
RH
261 va_end (args);
262
263 as_bad_internal (file, line, buffer);
264}
265
ef99799a
KH
266/* Send to stderr a string as a fatal message, and print location of
267 error in input file(s).
268 Please only use this for when we DON'T have some recovery action.
269 It xexit()s with a warning status. */
252b5132 270
c488923f 271void
ef99799a 272as_fatal (const char *format, ...)
252b5132
RH
273{
274 va_list args;
275
276 as_show_where ();
277 va_start (args, format);
278 fprintf (stderr, _("Fatal error: "));
279 vfprintf (stderr, format, args);
280 (void) putc ('\n', stderr);
281 va_end (args);
d4887adc
NC
282 /* Delete the output file, if it exists. This will prevent make from
283 thinking that a file was created and hence does not need rebuilding. */
284 if (out_file_name != NULL)
bb14f524 285 unlink_if_ordinary (out_file_name);
252b5132 286 xexit (EXIT_FAILURE);
ef99799a 287}
252b5132 288
ef99799a
KH
289/* Indicate assertion failure.
290 Arguments: Filename, line number, optional function name. */
252b5132
RH
291
292void
254d758c 293as_assert (const char *file, int line, const char *fn)
252b5132
RH
294{
295 as_show_where ();
296 fprintf (stderr, _("Internal error!\n"));
297 if (fn)
7ac01895 298 fprintf (stderr, _("Assertion failure in %s at %s:%d.\n"),
252b5132
RH
299 fn, file, line);
300 else
7ac01895 301 fprintf (stderr, _("Assertion failure at %s:%d.\n"), file, line);
252b5132
RH
302 fprintf (stderr, _("Please report this bug.\n"));
303 xexit (EXIT_FAILURE);
304}
305
306/* as_abort: Print a friendly message saying how totally hosed we are,
307 and exit without producing a core file. */
ef99799a 308
252b5132 309void
254d758c 310as_abort (const char *file, int line, const char *fn)
252b5132
RH
311{
312 as_show_where ();
313 if (fn)
7ac01895 314 fprintf (stderr, _("Internal error, aborting at %s:%d in %s\n"),
252b5132
RH
315 file, line, fn);
316 else
7ac01895 317 fprintf (stderr, _("Internal error, aborting at %s:%d\n"),
252b5132
RH
318 file, line);
319 fprintf (stderr, _("Please report this bug.\n"));
320 xexit (EXIT_FAILURE);
321}
322
323/* Support routines. */
324
252b5132 325void
254d758c 326sprint_value (char *buf, valueT val)
252b5132
RH
327{
328 if (sizeof (val) <= sizeof (long))
329 {
330 sprintf (buf, "%ld", (long) val);
331 return;
332 }
252b5132
RH
333 if (sizeof (val) <= sizeof (bfd_vma))
334 {
335 sprintf_vma (buf, val);
336 return;
337 }
252b5132
RH
338 abort ();
339}
e5976317
NC
340
341#define HEX_MAX_THRESHOLD 1024
342#define HEX_MIN_THRESHOLD -(HEX_MAX_THRESHOLD)
343
344static void
cd0bbe6e
TS
345as_internal_value_out_of_range (const char * prefix,
346 offsetT val,
347 offsetT min,
348 offsetT max,
3b4dbbbf 349 const char * file,
cd0bbe6e
TS
350 unsigned line,
351 int bad)
e5976317
NC
352{
353 const char * err;
354
355 if (prefix == NULL)
356 prefix = "";
357
b84bf58a
AM
358 if (val >= min && val <= max)
359 {
360 addressT right = max & -max;
361
362 if (max <= 1)
363 abort ();
364
365 /* xgettext:c-format */
931774a9 366 err = _("%s out of domain (%d is not a multiple of %d)");
b84bf58a
AM
367 if (bad)
368 as_bad_where (file, line, err,
369 prefix, (int) val, (int) right);
370 else
371 as_warn_where (file, line, err,
372 prefix, (int) val, (int) right);
931774a9 373 return;
b84bf58a
AM
374 }
375
e5976317
NC
376 if ( val < HEX_MAX_THRESHOLD
377 && min < HEX_MAX_THRESHOLD
378 && max < HEX_MAX_THRESHOLD
379 && val > HEX_MIN_THRESHOLD
380 && min > HEX_MIN_THRESHOLD
381 && max > HEX_MIN_THRESHOLD)
e5976317
NC
382 {
383 /* xgettext:c-format */
384 err = _("%s out of range (%d is not between %d and %d)");
385
386 if (bad)
2159ac21
AM
387 as_bad_where (file, line, err,
388 prefix, (int) val, (int) min, (int) max);
e5976317 389 else
2159ac21
AM
390 as_warn_where (file, line, err,
391 prefix, (int) val, (int) min, (int) max);
e5976317 392 }
e5976317
NC
393 else
394 {
395 char val_buf [sizeof (val) * 3 + 2];
396 char min_buf [sizeof (val) * 3 + 2];
397 char max_buf [sizeof (val) * 3 + 2];
398
399 if (sizeof (val) > sizeof (bfd_vma))
400 abort ();
401
0af1713e
AM
402 sprintf_vma (val_buf, (bfd_vma) val);
403 sprintf_vma (min_buf, (bfd_vma) min);
404 sprintf_vma (max_buf, (bfd_vma) max);
e5976317
NC
405
406 /* xgettext:c-format. */
407 err = _("%s out of range (0x%s is not between 0x%s and 0x%s)");
408
409 if (bad)
410 as_bad_where (file, line, err, prefix, val_buf, min_buf, max_buf);
411 else
412 as_warn_where (file, line, err, prefix, val_buf, min_buf, max_buf);
413 }
e5976317
NC
414}
415
416void
417as_warn_value_out_of_range (char * prefix,
418 offsetT value,
419 offsetT min,
420 offsetT max,
3b4dbbbf 421 const char * file,
e5976317
NC
422 unsigned line)
423{
424 as_internal_value_out_of_range (prefix, value, min, max, file, line, 0);
425}
426
427void
428as_bad_value_out_of_range (char * prefix,
429 offsetT value,
430 offsetT min,
431 offsetT max,
3b4dbbbf 432 const char * file,
e5976317
NC
433 unsigned line)
434{
435 as_internal_value_out_of_range (prefix, value, min, max, file, line, 1);
436}