Commit Graph

419 Commits

Author SHA1 Message Date
H. Peter Anvin (Intel)
fb118aecc5 obsolete: make the message clearer in the case of NEVER,!NOP
"instruction never implemented and removed from the target CPU"

... doesn't really make sense, so change it to ...

"instruction never implemented and invalid on the target CPU"

(still may seen redundant, but it is to distingush it from "and is a
noop on...")

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-09 15:01:28 -07:00
H. Peter Anvin (Intel)
5b39461178 obsolete handing: handle a few more subcases in a useful way
Distinguish instructions which have once been valid (OBSOLETE) from
those that never saw the light of day (NEVER). Futhermore, flag
instructions which devolve to an architectural noop from those with
undefined behavior and possibly recycled opcodes.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-09 14:52:16 -07:00
H. Peter Anvin (Intel)
fb11889040 BR 3392590: add warning for valid but obsolete instructions
Just becase one is compiling for an old CPU doesn't mean one wants to
use obsolete instructions that would not be forward compatible. Rename
the "obsolete" warning to "obsolete-removed" and create a new
"obsolete-valid" warning to go with it (-w[+-]obsolete controls both
options, as usual.)

Suggested-by: C. Masloch <pushbx@38.de>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-09 14:21:42 -07:00
H. Peter Anvin (Intel)
d73b10abd5 warnings.pl: BR 3392585: don't use scalar(%hash)
The idiom scalar(%hash) seems similar to scalar(@array), and in fact
is in current versions of Perl. However, in older versions of Perl,
the former is totally useless:

       Prior to Perl 5.25 the value returned was a string consisting
       of the number of used buckets and the number of allocated
       buckets, separated by a slash.  This is pretty much useful only
       to find out whether Perl's internal hashing algorithm is
       performing poorly on your data set.  For example, you stick
       10,000 things in a hash, but evaluating %HASH in scalar context
       reveals "1/16", which means only one out of sixteen buckets has
       been touched, and presumably contains all 10,000 of your items.
       This isn't supposed to happen.

       As of Perl 5.25 the return was changed to be the count of keys
       in the hash. If you need access to the old behavior you can use
       "Hash::Util::bucket_ratio()" instead.

Use scalar(keys %hash) instead.

Reported-by: Orkan Sezer <sezeroz@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-09 13:45:41 -07:00
H. Peter Anvin (Intel)
177a05d0ce perl files: clean up warnings
Clean up some perl warnings, some of which were legitimate (apparently
undef doesn't actually take a list of arguments, a common enough
mistake that it is mentioned in the man page!, and a list of variables
after "my" can be cantankerous), and some of which were nuisance but
were easy enough to clean up.

Maybe this can resolve the problems with very old version of Perl?

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-09 13:30:19 -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 (Intel)
524918394d labels.c: don't use ERR_NOTE for additional information
ERR_NOTE just confuses things, especially in the case of a suppressed
warning.

The preprocessor doesn't use it for unwinding macros, either.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-09 03:55:29 -07:00
H. Peter Anvin (Intel)
b1e15f42fe Add implicitly sized versions of the K instructions
This allows the K instructions to be specified without a size suffix
as long as the operands are sized; this matches the way most other x86
instructions work. As this is not the syntax specified in the SDM,
don't use it for disassembly.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-09 02:44:46 -07:00
H. Peter Anvin (Intel)
1c21a53e4e preproc: fix parsing of single-line macro arguments, cleanups
The single-line macro argument parsing was completely broken as a
comma would not be recognized as an argument separator.

In the process of fixing this, make a fair bit of code cleanups.

Note: reverse tokens for smacro->expansion doesn't actually make any
sense anymore, might reconsider that.

This checkin also removes the distinction between "magic" and plain
smacros; the only difference is which specific expand method is being
invoked.

Finally, extend the allocating-string functions such that *all* the
allocating string functions support querying the length of the string
a posteori.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-09 02:34:21 -07:00
H. Peter Anvin (Intel)
875eb24b29 preproc.c: fix macro descent
We have to call expand_one_smacro() recursively, otherwise we will not
expand smacros which point to other smacros. We cannot simply do this
by looping after token pasting, because we need to make sure we don't
recursively expand the same smacro.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-07 17:14:35 -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 (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
H. Peter Anvin (Intel)
be99ebd656 assemble.c: capitalize LOCK prefix
LOCK is a keyword and not a descriptive term here, capitalize it.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-13 22:12:37 -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)
9f89eb38fc Merge remote-tracking branch 'origin/master' into mkwarnings 2018-12-13 19:18:49 -08:00
H. Peter Anvin (Intel)
26572c6e37 warnings: change WARN_MNP -> WARN_MACRO_PARAMS
This one got missed during constant name conversion. Make the
constants match the options.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-13 16:51:45 -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)
3c896de5a3 warnings.pl: script to harvest warnings directly from the source
This will make it a lot easier to create new warning categories by
inserting a block comment directly in the source code near where the
warning is used.

