H. Peter Anvin | 22538e2 | 2016-05-25 05:42:47 -0700 | [diff] [blame] | 1 | /* ----------------------------------------------------------------------- * |
| 2 | * |
H. Peter Anvin | b20bc73 | 2017-03-07 19:23:03 -0800 | [diff] [blame] | 3 | * Copyright 1996-2017 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. |
| 17 | * |
| 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 |
| 47 | * the [warning] directive. Entry zero isn't an actual warning, but |
| 48 | * it used for -w+error/-Werror. |
| 49 | */ |
| 50 | const struct warning warnings[ERR_WARN_MAX+1] = { |
| 51 | {"error", "treat warnings as errors", false}, |
| 52 | {"macro-params", "macro calls with wrong parameter count", true}, |
| 53 | {"macro-selfref", "cyclic macro references", false}, |
| 54 | {"macro-defaults", "macros with more default than optional parameters", true}, |
| 55 | {"orphan-labels", "labels alone on lines without trailing `:'", true}, |
| 56 | {"number-overflow", "numeric constant does not fit", true}, |
| 57 | {"gnu-elf-extensions", "using 8- or 16-bit relocation in ELF32, a GNU extension", false}, |
| 58 | {"float-overflow", "floating point overflow", true}, |
| 59 | {"float-denorm", "floating point denormal", false}, |
| 60 | {"float-underflow", "floating point underflow", false}, |
| 61 | {"float-toolong", "too many digits in floating-point number", true}, |
| 62 | {"user", "%warning directives", true}, |
| 63 | {"lock", "lock prefix on unlockable instructions", true}, |
| 64 | {"hle", "invalid hle prefixes", true}, |
| 65 | {"bnd", "invalid bnd prefixes", true}, |
| 66 | {"zext-reloc", "relocation zero-extended to match output format", true}, |
| 67 | {"ptr", "non-NASM keyword used in other assemblers", true}, |
H. Peter Anvin | a6e26d9 | 2017-03-07 21:32:37 -0800 | [diff] [blame^] | 68 | {"bad-pragma", "empty or malformed %pragma", false}, |
| 69 | {"unknown-pragma", "unknown %pragma facility or directive", false}, |
| 70 | {"not-my-pragma", "%pragma not applicable to this compilation", false} |
H. Peter Anvin | b20bc73 | 2017-03-07 19:23:03 -0800 | [diff] [blame] | 71 | }; |
| 72 | bool warning_on[ERR_WARN_MAX+1]; /* Current state */ |
| 73 | bool warning_on_global[ERR_WARN_MAX+1]; /* Command-line state, for reset */ |
H. Peter Anvin | 22538e2 | 2016-05-25 05:42:47 -0700 | [diff] [blame] | 74 | |
| 75 | vefunc nasm_verror; /* Global error handling function */ |
| 76 | |
| 77 | void nasm_error(int severity, const char *fmt, ...) |
| 78 | { |
| 79 | va_list ap; |
| 80 | |
| 81 | va_start(ap, fmt); |
| 82 | nasm_verror(severity, fmt, ap); |
| 83 | va_end(ap); |
| 84 | } |
| 85 | |
| 86 | no_return nasm_fatal(int flags, const char *fmt, ...) |
| 87 | { |
| 88 | va_list ap; |
| 89 | |
| 90 | va_start(ap, fmt); |
| 91 | nasm_verror(flags | ERR_FATAL, fmt, ap); |
| 92 | abort(); /* We should never get here */ |
| 93 | } |
| 94 | |
| 95 | no_return nasm_panic(int flags, const char *fmt, ...) |
| 96 | { |
| 97 | va_list ap; |
| 98 | |
| 99 | va_start(ap, fmt); |
| 100 | nasm_verror(flags | ERR_PANIC, fmt, ap); |
| 101 | abort(); /* We should never get here */ |
| 102 | } |
| 103 | |
| 104 | no_return nasm_panic_from_macro(const char *file, int line) |
| 105 | { |
| 106 | nasm_panic(ERR_NOFILE, "Internal error at %s:%d\n", file, line); |
| 107 | } |
| 108 | |
| 109 | no_return nasm_assert_failed(const char *file, int line, const char *msg) |
| 110 | { |
| 111 | nasm_fatal(0, "assertion %s failed at %s:%d", msg, file, line); |
| 112 | } |