Commit graph

4066 commits

Author SHA1 Message Date
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
9953992686 nasm.h: fix definition of isidchar()
isidchar() also should accept digits.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-28 13:02:12 -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
a074339854 nasm.h: replace is*() macros with inline functions, '?' for TASM mode
Replace all the is*() macros with inline functions. Disallow '?' in
identifiers unless we are in TASM mode.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
is allowed in
2018-11-28 11:53:05 -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
c06c87dbb5 changes.src: fp bug: there are probably other corner cases
There are probably other corner cases where we could at the very
least produce an incorrectly rounded result, so be a bit more cagey
about the description of the bug.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-28 09:50:14 -08:00
H. Peter Anvin
ee75ec2eed NASM 2.14.01rc1 2018-11-26 21:40:01 -08:00
H. Peter Anvin
d7498067ca BR 3392368: actually fix the documentation; add test case
Add a mimimal test case for this bug; correct the documentation.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-26 21:38:14 -08:00
H. Peter Anvin
8fa279954c Correctly document the BR 3392368 fix, add test case
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-26 14:59:35 -08:00
H. Peter Anvin
88959910d8 changes.src: document more fixes
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-26 14:38:32 -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
H. Peter Anvin
4885cc2ba8 BR 3392532: outobj: fix forward references to the SEG of external symbols
External symbols are defined via deflabel(), but deflabel() is not
called until pass0 == 1. Until that happens, segbase has no way to
know what the proper segment base of the segment actually is.

Thus, testing for pass0 == 0 will always fail for a forward reference;
correct the test to test for pass0 < 2, i.e. the assert should fail
only for the final code-generation pass.

Reported-by: <stsp@list.ru>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-26 13:41:37 -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
85261a2b57 test: Use NASM_TEST_RUN environment
To placate false positives in outputs which
writes nasm comment an signature into binary
form.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-24 17:06:57 +03:00
Cyrill Gorcunov
f6b1720a2d version: Make them dynamic for regression tests sake
When we are running regression tests we compare binary
forms and the strings better to be the constants to not
trigger false positives.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-24 16:59:32 +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
afd8d2f11a test: nasm-t -- Test for sigsegv on multiple outputs
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
69f77d5c34 test: nasm-t -- Add br3392528
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-14 10:26:26 +03: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
fcc85aeef7 test: nasm-t -- Extend inctest
To address https://bugzilla.nasm.us/show_bug.cgi?id=3392527

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-12 23:28:18 +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
7373a8e606 test: nasm-t -- Add br560575
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-11 21:43:46 +03:00
Cyrill Gorcunov
9354f72a41 test: nasm-t -- Add br978756
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-11 21:43:46 +03:00
Cyrill Gorcunov
634b0e405b test: nasm-t -- Add br3392259
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-11 21:43:46 +03:00
Cyrill Gorcunov
f9e3e8168b test: nasm-t -- Add br3392252
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-11 21:43:46 +03:00
Cyrill Gorcunov
6fcb91cbc1 test: nasm-t -- Add br3200749
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-11 21:43:46 +03:00
Cyrill Gorcunov
3d5195704d test: nasm-t -- Add br3385573
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-11 21:43:46 +03:00
Cyrill Gorcunov
e8d773c578 test: nasm-t -- Add br3189064
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-11 21:43:46 +03:00
Cyrill Gorcunov
679a470aa7 test: nasm-t -- Add br3187743
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-11 21:43:46 +03:00
Cyrill Gorcunov
f4c33801a2 test: nasm-t -- Add br3174983
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-11 21:43:46 +03:00