Commit Graph

71 Commits

Author SHA1 Message Date
H. Peter Anvin
86b2e93081 assemble: fix too aggressive dropping of overflow warnings
Drop down to OUT_WRAP when the size is big enough, as opposed to not
doing any tests at all.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 18:20:07 -07:00
H. Peter Anvin (Intel)
41e9705054 assemble.c: fix signed/unsigned comparison warning
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>
2019-08-19 15:47:36 -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)
02b60ddd1c LEA: allow immediate syntax; ignore operand size entirely
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>
2019-08-14 15:23:00 -07:00
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
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
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 (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
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
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
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)
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)
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)
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)
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
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
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
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
H. Peter Anvin (Intel)
e8ceba5979 assemble: defer MERR_OPSIZEMISSING
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>
2018-06-28 02:22:55 -07: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
c51369067c errors: simplify nasm_fatal() and nasm_panic()
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>
2018-06-15 18:20:17 -07:00
H. Peter Anvin
ed859f72a1 output: remove ABSOLUTE handling, OUT_RAWDATA asserts
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>
2018-06-15 00:03:53 -07:00
Chang S. Bae
427d8e3e57 output: macho -- Avoid conversion of addresses to RAWDATA
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>
2018-05-05 23:44:33 +03:00
H. Peter Anvin
1b53750430 Merge tag 'nasm-2.13.03'
NASM 2.13.03

Resolved Conflicts:
	include/iflag.h
	version
	x86/insns-iflags.ph

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-02-07 13:51:54 -08:00
H. Peter Anvin
a7ecf2646d iflag: automatically assign values, saner handling of CPU levels
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>
2018-02-06 14:43:07 -08:00
H. Peter Anvin
ece809789e Merge remote-tracking branch 'origin/nasm-2.13.xx'
Resolved conflicts:
	version

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-11-01 10:37:18 -07:00
H. Peter Anvin
89215e9e37 Remove duplicate warnings for immediate overflow
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>
2017-10-11 13:14:01 -07:00
H. Peter Anvin
94ead27971 BR 3392437: Fix diagnostic for negative value in TIMES
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>
2017-09-27 15:22:23 -07:00
H. Peter Anvin
fbce0bfb4e Merge remote-tracking branch 'origin/nasm-2.13.xx'
Resolved Conflicts:
	asm/directiv.dat
	asm/preproc.c
	misc/omfdump.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-08-16 22:41:40 -07:00
H. Peter Anvin
ff04a9ffe8 BR 3392421: consider mode decorators in instruction matching
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>
2017-08-16 21:48:52 -07:00
Martin Storsjö
869087d53d Use cpu_to_le64 instead of htole64
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>
2017-05-24 10:19:56 -07:00
H. Peter Anvin
a7b6bfca68 Sanitize the handling of segments a bit
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>
2017-05-03 17:33:04 -07:00
H. Peter Anvin
af9fe8f597 Don't sort opcodes; move all pseudo-ops to the beginning
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>
2017-05-01 21:44:24 -07:00
H. Peter Anvin
d23066906c incbin: remove pointless call to lfmt->set_offset()
We already have the correct offset; otherwise the times == 1 case
would not work.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-05-01 21:29:05 -07:00
H. Peter Anvin
3e458a89d8 a) Fix handling of DZ/ZWORD; b) don't crash on TIMES JMP
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>
2017-05-01 21:13:15 -07:00
H. Peter Anvin
5810c594c9 listing: fix base address for TIMES
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>
2017-05-01 19:51:09 -07:00
H. Peter Anvin
5f93c9597d Revert "asm/assemble.c: correct the listing address for TIMES"
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>
2017-05-01 19:44:34 -07:00
H. Peter Anvin
440ba7e13e asm/assemble.c: correct the listing address for TIMES
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>
2017-05-01 15:39:15 -07:00
H. Peter Anvin
217e714e6b output/legacy.c: OUT_SEGMENT -> OUT_ADDRESS with a zero addend
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>
2017-05-01 15:10:47 -07:00
Henrik Gramner
16d4db3aab Fix ModR/M.mod for EVEX instructions
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>
2017-04-20 17:48:44 -07:00
H. Peter Anvin
e83311c73d BR 3392396: fix EVEX compressed displacements
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>
2017-04-06 18:52:08 -07:00
H. Peter Anvin
8f62246560 Further improve error messages for confused decorators
Try to generate more sensible error messages for bogus combinations
of decorators.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-02 19:02:29 -07:00