H. Peter Anvin | 22538e2 | 2016-05-25 05:42:47 -0700 | [diff] [blame] | 1 | /* ----------------------------------------------------------------------- * |
H. Peter Anvin | b2047cb | 2017-03-08 01:26:40 -0800 | [diff] [blame] | 2 | * |
H. Peter Anvin | 987dc9c | 2018-06-12 13:50:37 -0700 | [diff] [blame] | 3 | * Copyright 1996-2018 The NASM Authors - All Rights Reserved |
H. Peter Anvin | 22538e2 | 2016-05-25 05:42:47 -0700 | [diff] [blame] | 4 | * 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 Anvin | b2047cb | 2017-03-08 01:26:40 -0800 | [diff] [blame] | 17 | * |
H. Peter Anvin | 22538e2 | 2016-05-25 05:42:47 -0700 | [diff] [blame] | 18 | * 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 Anvin | b20bc73 | 2017-03-07 19:23:03 -0800 | [diff] [blame] | 35 | * error.c - error message handling routines for the assembler |
H. Peter Anvin | 22538e2 | 2016-05-25 05:42:47 -0700 | [diff] [blame] | 36 | */ |
| 37 | |
| 38 | #include "compiler.h" |
| 39 | |
| 40 | #include <stdlib.h> |
| 41 | |
| 42 | #include "nasmlib.h" |
H. Peter Anvin | b20bc73 | 2017-03-07 19:23:03 -0800 | [diff] [blame] | 43 | #include "error.h" |
| 44 | |
| 45 | /* |
| 46 | * Description of the suppressible warnings for the command line and |
H. Peter Anvin | b2047cb | 2017-03-08 01:26:40 -0800 | [diff] [blame] | 47 | * the [warning] directive. |
H. Peter Anvin | b20bc73 | 2017-03-07 19:23:03 -0800 | [diff] [blame] | 48 | */ |
H. Peter Anvin (Intel) | 77f53ba | 2018-12-12 14:38:50 -0800 | [diff] [blame] | 49 | const struct warning warnings[WARN_ALL+1] = { |
H. Peter Anvin (Intel) | 93367ea | 2018-12-12 15:58:32 -0800 | [diff] [blame^] | 50 | {NULL, NULL, true}, /* must be true - used for unconditional enable */ |
H. Peter Anvin | b20bc73 | 2017-03-07 19:23:03 -0800 | [diff] [blame] | 51 | {"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 Anvin | a6e26d9 | 2017-03-07 21:32:37 -0800 | [diff] [blame] | 67 | {"bad-pragma", "empty or malformed %pragma", false}, |
| 68 | {"unknown-pragma", "unknown %pragma facility or directive", false}, |
H. Peter Anvin | b2047cb | 2017-03-08 01:26:40 -0800 | [diff] [blame] | 69 | {"not-my-pragma", "%pragma not applicable to this compilation", false}, |
| 70 | {"unknown-warning", "unknown warning in -W/-w or warning directive", false}, |
H. Peter Anvin | 987dc9c | 2018-06-12 13:50:37 -0700 | [diff] [blame] | 71 | {"negative-rep", "regative %rep count", true}, |
H. Peter Anvin (Intel) | b45c03a | 2018-06-27 21:03:38 -0700 | [diff] [blame] | 72 | {"phase", "phase error during stabilization", false}, |
H. Peter Anvin | b2047cb | 2017-03-08 01:26:40 -0800 | [diff] [blame] | 73 | |
H. Peter Anvin (Intel) | 93367ea | 2018-12-12 15:58:32 -0800 | [diff] [blame^] | 74 | /* THESE ENTRIES SHOULD COME LAST */ |
| 75 | {"other", "any warning not specifially mentioned below", true}, |
H. Peter Anvin | b2047cb | 2017-03-08 01:26:40 -0800 | [diff] [blame] | 76 | {"all", "all possible warnings", false} |
H. Peter Anvin | b20bc73 | 2017-03-07 19:23:03 -0800 | [diff] [blame] | 77 | }; |
H. Peter Anvin | b2047cb | 2017-03-08 01:26:40 -0800 | [diff] [blame] | 78 | |
H. Peter Anvin (Intel) | 77f53ba | 2018-12-12 14:38:50 -0800 | [diff] [blame] | 79 | uint8_t warning_state[WARN_ALL];/* Current state */ |
| 80 | uint8_t warning_state_init[WARN_ALL]; /* Command-line state, for reset */ |
H. Peter Anvin | 22538e2 | 2016-05-25 05:42:47 -0700 | [diff] [blame] | 81 | |
| 82 | vefunc nasm_verror; /* Global error handling function */ |
| 83 | |
| 84 | void nasm_error(int severity, const char *fmt, ...) |
| 85 | { |
| 86 | va_list ap; |
| 87 | |
| 88 | va_start(ap, fmt); |
| 89 | nasm_verror(severity, fmt, ap); |
| 90 | va_end(ap); |
| 91 | } |
| 92 | |
H. Peter Anvin | 6686fc6 | 2018-02-22 14:52:50 -0800 | [diff] [blame] | 93 | fatal_func nasm_fatal(int flags, const char *fmt, ...) |
H. Peter Anvin | 22538e2 | 2016-05-25 05:42:47 -0700 | [diff] [blame] | 94 | { |
| 95 | va_list ap; |
| 96 | |
| 97 | va_start(ap, fmt); |
| 98 | nasm_verror(flags | ERR_FATAL, fmt, ap); |
| 99 | abort(); /* We should never get here */ |
| 100 | } |
| 101 | |
H. Peter Anvin | 6686fc6 | 2018-02-22 14:52:50 -0800 | [diff] [blame] | 102 | fatal_func nasm_panic(int flags, const char *fmt, ...) |
H. Peter Anvin | 22538e2 | 2016-05-25 05:42:47 -0700 | [diff] [blame] | 103 | { |
| 104 | va_list ap; |
| 105 | |
| 106 | va_start(ap, fmt); |
| 107 | nasm_verror(flags | ERR_PANIC, fmt, ap); |
| 108 | abort(); /* We should never get here */ |
| 109 | } |
| 110 | |
H. Peter Anvin | 6686fc6 | 2018-02-22 14:52:50 -0800 | [diff] [blame] | 111 | fatal_func nasm_panic_from_macro(const char *file, int line) |
H. Peter Anvin | 22538e2 | 2016-05-25 05:42:47 -0700 | [diff] [blame] | 112 | { |
| 113 | nasm_panic(ERR_NOFILE, "Internal error at %s:%d\n", file, line); |
| 114 | } |
| 115 | |
H. Peter Anvin | 6686fc6 | 2018-02-22 14:52:50 -0800 | [diff] [blame] | 116 | fatal_func nasm_assert_failed(const char *file, int line, const char *msg) |
H. Peter Anvin | 22538e2 | 2016-05-25 05:42:47 -0700 | [diff] [blame] | 117 | { |
H. Peter Anvin | b2047cb | 2017-03-08 01:26:40 -0800 | [diff] [blame] | 118 | nasm_panic(0, "assertion %s failed at %s:%d", msg, file, line); |
| 119 | } |
| 120 | |
| 121 | /* |
| 122 | * This is called when processing a -w or -W option, or a warning directive. |
| 123 | * Returns true if if the action was successful. |
| 124 | */ |
| 125 | bool set_warning_status(const char *value) |
| 126 | { |
| 127 | enum warn_action { WID_OFF, WID_ON, WID_RESET }; |
| 128 | enum warn_action action; |
| 129 | uint8_t mask; |
| 130 | int i; |
| 131 | bool ok = false; |
| 132 | |
| 133 | value = nasm_skip_spaces(value); |
| 134 | switch (*value) { |
| 135 | case '-': |
| 136 | action = WID_OFF; |
| 137 | value++; |
| 138 | break; |
| 139 | case '+': |
| 140 | action = WID_ON; |
| 141 | value++; |
| 142 | break; |
| 143 | case '*': |
| 144 | action = WID_RESET; |
| 145 | value++; |
| 146 | break; |
| 147 | case 'N': |
| 148 | case 'n': |
| 149 | if (!nasm_strnicmp(value, "no-", 3)) { |
| 150 | action = WID_OFF; |
| 151 | value += 3; |
| 152 | break; |
| 153 | } else if (!nasm_stricmp(value, "none")) { |
| 154 | action = WID_OFF; |
| 155 | value = NULL; |
| 156 | break; |
| 157 | } |
| 158 | /* else fall through */ |
| 159 | default: |
| 160 | action = WID_ON; |
| 161 | break; |
| 162 | } |
| 163 | |
| 164 | mask = WARN_ST_ENABLED; |
| 165 | |
| 166 | if (value && !nasm_strnicmp(value, "error", 5)) { |
| 167 | switch (value[5]) { |
| 168 | case '=': |
| 169 | mask = WARN_ST_ERROR; |
| 170 | value += 6; |
| 171 | break; |
| 172 | case '\0': |
| 173 | mask = WARN_ST_ERROR; |
| 174 | value = NULL; |
| 175 | break; |
| 176 | default: |
| 177 | /* Just an accidental prefix? */ |
| 178 | break; |
| 179 | } |
| 180 | } |
| 181 | |
| 182 | if (value && !nasm_stricmp(value, "all")) |
| 183 | value = NULL; |
| 184 | |
| 185 | /* This is inefficient, but it shouldn't matter... */ |
H. Peter Anvin (Intel) | 93367ea | 2018-12-12 15:58:32 -0800 | [diff] [blame^] | 186 | for (i = 1; i < WARN_ALL; i++) { |
H. Peter Anvin | b2047cb | 2017-03-08 01:26:40 -0800 | [diff] [blame] | 187 | if (!value || !nasm_stricmp(value, warnings[i].name)) { |
| 188 | ok = true; /* At least one action taken */ |
| 189 | switch (action) { |
| 190 | case WID_OFF: |
| 191 | warning_state[i] &= ~mask; |
| 192 | break; |
| 193 | case WID_ON: |
| 194 | warning_state[i] |= mask; |
| 195 | break; |
| 196 | case WID_RESET: |
| 197 | warning_state[i] &= ~mask; |
| 198 | warning_state[i] |= warning_state_init[i] & mask; |
| 199 | break; |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | return ok; |
H. Peter Anvin | 22538e2 | 2016-05-25 05:42:47 -0700 | [diff] [blame] | 205 | } |