Ponderance: if data->bits < globalbits, should we actually use
OUT_UNSIGNED rather than OUT_WRAP here?
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
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>
The memory operand size of LEA doesn't matter in any way as it isn't
"real memory". Add an ANYSIZE option to ignore sizes entirely.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
"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>
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>
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>
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>
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>
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>
"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>
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>
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>
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>
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>
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>
* 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>
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>
In order for the machinery that deduces memory operand sizes when they
are not provided to work correctly, we need to make sure that
MERR_OPSIZEMISSING is only issued by matches() as the last resort;
that way all other error conditions will have been filtered out and we
know at the very end if we have exactly one option left.
This is a partial revert of cd26fccab4,
but does not affect the functionality introduced by that patch.
Reported-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
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>
Nearly all instances of nasm_fatal() and nasm_panic() take a flags
argument of zero. Simplify the code by making nasm_fatal and
nasm_panic default to no flags, and add an alternate version if flags
really are desired. This also means that every call site doesn't have
to initialize a zero argument.
Furthermore, ERR_NOFILE is now often not necessary, as the error code
will no longer cause a null reference if there is no current
file. Therefore, we can remove many instances of ERR_NOFILE which only
deprives the user of information.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
ABSOLUTE handling can be done centrally, and shouldn't need to be in
every backend. Simply drop the call to ofmt->output().
Many backends have an assert for OUT_RAWDATA not having a target
segment; this doesn't make any sense as output/legacy.c will not allow
that to happen.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Without relocation, the linker may do erroneous dead strip.
For the relocation, the conversion of addresses to RAWDATA
should be avoided for Mach-O.
https://bugzilla.nasm.us/show_bug.cgi?id=3392469
Reported-by: Andrew Fish <afish@apple.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Automatically assign values to the instruction flags; we ended up with
a case where pushing flags into the next dword caused comparison
failures due to other places in the code explicitly comparing
field[3].
This creates necessary defines for this not to happen; it also cleans
up a fair bit of the iflag code.
This resolves BR 3392454.
Reported-by: Thomasz Kantecki <tomasz.kantecki@intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
For immediates, we had one overflow test in the bytecode interpreter
(in most cases via warn_overflow_opd()) and one in out(); this meant
we got two warnings instead of one every time. Replace with only the
one in out().
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Issue a diagnostic and don't panic for invalid TIMES values.
Reported-by: C. Masloch <pushbx@38.de>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
We have to consider mode decorators when considering instruction
matching, otherwise we end up falling back to VEX encoding if it is
available, losing the decorator. See BR 3392421.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This fixes compilation on macOS, Windows, and quite likely a number of
other platforms.
Signed-off-by: Martin Storsjö <martin@martin.st>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Make the internal handling of segment numbers just a little more
sane. The whole use of when we have done ofmt->segbase or not is
crazy, though...
In the meantime, add a few more hacks to the dbg output format to make
it more useful.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
We don't need to sort opcodes anymore, since we are using an O(1) hash
and not binary search. Instead, sort them in the order they first
appear in insns.dat; this lets us move all the pseudo-ops to a
contiguous range at the start of the file, for more efficient
handling.
Change the functions that process pseudo-ops accordingly.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
a) Fix a number of missing instances of DZ and ZWORD.
b) NASM would crash if TIMES was used on an instruction which varies
in size, e.g. JMP. Fix this by moving the handling of TIMES at a
higher level, so we generate the instruction "de novo" for each
iteration. The exception is INCBIN, so we can avoid reading the
included file over and over.
c) When using the RESx instructions, just fold TIMES into the reserved
space size; there is absolutely no point to iterate over it.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
A simpler, and actually correct fix for the listing address for
TIMES. The listing interface is quite frankly insane, but it probably
is better to fix it in 2.14+ and not in the maintenance branch.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This reverts commit 440ba7e13e.
The fix is wrong; it causes the listing file to *only* show <rept>,
without showing the first iteration.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
We need to set the listing offset before calling LIST_TIMES, but we
had already advanced data.offset by calling out(). Move the call to
lfmt->set_offset() and lfmt->uplevel() to the top and out of the loop;
there is no reason for it to be in the loop in the first place.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
The legacy output doesn't distinguish between segments and other
addresses, so we need to force the offset to zero before passing it
down to the output layer.
This addresses BR 3392406.
Reported-by: <rugxulo@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
It was incorrectly set to 01b in some cases when where it should be 10b.
Fixes BR 3392402.
Signed-off-by: Henrik Gramner <henrik@gramner.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
The fvm: annotation to generate the correct EVEX compressed
displacements had inadvertently gotten dropped from a handful of
instructions in checkin c33d95fde9:
BR 3392370: {z} decorator allowed on MOVDQ* memory operands
Put them back, and verify they work.
Reported-by: Henrik <henrik@gramner.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>