Commit Graph

126 Commits

Author SHA1 Message Date
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
3c755dac88 opflags: Convert is_class and is_reg_class to helpers
So we can test for out of bound access and make
helpers safe to use.

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

Reported-by: Jun <jxx13@psu.edu>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-13 22:57:30 +03:00
Cyrill Gorcunov
0bdd7f1546 opflags: Style unification
No func change.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-01 01:09:43 +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)
b45c03ab42 asm: add a default-off warning for phase error in pass 1
Add a default-off warning for phase error in pass 1.  This is default
off because of the lateness in the release cycle, but cases where we
have such instability should be investigated further.  For now, the
warning is here so we can debug these problems in the field.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-27 21:03:38 -07:00
H. Peter Anvin (Intel)
d644119ded subsections: don't lose the offset in the parent section
We don't want to lose the offset into the parent section when we
create a subsection, at least not for the MachO backend which is
currently the only user of subsections. Allow ofmt->herelabel() to set
a flag to copy the section offset from the previous section.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-27 20:20:21 -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
2c57d0a5ca RAA: make pointer vs integer RAAs type safe
Use pseudo-types to make it impossible to confuse RAAs made of
integers and RAAs made of pointers.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-18 17:11:54 -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
H. Peter Anvin
8eb3096f7a nasm.h: remove unused constants
Remove unused constants for prefix and suffix, long since obsolete.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-18 11:12:49 -07:00
H. Peter Anvin
94adf7d765 eval: add support for signed shift operators <<< and >>>
Add support for signed shifts.  The operators are <<< and >>>,
although the former is (inherently) idntical to <<.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-06-15 18:37:32 -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
79561027a0 Make limits 64 bits, add globallines limit to configurable limits
Make all limit counters 64 bits, in case someone really has a usage
for an insanely large program. The globallines limit was omitted, add
it to the list of configurable limits.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-06-15 17:57:15 -07:00
H. Peter Anvin
a3d96d02b0 Make limits 64 bits, add globallines limit to configurable limits
Make all limit counters 64 bits, in case someone really has a usage
for an insanely large program. The globallines limit was omitted, add
it to the list of configurable limits.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-06-15 17:56:25 -07:00
H. Peter Anvin
e803010163 nasm.h: remove unused constants
Remove unused constants for prefix and suffix, long since obsolete.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 20:28:57 -07:00
H. Peter Anvin
903ea54857 RAA: clean up the RAA infrastructure, make it support larger indicies
Make the RAA infrastructure a bit cleaner, make it support 64-bit
indicies, and reduce the memory overhead of a sparse or small RAA --
the old code would allocate a *minimum* of 256K for each RAA.  The new
code reduces that to 16K, and will not mandatorily allocate an entry
in the zero position.

The new shift, 11, was chosen so that a 32-bit RAA value will need 3
layers and a 64-bit value 6 layers, without excessive waste.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 20:23:49 -07:00
H. Peter Anvin
9401f81416 ilog2: return unsigned int for applicable routines
For the routines where we can't return a negative value, return an
unsigned value.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 19:20:08 -07:00
H. Peter Anvin
29695c85fb labels: add a subsection field available for backend use
Allow the subsection to store a subsection value directly in the
label, rather than having to do strange encoding hacks.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 17:04:32 -07:00
H. Peter Anvin
13587802fe segalloc: DO NOT reset segment numbers
We are not supposed to reset the segment numbers; this was an
attempted fix for a convergence bug that didn't actually exist. The
backend is required to return the same segment number for the same
segment; if it does not, the front end will not converge, but that is
in fact the correct behavior.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 16:42:03 -07:00
H. Peter Anvin
e39202c96a RAA: add functions for storing pointers in RAA's
RAAs can, and should be, usable for storing pointers as well as
integers. In reality it is exactly the same code, but make it explicit
by having different entry points.  In the actual RAA the data is
stored as a union, which in practice will not occupy any more space
than the existing code.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 16:05:34 -07:00
H. Peter Anvin
987dc9c9db Make any execution limit configurable, add eval limit
Make any "deadman"-style execution limit configurable on the command
line (--limit-foo) or via a pragma (%pragma limit foo).

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-12 13:54:42 -07:00
H. Peter Anvin
734824823e Unbreak special segment symbols, unbreak COMMON
Recent changes broke:

1. Backend-provided special segments, due to seg_alloc() getting
   reset.
2. COMMON; the old code would pass size in the "offset" *without*
   setting it in the label structure. Containing all this information
   in the label structure requires another field.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-11 14:54:14 -07:00
H. Peter Anvin
0599034321 Add --pragma and --before option; make --include = -P
Add --pragma to add pragmas on the command line; --before option to
add *any* statement on the command line, and add --include as an alias
for -P for familiarity with other toolchains.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-11 13:32:42 -07:00
H. Peter Anvin
98578071b9 Cleanup of label renaming infrastructure, add subsection support
In order to support Mach-O better, add support for subsections, as
used by Mach-O "subsections_via_symbols". We also want to add
infrastructure to support this by downcalling to the backend to
indicate if a new subsection is needed.

