Skip to content

Commit a8bcdb6

Browse files
author
H. Peter Anvin
committed
Warnings: disaggregate from source and tidy up documentation
The idea of putting the warnings in the source code was a nice one, really, but it ended up being a nightmare from the perspective of build dependencies. Disaggregate them, and tweak the documentation for easier reading. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
1 parent bb3a51e commit a8bcdb6

File tree

14 files changed

+525
-602
lines changed

14 files changed

+525
-602
lines changed

Makefile.in

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -416,37 +416,19 @@ editors: $(EDITORS)
416416
WARNTIMES = $(WARNFILES:=.time)
417417

418418
.PHONY: warnings
419-
warnings:
420-
$(RM_F) $(WARNFILES) $(WARNTIMES) asm/warnings.time
421-
$(MAKE) asm/warnings.time
419+
warnings: $(WARNFILES)
422420

423-
asm/warnings.time: $(WARNSRCS) asm/warnings.pl
424-
$(EMPTY) asm/warnings.time
425-
$(MAKE) $(WARNTIMES)
426-
427-
asm/warnings_c.h.time: asm/warnings.pl asm/warnings.time
421+
asm/warnings_c.h: asm/warnings.pl asm/warnings.dat
428422
$(RUNPERL) $(srcdir)/asm/warnings.pl c asm/warnings_c.h \
429-
$(srcdir) $(WARNSRCS)
430-
$(EMPTY) asm/warnings_c.h.time
431-
432-
asm/warnings_c.h: asm/warnings_c.h.time
433-
$(SIDE)
423+
$(srcdir)/asm/warnings.dat
434424

435-
include/warnings.h.time: asm/warnings.pl asm/warnings.time
425+
include/warnings.h: asm/warnings.pl asm/warnings.dat
436426
$(RUNPERL) $(srcdir)/asm/warnings.pl h include/warnings.h \
437-
$(srcdir) $(WARNSRCS)
438-
$(EMPTY) include/warnings.h.time
427+
$(srcdir)/asm/warnings.dat
439428

440-
include/warnings.h: include/warnings.h.time
441-
$(SIDE)
442-
443-
doc/warnings.src.time: asm/warnings.pl asm/warnings.time
429+
doc/warnings.src: asm/warnings.pl asm/warnings.dat
444430
$(RUNPERL) $(srcdir)/asm/warnings.pl doc doc/warnings.src \
445-
$(srcdir) $(WARNSRCS)
446-
$(EMPTY) doc/warnings.src.time
447-
448-
doc/warnings.src : doc/warnings.src.time
449-
$(SIDE)
431+
$(srcdir)/asm/warnings.dat
450432

451433
$(PERLREQ): $(DIRS)
452434

asm/assemble.c

