Commit Graph

308 Commits

Author SHA1 Message Date
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 (Intel)
77335213e3 assemble: shuffle a few assignments around
Shuffle around a few assignments which might help the compiler need to
spill less.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-06 23:22:48 -07:00
H. Peter Anvin (Intel)
41bb8a8114 Warn if trying to assemble obsolete instructions
Print a warning if one tries to assemble an obsolete instruction,
unless there is an exact match for the CPU directive.

For example:

	CPU 386
	POP CS		; Warning - obsolete instruction

	CPU 8086
	POP CS		; No warning

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-06 22:56:51 -07:00
H. Peter Anvin (Intel)
d13a6f9708 iflag.h: fix IF_CPU_LEVEL_MASK, add missing CPU definitions
Fix the definition of IF_CPU_LEVEL_MASK (which was missing the top
bit, IFM_ANY itself).

Add CPU definitions that we actually have into directiv.c.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-06 22:33:14 -07:00
H. Peter Anvin (Intel)
ca47c843ed warnings.pl: move comment
Move a comment to where it makes more sense.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-06 19:30:36 -07:00
H. Peter Anvin (Intel)
65c958d59f warnings.pl: warn on duplicate definition instead of broken output
Have warnings.pl give a warning(!) message if a warning definition is
found to be duplicated, including the location of both
definitions. Much better than silently creating bogus output.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-06 19:28:57 -07:00
H. Peter Anvin (Intel)
873ceee29f Replace nasm_error(ERR_WARNING|...) with nasm_warn()
Remove a few remaining instances of nasm_error(ERR_WARNING).

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-06 19:18:36 -07:00
H. Peter Anvin
959702baa8 asm/assemble.c: stylistic fix to bnd warning
Clean up the style for the bnd warning.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-06-06 20:56:50 -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
db6960c3fa quote: improve comment
Explain why 0xfc + vb5 cannot overflow a byte value.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-06-06 17:32:44 -07:00
H. Peter Anvin
10d9589f02 quote: emit invalid UTF-8 rather than just dropping a strange value
If an UTF-8 value exceeds 0x7fffffff, there is no legitimate encoding
for it. However, using FE or FF as leading bytes provide at least some
kind of encoding. This is assembly, and the programmer is (almost?)
always right. It might be worthwhile to add a suppressible warning for
invalid UTF-8 strings in general, though, including any character >
0x10ffff, surrogates, or a string that is constructed by hand.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-06-06 17:28:51 -07:00
H. Peter Anvin
236f4a832b strfunc: better error messages if a string transform fails
Let the user know what string transform actually failed on them.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-06-06 17:17:16 -07:00
H. Peter Anvin
d4b20355d2 asm/quote.c: fix range cutoffs for UTF-8
The various UTF-8 byte cutoffs were off by a factor of 2. Fix.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-06-06 17:16:45 -07:00
H. Peter Anvin
4d7bf79ed7 quote.c: let nasm_skip_string() return NULL for a non-string
Returning NULL makes more sense than returning the initial pointer
(the only other sensible alternative would be to return a pointer the
final null character.)

This currently can't happen, as all callers to nasm_skip_string()
currently explicitly tests for an initial quote.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-06-06 16:29:52 -07:00
H. Peter Anvin
5282cea85b Merge branch 'master' of ssh://repo.or.cz/nasm
Resolved Conflicts:
	asm/preproc.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-06-06 16:26:22 -07:00
H. Peter Anvin
249c217070 quote: drop merging of adjacent strings; allow some control chars
The merging of adjacent ' or " strings really does nothing but
introduce gratuitous incompatiblities; drop it.

Allow *some* control characters (BEL BS TAB ESC) in
nasm_unquote_cstr().