Currently this supports a maximum of 2^14 subsections per section for
Mach-O; this can be addressed by adding a level of indirection (or
cleaning up the handling of sections so we have an actual data
structure.)

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-01 18:06:25 -07:00
H. Peter Anvin
892c4818ce Add support for backend-defined subsections and label hacks
MachO has this odd thing called "subsections via symbols", by which a
symbol can magically start what effectively is a new section. To
support this, add support for a calldown into the backend when a new
symbol is defined *at the current output location*, and allow it to
switch the current segment.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-05-30 14:48:18 -07:00
H. Peter Anvin
740ec3572b malloc: simplify nasm_malloc code, add nasm_strcatn()
Simplify the nasm_malloc() code by moving the pointer check into a
common subroutine.

We can now issue a filename error even for failures like malloc().

Add support for the gcc sentinel attribute (verify that a list ends
with NULL).

Add a handful of safe_alloc attributes.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-05-30 11:40:42 -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
Cyrill Gorcunov
dd6a2cdcf4 Revert "compiler: Add fallthrough() helper"
This reverts commit 8ba28e13ea.
2018-02-25 22:25:57 +03:00
Cyrill Gorcunov
8ba28e13ea compiler: Add fallthrough() helper
https://bugzilla.nasm.us/show_bug.cgi?id=3392465

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-02-25 17:09:11 +03:00
Cyrill Gorcunov
fff27ab229 compiler: Fix typo in 6686fc6
https://bugzilla.nasm.us/show_bug.cgi?id=3392464

Reported-by: sezeroz@gmail.com
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-02-24 15:11:32 +03:00
H. Peter Anvin
281f5bd92c Merge branch 'master' of ssh://repo.or.cz/srv/git/nasm 2018-02-22 14:53:46 -08:00
H. Peter Anvin
6686fc627e Introduce cold function attribute
Attribute to deemphasize certain code paths.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-02-22 14:52:50 -08:00
H. Peter Anvin
99d45c850e Fix problem with C99 inlines and -Werror=missing-prototypes
Some older versions of gcc (gcc 4.2.1 at least) produce a warning,
promoted to error, on C99 inlines.  Do some work to figure out if we
need to fall back to GNU inline syntax.

Fix some issues with GNU inline syntax.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-02-20 12:34:17 -08:00
Cyrill Gorcunov
53371ddd17 Merge branch 'nasm-2.13.xx'
* nasm-2.13.xx:
  nasmlib: Drop pure_func attrib from seg_alloc
  nasmlib: Drop unused seg_init
2018-02-10 00:44:07 +03:00
Cyrill Gorcunov
9f45a77f46 nasmlib: Drop pure_func attrib from seg_alloc
It not only reads static variable but writes it back as well.

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

Reported-by: Michael Šimáček <msimacek@redhat.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-02-10 00:40:46 +03:00
Cyrill Gorcunov
5eb1838b4d nasmlib: Drop unused seg_init
The helper has been eliminated in 2c4a4d5810

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-02-10 00:34:10 +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
81b62b9f54 Eliminate filename length restrictions, remote ofmt->filename()
Get rid of remaining dependencies on FILENAME_MAX, which ought to have
been removed a long time ago.

Remove ofmt->filename(); all implementations pretty much do the same
thing and there is absolutely no reason to duplicate that
functionality all over the place.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-12-20 13:38:20 -08:00
H. Peter Anvin
7a6bf74d02 error: add ERR_TOPFILE
Add ERR_TOPFILE, for cases where displaying the current file and line
are completely inappropriate.  Instead, display the main input file,
or, if not available, the output file.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-12-20 12:10:13 -08:00
H. Peter Anvin
f52ea70dd1 bytesex.h: more simplifications and add const
Add more simplifications where it is practical; unify WRITECHAR() as
it has no need for byte swapping in any way.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-11-29 17:19:27 -08:00
H. Peter Anvin
df5548a40c bytesex.h: make sure WRITE*() doesn't screw up on wrong pointer type
Make the WRITE*() macros independent of pointer type.  As it was, we
would get totally wrong result on X86_MEMORY machines if the pointer
was not uint8_t *.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-11-29 17:07:58 -08:00
H. Peter Anvin
7370483b00 bytesex.h: remove an unnecessary double expansion in WRITEADDR()
We can't really avoid the double expansion of (p), but the WRITE*()
macros all do that.  However, there is no reason to double-expand (s).

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-11-29 16:59:49 -08:00
H. Peter Anvin
8cdde2bbaa bytesex.h: simplify the trivial case of cpu_to_le*()
In the trivial case, cpu_to_le*() can just be macros containing a
single cast.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-11-29 16:56:59 -08:00
H. Peter Anvin
b533f545e4 compiler.h: HAVE___BUILTIN_CONSTANT_P has 3 underscores
HAVE_ + __BUILTIN_CONSTANT_P makes 3 underscores...

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-11-29 16:48:27 -08:00
H. Peter Anvin
03a5187c59 compiler.h: indentation cleanup
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-11-29 16:36:14 -08:00
H. Peter Anvin
b230622576 bytesex.h: unify and optimize WRITEADDR()
WRITEADDR() really doesn't need multiple implementations.  Unify them,
and optimize the case of a constant length argument (not sure if that
is currently used, however.)

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-11-29 16:05:59 -08:00
H. Peter Anvin
cb7da7e7f6 compiler.h: add is_constant()
Add macro is_constant() to return true if and only if the value is a
compile-time constant.  It may never return true, however.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-11-29 16:05:05 -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
aaefc7fe6b BR 3392442: correct vmin in overflow_general()
The calculation of vmin in overflow_general() was bogus, causing
silliness like ~80h being warned about in a byte context.

Reported-by: C. Masloch <pushbx@38.de>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-10-11 13:12:17 -07:00