This block comment should look like:

     /*
      *!warning-name {on|off|err} this is a warning
      *!
      *! needs a help text.
      */
      nasm_warnf(WARN_WARNING_NAME, ...);

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-13 16:33:39 -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)
fef75c265a warnings: Make WARN_ constants consistent with -w options
Not only does this make it consistent, but allows for automation.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-12 18:13:47 -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)
950dee9edc BR 3392535: warning on redefine, promote define-on-pass2 to error
If we redefine consistently, make it a suppressed-by-default warning.
If we end up doing the define on pass 2, promote that to a
default-error warning; using a default-error warning allows the user
to demote it should they so wish.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Requested-by: C. Masloch <pushbx@38.de>
2018-12-12 16:49:07 -08:00
H. Peter Anvin (Intel)
46016cb368 listing.c: handle multiple error messages on a single line
We may produce an arbitrary number of error messages on a single line;
include all of them in the list file.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-12 16:47:04 -08:00
H. Peter Anvin (Intel)
bdf017c89c warnings: WARN_OTHER is now "above", not "below"
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-12 16:12:36 -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 (Intel)
ebb05a0e5f hashtbl: revamp the hash table interface, support binary keys
Add binary key support to the hash table interface. Clean up the
interface to contain less extraneous crud.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-11 13:18:49 -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
026b62f264 srcfile: simplify and make most functions inline
Simplify the srcfile subsystem by making it official that any pointer
passed to src_get() needs to have been obtained from the srcfile
subsystem itself.

Move a lot of the srcfile operations into inline code; often they
amount to a single machine instruction...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-10 23:28:01 -08:00
H. Peter Anvin
1aa794527f Move srcfile.c to asm/
srcfile.c is not used by anything outside asm/, so move it there.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-10 23:03:04 -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
H. Peter Anvin
a7bc437eab asm/labels.c: use error helpers
Replace explicit calls to nasm_error() with error helpers.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-10 22:46:24 -08:00
H. Peter Anvin
d351efc97d error: add nasm_note() helper, clean up helper generation
It is fairly easy to more compactly create error helpers since we are
using preprocessor hacks anyway, so do exactly that.

Create nasm_note() helpers for the new NOTE severity class.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-10 22:46:20 -08:00
H. Peter Anvin
36e3c70790 Merge remote-tracking branch 'origin/nasm-2.14.xx'
Resolved Conflicts:
	asm/labels.c
	include/error.h
	version
2018-12-10 21:28:59 -08:00
H. Peter Anvin
54aac9d3c1 errors: add ERR_NOTE and a default clause to error disposition
ERR_NOTE has no action. Have a default clause as well, for good
measure.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-10 21:14:57 -08:00
H. Peter Anvin
b424ae3130 BR 3392534: error out on an inconsistently redefined label
If a label is redefined in the same pass, and the value is
inconsistent, then error out. While we are at it, give the source
location of the previous definition.

This explicitly rejects BR 3392535; there seems to be no reason to
reject duplicate definitions with the same value, as there is no
inconsistency involved.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-10 13:30:51 -08:00
H. Peter Anvin
d84f9a7153 error: add new severity level "note"
Add a new severity level "note", intended to be used to give
additional information about a previous error.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-10 13:29:35 -08:00
H. Peter Anvin
070c50fe72 nasm: clean up error messages somewhat
If warnings are errors, print [-w+error=xxxx] and prefix error:.

