asm: factor out more warnings into warning classes

Hopefully we'll eventually get rid of WARN_OTHER completely...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This commit is contained in:
H. Peter Anvin 2022-11-08 17:50:45 -08:00
parent 63049146f6
commit caffd140c0
7 changed files with 8092 additions and 8042 deletions

View File

@ -275,7 +275,7 @@ x86/regs.h: x86/regs.dat x86/regs.pl
WARNFILES = asm/warnings.c include/warnings.h doc/warnings.src
warnings:
$(RM_F) $(WARNFILES)
$(RM_F) $(WARNFILES) $(WARNFILES:=.time)
$(MAKE) asm/warnings.time
asm/warnings.time: $(ALLOBJ_NW:.$(O)=.c)

View File

@ -595,7 +595,8 @@ static bool jmp_match(int32_t segment, int64_t offset, int bits,
/* jmp short (opcode eb) cannot be used with bnd prefix. */
ins->prefixes[PPS_REP] = P_none;
/*!
*!bnd [on] invalid BND prefixes
*!prefix-bnd [on] invalid BND prefix
*!=bnd
*! warns about ineffective use of the \c{BND} prefix when the
*! \c{JMP} instruction is converted to the \c{SHORT} form.
*! This should be extremely rare since the short \c{JMP} only
@ -603,7 +604,7 @@ static bool jmp_match(int32_t segment, int64_t offset, int bits,
*! it is legitimate, it may be necessary to use
*! \c{bnd jmp dword}.
*/
nasm_warn(WARN_BND | ERR_PASS2 ,
nasm_warn(WARN_PREFIX_BND|ERR_PASS2 ,
"jmp short does not init bnd regs - bnd prefix dropped");
}
@ -1203,7 +1204,8 @@ static void bad_hle_warn(const insn * ins, uint8_t hleok)
ww = w_inval; /* HLE requires operand 0 to be memory */
/*!
*!hle [on] invalid HLE prefixes
*!prefix-hle [on] invalid HLE prefix
*!=hle
*! warns about invalid use of the HLE \c{XACQUIRE} or \c{XRELEASE}
*! prefixes.
*/
@ -1213,14 +1215,14 @@ static void bad_hle_warn(const insn * ins, uint8_t hleok)
case w_lock:
if (ins->prefixes[PPS_LOCK] != P_LOCK) {
nasm_warn(WARN_HLE | ERR_PASS2,
nasm_warn(WARN_PREFIX_HLE|ERR_PASS2,
"%s with this instruction requires lock",
prefix_name(rep_pfx));
}
break;
case w_inval:
nasm_warn(WARN_HLE | ERR_PASS2,
nasm_warn(WARN_PREFIX_HLE|ERR_PASS2,
"%s invalid with this instruction",
prefix_name(rep_pfx));
break;
@ -1423,11 +1425,17 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
case 0320:
{
/*! prefix-opsize [on] invalid operand size prefix
*! warns that an operand prefix (\c{o16}, \c{o32}, \c{o64},
*! \c{osp}) invalid for the specified instruction has been specified.
*! The operand prefix will be ignored by the assembler.
*/
enum prefixes pfx = ins->prefixes[PPS_OSIZE];
if (pfx == P_O16)
break;
if (pfx != P_none)
nasm_warn(WARN_OTHER|ERR_PASS2, "invalid operand size prefix");
nasm_warn(WARN_PREFIX_OPSIZE|ERR_PASS2,
"invalid operand size prefix, must be o16");
else
ins->prefixes[PPS_OSIZE] = P_O16;
break;
@ -1439,7 +1447,8 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
if (pfx == P_O32)
break;
if (pfx != P_none)
nasm_warn(WARN_OTHER|ERR_PASS2, "invalid operand size prefix");
nasm_warn(WARN_PREFIX_OPSIZE|ERR_PASS2,
"invalid operand size prefix, must be o32");
else
ins->prefixes[PPS_OSIZE] = P_O32;
break;
@ -1493,11 +1502,22 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
break;
case 0340:
/*!
*!forward [on] forward reference may have unpredictable results
*! warns that a forward reference is used which may have
*! unpredictable results, notably in a \c{RESB}-type
*! pseudo-instruction. These would be \i\e{critical
*! expressions} (see \k{crit}) but are permitted in a
*! handful of cases for compatibility with older
*! versions of NASM. This warning should be treated as a
*! severe programming error as the code could break at
*! any time for any number of reasons.
*/
if (!absolute_op(&ins->oprs[0]))
nasm_nonfatal("attempt to reserve non-constant"
" quantity of BSS space");
else if (ins->oprs[0].opflags & OPFLAG_FORWARD)
nasm_warn(WARN_OTHER, "forward reference in RESx "
nasm_warn(WARN_FORWARD, "forward reference in RESx "
"can have unpredictable results");
else
length += ins->oprs[0].offset * resb_bytes(ins->opcode);
@ -1723,10 +1743,11 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
if (has_prefix(ins, PPS_LOCK, P_LOCK) && lockcheck &&
(!itemp_has(temp,IF_LOCK) || !is_class(MEMORY, ins->oprs[0].type))) {
/*!
*!lock [on] LOCK prefix on unlockable instructions
*!prefix-lock [on] LOCK prefix on unlockable instructions
*!=lock
*! warns about \c{LOCK} prefixes on unlockable instructions.
*/
nasm_warn(WARN_LOCK | ERR_PASS2 , "instruction is not lockable");
nasm_warn(WARN_PREFIX_LOCK|ERR_PASS2 , "instruction is not lockable");
}
bad_hle_warn(ins, hleok);
@ -1788,20 +1809,26 @@ static int emit_prefix(struct out_data *data, const int bits, insn *ins)
c = 0xF3;
break;
case R_CS:
/*!
*!prefix-seg [on] segment prefix ignored in 64-bit mode
*! warns that an \c{es}, \c{cs}, \c{ss} or \c{ds} segment override
*! prefix has no effect in 64-bit mode. The prefix will still be
*! generated as requested.
*/
if (bits == 64)
nasm_warn(WARN_OTHER|ERR_PASS2, "cs segment base generated, "
nasm_warn(WARN_PREFIX_SEG|ERR_PASS2, "cs segment base generated, "
"but will be ignored in 64-bit mode");
c = 0x2E;
break;
case R_DS:
if (bits == 64)
nasm_warn(WARN_OTHER|ERR_PASS2, "ds segment base generated, "
nasm_warn(WARN_PREFIX_SEG|ERR_PASS2, "ds segment base generated, "
"but will be ignored in 64-bit mode");
c = 0x3E;
break;
case R_ES:
if (bits == 64)
nasm_warn(WARN_OTHER|ERR_PASS2, "es segment base generated, "
nasm_warn(WARN_PREFIX_SEG|ERR_PASS2, "es segment base generated, "
"but will be ignored in 64-bit mode");
c = 0x26;
break;
@ -1813,7 +1840,7 @@ static int emit_prefix(struct out_data *data, const int bits, insn *ins)
break;
case R_SS:
if (bits == 64) {
nasm_warn(WARN_OTHER|ERR_PASS2, "ss segment base generated, "
nasm_warn(WARN_PREFIX_SEG|ERR_PASS2, "ss segment base generated, "
"but will be ignored in 64-bit mode");
}
c = 0x36;
@ -2013,7 +2040,7 @@ static void gencode(struct out_data *data, insn *ins)
nasm_nonfatal("non-absolute expression not permitted "
"as argument %d", c & 7);
else if (opy->offset & ~mask)
nasm_warn(ERR_PASS2 | WARN_NUMBER_OVERFLOW,
nasm_warn(ERR_PASS2|WARN_NUMBER_OVERFLOW,
"is4 argument exceeds bounds");
c = opy->offset & mask;
goto emit_is4;
@ -2035,7 +2062,7 @@ static void gencode(struct out_data *data, insn *ins)
case4(0254):
if (absolute_op(opx) &&
(int32_t)opx->offset != (int64_t)opx->offset) {
nasm_warn(ERR_PASS2 | WARN_NUMBER_OVERFLOW,
nasm_warn(ERR_PASS2|WARN_NUMBER_OVERFLOW,
"signed dword immediate exceeds bounds");
}
out_imm(data, opx, 4, OUT_SIGNED);
@ -2105,7 +2132,7 @@ static void gencode(struct out_data *data, insn *ins)
/* If this wasn't explicitly byte-sized, warn as though we
* had fallen through to the imm16/32/64 case.
*/
nasm_warn(ERR_PASS2 | WARN_NUMBER_OVERFLOW,
nasm_warn(ERR_PASS2|WARN_NUMBER_OVERFLOW,
"%s value exceeds bounds",
(opx->type & BITS8) ? "signed byte" :
s == 16 ? "word" :
@ -2847,9 +2874,15 @@ static int process_ea(operand *input, ea *output, int bits,
input->type |= IP_REL;
}
if ((input->type & IP_REL) == IP_REL) {
/*!
*!ea-absolute [on] absolute address cannot be RIP-relative
*! warns that an address that is inherently absolute cannot
*! be generated with RIP-relative encoding using \c{REL},
*! see \k{REL & ABS}.
*/
if (input->segment == NO_SEG ||
(input->opflags & OPFLAG_RELATIVE)) {
nasm_warn(WARN_OTHER|ERR_PASS2,
nasm_warn(WARN_EA_ABSOLUTE|ERR_PASS2,
"absolute address can not be RIP-relative");
input->type &= ~IP_REL;
input->type |= MEMORY;
@ -2864,8 +2897,15 @@ static int process_ea(operand *input, ea *output, int bits,
if (eaflags & EAF_BYTEOFFS ||
(eaflags & EAF_WORDOFFS &&
input->disp_size != (addrbits != 16 ? 32 : 16)))
nasm_warn(WARN_OTHER, "displacement size ignored on absolute address");
input->disp_size != (addrbits != 16 ? 32 : 16))) {
/*!
*!ea-dispsize [on] displacement size ignored on absolute address
*! warns that NASM does not support generating displacements for
*! inherently absolute addresses that do not match the address size
*! of the instruction.
*/
nasm_warn(WARN_EA_DISPSIZE, "displacement size ignored on absolute address");
}
if ((eaflags & EAF_SIB) || (bits == 64 && (~input->type & IP_REL))) {
output->sib_present = true;

View File

@ -853,10 +853,6 @@ name, for example \c{label-orphan}; you can enable warnings of
this class by the command-line option \c{-w+label-orphan} and
disable it by \c{-w-label-orphan}.
The current \i{warning classes} are:
\& warnings.src
Since version 2.15, NASM has group aliases for all prefixed warnings,
so they can be used to enable or disable all warnings in the group.
For example, -w+float enables all warnings with names starting with float-*.
@ -877,6 +873,7 @@ of course.
In addition, you can control warnings in the source code itself, using
the \i\c{[WARNING]} directive. See \k{asmdir-warning}.
See \k{warnings} for the complete list of warning classes.
\S{opt-v} The \i\c{-v} Option: Display \i{Version} Info
@ -1353,8 +1350,13 @@ symbols.
BSS section of a module: they declare \e{uninitialized} storage
space. Each takes a single operand, which is the number of bytes,
words, doublewords or whatever to reserve. The operand to a
\c{RESB}-type pseudo-instruction is a \i\e{critical expression}: see
\k{crit}.
\c{RESB}-type pseudo-instruction \e{would} be a \i\e{critical
expression} (see \k{crit}), except that for legacy compatibility
reasons forward references are permitted, however \e{the code will be
extremely fragile and this should be considered a severe programming
error.} A warning will be issued; code generating this warning should
be remedied as quickly as possible (see the \c{forward} class in
\k{warnings}.)
For example:
@ -5306,7 +5308,7 @@ value can be saved away and invoked later to restore the setting.
\H{asmdir-warning} \i\c{[WARNING]}: Enable or disable warnings
The \c{[WARNING]} directive can be used to enable or disable classes
of warnings in the same way as the \c{-w} option, see \k{opt-w} for
of warnings in the same way as the \c{-w} option, see \k{warnings} for
more details about warning classes.
\b \c{[warning +}\e{warning-class}\c{]} enables warnings for
@ -5324,7 +5326,7 @@ more details about warning classes.
\b \c{[warning pop]} restores the current warning state from the stack.
The \c{[WARNING]} directive also accepts the \c{all}, \c{error} and
\c{error=}\e{warning-class} specifiers.
\c{error=}\e{warning-class} specifiers, see \k{opt-w}.
No "user form" (without the brackets) currently exists.
@ -8613,6 +8615,14 @@ in which \c{$} and \c{$$} are offsets from the same section base,
and so their difference is a pure number. This will solve the
problem and generate sensible code.
\A{warnings} \I{warning class}\I{warning classes, list}\i{List of Warning Classes}
These are the warning classes currently defined by NASM for the
purpose of enabling, disabling and promoting to error. See \k{opt-w}
and \k{asmdir-warning}.
\& warnings.src
\A{ndisasm} \i{Ndisasm}
The Netwide Disassembler, NDISASM

View File

@ -1,8 +1,8 @@
./travis/test/br2496848.asm:8: warning: numeric constant 0x1ffffffffffffffff does not fit in 64 bits [-w+number-overflow]
./travis/test/br2496848.asm:10: warning: displacement size ignored on absolute address [-w+other]
./travis/test/br2496848.asm:10: warning: displacement size ignored on absolute address [-w+other]
./travis/test/br2496848.asm:10: warning: displacement size ignored on absolute address [-w+ea-dispsize]
./travis/test/br2496848.asm:10: warning: displacement size ignored on absolute address [-w+ea-dispsize]
./travis/test/br2496848.asm:16: warning: dword data exceeds bounds [-w+number-overflow]
./travis/test/br2496848.asm:18: warning: absolute address can not be RIP-relative [-w+other]
./travis/test/br2496848.asm:18: warning: absolute address can not be RIP-relative [-w+ea-absolute]
./travis/test/br2496848.asm:22: warning: byte data exceeds bounds [-w+number-overflow]
./travis/test/br2496848.asm:22: warning: byte data exceeds bounds [-w+number-overflow]
./travis/test/br2496848.asm:23: warning: byte data exceeds bounds [-w+number-overflow]

View File

@ -1,4 +1,4 @@
./travis/test/hle.asm:5: warning: instruction is not lockable [-w+lock]
./travis/test/hle.asm:7: warning: xacquire invalid with this instruction [-w+hle]
./travis/test/hle.asm:13: warning: xacquire invalid with this instruction [-w+hle]
./travis/test/hle.asm:17: warning: xacquire invalid with this instruction [-w+hle]
./travis/test/hle.asm:5: warning: instruction is not lockable [-w+prefix-lock]
./travis/test/hle.asm:7: warning: xacquire invalid with this instruction [-w+prefix-hle]
./travis/test/hle.asm:13: warning: xacquire invalid with this instruction [-w+prefix-hle]
./travis/test/hle.asm:17: warning: xacquire invalid with this instruction [-w+prefix-hle]

View File

@ -1,6 +1,6 @@
./travis/test/prefix66.asm:4: warning: invalid operand size prefix [-w+other]
./travis/test/prefix66.asm:7: warning: invalid operand size prefix [-w+other]
./travis/test/prefix66.asm:13: warning: invalid operand size prefix [-w+other]
./travis/test/prefix66.asm:16: warning: invalid operand size prefix [-w+other]
./travis/test/prefix66.asm:22: warning: invalid operand size prefix [-w+other]
./travis/test/prefix66.asm:25: warning: invalid operand size prefix [-w+other]
./travis/test/prefix66.asm:4: warning: invalid operand size prefix, must be o16 [-w+prefix-opsize]
./travis/test/prefix66.asm:7: warning: invalid operand size prefix, must be o32 [-w+prefix-opsize]
./travis/test/prefix66.asm:13: warning: invalid operand size prefix, must be o16 [-w+prefix-opsize]
./travis/test/prefix66.asm:16: warning: invalid operand size prefix, must be o32 [-w+prefix-opsize]
./travis/test/prefix66.asm:22: warning: invalid operand size prefix, must be o16 [-w+prefix-opsize]
./travis/test/prefix66.asm:25: warning: invalid operand size prefix, must be o32 [-w+prefix-opsize]

File diff suppressed because it is too large Load Diff