Commit Graph

166 Commits

Author SHA1 Message Date
Cyrill Gorcunov
da3780dc22 Fix small typo in comment
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-09-22 14:10:36 +03:00
Cyrill Gorcunov
69bb052e00 asm: Restore showing output for preproc mode in stdout
Before the commit 81b62b9f54
we've been always putting -E,-e results into stdout if no
output file provded. So bring this backward compatibility
back.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-09-22 13:46:45 +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
af59af466a float: fix bogus pass flags for errors and warnings
Formatting errors -- syntax errors -- are errors, no matter which pass
they end up in.  ERR_PASS1 is just plain crazy: if we end up with a
formatting error on the code-generation pass, we are in a world of
hurt.

Defer warnings to the code-generation pass; that's the pass which
matters value-wise, and that way we get the warnings in the list file,
too.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-07-06 03:11:52 -07:00
Adam Majer
c7c28357c8 asm/float.c: fix buffer underflow in float parsing
When we suffer an underflow that cross limb boundaries, it is possible
to end up with a stack underflow.  Put in an explicit check for this
case (the mantissa will be zero in this case.)

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

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
diff --git a/asm/float.c b/asm/float.c
index dcf69fea..2965d3db 100644
--- a/asm/float.c
+++ b/asm/float.c
@@ -608,6 +608,8 @@ static void ieee_shr(fp_limb *mant, int i)
         if (offs)
             for (j = MANT_LIMBS-1; j >= offs; j--)
                 mant[j] = mant[j-offs];