Use the same spacing for filename and non-filename error messages.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-10 13:06:48 -08:00
Cyrill Gorcunov
b449ce49d9 stdscan: Use nasm_error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-01 21:02:51 +03:00
Cyrill Gorcunov
a14e65699b parser: Use nasm_error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-01 20:20:50 +03:00
Cyrill Gorcunov
98bf1ba980 listing: Use nasm_error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-01 20:04:53 +03:00
Cyrill Gorcunov
46c37b3772 labels: Use nasm_error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-01 20:03:55 +03:00
Cyrill Gorcunov
194f93322f float: Use nasm_error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-01 20:01:40 +03:00
Cyrill Gorcunov
636506b78c eval: Use nasm_error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-01 19:54:15 +03:00
Cyrill Gorcunov
7c5de5b7e1 directiv: Use nasm_ error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-01 14:17:40 +03:00
H. Peter Anvin
53e2e4c099 nctype: add nasm_isquote()
Add nasm_isquote() to test for a NASM quoted string.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-28 15:01:40 -08:00
H. Peter Anvin
1350620bf1 ctype: create our own ctype table
Create our own ctype table where we can do the tests we want to do
cheaply, instead of calling ctype functions and then adding additional
tests all over the code.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-28 14:55:58 -08:00
H. Peter Anvin
099cc17739 eval: implement the C ? : operator
Add the C ternary conditional ? : operator.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-28 13:13:16 -08:00
H. Peter Anvin
1722fcf81c preproc.c: tell us which macro definition has too many defaults
We can always be nicer to the user by being more verbose.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-28 13:05:42 -08:00
H. Peter Anvin
c77f5079e5 Merge remote-tracking branch 'origin/nasm-2.14.xx'
Resolved Conflicts:
	asm/nasm.c
	version

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-28 12:47:25 -08:00
H. Peter Anvin
3475462ee8 nasm: fix the combination -E -MD, handle -MD without a filename
-E -MD should work and output a dependency file.
-MD can be used without a filename; there is a default filename or
-\c{-MF} can be used.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-28 12:40:58 -08:00
H. Peter Anvin
6fdf710824 eval: 'i' and 'j' are names normally used for iteration variables
Single letter variables in the sequence i, j, k... are normally used
for integer-valued iterators. Rename the token-type variable 'tt', and
use 'tto' (token type, old) when the value is saved across a scan.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-28 10:33:16 -08:00
H. Peter Anvin
99fcda0e76 expr: wrap the call to the scanner
*Every* call to the scanner is of the form i = scan(scpriv, tokval).
Wrap that in a static function instead of duplicating the code over
and over.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-28 10:27:30 -08:00
H. Peter Anvin
ef427b3fa1 eval: drop passing (critical) as an argument
There is no point in passing (critical) as an argument when
we alredy rely on a bunch of static variables.  If eval needs to be
reentrant, we should instead have something like "struct eval_state"
and pass a pointer to that as an argument.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-28 10:19:50 -08:00
H. Peter Anvin
ca605a3c38 expr: allow any expression to contain relational operators
There is absolutely no reason not to allow relational operators in
arbitrary contexts. and doing so can be quite useful.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-28 10:13:48 -08:00
H. Peter Anvin
a0ed5b3ffa Merge branch 'master' of ssh://repo.or.cz/nasm 2018-11-28 09:56:15 -08:00
H. Peter Anvin
79a070eea9 BR 3392368: correct handling of exact limb switch
When we have an exact limb switch, we may end up with a case where the
value no longer has any remaining valid bits.  In that case, we end up
relying on the expression *mp |= v << ms shifting the bits on the
subsequent limb all the way to zero, but that is not how real hardware
works when the shift count equals the width of the type. This is
undefined behavior and does, in fact, produce the wrong result.

Instead, change the test for limb shift to (ms < 0), meaning that we
defer the advance to the next limb until we actually need it. At that
point, change the shift into the *old* limb to have a cast to
(fp_2limb) which means the shift right of LIMB_BITS is valid and
produces a zero value as expected.

Reported-by: Brooks Moses <bmoses@google.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-26 14:17:40 -08:00
H. Peter Anvin
da79432255 BR 3392529: remove excess printf() argument
The input file is provided by nasm_error(), we should not include it
in the printf list (compiler warning + wrong message.)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-26 14:15:46 -08:00
Cyrill Gorcunov
295b795d71 preproc: Use error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-25 13:09:53 +03:00
Cyrill Gorcunov
00526d9845 assemble: Use nasm_ error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-25 01:45:49 +03:00
Cyrill Gorcunov
c3527dd6b2 error: Cover all levels with helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-25 01:15:51 +03:00
Cyrill Gorcunov
3351072306 error: Style liftup
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-24 18:58:11 +03:00
Cyrill Gorcunov
8c0666b0e6 preproc: Pass include paths as strlist
Instead of copying data just reuse already
allocated paths.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-24 14:33:48 +03:00
Cyrill Gorcunov
b7bb5acdaf strlist: Rework to drop type
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-24 13:24:09 +03:00
Cyrill Gorcunov
8e0acaad66 Pass input filename into error message
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-24 12:12:15 +03:00
Cyrill Gorcunov
f5a48a6ba2 Fix sigsegv if two outputs specified
outname is only set up by pass two so
earlier access may lead to sigsegv.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-24 12:02:13 +03:00
Cyrill Gorcunov
744100dc14 Merge branch 'nasm-2.14.xx'
* nasm-2.14.xx:
  Fix undefined behavior when shifting left by 32 bits
  BR 3392529: if the default output name is the same as input -> nasm.out
