Commit Graph

123 Commits

Author SHA1 Message Date
H. Peter Anvin (Intel)
41d91a9273 preproc: mmacro argument fixes; listing option for mmacro args
Correctly handle empty mmacro arguments that still have preceding
whitespace tokens.

Default mmacro parameters are obtained by count_mmac_params() so they,
too, need to be shifted over by one.

Add an option to list mmacro calls with arguments. Name this -Lm;
remove the old -Lm option to -Ls since it is related to single-line
macros.

Trivially optimize the case where an mmacro is called from within
itself: if all possible mmacros are excluded by loop removal, there is
no need to delve into the mmac processing code.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-20 16:03:46 -07:00
H. Peter Anvin (Intel)
b83621350c listing: add the -L+ option to enable all listing options
-L+ or %pragma list options ++ will enable all possible listing
 options.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-19 13:11:34 -07:00
H. Peter Anvin (Intel)
93d41d8296 BR 3392576: don't segfault on a bad %pragma limit
Don't segfault on a bad %pragma limit. Instead treat a NULL pointer as
an empty string.

Reported-by: Ren Kimura <rkx1209dev@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-16 01:12:54 -07:00
H. Peter Anvin (Intel)
9fbd9fb859 preproc: fix mmacro nesting prevention
BR 3392602: mmacros should not nest unless so explicitly specified.

Reported-by: C. Masloch <pushbx@38.de>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-15 19:26:52 -07:00
H. Peter Anvin
d91519a107 listing: encapsulate the list_options encoding, make more comprehensive
Encapsulate the list_options() encoding in an inline function. We only
ever compute a mask with a non-constant input in two places (command
line and pragma parsing), so a slightly more complex mapping is of no
consequence; thus map a-z, A-Z and 0-9 as being the most likely
characters we may want to use as options. Space is left for two more :)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 18:04:04 -07:00
H. Peter Anvin
59d4ccc2b0 Add %pragma list options
Add a %pragma to set (or clear) listing options. It only takes effect
on the next assembly pass, however!

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 06:45:12 -07:00
H. Peter Anvin
6686de2bab preproc: add listing options to override nolist; some cleanups
Add listing options:

    -Lb    to show builtin macro packages
    -Lf    to override .nolist

Do some cleanups in the process, in particular generalize read_line()
between stdmac and file alternatives.

When processing stdmac, create an istk entry for it. This means stdmac
can be identified by istk->fp == NULL. At some future date there could
even be a function pointer to an appropriate read function.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 05:33:14 -07:00
H. Peter Anvin
a2c1c7d0d4 listing: coalesce TIMES in non-final passes, print <len>, clarify hex
Merge TIMES in the nonfinal passes, there is no point in getting <len
...> an arbitrary number of times.

Actually print <len> (OUT_RAWDATA without a data pointer), not <res>
(OUT_RESERVE).

Dropping the zero-fill for the hex format made the listing more
manageable, but it also doesn't immediately look like hex, plus there
is now the -Ld option. Put an h after hex (shorter than leading 0x) to
make it obvious.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 02:45:41 -07:00
H. Peter Anvin
355bfb879d Stylistic improvements to help text
Trivial stylistic improvements to the help text.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 01:55:00 -07:00
H. Peter Anvin
322bee0aac Additional listing options, improve help output, fix macro limits
Additional listing options:

   -Ld to display counts in decimal
   -Lp to output a list file in every pass (to make sure one exists)

Clean up the help output and make it comprehensive. The -hf and -y
options are no longer necessary, although they are supported for
backwards compatiblity.

Fix macro-levels so it actually count descent levels; a new
macro-tokens limit introduced for the actual token limit.

