Commit Graph

375 Commits

Author SHA1 Message Date
H. Peter Anvin (Intel)
2383281768 Merge tag 'nasm-2.15rc8'
NASM 2.15rc8
2020-06-14 23:02:53 -07:00
H. Peter Anvin (Intel)
42894381c9 preproc: even more handling of backwards compatibility for mmacros
Legacy multi-line macro argument expansion really is very
complicated. With these changes, all legacy tests seem to pass, and
the only differences with NASM 2.14.xx are that some macros which
should have been expanded and were not now are.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-14 19:42:22 -07:00
H. Peter Anvin (Intel)
0fec737e26 test/ifdef.asm: test for simple %ifdef
For some reason, %ifdef is failing now?!

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-05 12:16:23 -07:00
H. Peter Anvin (Intel)
dfa39a189b preproc: add %require directive
Most programming languages these days have a "require" directive,
which is analogous to %include except that it automatically
guards against multiple inclusion. This is useful enough to add,
since with nasm_realpath() we can now to this (mostly) reliably.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-05 11:50:40 -07:00
H. Peter Anvin (Intel)
5b4de52083 BR 3392667: more reasonable limit for expression descent
Set an expression descent limit to 8192, which is more reasonable to
expect to work on most platforms. Furthermore, if getrlimit() exists,
then try to use it to see if we need to further limit the size.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-01 13:21:05 -07:00
H. Peter Anvin (Intel)
5d68f9823e preproc: error out if an include file exists but can't be opened
If an include file exists, but cannot be opened, that is still a
critical error.

However, downgrade this from a fatal to a nonfatal error. There really
isn't any reason to stop cold here.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-01 12:32:35 -07:00
H. Peter Anvin (Intel)
6e71496e3c BR 3392669: in expand_one_smacro(), we may reach EOL before tafter
If the rest of the line is consumed, we may never see tafter, so we
have to test for end of line at line 5412.  We already do at 5397, so
it clearly should have been there all along.

Reported-by: <puppet@zju.edu.cn>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-01 12:21:10 -07:00
H. Peter Anvin (Intel)
a762cd4e54 BR 3392668: preproc: test for macro in TOK_LOCAL_SYMBOL
TOK_LOCAL_SYMBOL is only applicable inside a macro; otherwise error
out just like we do for TOK_MMACRO_PARAM.

This *partially* addresses BR 3392668.

Reported-by: <puppet@zju.edu.cn>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-01 11:49:08 -07:00
Chang S. Bae
c32fb08319 test: Add BR3392607
Reported-by: Henrik Gramner <herik@gramner.com>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392607
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2020-04-22 00:10:21 +00:00
Chang S. Bae
ee8edad40b test: Add BR3392661
Suggested-by: <mae.bdf@outlook.com>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392661
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2020-04-22 00:08:28 +00:00
Chang S. Bae
5f8d0ec1f6 test: Add BR3392660
Suggested-by: C. Masloch <pushbx@ulukai.org>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392660
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2020-04-21 21:35:54 +00:00
Chang S. Bae
9e019f249c test: Add BR3392640
Suggested-by: C. Masloch <pushbx@ulukai.org>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392640
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2020-04-21 21:12:39 +00:00
Chang S. Bae
0197c966da test: Add BR3392630
Add the test code into the existing xdefine testing.

Suggested-by: C. Masloch <pushbx@ulukai.org>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392630
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2020-04-21 21:11:33 +00:00
Chang S. Bae
bb96fdc74c test: Add BR3392626
There are many similar preprocessor loop cases but located
on each bug-report basis. While it looks to be better to
consolidate them together, add one more test case like what
was done before.

Suggested-by: C. Masloch <pushbx@ulukai.org>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392626
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2020-04-21 21:00:56 +00:00
H. Peter Anvin
2cd1a6fb70 test: test case for BR 3392655, overflow during bin format link
The bin format linker should warn if a relocation overflows its
virtual address.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2020-03-31 10:23:43 -07:00
H. Peter Anvin (Intel)
e91f5cc132 preproc: fix %undef of macro aliases, and add %ifdefalias
Macro aliases can legitimately point to nonexistent
macros. Furthermore, %undef should remove the pointed-at macro, not
the alias. This led to an infinite loop in the existing code; fix
that.

Add an %ifdefalias directive to test for the existence of an alias.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-10-23 12:59:06 -07:00
H. Peter Anvin (Intel)
4b58ec1b8f preproc: properly protect %xdefine params (see below), cleanups
1. %xdefine was broken because the code used i as a loop, which is
   a standard use for the name i. To avoid that confusion in the
   future, use "op" rather than "i" to hold the directive constant.

2. Once (1) was fixed, the smacro expansion code would fail because of
   parameter token numbers being indistinguishable between the ongoing
   expansion and the %xdefine parameters. In a first pass, mark the
   parameters with a new TOK_XDEF_PARAM token number, and change them
   to proper parameter token numbers in a second pass, which is now
   moved into define_smacro() which is where it arguably belongs.

3. Add a few tests for token pasting and xdefine with and without
   parameters.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-10-23 12:00:50 -07:00
H. Peter Anvin (Intel)
84b852bff0 Implement an enhanced version of MASM's dup() and "db ?" syntax.
Add support for complex data (Dx) statement expressions involving both
initialized and uninitialized data. In addition, we have support for
overriding the size of each element on an individual item and/or list
basis.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-10-16 14:29:16 -07:00
H. Peter Anvin
d03a6c8ffe preproc: fix the detection of the >= operator
There are *four* operators starting with ">": > >> >>> and >=.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-10-07 21:29:05 -07:00
H. Peter Anvin
d983b62233 preproc: make %exitrep do what it is supposed to
%exitrep should should stop emitting code immediately, not just
terminate the loop when we hit %endrep. There is a bunch of hacky code
that special-cases that using istk->in_progress == 0.