2018-11-23 23:52:11 +03:00
Michael Bradshaw
fd14310469 Fix undefined behavior when shifting left by 32 bits
See https://bugzilla.nasm.us/show_bug.cgi?id=3392368

Signed-off-by: Michael Bradshaw <mjbshaw@google.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-23 23:51:16 +03:00
H. Peter Anvin (Intel)
7b6371b9d3 BR 3392529: if the default output name is the same as input -> nasm.out
If no output filename is specified, then a default filename is used
based on the input filename. If that ends up the *same* as the input
filename, change the output filename to "nasm.out".

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-11-20 10:56:57 -08:00
Cyrill Gorcunov
3079f7966d preproc: Fix malformed parameter count
readnum returns 64bit number which may become
a negative integer upon conversion which in
turn lead to out of bound array access.

Fix it by explicit conversion with bounds check

 | POC6:2: error: parameter count `2222222222' is out of bounds [0; 2147483647]

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-14 10:26:26 +03:00
Cyrill Gorcunov
feabd742a3 preproc_init: Just clean include path
It is more natural to keep include path valid
during the whole lifetime.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-13 01:23:47 +03:00
Cyrill Gorcunov
e358851526 Merge branch 'nasm-2.14.xx'
* nasm-2.14.xx:
  preproc: command-line preproc directive after system-generated

gorcunov@: Had to fix include_path StrList conversion,
it is a bit ugly by now, will rework.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-13 01:09:27 +03:00
Cyrill Gorcunov
0135a8147e Merge nasm-2.14
* commit '9a1216a1efa0ccb48e5df97acc763ea3de71e0ce':
  NASM 2.14
  nasmdoc.src: fix compound word
  doc: Add a description for a useful case of mangling symbols
  preproc: Don't access out of bound data on malformed input
  rdstrnum: Make sure we dont shift out of bound
  preproc: Fix out of bound access on malformed input
  doc: Clarify %include search directory semantics

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-12 23:21:43 +03:00
H. Peter Anvin
bf6230baa9 preproc: command-line preproc directive after system-generated
BR 3392527: make sure that all command-line specified preprocessing
directives are processed after the system-generated ones. In
particular __OUTPUT_FORMAT__ was generated after command line pass 2,
at which point -p, -d, -u, --pragma and --before had already been
processed.

There is no reason to split up defined_macros() anymore: the right
place to execute it is simply between command line passes 1 and 2. We
can also set dfmt here, which lets us define a __DEBUG_FORMAT__ macro
as well.

Finally move some options that have no business being processed in
pass 2 to pass 1.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-11 13:36:13 -08:00
Cyrill Gorcunov
4b5b737d49 preproc: Don't access out of bound data on malformed input
There are a number of places still where we test text
data which is potentially may be an empty string. This
is known to happen on fuzzer input but usually doesn't
take place in regular valid programs. Surely we need
to revisit preprocessor code for this kind of errors.

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-29 22:54:34 +03:00
Cyrill Gorcunov
b756372b06 rdstrnum: Make sure we dont shift out of bound
Otherwise we may hit underfined behavior.

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-29 22:25:16 +03:00
Cyrill Gorcunov
661f723d39 preproc: Fix out of bound access on malformed input
A fuzzer revealed a problem in preproc code.

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

Reported-by: ganshuitao <ganshuitao@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-28 20:39:34 +03:00
H. Peter Anvin (Intel)
f7106d06e4 strlist: use a hash table
Use a hash table to enforce uniqueness in a string list. It is still
an ordered list, however, and can be walked in insertion order.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-10-25 12:33:58 -07:00
Cyrill Gorcunov
eb82f99367 Merge branch 'nasm-2.14.xx'
* nasm-2.14.xx:
  preproc: Make the preprocessor use nasm_catfile for include
  path: nasm_catfile -- Fix incorrect return of filename only
2018-10-21 15:06:36 +03:00
night199uk
fdb1a1b151 preproc: Make the preprocessor use nasm_catfile for include
All include paths to nasm must already have a trailing separator
prefix which is uncommon among tools. Change to using nasm_catfile
which gives a more normal behaviour.

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

Signed-off-by: night199uk <night199uk@hermitcrabslab.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-19 01:00:11 +03:00
Cyrill Gorcunov
f7b44f6092 Merge branch 'nasm-2.14.xx'
* nasm-2.14.xx: (83 commits)
  NASM 2.14rc16
  doc: Update changes
  preproc: expand_smacro -- Fix nil dereference on error path
  eval: Eliminate division by zero
  doc: Update changes
  opflags: Convert is_class and is_reg_class to helpers
  preproc: Fix out of range access in expand mmacro
  doc: Update changes
  parser: Fix sigsegv on certain equ instruction parsing
  labels: Make sure nil label is never passed
  labels: Don't nil dereference if no label provided
  macho: Add warning message in macho_output()
  macho/reloc: Fix addr size sensitive conditions
  macho/reloc: Fix macho_output() to get the offset adjustments by add_reloc()
  macho/reloc: Fixed offset adjustment in add_reloc()
  macho/reloc: Allow absolute relocation when forcing a symbol reference
  macho/reloc: Adjust SUB relocation information
  macho/reloc: Fixed in handling GOT/GOTLOAD/TLV relocations
  macho/reloc: Simplified relocation for REL/BRANCH
  macho/sym: Record initial symbol number always
  ...

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-15 22:58:13 +03:00
Cyrill Gorcunov
980dd658b5 preproc: expand_smacro -- Fix nil dereference on error path
When error happened earlier we might have a.mac already
handled and set to nil.

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-14 19:25:32 +03:00
Cyrill Gorcunov
ceec0d8187 eval: Eliminate division by zero
When doing division we should detect if the value we're
divided by is not zero. Instead of is_unknown() helper
we should use is_just_unknown().

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

Reported-by: Jun <jxx13@psu.edu>
Reported-by: stuartly <situlingyun@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-14 01:49:43 +03:00
Cyrill Gorcunov
67f2ca2b3f preproc: Fix out of range access in expand mmacro
On specially crafetd malformed input file the params
might be zapped (say due to invalid syntax) so we might
access out of bound having nil dereference in best case.

Note the later code in this helper uses tok_isnt_ helper
which already has similar check.

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

Reported-by: Jordan Zebor <j.zebor@f5.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-13 19:41:01 +03:00
Cyrill Gorcunov
a28c40d546 parser: Fix sigsegv on certain equ instruction parsing
We should check for bounds when accessing nasm_reg_flags.
Seems this bug was for long time already.

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

Reported-by: Jordan Zebor <j.zebor@f5.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-13 18:10:30 +03:00
Cyrill Gorcunov
8e740c6773 labels: Make sure nil label is never passed
We already catched a case where we've missed
test for non nil label and in result got sigsegv,
lets rather panic next time.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-13 17:18:05 +03:00
Cyrill Gorcunov
e996d28c70 labels: Don't nil dereference if no label provided
An equ without label may cause nil dereference

 |	equ 0x100

Fixes 98578071b9

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-13 16:18:16 +03:00
Cyrill Gorcunov
c713b5f994 preproc: parse_size -- Check for string provided
In case if the string is nil we will have sigsegv.

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-09-29 14:31:26 +03:00
Cyrill Gorcunov
da3780dc22 Fix small typo in comment
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-09-22 14:10:36 +03:00
Cyrill Gorcunov
69bb052e00 asm: Restore showing output for preproc mode in stdout
Before the commit 81b62b9f54
we've been always putting -E,-e results into stdout if no
output file provded. So bring this backward compatibility
back.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-09-22 13:46:45 +03:00
Chang S. Bae
a578634b61 optimization: Introduce new flag to turn-off selectively
While configuring optimization in a level is conventional,
a certain optimization tends to conflict with some pragma.

For example, jump match conflicts with Mach-O's
"subsections-via-symbols" macro.

This configurability will workaround such conflicts.

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2018-08-16 00:01:31 +03:00