The ` state machine can be greatly simplified by treating \0 as just
another character and let it terminate the string in appropriate
contexts, just like `. The only difference with ` is when it occurs
in state st_backslash: you can't escape the null character.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-06-06 16:21:01 -07:00
Chang S. Bae
fea22697e2 preproc: Fix the initial enum value in stdmac_ptr()
TOKEN_ID is from enum pp_token_type, but struct Type has enum
token_type. TOK_ID seems to be a matched one.s

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2019-06-02 23:51:25 +03:00
H. Peter Anvin (Intel)
a7afe276da preproc: factor out getting a line of tokens and detokenizing it
Split the code for getting a line of tokens from the code that sets
verror and detokenizes the resulting string.

While we are at it, merge the handling of EOF and ^Z into the general
loop in read_line().

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-04-26 00:34:04 -07:00
H. Peter Anvin (Intel)
41e9682efe preproc: massive cleanup of smacro expansion
The smacro expansion code was virtually impossible to understand, and
was leading to very strange failures. Clean it up, and do much better
handling of magic macros.  This should also allow for recursive
macros, but recursive macros are extremely tricky in that it is very
hard to keep them from recursing forever, unless there is at least one
argument which is never expanded. They are not currently implemented.

Even so, I believe token pasting makes it possible to create infinite
loops; e.g.:

%define foo foo %+

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-04-25 18:00:32 -07:00
H. Peter Anvin (Intel)
9bb55bd127 Merge branch 'evalmacro'
Resolved Conflicts:
	asm/preproc.c
	output/elf.h
	output/outelf.c
	output/outelf.h
	version

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-04-24 11:14:43 -07:00
H. Peter Anvin
bb42d30737 quote: disallow control characters in C strings; concatendate; cleanups
In nasm_unquote_cstr(), disallow any control character, not just
NUL. This will matter when allowing quoting symbols.

Merge nasm_unquote() and nasm_unquote_cstr().

Strings can now be concatenated, C style: adjacent quoted strings
(including whitespace-separated) are merged into a single string.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-04-22 14:34:22 -07:00
Cyrill Gorcunov
982186a1a3 preproc: Fix nil dereference on error paths
https://bugzilla.nasm.us/show_bug.cgi?id=3392562

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2019-03-16 23:19:12 +03:00
H. Peter Anvin
8b26247442 preproc: add %i... variants, evaluated macro parameters, cleanups
All directives which create single-line macros now have %i... variants
to define case-insensitive versions. Case insensitive rather sucks,
but at least this way it is consistent.

Single-line macro parameters can now be evaluated as a number, as done
by %assign. To do so, declare a parameter starting with =, for
example:

%define foo(x,=y) mov [x],macro_array_y

... would evaluate y as a number but leave x as a string.

NOTE: it would arguably be better to have this as a per-instance
basis, but it is easily handled by having a secondary macro called
with the same argument twice.

Finally, add a more consistent method for defining "magic" macros,
which need to be evaluated at runtime. For now, it is only used by the
special macros __FILE__, __LINE__, __BITS__, __PTR__, and __PASS__.

__PTR__ is a new macro which evaluates to word, dword or qword
matching the value of __BITS__.

The magic macro framework, however, provides a natural hook for a
future plug-in infrastructure to hook into a scripting language.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-02-26 14:00:54 -08: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 (Intel)
38ddb19977 Warnings: move zeroing reserved space to a separate warning class
Zeroing reserved space in a progbits section really should be a
separate warning class, so it can be controlled independently.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-01-11 12:27:02 -08:00
H. Peter Anvin
ef4f23d76a tokhash.pl: zero all the fields for a not-found token
Make sure we zero all the token fields if we don't find something in
the hash.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-29 20:14:50 -08:00
H. Peter Anvin
6a4f0b36c8 tokens.dat: TOKEN_SIZE sizes belong in inttwo, not in flags
TOKEN_SIZE size values ended up in the wrong place, which caused
parser errors due to being mistaken as flags.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-29 20:13:35 -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
c2f3f26015 Replace <ctype.h> includes with "nctype.h"
For almost everything we should use "nctype.h". Right now we don't
have a nasm_toupper() to use <ctype.h> for things that need toupper().

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-27 12:37:25 -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
Cyrill Gorcunov
532d9f9dcb listing: list_emit -- Don't forget to zap listerr_head
In list_emit we walk over listerr_head freeing the list,
but the head pointer remain carrying old value. Need
to clean it up once traverse is done to not access
already freed memory later.

https://bugzilla.nasm.us/show_bug.cgi?id=3392538

Reported-by: russvz@comcast.net
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-25 13:11:55 +03:00
H. Peter Anvin
11599f49da Factor out size tokens and annotate with the corresponding size
There is space in the token table to explicitly encode the size
corresponding to a size token. We might as well do so...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-24 12:45:58 -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
5358b98405 Don't convert the various RESx instructions to RESB
All it does is complicate things; instead leave the opcode where it
is.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-18 18:06:26 -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)
0402a2d402 labels.c: redefine test should be passn, not pass0
Stupid thinko: lpass should be passn + 1, not pass0 + 1.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-14 13:01: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)
9df075595e Restore the ability to have ? in identifiers, except ? itself
? in identifiers turns out to be used in the field even in non-TASM
mode. Resolve this by allowing it in an identifier still, but treat
'?' by itself the same as we would a keyword, meaning that it needs to
be separated from other identifier characters.

In other words:

	a ? b : c	; conditional expression
	a?b:c		; seg:off expression seg = a?b, off = c

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-14 00:57:05 -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)
628c93f0dc listing: use a non-uniqizing strlist to buffer error messages
Generic code is a wonderful thing...

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-13 23:06:05 -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