Slightly simplify the limits code.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 01:46:58 -07:00
H. Peter Anvin (Intel)
5067fde483 asm/nasm.c: make --debug=level actually work
Turns out there was no support for optional arguments at all.
[
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-09 16:10:17 -07:00
H. Peter Anvin (Intel)
d6e817751e listing: add -L option for additional listing info
Add an -L option for additional listing information. Currently
supported is -Le, which emits each line after processing through the
preprocessor, and -Lm, which displays each single-line macro defined
or undefined.

NASM doesn't preserve the names of unused arguments, nor does it have
any technical reason to do so. Instead of adding complexity to save
them, make unnamed parameters official by specifying an empty string
in the argument list.

This has the additional advantage that () is now simply considered a
single empty argument, which means that NASM should now properly
handle things like:

%define myreg() eax
	mov edx,myreg()

... similar to how the C preprocessor allows an empty macro argument
list which is distinct from a macro with no arguments whatsoever.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-09 08:39:02 -07:00
H. Peter Anvin (Intel)
d66927a677 Diagnostics: make debug more dynamic, note -> info, add listmsg level
Make debug messages more dynamic by making it easy to conditionalize
the messages.

Change ERR_NOTE to ERR_INFO which reflects the usage better.  Other
compilers use note: for additional information.

Don't unwind the macro stack with ERR_HERE; it is only going to give
confusing results as it will unwind the wrong macro stack.

Add ERR_LISTMSG level which is *always* suppressed, but will still
appear in the list file.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-09 04:28:55 -07:00
H. Peter Anvin
0d4d431a01 Merge empty reservations from TIMES; add counts in listings
For constructs like TIMES xx RESB yy merge the TIMES and RESB and feed
a single reservation to the backend; this can (obviously) be
dramatically faster.

Add byte count in listings for <incbin> and repeat count to <rept>; to
make them more reasonable in length shorten to <bin ...> and <rep ...>
respectively, and don't require leading zeroes in bin/rep/res count.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-07 00:59:24 -07:00
H. Peter Anvin
fdeb3b0d01 Add group aliases for all prefixed warnings.
For example, -w+float will now enable all warnings with names staring
with float-*.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-06-06 20:53:17 -07:00
H. Peter Anvin (Intel)
1df7263ae9 warnings: add [warning push] and [warning pop]
Add [warning push] and [warning pop] directives.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-01-11 13:13:03 -08:00
H. Peter Anvin
8960e1bc83 Remove #includes already provided by "compiler.h"
"compiler.h" already includes a bunch of common include files. There
is absolutely no reason to duplicate them in individual files, and in
fact it robs us of central control of how these files are used.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-27 12:45:44 -08:00
H. Peter Anvin
bd2803964e Merge tag 'nasm-2.14.03rc1'
NASM 2.14.03rc1

Resolved Conflicts:
	asm/labels.c
	include/error.h

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-27 11:37:22 -08:00
H. Peter Anvin
4cf86ddde8 BR 3392539: some errors can "cascade". Allow suppressing if dead.
In BR 3392539, the error:

helloW.s:18: error: label `rurt' changed during code generation
[-w+error=label-redef-late]

... occurs a number of times after we have already issued an
error. This is because the erroring instruction computes to a
different size during code generation; this causes each subsequent
label to cause a phase error.

The phase error simply doesn't make much sense to report: if we are
already committed to erroring out, it is more likely an error cascade
rather than an error in its own right, so just suppress it in that
case.

Reported-by: <russvz@comcast.net>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-27 11:24:17 -08:00
H. Peter Anvin
2e53f27e9d Move <string.h> inclusion to compiler.h
There is absolutely no reason not to include <string.h> globally, and
with the inline function for mempcpy() we need it there anyway.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-26 06:32:37 -08:00
H. Peter Anvin
2965154684 assemble_file(): break up this gigantic mess
Break up this gigantic mess which touches way too many layers.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-18 19:14:40 -08:00
H. Peter Anvin (Intel)
5df6ca712d With buffered warnings, change the handling of error passes
With buffered warnings, most warnings *must* be issued on every pass,
so ERR_PASS1 is simply wrong in most cases.

ERR_PASS1 now means "force this warning to be output even in
pass_first(). This is to be used for the case where the warning is
only executed in pass_first() code; this is highly discouraged as it
means the warnings will not appear in the list file and subsequent
passes may make the warning suddenly vanish.

ERR_PASS2 just as before suppresses an error or warning unless we are
in pass_final().

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-18 12:25:11 -08:00
H. Peter Anvin (Intel)
e55d03dd47 Clean up the handling of various passes
The use of pass0, pass1, pass2, and "pass" passed as an argument is
really confusing and already caused a severe bug in the 2.14.01
release cycle. Clean them up and be far more explicit about what
various passes mean.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-18 11:14:59 -08:00
Cyrill Gorcunov
35d047632b nasm: Fix condition in skip_this_pass
We should not match both condition.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-16 01:21:13 +03:00
Cyrill Gorcunov
988cc1222c asm/nasm.c: Drop tabs
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-15 23:44:46 +03:00
H. Peter Anvin (Intel)
c3c6cea838 warnings: make WARN_* constant obligatory for warnings
Make it an error to have ERR_WARNING without a suppression level.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-14 13:44:35 -08:00
H. Peter Anvin (Intel)
80c4f23c52 nasm_warnf() -> nasm_warn()
We want to strongly encourage writers of warnings to create warning
categories, so remove the flagless nasm_warn() and change nasm_warnf()
to nasm_warn().

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-14 13:33:24 -08:00
H. Peter Anvin (Intel)
727c85263f Merge tag 'nasm-2.14.01rc5'
NASM 2.14.01rc5

Resolved Conflicts:
	asm/labels.c
	asm/nasm.c
	version
2018-12-14 13:24:19 -08:00
H. Peter Anvin (Intel)
1e2358b17f Document the -Ov option, minor fix for gcc -Og
The -Ov option is useful but was undocumented.

Add an initialization to keep gcc from complaining at optimization
level -Og.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-14 13:02:39 -08:00
H. Peter Anvin (Intel)
800c168688 --no-line: new option to ignore %line directives
For debugging preprocessed code, it is useful to be able to ignore
%line directives rather than having to filter them out externally.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-14 12:22:11 -08:00
H. Peter Anvin (Intel)
374312cde4 strlist, warnings: improve strlist, buffer warnings until error
Make strlist_free() take a pointer to a pointer, so we can set it to
NULL.

Buffer warnings on a strlist until we either get an error or we are in
pass 2. Hopefully this should let us get rid of a lot of the ERR_PASS*
bullshit, which far too often causes messages to get lost.

asm/labels.c contains one example of a warning that cannot be made
correct with a specific pass number.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-14 00:17:13 -08:00
H. Peter Anvin (Intel)
7bb13eac11 strlist: can be unique or not, add printf functions
Make it a selectable option at allocation time if a strlist should
contain only unique strings or not. If not, we omit the hash table and
strlist_find() will not do anything.

Add printf()-style functions to a strlist.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-13 22:48:14 -08:00
H. Peter Anvin (Intel)
723ab481a6 warnings: define warning classes at point of use
It is extremely desirable to allow the user fine-grained control of
warnings, but this has been complicated by the fact that a warning
class has had to be defined in no less than three places (error.h,
error.c, nasmdoc.src) before it can be used in source code. Instead,
use a script to define these via magic comments at the point of use.

This hopefully will encourage creating new classes as needed.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-13 21:53:31 -08:00
H. Peter Anvin (Intel)
190e846563 errors: correct message saying -w+error= ... is in use when it is not
Correct the test for when -w+error= is the correct thing to print.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-13 21:45:59 -08:00
H. Peter Anvin (Intel)
6bde2ed880 errors: change the severity parameter from "int" to "errflags"
Change the severity parameter to the error function from "int" to an
unsigned typedef, currently uint32_t.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-13 19:42:38 -08:00
H. Peter Anvin (Intel)
df2195b6a9 Merge remote-tracking branch 'origin/nasm-2.14.xx'
Resolved Conflicts:
	Makefile.in
	Mkfiles/msvc.mak
	Mkfiles/openwcom.mak
	asm/nasm.c
	nasmlib/alloc.c

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-13 16:43:43 -08:00
H. Peter Anvin (Intel)
3b91f4c117 malloc: handle potential infinite loop in nasm_alloc_failed()
It is possible on memory exhaustion that nasm_fatal() might cause
another allocation error, thus calling nasm_alloc_failed() again. If
we find us in nasm_alloc_failed() for a second time, try to get a
message out and then call abort().

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-13 13:55:25 -08:00
H. Peter Anvin (Intel)
8e08fb6da7 Merge remote-tracking branch 'origin/nasm-2.14.xx'
Resolved Conflicts:
	asm/assemble.c
	asm/directiv.c
	asm/error.c
	asm/float.c
	asm/labels.c
	asm/listing.c
	asm/nasm.c
	asm/parser.c
	asm/preproc.c
	asm/stdscan.c
	include/error.h
	output/outelf.c
	version

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-12 18:05:52 -08:00
H. Peter Anvin (Intel)
df4d342599 warnings: rename ERR_WARN_* to WARN_*
The prefix ERR_WARN_ is unnecessarily long and may be a disincentive
to create new warning categories. Change it to WARN_*, it is still
plenty distinctive.

This is equivalent to nasm-2.14.xx checkin 77f53ba6d4.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-12 17:48:38 -08:00
H. Peter Anvin
e2f5edbb3a error: new flag ERR_HERE
ERR_HERE is used to mark messages of the form "... here" so that we
can emit sane output to the list file with filename and line number,
instead of a nonsensical "here" which could point almost anywhere.

This patch contains some changes from the one in the master branch to
make the code cleaner.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-12 17:43:25 -08:00
H. Peter Anvin
c0b32a3650 errors: unify nasm_verror_{gnu,vc} and remove some ERR_NOFILE
The differences between nasm_verror_{gnu,vc} are a short handful of
strings, so unify them. Remove some additional ERR_NOFILE that are not
necessary.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-12 17:16:02 -08:00
H. Peter Anvin
dea7f4733f error: remove unused ERR_TOPFILE
The flag ERR_TOPFILE was not used anywhere, remove it.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-12 17:00:19 -08:00
H. Peter Anvin (Intel)
eb48c1191d warnings: make it possible for a warning to default to an error
This allows us to do soft-migration of warnings to errors; they will
now be nonfatal errors by default, but gives the user the option to
demote them.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-12 16:11:08 -08:00
H. Peter Anvin (Intel)
93367ea97b warnings; move WARN_OTHER to the end; allow non-warnings to be suppressed
Putting WARN_OTHER at the end of the list creates a number of
advantages and simplifications:

1. It is more user friendly! It is far more of a logical location for
   the default case to be at the end of the printed list.
2. The value 0 can be used in a number of places to indicate a
   non-suppressible event. By having warning_state[0] always contain
   WARN_ST_ENABLED, we can always do the table lookup, even.
3. It means non-warnings (except fatal/panic) can now be conditioned
   on warning states. In those cases, WARN_*, including WARN_OTHER,
   can be added to the mask for any category. This is especially
   useful for notes.

The only downside is that we have to explicitly detect the case where
we have ERR_WARNING but no WARN_ flag. This is a trivial test.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-12 15:58:32 -08:00
H. Peter Anvin (Intel)
77f53ba6d4 warnings: rename ERR_WARN_* to WARN_*
The prefix ERR_WARN_ is unnecessarily long and may be a disincentive
to create new warning categories. Change it to WARN_*, it is still
plenty distinctive.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-12 14:38:50 -08:00
H. Peter Anvin (Intel)
64471097ca strlist: merge the strtbl and strlist interfaces
The currently-unused strtbl was basically a slightly different version
of strlist, with the find and linearize capabilities. Merge these two
together by augmenting strlist to have the same capabilities.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-11 13:37:32 -08:00
H. Peter Anvin
ddb290681e error: new flag ERR_HERE
ERR_HERE is used to mark messages of the form "... here" so that we
can emit sane output to the list file with filename and line number,
instead of a nonsensical "here" which could point almost anywhere.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-11 00:06:29 -08:00
H. Peter Anvin
77016c8ff4 errors: unify nasm_verror_{gnu,vc} and remove some ERR_NOFILE
The differences between nasm_verror_{gnu,vc} are a short handful of
strings, so unify them. Remove some additional ERR_NOFILE that are not
necessary.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-10 22:46:30 -08:00
H. Peter Anvin
5bdc235e02 error: remove unused ERR_TOPFILE
The flag ERR_TOPFILE was not used anywhere, remove it.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-10 22:46:28 -08:00
H. Peter Anvin
c55702ecb8 nasm.c: use error helpers, remove ERR_NOFILE
The current error handlers are much smarter about missing filenames,
and thus using ERR_NOFILE just makes it harder for the programmer.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-10 22:46:26 -08:00