Commit Graph

138 Commits

Author SHA1 Message Date
H. Peter Anvin
53e2e4c099 nctype: add nasm_isquote()
Add nasm_isquote() to test for a NASM quoted string.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-28 15:01:40 -08:00
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
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
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
a0ed5b3ffa Merge branch 'master' of ssh://repo.or.cz/nasm 2018-11-28 09:56:15 -08: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
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
H. Peter Anvin (Intel)
f7106d06e4 strlist: use a hash table
Use a hash table to enforce uniqueness in a string list. It is still
an ordered list, however, and can be walked in insertion order.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-10-25 12:33:58 -07: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
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
3bb1dd0bee eval: add spaceship operator <=>
<=> returns -1, 0, or 1 depending on the ordering of two values.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-06-15 18:46:11 -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