Skip to content

Commit caffd14

Browse files
author
H. Peter Anvin
committed
asm: factor out more warnings into warning classes
Hopefully we'll eventually get rid of WARN_OTHER completely... Signed-off-by: H. Peter Anvin <[email protected]>
1 parent 6304914 commit caffd14

File tree

7 files changed

+8092
-8042
lines changed

7 files changed

+8092
-8042
lines changed

Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ x86/regs.h: x86/regs.dat x86/regs.pl
275275
WARNFILES = asm/warnings.c include/warnings.h doc/warnings.src
276276

277277
warnings:
278-
$(RM_F) $(WARNFILES)
278+
$(RM_F) $(WARNFILES) $(WARNFILES:=.time)
279279
$(MAKE) asm/warnings.time
280280

281281
asm/warnings.time: $(ALLOBJ_NW:.$(O)=.c)

asm/assemble.c

Lines changed: 60 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -595,15 +595,16 @@ static bool jmp_match(int32_t segment, int64_t offset, int bits,
595595
/* jmp short (opcode eb) cannot be used with bnd prefix. */
596596
ins->prefixes[PPS_REP] = P_none;
597597
/*!
598-
*!bnd [on] invalid BND prefixes
598+
*!prefix-bnd [on] invalid BND prefix
599+
*!=bnd
599600
*! warns about ineffective use of the \c{BND} prefix when the
600601
*! \c{JMP} instruction is converted to the \c{SHORT} form.
601602
*! This should be extremely rare since the short \c{JMP} only
602603
*! is applicable to jumps inside the same module, but if
603604
*! it is legitimate, it may be necessary to use
604605
*! \c{bnd jmp dword}.
605606
*/
606-
nasm_warn(WARN_BND | ERR_PASS2 ,
607+
nasm_warn(WARN_PREFIX_BND|ERR_PASS2 ,
607608
"jmp short does not init bnd regs - bnd prefix dropped");
608609
}
609610

@@ -1203,7 +1204,8 @@ static void bad_hle_warn(const insn * ins, uint8_t hleok)
12031204
ww = w_inval; /* HLE requires operand 0 to be memory */
12041205

12051206
/*!
1206-
*!hle [on] invalid HLE prefixes
1207+
*!prefix-hle [on] invalid HLE prefix
1208+
*!=hle
12071209
*! warns about invalid use of the HLE \c{XACQUIRE} or \c{XRELEASE}
12081210
*! prefixes.
12091211
*/
@@ -1213,14 +1215,14 @@ static void bad_hle_warn(const insn * ins, uint8_t hleok)
12131215

12141216
case w_lock:
12151217
if (ins->prefixes[PPS_LOCK] != P_LOCK) {
1216-
nasm_warn(WARN_HLE | ERR_PASS2,
1218+
nasm_warn(WARN_PREFIX_HLE|ERR_PASS2,
12171219
"%s with this instruction requires lock",
12181220
prefix_name(rep_pfx));
12191221
}
12201222
break;
12211223

12221224
case w_inval:
1223-
nasm_warn(WARN_HLE | ERR_PASS2,
1225+
nasm_warn(WARN_PREFIX_HLE|ERR_PASS2,
12241226
"%s invalid with this instruction",
12251227
prefix_name(rep_pfx));
12261228
break;
@@ -1423,11 +1425,17 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
14231425

14241426
case 0320:
14251427
{
1428+
/*! prefix-opsize [on] invalid operand size prefix
1429+
*! warns that an operand prefix (\c{o16}, \c{o32}, \c{o64},
1430+
*! \c{osp}) invalid for the specified instruction has been specified.
1431+
*! The operand prefix will be ignored by the assembler.
1432+
*/
14261433
enum prefixes pfx = ins->prefixes[PPS_OSIZE];
14271434
if (pfx == P_O16)
14281435
break;
14291436
if (pfx != P_none)
1430-
nasm_warn(WARN_OTHER|ERR_PASS2, "invalid operand size prefix");
1437+
nasm_warn(WARN_PREFIX_OPSIZE|ERR_PASS2,
1438+
"invalid operand size prefix, must be o16");
14311439
else
14321440
ins->prefixes[PPS_OSIZE] = P_O16;
14331441
break;
@@ -1439,7 +1447,8 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
14391447
if (pfx == P_O32)
14401448
break;
14411449
if (pfx != P_none)
1442-
nasm_warn(WARN_OTHER|ERR_PASS2, "invalid operand size prefix");
1450+
nasm_warn(WARN_PREFIX_OPSIZE|ERR_PASS2,
1451+
"invalid operand size prefix, must be o32");
14431452
else
14441453
ins->prefixes[PPS_OSIZE] = P_O32;
14451454
break;
@@ -1493,11 +1502,22 @@ static int64_t calcsize(int32_t segment, int64_t offset, int bits,
14931502
break;
14941503

14951504
case 0340:
1505+
/*!
1506+
*!forward [on] forward reference may have unpredictable results
1507+
*! warns that a forward reference is used which may have
1508+
*! unpredictable results, notably in a \c{RESB}-type
1509+
*! pseudo-instruction. These would be \i\e{critical
1510+
*! expressions} (see \k{crit}) but are permitted in a
1511+
*! handful of cases for compatibility with older
1512+
*! versions of NASM. This warning should be treated as a
1513+
*! severe programming error as the code could break at
1514+
*! any time for any number of reasons.
1515+
*/
14961516
if (!absolute_op(&ins->oprs[0]))
14971517
nasm_nonfatal("attempt to reserve non-constant"
14981518
" quantity of BSS space");
14991519
else if (ins->oprs[0].opflags & OPFLAG_FORWARD)
1500-
nasm_warn(WARN_OTHER, "forward reference in RESx "
1520+
nasm_warn(WARN_FORWARD, "forward reference in RESx "
15011521
"can have unpredictable results");
15021522
else
15031523
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,
17231743
if (has_prefix(ins, PPS_LOCK, P_LOCK) && lockcheck &&
17241744
(!itemp_has(temp,IF_LOCK) || !is_class(MEMORY, ins->oprs[0].type))) {
17251745
/*!
1726-
*!lock [on] LOCK prefix on unlockable instructions
1746+
*!prefix-lock [on] LOCK prefix on unlockable instructions
1747+
*!=lock
17271748
*! warns about \c{LOCK} prefixes on unlockable instructions.
17281749
*/
1729-
nasm_warn(WARN_LOCK | ERR_PASS2 , "instruction is not lockable");
1750+
nasm_warn(WARN_PREFIX_LOCK|ERR_PASS2 , "instruction is not lockable");
17301751
}
17311752

17321753
bad_hle_warn(ins, hleok);
@@ -1788,20 +1809,26 @@ static int emit_prefix(struct out_data *data, const int bits, insn *ins)
17881809
c = 0xF3;
17891810
break;
17901811
case R_CS:
1812+
/*!
1813+
*!prefix-seg [on] segment prefix ignored in 64-bit mode
1814+
*! warns that an \c{es}, \c{cs}, \c{ss} or \c{ds} segment override
1815+
*! prefix has no effect in 64-bit mode. The prefix will still be
1816+
*! generated as requested.
1817+
*/
17911818
if (bits == 64)
1792-
nasm_warn(WARN_OTHER|ERR_PASS2, "cs segment base generated, "
1819+
nasm_warn(WARN_PREFIX_SEG|ERR_PASS2, "cs segment base generated, "
17931820
"but will be ignored in 64-bit mode");
17941821
c = 0x2E;
17951822
break;
17961823
case R_DS:
17971824
if (bits == 64)
1798-
nasm_warn(WARN_OTHER|ERR_PASS2, "ds segment base generated, "
1825+
nasm_warn(WARN_PREFIX_SEG|ERR_PASS2, "ds segment base generated, "
17991826
"but will be ignored in 64-bit mode");
18001827
c = 0x3E;
18011828
break;
18021829
case R_ES:
18031830
if (bits == 64)
1804-
nasm_warn(WARN_OTHER|ERR_PASS2, "es segment base generated, "
1831+
nasm_warn(WARN_PREFIX_SEG|ERR_PASS2, "es segment base generated, "
18051832
"but will be ignored in 64-bit mode");
18061833
c = 0x26;
18071834
break;
@@ -1813,7 +1840,7 @@ static int emit_prefix(struct out_data *data, const int bits, insn *ins)
18131840
break;
18141841
case R_SS:
18151842
if (bits == 64) {
1816-
nasm_warn(WARN_OTHER|ERR_PASS2, "ss segment base generated, "
1843+
nasm_warn(WARN_PREFIX_SEG|ERR_PASS2, "ss segment base generated, "
18171844
"but will be ignored in 64-bit mode");
18181845
}
18191846
c = 0x36;
@@ -2013,7 +2040,7 @@ static void gencode(struct out_data *data, insn *ins)
20132040
nasm_nonfatal("non-absolute expression not permitted "
20142041
"as argument %d", c & 7);
20152042
else if (opy->offset & ~mask)
2016-
nasm_warn(ERR_PASS2 | WARN_NUMBER_OVERFLOW,
2043+
nasm_warn(ERR_PASS2|WARN_NUMBER_OVERFLOW,
20172044
"is4 argument exceeds bounds");
20182045
c = opy->offset & mask;
20192046
goto emit_is4;
@@ -2035,7 +2062,7 @@ static void gencode(struct out_data *data, insn *ins)
20352062
case4(0254):
20362063
if (absolute_op(opx) &&
20372064
(int32_t)opx->offset != (int64_t)opx->offset) {
2038-
nasm_warn(ERR_PASS2 | WARN_NUMBER_OVERFLOW,
2065+
nasm_warn(ERR_PASS2|WARN_NUMBER_OVERFLOW,
20392066
"signed dword immediate exceeds bounds");
20402067
}
20412068
out_imm(data, opx, 4, OUT_SIGNED);
@@ -2105,7 +2132,7 @@ static void gencode(struct out_data *data, insn *ins)
21052132
/* If this wasn't explicitly byte-sized, warn as though we
21062133
* had fallen through to the imm16/32/64 case.
21072134
*/
2108-
nasm_warn(ERR_PASS2 | WARN_NUMBER_OVERFLOW,
2135+
nasm_warn(ERR_PASS2|WARN_NUMBER_OVERFLOW,
21092136
"%s value exceeds bounds",
21102137
(opx->type & BITS8) ? "signed byte" :
21112138
s == 16 ? "word" :
@@ -2847,9 +2874,15 @@ static int process_ea(operand *input, ea *output, int bits,
28472874
input->type |= IP_REL;
28482875
}
28492876
if ((input->type & IP_REL) == IP_REL) {
2877+
/*!
2878+
*!ea-absolute [on] absolute address cannot be RIP-relative
2879+
*! warns that an address that is inherently absolute cannot
2880+
*! be generated with RIP-relative encoding using \c{REL},
2881+
*! see \k{REL & ABS}.
2882+
*/
28502883
if (input->segment == NO_SEG ||
28512884
(input->opflags & OPFLAG_RELATIVE)) {
2852-
nasm_warn(WARN_OTHER|ERR_PASS2,
2885+
nasm_warn(WARN_EA_ABSOLUTE|ERR_PASS2,
28532886
"absolute address can not be RIP-relative");
28542887
input->type &= ~IP_REL;
28552888
input->type |= MEMORY;
@@ -2864,8 +2897,15 @@ static int process_ea(operand *input, ea *output, int bits,
28642897

28652898
if (eaflags & EAF_BYTEOFFS ||
28662899
(eaflags & EAF_WORDOFFS &&
2867-
input->disp_size != (addrbits != 16 ? 32 : 16)))
2868-
nasm_warn(WARN_OTHER, "displacement size ignored on absolute address");
2900+
input->disp_size != (addrbits != 16 ? 32 : 16))) {
2901+
/*!
2902+
*!ea-dispsize [on] displacement size ignored on absolute address
2903+
*! warns that NASM does not support generating displacements for
2904+
*! inherently absolute addresses that do not match the address size
2905+
*! of the instruction.
2906+
*/
2907+
nasm_warn(WARN_EA_DISPSIZE, "displacement size ignored on absolute address");
2908+
}
28692909

28702910
if ((eaflags & EAF_SIB) || (bits == 64 && (~input->type & IP_REL))) {
28712911
output->sib_present = true;

doc/nasmdoc.src

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -853,10 +853,6 @@ name, for example \c{label-orphan}; you can enable warnings of
853853
this class by the command-line option \c{-w+label-orphan} and
854854
disable it by \c{-w-label-orphan}.
855855

856-
The current \i{warning classes} are:
857-
858-
\& warnings.src
859-
860856
Since version 2.15, NASM has group aliases for all prefixed warnings,
861857
so they can be used to enable or disable all warnings in the group.
862858
For example, -w+float enables all warnings with names starting with float-*.
@@ -877,6 +873,7 @@ of course.
877873
In addition, you can control warnings in the source code itself, using
878874
the \i\c{[WARNING]} directive. See \k{asmdir-warning}.
879875

876+
See \k{warnings} for the complete list of warning classes.
880877

881878
\S{opt-v} The \i\c{-v} Option: Display \i{Version} Info
882879

@@ -1353,8 +1350,13 @@ symbols.
13531350
BSS section of a module: they declare \e{uninitialized} storage
13541351
space. Each takes a single operand, which is the number of bytes,
13551352
words, doublewords or whatever to reserve. The operand to a
1356-
\c{RESB}-type pseudo-instruction is a \i\e{critical expression}: see
1357-
\k{crit}.
1353+
\c{RESB}-type pseudo-instruction \e{would} be a \i\e{critical
1354+
expression} (see \k{crit}), except that for legacy compatibility
1355+
reasons forward references are permitted, however \e{the code will be
1356+
extremely fragile and this should be considered a severe programming
1357+
error.} A warning will be issued; code generating this warning should
1358+
be remedied as quickly as possible (see the \c{forward} class in
1359+
\k{warnings}.)
13581360

13591361
For example:
13601362

@@ -5306,7 +5308,7 @@ value can be saved away and invoked later to restore the setting.
53065308
\H{asmdir-warning} \i\c{[WARNING]}: Enable or disable warnings
53075309

53085310
The \c{[WARNING]} directive can be used to enable or disable classes
5309-
of warnings in the same way as the \c{-w} option, see \k{opt-w} for
5311+
of warnings in the same way as the \c{-w} option, see \k{warnings} for
53105312
more details about warning classes.
53115313

53125314
\b \c{[warning +}\e{warning-class}\c{]} enables warnings for
@@ -5324,7 +5326,7 @@ more details about warning classes.
53245326
\b \c{[warning pop]} restores the current warning state from the stack.
53255327

53265328
The \c{[WARNING]} directive also accepts the \c{all}, \c{error} and
5327-
\c{error=}\e{warning-class} specifiers.
5329+
\c{error=}\e{warning-class} specifiers, see \k{opt-w}.
53285330

53295331
No "user form" (without the brackets) currently exists.
53305332

@@ -8613,6 +8615,14 @@ in which \c{$} and \c{$$} are offsets from the same section base,
86138615
and so their difference is a pure number. This will solve the
86148616
problem and generate sensible code.
86158617

8618+
\A{warnings} \I{warning class}\I{warning classes, list}\i{List of Warning Classes}
8619+
8620+
These are the warning classes currently defined by NASM for the
8621+
purpose of enabling, disabling and promoting to error. See \k{opt-w}
8622+
and \k{asmdir-warning}.
8623+
8624+
\& warnings.src
8625+
86168626
\A{ndisasm} \i{Ndisasm}
86178627

86188628
The Netwide Disassembler, NDISASM

travis/test/br2496848.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
./travis/test/br2496848.asm:8: warning: numeric constant 0x1ffffffffffffffff does not fit in 64 bits [-w+number-overflow]
2-
./travis/test/br2496848.asm:10: warning: displacement size ignored on absolute address [-w+other]
3-
./travis/test/br2496848.asm:10: warning: displacement size ignored on absolute address [-w+other]
2+
./travis/test/br2496848.asm:10: warning: displacement size ignored on absolute address [-w+ea-dispsize]
3+
./travis/test/br2496848.asm:10: warning: displacement size ignored on absolute address [-w+ea-dispsize]
44
./travis/test/br2496848.asm:16: warning: dword data exceeds bounds [-w+number-overflow]
5-
./travis/test/br2496848.asm:18: warning: absolute address can not be RIP-relative [-w+other]
5+
./travis/test/br2496848.asm:18: warning: absolute address can not be RIP-relative [-w+ea-absolute]
66
./travis/test/br2496848.asm:22: warning: byte data exceeds bounds [-w+number-overflow]
77
./travis/test/br2496848.asm:22: warning: byte data exceeds bounds [-w+number-overflow]
88
./travis/test/br2496848.asm:23: warning: byte data exceeds bounds [-w+number-overflow]

travis/test/hle.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
./travis/test/hle.asm:5: warning: instruction is not lockable [-w+lock]
2-
./travis/test/hle.asm:7: warning: xacquire invalid with this instruction [-w+hle]
3-
./travis/test/hle.asm:13: warning: xacquire invalid with this instruction [-w+hle]
4-
./travis/test/hle.asm:17: warning: xacquire invalid with this instruction [-w+hle]
1+
./travis/test/hle.asm:5: warning: instruction is not lockable [-w+prefix-lock]
2+
./travis/test/hle.asm:7: warning: xacquire invalid with this instruction [-w+prefix-hle]
3+
./travis/test/hle.asm:13: warning: xacquire invalid with this instruction [-w+prefix-hle]
4+
./travis/test/hle.asm:17: warning: xacquire invalid with this instruction [-w+prefix-hle]

travis/test/prefix66.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
./travis/test/prefix66.asm:4: warning: invalid operand size prefix [-w+other]
2-
./travis/test/prefix66.asm:7: warning: invalid operand size prefix [-w+other]
3-
./travis/test/prefix66.asm:13: warning: invalid operand size prefix [-w+other]
4-
./travis/test/prefix66.asm:16: warning: invalid operand size prefix [-w+other]
5-
./travis/test/prefix66.asm:22: warning: invalid operand size prefix [-w+other]
6-
./travis/test/prefix66.asm:25: warning: invalid operand size prefix [-w+other]
1+
./travis/test/prefix66.asm:4: warning: invalid operand size prefix, must be o16 [-w+prefix-opsize]
2+
./travis/test/prefix66.asm:7: warning: invalid operand size prefix, must be o32 [-w+prefix-opsize]
3+
./travis/test/prefix66.asm:13: warning: invalid operand size prefix, must be o16 [-w+prefix-opsize]
4+
./travis/test/prefix66.asm:16: warning: invalid operand size prefix, must be o32 [-w+prefix-opsize]
5+
./travis/test/prefix66.asm:22: warning: invalid operand size prefix, must be o16 [-w+prefix-opsize]
6+
./travis/test/prefix66.asm:25: warning: invalid operand size prefix, must be o32 [-w+prefix-opsize]

0 commit comments

Comments
 (0)