+    } else if (MANT_LIMBS-1-offs < 0) {
+        j = MANT_LIMBS-1;
     } else {
         n = mant[MANT_LIMBS-1-offs] >> sr;
         for (j = MANT_LIMBS-1; j > offs; j--) {
2018-07-06 03:08:15 -07:00
Cyrill Gorcunov
70d429676b labels: Add missing backend type for extern symbols
Typo in 98578071b9

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-07-01 02:00:12 +03:00
Cyrill Gorcunov
a8e3d6a836 labels: Shrink declare_label
No need to pass unused 'created', find_label can
handle nil here.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-06-30 20:02:24 +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 (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 (Intel)
12810fac92 nasm.c: min 2 optimization passes, don't re-run pass 1
We may not even have the most basic stabilization done unless we run
at least two optimization passes, e.g. in the case of subsections.
However, we cannot run more than one stabilization pass (pass0 == 1);
for one thing we'll call ofmt->symdef() multiple times on the same
symbol, which is not allowed.  If we haven't achieved stability by the
time we decide to run a stabilization pass, plod on and hope for the
best.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-27 20:17:33 -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
Chang S. Bae
1af6ef4e14 nasm: fix some typo and description for the option help
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 14:14:44 -07:00
H. Peter Anvin (Intel)
415b6b3df1 absolute: in absolute space, need to use absolute.segment
We can be in absolute space and still end up with segment-relative
references.  This is in fact the meaning of absolute.segment.  Make
sure we define the labels appropriately.

Reported-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 14:09:52 -07:00
H. Peter Anvin, Intel
c5e45f6b70 labels: auto-promote EXTERN labels to GLOBAL if defined
If we define a label which was previously declared EXTERN, then
automatically treat is as GLOBAL.

Previously, we would fail to converge and loop forever, which is
obviously not what we want.  This is more user-friendly anyway.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 13:16:53 -07:00
H. Peter Anvin, Intel
4fb2acc0d3 labels: if we have overridden EXTERN, don't call define_label()
If we have overridden EXTERN, then we should not call define_label()
on it again.  Return a fail status from declare_label(), indicating
that the type declaration failed, but of course we don't print an
error message.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 13:11:01 -07:00
H. Peter Anvin, Intel
2139874de2 labels: fix formatting of warning message
Output was backwards...

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 13:03:39 -07:00
H. Peter Anvin, Intel
87d9e626c3 nasm: need to call init_labels() before command line parsing
The prefix and suffix options call perm_alloc() in labels.c, which is
not available until init_labels() have run.  There is no reason not to
call init_labels() early.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 12:58:49 -07:00
H. Peter Anvin, Intel
bc77f9c587 labels: don't update the local variable base for *ANY* dot labels
..@ labels (macro-local) are NASM specials, although not "magic": they
are explicitly defined to not preturb the local label base name.
However, they return false for both islocal() and ismagic(), so we
need to add a new function containing the correct test for when the
local label base should be advanced.

Reported-by: <balducci@units.it>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Cc: Bae, Chang Seok <chang.seok.bae@intel.com>
2018-06-25 12:45:14 -07:00
H. Peter Anvin
a7c8e39686 labels: pass the mangled name to the backend for fixups
ofmt->symdef() always takes the mangled label name, make sure we
actually do the correct thing even for forward fixups.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-18 14:17:26 -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
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
14a10935f7 Merge commit '7daa26f9ba3ca45813d16ce540564448c13b16fa' into nasm-2.14.xx
Merge in some warning workarounds/possible bugs discovered by a recent
gcc.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-06-15 17:25:57 -07:00
H. Peter Anvin
46c839a03d labels: allocation of a segment number counts as a change
If we allocate a new segment number, that has to cause
global_offset_changed to be incremented.  Thus, we should not update
lptr->defn.segment until that would ordinarily be done.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 20:00:07 -07:00
H. Peter Anvin
af5f918a92 Don't keep assigning segment numbers to EXTERN or COMMON
If a symbol is EXTERN or COMMON, then we should not keep assigning it
new segment numbers over and over. Instead, change the label code so
that it assignes a new segment value if and only if one has not been
assigned before.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 19:53:45 -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
c805fd774d Fix parsing of long options; actually warn on bad limit
Fix the parsing of long options (arguments with = broke things.)

Actually issue a warning if we specify a wrong limit on the command
line.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-12 14:23:05 -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
Cyrill Gorcunov
a7f318c307 directive: Make cpu directive case insensitive back again
During code suffle we occasionally made cpu directive to
take letter case into account despite the documentation.

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

Reported-by: Rebecca Cran <rebecca@bluestop.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-06-07 00:06:58 +03:00
H. Peter Anvin
7daa26f9ba gcc: fix mistakes discovered by recent gcc
Recent versions of gcc issue a couple of warnings, which may be real
bugs.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-06-02 23:48:16 -07:00
H. Peter Anvin
3cb9068ee0 asm/directiv.c: fix bug in perm_alloc()
Fix dumb thinko in perm_alloc().

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-01 21:05:45 -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
b7136487bd pragma.c: make the generic "output" and "debug" pragma namespaces work
"output" and "debug" are supposed to redirect to the current output
and debug formats. Fix it so it actually does.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-05-30 14:42:06 -07:00
H. Peter Anvin
6d36d8684c Fix implicit fallthrough that trips -Werror
-Werror now trips on implicit fallthroughs. There is also at least one
that probably should not be, although it appears to be harmless.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-05-08 12:45:00 -07:00
Chang S. Bae
f0ceb1e122 assemble: Check global line limit
Without the limit, the while loop opens to semi-infinite
that will exhaustively consume the heap space. Also, the
index value gets into the garbage.

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

Reported-by : Dongliang Mu <mudongliangabcd@gmail.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
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
72fd205bcf Revert "Use fallthrough() to placate compiler"
This reverts commit 8a7c6009fb.
2018-02-25 22:25:07 +03:00
Cyrill Gorcunov
8a7c6009fb Use fallthrough() to placate compiler
https://bugzilla.nasm.us/show_bug.cgi?id=3392465

Reported-by: Ozkan Sezer <sezeroz@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-02-25 17:21:54 +03:00
Cyrill Gorcunov
8a231080e0 get_cpu: Fix a7ecf2646d
The call to iflag_clear_all has been occasionally dropped,
bring it back.

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

Reported-by: sezeroz@gmail.com
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-02-25 13:25:19 +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
3366e31b8a asm: allow abort on panic to be specified at runtime
New option --abort-on-panic to make debugging easier.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-02-07 14:14:36 -08: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
dcbaf677d4 error: add --enable-panic-abort config options
For debugging purposes, make it possible to force calling abort() on
ERR_PANIC.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-12-20 12:10:33 -08:00