The handling of the tail of %exitrep, %include and non-emitting
conditionals using entirely different mechanisms is just dumb. They
need to be unified.

Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392612
Reported-by: Jason Hood <jadoxa@yahoo.com.au>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-10-07 21:25:18 -07:00
H. Peter Anvin
0209ecb179 test: add a test for symbol prefixes via %pragma
Add a test for symbol prefixes via %pragma, including overlapping
directives.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-09-30 13:30:15 -07:00
H. Peter Anvin
e47f4b7ad5 elf: fix "object" symbol keyword
The "object" symbol keyword would incorrectly generate STT_NOTYPE
instead of STT_OBJECT. Add test for weak object references; they are
different from plain weak references in that they are guaranteed to
resolve to zero if the symbol is not found.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 17:45:11 -07:00
H. Peter Anvin
90b1ccff86 Drop unnecessary EXTERN symbols
Currently, NASM always issues as an unknown symbol any symbol declared
EXTERN. This is highly undesirable when using common header files,
as it might cause the linker to pull in a bunch of unnecessary
modules, depending on how smart the linker is.

Add a new REQUIRED directive which behaves like the old EXTERN, for
the use cases which might still need this behavior.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 20:21:03 -04:00
H. Peter Anvin
495fda6341 elf: support weak global and extern references
A global or extern definition can now contain the keyword "weak" (or
"strong", although that is the default) to create a weak symbol or a
weak external reference, respectively.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 14:27:50 -04:00
H. Peter Anvin (Intel)
a1a844697d preproc: fix varadic macros, add conditional comma operator
Fix the (severely broken handling of) varadic macros.

Add a conditional comma operator "%,". This expands to a comma unless
followed by a null expansion of some sort, which allows suppressing
the comma before an empty argument (usually varadic, but not
necessarily.)

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-20 01:32:28 -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)
2586cee21d BR 3392472: don't complain on wraparound for lower bit modes
If the address we are using is >= the size of the instruction, then
don't complain on overflow as we can wrap around the top and bottom of
the address space just fine.

Alternatively we could downgrade it to OUT_WRAP in that case.

Reported-by: C. Masloch <pushbx@38.de>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-16 01:44:49 -07:00
H. Peter Anvin (Intel)
fe90f152d1 test: very simple test for MASM displacement syntax
Very trivial test of MASM package.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-14 15:46:01 -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 (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)
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)
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)
d2de48925e br3392586: add test case for smacro descent
Add test case for smacro descent from bug 3392586.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-07 17:17:54 -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)
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
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
b2004511dd ELF: handle more than 32,633 sections
Dead code elimination in ELF uses separate ELF sections for every
functions or data items that may be garbage collected. This can end up
being more than 32,633 sections which, when the ELF internal and
relocation sections are added in, can exceed the legacy ELF maximum of
65,279 sections.

Newer versions of the ELF specification has added support for much
larger number of sections by putting a place holder value (usually
SHN_XINDEX == 0xffff, but 0 in some cases) into fields where the
section index is a 16-bit value, and storing the full value in a
diffent place: the program header uses entries in section header 0,
the symbol table uses an auxiliary segment with the additional
indicies; the section header did not need it as the sh_link field is
already 32 (or 64) bits long.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-02-26 00:02:35 -08:00
H. Peter Anvin
69fa3c2e8e outelf: hash sections for performance
Use a hash table to look up sections by name, and an RAA to look up
sections by index; thus remove O(n) searches. This becomes important
since ELF uses sections for dead code elimination.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-01-12 00:35:20 -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
5079ea0b01 BR 3392538: test case for double free in listing module
Test case from bug 3392538 for double free in the listing module.

This is the test case only, not a fix.

Reported-by: <russyz@comcast.net>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-24 12:41:57 -08:00
H. Peter Anvin
7f688841ce insns.dat: accept explicit ax/eax/rax operand to CLZERO
AMD documents this instruction with an rax operand. The error behavior
implies this is an address-size-sensitive instruction. Add support for
specifying the explicit operand, but consistent with normal ndisasm
behavior, don't disassemble the implicit operand.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-22 17:52:27 -08:00
H. Peter Anvin (Intel)
e7f4e0e229 test/Makefile: add .aout target
We had no target for generating an aout format file.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-18 11:24:29 -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
cd26fccab4 asm: support the +n syntax for register sets
Support the +n syntax for multiple contiguous registers, and emit it
in the output from ndisasm as well.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 17:15:08 -07:00
H. Peter Anvin, Intel
6bc18f1978 test: make absolute.asm buildable even when not in binary mode
absolute.asm is useful even for other backends, so explicitly test to
see if ORG is possible for this format.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 13:24:51 -07:00
H. Peter Anvin, Intel
59242bd10a test: add test for context-local labels and extern label promotion
Add a simple test case for context-local (%$) labels not disturbing
the local variable namespace, and extern labels getting promoted to
global.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 13:19:32 -07:00
H. Peter Anvin
1bcc1e012a test: test for ELF symbol visibility
Add test for declaring ELF visibility.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-18 11:37:17 -07:00
H. Peter Anvin
f7be8b3253 pragma: define a hander for generic output (and debug) pragmas
There are cases where we may want to implement generic pragmas, while
still make them selective based on output and/or debug formats.
Initially, use this for the prefix/suffix options.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Cc: Chang Seok Bae <chang.seok.bae@intel.com>
2018-06-18 11:34:33 -07:00