blob: 0c7aa64bbe2eedbe865998825fe6b1a67f1afd0c [file] [log] [blame]
H. Peter Anvin22538e22016-05-25 05:42:47 -07001/* ----------------------------------------------------------------------- *
H. Peter Anvinb2047cb2017-03-08 01:26:40 -08002 *
H. Peter Anvin987dc9c2018-06-12 13:50:37 -07003 * Copyright 1996-2018 The NASM Authors - All Rights Reserved
H. Peter Anvin22538e22016-05-25 05:42:47 -07004 * See the file AUTHORS included with the NASM distribution for
5 * the specific copyright holders.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following
9 * conditions are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
H. Peter Anvinb2047cb2017-03-08 01:26:40 -080017 *
H. Peter Anvin22538e22016-05-25 05:42:47 -070018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 *
32 * ----------------------------------------------------------------------- */
33
34/*
H. Peter Anvinb20bc732017-03-07 19:23:03 -080035 * error.c - error message handling routines for the assembler
H. Peter Anvin22538e22016-05-25 05:42:47 -070036 */
37
38#include "compiler.h"
39
40#include <stdlib.h>
41
42#include "nasmlib.h"
H. Peter Anvinb20bc732017-03-07 19:23:03 -080043#include "error.h"
44
45/*
46 * Description of the suppressible warnings for the command line and
H. Peter Anvinb2047cb2017-03-08 01:26:40 -080047 * the [warning] directive.
H. Peter Anvinb20bc732017-03-07 19:23:03 -080048 */
H. Peter Anvinb2047cb2017-03-08 01:26:40 -080049const struct warning warnings[ERR_WARN_ALL+1] = {
50 {"other", "any warning not specifially mentioned below", true},
H. Peter Anvinb20bc732017-03-07 19:23:03 -080051 {"macro-params", "macro calls with wrong parameter count", true},
52 {"macro-selfref", "cyclic macro references", false},
53 {"macro-defaults", "macros with more default than optional parameters", true},
54 {"orphan-labels", "labels alone on lines without trailing `:'", true},
55 {"number-overflow", "numeric constant does not fit", true},
56 {"gnu-elf-extensions", "using 8- or 16-bit relocation in ELF32, a GNU extension", false},
57 {"float-overflow", "floating point overflow", true},
58 {"float-denorm", "floating point denormal", false},
59 {"float-underflow", "floating point underflow", false},
60 {"float-toolong", "too many digits in floating-point number", true},
61 {"user", "%warning directives", true},
62 {"lock", "lock prefix on unlockable instructions", true},
63 {"hle", "invalid hle prefixes", true},
64 {"bnd", "invalid bnd prefixes", true},
65 {"zext-reloc", "relocation zero-extended to match output format", true},
66 {"ptr", "non-NASM keyword used in other assemblers", true},
H. Peter Anvina6e26d92017-03-07 21:32:37 -080067 {"bad-pragma", "empty or malformed %pragma", false},
68 {"unknown-pragma", "unknown %pragma facility or directive", false},
H. Peter Anvinb2047cb2017-03-08 01:26:40 -080069 {"not-my-pragma", "%pragma not applicable to this compilation", false},
70 {"unknown-warning", "unknown warning in -W/-w or warning directive", false},
H. Peter Anvin987dc9c2018-06-12 13:50:37 -070071 {"negative-rep", "regative %rep count", true},
H. Peter Anvin (Intel)b45c03a2018-06-27 21:03:38 -070072 {"phase", "phase error during stabilization", false},
H. Peter Anvinb2047cb2017-03-08 01:26:40 -080073
74 /* THIS ENTRY MUST COME LAST */
75 {"all", "all possible warnings", false}
H. Peter Anvinb20bc732017-03-07 19:23:03 -080076};
H. Peter Anvinb2047cb2017-03-08 01:26:40 -080077
78uint8_t warning_state[ERR_WARN_ALL];/* Current state */
79uint8_t warning_state_init[ERR_WARN_ALL]; /* Command-line state, for reset */
H. Peter Anvin22538e22016-05-25 05:42:47 -070080
81vefunc nasm_verror; /* Global error handling function */
82
83void nasm_error(int severity, const char *fmt, ...)
84{
85 va_list ap;
86
87 va_start(ap, fmt);
88 nasm_verror(severity, fmt, ap);
89 va_end(ap);
90}
91
H. Peter Anvinc5136902018-06-15 18:20:17 -070092fatal_func nasm_fatal(const char *fmt, ...)
93{
94 va_list ap;
95
96 va_start(ap, fmt);
97 nasm_verror(ERR_FATAL, fmt, ap);
98 abort(); /* We should never get here */
99}
100
101fatal_func nasm_fatal_fl(int flags, const char *fmt, ...)
H. Peter Anvin22538e22016-05-25 05:42:47 -0700102{
103 va_list ap;
104
105 va_start(ap, fmt);
106 nasm_verror(flags | ERR_FATAL, fmt, ap);
107 abort(); /* We should never get here */
108}
109
H. Peter Anvinc5136902018-06-15 18:20:17 -0700110fatal_func nasm_panic(const char *fmt, ...)
111{
112 va_list ap;
113
114 va_start(ap, fmt);
115 nasm_verror(ERR_PANIC, fmt, ap);
116 abort(); /* We should never get here */
117}
118
119fatal_func nasm_panic_fl(int flags, const char *fmt, ...)
H. Peter Anvin22538e22016-05-25 05:42:47 -0700120{
121 va_list ap;
122
123 va_start(ap, fmt);
124 nasm_verror(flags | ERR_PANIC, fmt, ap);
125 abort(); /* We should never get here */
126}
127
H. Peter Anvin6686fc62018-02-22 14:52:50 -0800128fatal_func nasm_panic_from_macro(const char *file, int line)
H. Peter Anvin22538e22016-05-25 05:42:47 -0700129{
H. Peter Anvinc5136902018-06-15 18:20:17 -0700130 nasm_panic("internal error at %s:%d\n", file, line);
H. Peter Anvin22538e22016-05-25 05:42:47 -0700131}
132
H. Peter Anvin6686fc62018-02-22 14:52:50 -0800133fatal_func nasm_assert_failed(const char *file, int line, const char *msg)
H. Peter Anvin22538e22016-05-25 05:42:47 -0700134{
H. Peter Anvinc5136902018-06-15 18:20:17 -0700135 nasm_panic("assertion %s failed at %s:%d", msg, file, line);
H. Peter Anvinb2047cb2017-03-08 01:26:40 -0800136}
137
138/*
139 * This is called when processing a -w or -W option, or a warning directive.
140 * Returns true if if the action was successful.
141 */
142bool set_warning_status(const char *value)
143{
144 enum warn_action { WID_OFF, WID_ON, WID_RESET };
145 enum warn_action action;
146 uint8_t mask;
147 int i;
148 bool ok = false;
149
150 value = nasm_skip_spaces(value);
151 switch (*value) {
152 case '-':
153 action = WID_OFF;
154 value++;
155 break;
156 case '+':
157 action = WID_ON;
158 value++;
159 break;
160 case '*':
161 action = WID_RESET;
162 value++;
163 break;
164 case 'N':
165 case 'n':
166 if (!nasm_strnicmp(value, "no-", 3)) {
167 action = WID_OFF;
168 value += 3;
169 break;
170 } else if (!nasm_stricmp(value, "none")) {
171 action = WID_OFF;
172 value = NULL;
173 break;
174 }
175 /* else fall through */
176 default:
177 action = WID_ON;
178 break;
179 }
180
181 mask = WARN_ST_ENABLED;
182
183 if (value && !nasm_strnicmp(value, "error", 5)) {
184 switch (value[5]) {
185 case '=':
186 mask = WARN_ST_ERROR;
187 value += 6;
188 break;
189 case '\0':
190 mask = WARN_ST_ERROR;
191 value = NULL;
192 break;
193 default:
194 /* Just an accidental prefix? */
195 break;
196 }
197 }
198
199 if (value && !nasm_stricmp(value, "all"))
200 value = NULL;
201
202 /* This is inefficient, but it shouldn't matter... */
203 for (i = 0; i < ERR_WARN_ALL; i++) {
204 if (!value || !nasm_stricmp(value, warnings[i].name)) {
205 ok = true; /* At least one action taken */
206 switch (action) {
207 case WID_OFF:
208 warning_state[i] &= ~mask;
209 break;
210 case WID_ON:
211 warning_state[i] |= mask;
212 break;
213 case WID_RESET:
214 warning_state[i] &= ~mask;
215 warning_state[i] |= warning_state_init[i] & mask;
216 break;
217 }
218 }
219 }
220
221 return ok;
H. Peter Anvin22538e22016-05-25 05:42:47 -0700222}