Lines changed: 2 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,6 @@ static void debug_macro_out(const struct out_data *data)
249249
* generator at the same time, flatten unnecessary relocations,
250250
* and verify backend compatibility.
251251
*/
252-
/*
253-
* This warning is currently issued by backends, but in the future
254-
* this code should be centralized.
255-
*
256-
*!zeroing [on] \c{RES}\e{x} in initialized section becomes zero
257-
*! a \c{RES}\e{x} directive was used in a section which contains
258-
*! initialized data, and the output format does not support
259-
*! this. Instead, this will be replaced with explicit zero
260-
*! content, which may produce a large output file.
261-
*/
262-
263252
/*
264253
* Add the entries in struct out_data for the rather bizarre legacy
265254
* backend interface, and then submit to the backend.
@@ -400,78 +389,6 @@ static void out(struct out_data *data)
400389
asize = amax = 0; /* No longer an address */
401390
}
402391
} else {
403-
/*!
404-
*!reloc-abs-byte [off] 8-bit absolute section-crossing relocation
405-
*! warns that an 8-bit absolute relocation that could
406-
*! not be resolved at assembly time was generated in
407-
*! the output format.
408-
*!
409-
*! This is usually normal, but may not be handled by all
410-
*! possible target environments
411-
*/
412-
/*!
413-
*!reloc-abs-word [off] 16-bit absolute section-crossing relocation
414-
*! warns that a 16-bit absolute relocation that could
415-
*! not be resolved at assembly time was generated in
416-
*! the output format.
417-
*!
418-
*! This is usually normal, but may not be handled by all
419-
*! possible target environments
420-
*/
421-
/*!
422-
*!reloc-abs-dword [off] 32-bit absolute section-crossing relocation
423-
*! warns that a 32-bit absolute relocation that could
424-
*! not be resolved at assembly time was generated in
425-
*! the output format.
426-
*!
427-
*! This is usually normal, but may not be handled by all
428-
*! possible target environments
429-
*/
430-
/*!
431-
*!reloc-abs-qword [off] 64-bit absolute section-crossing relocation
432-
*! warns that a 64-bit absolute relocation that could
433-
*! not be resolved at assembly time was generated in
434-
*! the output format.
435-
*!
436-
*! This is usually normal, but may not be handled by all
437-
*! possible target environments
438-
*/
439-
/*!
440-
*!reloc-rel-byte [off] 8-bit relative section-crossing relocation
441-
*! warns that an 8-bit relative relocation that could
442-
*! not be resolved at assembly time was generated in
443-
*! the output format.
444-
*!
445-
*! This is usually normal, but may not be handled by all
446-
*! possible target environments
447-
*/
448-
/*!
449-
*!reloc-rel-word [off] 16-bit relative section-crossing relocation
450-
*! warns that a 16-bit relative relocation that could
451-
*! not be resolved at assembly time was generated in
452-
*! the output format.
453-
*!
454-
*! This is usually normal, but may not be handled by all
455-
*! possible target environments
456-
*/
457-
/*!
458-
*!reloc-rel-dword [off] 32-bit relative section-crossing relocation
459-
*! warns that a 32-bit relative relocation that could
460-
*! not be resolved at assembly time was generated in
461-
*! the output format.
462-
*!
463-
*! This is usually normal, but may not be handled by all
464-
*! possible target environments
465-
*/
466-
/*!
467-
*!reloc-rel-qword [off] 64-bit relative section-crossing relocation
468-
*! warns that an 64-bit relative relocation that could
469-
*! not be resolved at assembly time was generated in
470-
*! the output format.
471-
*!
472-
*! This is usually normal, but may not be handled by all
473-
*! possible target environments
474-
*/
475392
int warn;
476393
const char *type;
477394

@@ -538,11 +455,6 @@ static void out(struct out_data *data)
538455
nasm_nonfatal("%u-bit signed relocation unsupported by output format %s",
539456
(unsigned int)(asize << 3), ofmt->shortname);
540457
} else {
541-
/*!
542-
*!zext-reloc [on] relocation zero-extended to match output format
543-
*! warns that a relocation has been zero-extended due
544-
*! to limitations in the output format.
545-
*/
546458
nasm_warn(WARN_ZEXT_RELOC,
547459
"%u-bit %s relocation zero-extended from %u bits",
548460
(unsigned int)(asize << 3),
@@ -1050,27 +962,9 @@ static int64_t assemble(insn *instruction)
1050962
* warning classes for "obsolete but valid for this
1051963
* specific CPU" and "obsolete and gone."
1052964
*
1053-
*!obsolete-removed [on] instruction obsolete and removed on the target CPU
1054-
*! warns for an instruction which has been removed
1055-
*! from the architecture, and is no longer included
1056-
*! in the CPU definition given in the \c{[CPU]}
1057-
*! directive, for example \c{POP CS}, the opcode for
1058-
*! which, \c{0Fh}, instead is an opcode prefix on
1059-
*! CPUs newer than the first generation 8086.
1060-
*
1061-
*!obsolete-nop [on] instruction obsolete and is a noop on the target CPU
1062-
*! warns for an instruction which has been removed
1063-
*! from the architecture, but has been architecturally
1064-
*! defined to be a noop for future CPUs.
1065-
*
1066-
*!obsolete-valid [on] instruction obsolete but valid on the target CPU
1067-
*! warns for an instruction which has been removed
1068-
*! from the architecture, but is still valid on the
1069-
*! specific CPU given in the \c{CPU} directive. Code
1070-
*! using these instructions is most likely not
1071-
*! forward compatible.
965+
* This currently doesn't really happen correctly;
966+
* it requires better information in insns.dat.
1072967
*/
1073-
1074968
whathappened = never ? "never implemented" : "obsolete";
1075969

1076970
if (!never && !iflag_cmp_cpu_level(&insns_flags[temp->iflag_idx], &cpu)) {
@@ -1417,12 +1311,6 @@ static void bad_hle_warn(const insn * ins, uint8_t hleok)
14171311
if (!is_class(MEMORY, ins->oprs[0].type))
14181312
ww = w_inval; /* HLE requires operand 0 to be memory */
14191313

1420-
/*!
1421-
*!prefix-hle [on] invalid HLE prefix
1422-
*!=hle
1423-
*! warns about invalid use of the HLE \c{XACQUIRE} or \c{XRELEASE}
1424-
*! prefixes.
1425-
*/
14261314
switch (ww) {
14271315
case w_none:
14281316
break;
@@ -1723,11 +1611,6 @@ static int64_t calcsize(insn *ins, const struct itemplate * const temp)
17231611
case 0320:
17241612
is_o16:
17251613
{
1726-
/*!prefix-opsize [on] invalid operand size prefix
1727-
*! warns that an operand prefix (\c{o16}, \c{o32}, \c{o64},
1728-
*! \c{osp}) invalid for the specified instruction has been specified.
1729-
*! The operand prefix will be ignored by the assembler.
1730-
*/
17311614
enum prefixes pfx = ins->prefixes[PPS_OSIZE];
17321615
ins->op_size = 16;
17331616
if (bits != 16 && pfx == P_OSP) {
@@ -1861,17 +1744,6 @@ static int64_t calcsize(insn *ins, const struct itemplate * const temp)
18611744
break;
18621745

18631746
case 0340:
1864-
/*!
1865-
*!forward [on] forward reference may have unpredictable results
1866-
*! warns that a forward reference is used which may have
1867-
*! unpredictable results, notably in a \c{RESB}-type
1868-
*! pseudo-instruction. These would be \i\e{critical
1869-
*! expressions} (see \k{crit}) but are permitted in a
1870-
*! handful of cases for compatibility with older
1871-
*! versions of NASM. This warning should be treated as a
1872-
*! severe programming error as the code could break at
1873-
*! any time for any number of reasons.
1874-
*/
18751747
/* The bytecode ends in 0, so opx points to operand 0 */
18761748
if (!absolute_op(opx)) {
18771749
nasm_nonfatal("attempt to reserve non-constant"
@@ -1960,16 +1832,6 @@ static int64_t calcsize(insn *ins, const struct itemplate * const temp)
19601832
if (ins->prefixes[PPS_REP] == P_BND) {
19611833
/* jmp short (opcode eb) cannot be used with bnd prefix. */
19621834
ins->prefixes[PPS_REP] = P_none;
1963-
/*!
1964-
*!prefix-bnd [on] invalid \c{BND} prefix
1965-
*!=bnd
1966-
*! warns about ineffective use of the \c{BND} prefix when the
1967-
*! \c{JMP} instruction is converted to the \c{SHORT} form.
1968-
*! This should be extremely rare since the short \c{JMP} only
1969-
*! is applicable to jumps inside the same module, but if
1970-
*! it is legitimate, it may be necessary to use
1971-
*! \c{bnd jmp dword}.
1972-
*/
19731835
if (!ins->dummy)
19741836
nasm_warn(WARN_PREFIX_BND,
19751837
"jmp short does not init bnd regs - bnd prefix dropped");
@@ -2196,21 +2058,8 @@ static int64_t calcsize(insn *ins, const struct itemplate * const temp)
21962058
if (lockcheck && has_prefix(ins, PPS_LOCK, P_LOCK)) {
21972059
if ((!itemp_has(temp,IF_LOCK) || !is_class(MEMORY, ins->oprs[0].type)) &&
21982060
(!itemp_has(temp,IF_LOCK1) || !is_class(MEMORY, ins->oprs[1].type))) {
2199-
/*!
2200-
*!prefix-lock-error [on] \c{LOCK} prefix on unlockable instruction
2201-
*!=lock
2202-
*! warns about \c{LOCK} prefixes on unlockable instructions.
2203-
*/
22042061
nasm_warn(WARN_PREFIX_LOCK_ERROR, "instruction is not lockable");
22052062
} else if (temp->opcode == I_XCHG) {
2206-
/*!
2207-
*!prefix-lock-xchg [on] superfluous \c{LOCK} prefix on \c{XCHG} instruction
2208-
*! warns about a \c{LOCK} prefix added to an \c{XCHG} instruction.
2209-
*! The \c{XCHG} instruction is \e{always} locking, and so this
2210-
*! prefix is not necessary; however, NASM will generate it if
2211-
*! explicitly provided by the user, so this warning indicates that
2212-
*! suboptimal code is being generated.
2213-
*/
22142063
nasm_warn(WARN_PREFIX_LOCK_XCHG,
22152064
"superfluous LOCK prefix on XCHG instruction");
22162065
}
@@ -2232,17 +2081,6 @@ static int64_t calcsize(insn *ins, const struct itemplate * const temp)
22322081
*/
22332082
if (ins->prefixes[PPS_SEG] == P_PT || ins->prefixes[PPS_SEG] == P_PN) {
22342083
if (!itemp_has(temp, IF_JCC_HINT)) {
2235-
/*!
2236-
*!prefix-hint-dropped [on] invalid branch hint prefix dropped
2237-
*! warns that the \c{{PT}} (predict taken) or \c{{PN}}
2238-
*! (predict not taken) branch prediction hint prefixes
2239-
*! are specified on an instruction that does not take
2240-
*! these prefixes. As these prefixes alias the segment
2241-
*! override prefixes, this may be a very serious error,
2242-
*! and therefore NASM will not generate these prefixes.
2243-
*! To force these prefixes to be emitted, use \c{DS} or
2244-
*! \c{CS}, instead, respectively.
2245-
*/
22462084
nasm_warn(WARN_PREFIX_HINT_DROPPED,
22472085
"invalid branch hint prefix dropped");
22482086
ins->prefixes[PPS_SEG] = 0;
@@ -2428,13 +2266,6 @@ static int emit_prefixes(struct out_data *data, const insn *ins)
24282266
c = r;
24292267
break;
24302268
default:
2431-
/*!
2432-
*!prefix-invalid [on] invalid prefix for instruction
2433-
*! this instruction is only valid with certain combinations
2434-
*! of prefixes. The prefix will still be generated as
2435-
*! requested, but the result may be a completely different
2436-
*! instruction.
2437-
*/
24382269
if (do_warn)
24392270
nasm_warn(WARN_PREFIX_INVALID,
24402271
"invalid prefix %s for instruction, result may be unexpected",
@@ -2453,12 +2284,6 @@ static int emit_prefixes(struct out_data *data, const insn *ins)
24532284
/* fall through */
24542285
case R_ES:
24552286
case R_SS:
2456-
/*!
2457-
*!prefix-seg [on] segment prefix ignored in 64-bit mode
2458-
*! warns that an \c{es}, \c{cs}, \c{ss} or \c{ds} segment override
2459-
*! prefix has no effect in 64-bit mode. The prefix will still be
2460-
*! generated as requested.
2461-
*/
24622287
if (do_warn && bits == 64) {
24632288
nasm_warn(WARN_PREFIX_SEG,
24642289
"%s segment override will be ignored in 64-bit mode",
@@ -3620,12 +3445,6 @@ static int process_ea(operand *input, int rfield, opflags_t rflags,
36203445
input->type |= IP_REL;
36213446
}
36223447
if ((input->type & IP_REL) == IP_REL) {
3623-
/*!
3624-
*!ea-absolute [on] absolute address cannot be RIP-relative
3625-
*! warns that an address that is inherently absolute cannot
3626-
*! be generated with RIP-relative encoding using \c{REL},
3627-
*! see \k{default-rel}.
3628-
*/
36293448
if (input->segment == NO_SEG ||
36303449
(input->opflags & OPFLAG_RELATIVE)) {
36313450
nasm_warn(WARN_EA_ABSOLUTE,
@@ -3644,12 +3463,6 @@ static int process_ea(operand *input, int rfield, opflags_t rflags,
36443463
if ((eaflags & EAF_BYTEOFFS) ||
36453464
((eaflags & EAF_WORDOFFS) &&
36463465
input->disp_size != (addrbits != 16 ? 32 : 16))) {
3647-
/*!
3648-
*!ea-dispsize [on] displacement size ignored on absolute address
3649-
*! warns that NASM does not support generating displacements for
3650-
*! inherently absolute addresses that do not match the address size
3651-
*! of the instruction.
3652-
*/
36533466
nasm_warn(WARN_EA_DISPSIZE, "displacement size ignored on absolute address");
36543467
}
36553468

asm/error.c

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -128,12 +128,6 @@ void pop_warnings(void)
128128

129129
memcpy(warning_state, ws->state, sizeof warning_state);
130130
if (!ws->next) {
131-
/*!
132-
*!warn-stack-empty [on] warning stack empty
133-
*! a \c{[WARNING POP]} directive was executed when
134-
*! the warning stack is empty. This is treated
135-
*! as a \c{[WARNING *all]} directive.
136-
*/
137131
nasm_warn(WARN_WARN_STACK_EMPTY, "warning stack empty");
138132
} else {
139133
warning_stack = ws->next;
@@ -168,15 +162,9 @@ void reset_warnings(void)
168162
* This is called when processing a -w or -W option, or a warning directive.
169163
* Returns ok if the action was successful.
170164
*
171-
* Special pseudo-warnings:
172-
*
173-
*!other [on] any warning not specifically mentioned above
174-
*! specifies any warning not included in any specific warning class.
175-
*
176-
*!all [all] all possible warnings
177-
*! is an group alias for \e{all} warning classes. Thus, \c{-w+all}
178-
*! enables all available warnings, and \c{-w-all} disables warnings
179-
*! entirely (since NASM 2.13).
165+
* Special pseudo-warnings (see warnings.dat):
166+
* all - all possible warnings
167+
* other - any warning not specifically assigned a class
180168
*/
181169
bool set_warning_status(const char *value)
182170
{
@@ -277,11 +265,6 @@ bool set_warning_status(const char *value)
277265
}
278266

279267
if (!ok && value) {
280-
/*!
281-
*!unknown-warning [off] unknown warning in \c{-W}/\c{-w} or warning directive
282-
*! warns about a \c{-w} or \c{-W} option or a \c{[WARNING]} directive
283-
*! that contains an unknown warning name or is otherwise not possible to process.
284-
*/
285268
nasm_warn(WARN_UNKNOWN_WARNING, "unknown warning name: %s", value);
286269
}
287270

0 commit comments

Comments
 (0)