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>
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>
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>
..@ 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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
"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>
-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>
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>
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>
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>
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>
We have hardcoded ERR_NOFILE in a number of places which really should
not need them, and it represents loss of information. Instead, be
robust in the handling either of no filename or no line number.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
For specially formed code we can have skip_white_
to end up with nil pointer which should be taken
into account.
https://bugzilla.nasm.us/show_bug.cgi?id=3392435
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
In case if smacro is called with inapropriate
number of arguments exit early. Actually we have
to handle this situation more gracefully but
this requires a way more efforts than two
line patches (need to refactor macro expansion).
https://bugzilla.nasm.us/show_bug.cgi?id=3392431
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.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>
For some output types, the bit size, globalbits, follow the section
(segment); make sure we actually update it!
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
For many (most?) targets these will be very small functions, so inline
them. However, just in case make these external library functions.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
When using the -MW option, enclose whitespace-containing filenames in
double quotes. There are probably quite a few other things we ought
to know how to do...
Signed-off-by: H. Peter Anvin <hpa@zytor.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>
Allow NASM to generate Watcom-style Makefile dependencies, in addition
to the default POSIX-style Makefile dependencies.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Use nasm_add_string_to_strlist() to avoid a memory leak.
nasm_add_to_strlist() requires that the caller manages the string
being added or not.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Some OMF toolchain can make use of file dependency information
embedded in the object files. As implemented here, we don't try to
absolutize the filenames, as that prevents moving around trees and is
OS-dependent.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This fixes the dependency listings as generated with -MD (if
assembling runs in multiple passes).
https://bugzilla.nasm.us/show_bug.cgi?id=3392420
gorcunov@: add missing zero byte
Signed-off-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
In some circumstantes this free is incorrect resulting
in usage after-free. Workaround it by not freeing memory
here.
https://bugzilla.nasm.us/show_bug.cgi?id=3392414
gorcunov@:
- slightly tuneup the comment
Signed-off-by: Adam Majer <amajer@suse.de>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This fixes the dependency listings as generated with -MD (if
assembling runs in multiple passes).
https://bugzilla.nasm.us/show_bug.cgi?id=3392420
gorcunov@: add missing zero byte
Signed-off-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Do all the generation and conversion of the compiler timestamp in one
place and make it available to modules.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
In some circumstantes this free is incorrect resulting
in usage after-free. Workaround it by not freeing memory
here.
https://bugzilla.nasm.us/show_bug.cgi?id=3392414
gorcunov@:
- slightly tuneup the comment
Signed-off-by: Adam Majer <amajer@suse.de>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.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>
There is no point in showing a number of a relative segment, so just
show [ssss]; even if there is a possible segment offset it is
linker-dependent and output format dependent.
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>
Remove casts from allocations. This is simply Not How To Do Things:
every cast carries a potential risk of being a toxic type misuse
(e.g. pointer as integer) and so any unnecessary cast is actively
harmful.
Note that a lot of allocations here are completely unnecessary: the
core code now guarantees that all filenames are permanently allocated
for the duration of the assembly, and so should be turned into const
char * without any further allocation. Any remaining malloc+strcpy
should be turned into nasm_strdup(), and nasm_new[n]() used whereever
possible.
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>
It turns out that the calculation of "twopwr" in ieee_flconvert_bin()
was more complex than necessary, and wrong in the case of a pure
fraction.
Reported-by: Roel <roelsuidgeest@zonnet.nl>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Add a generic facility for generating perfect string hashes, where all
that is needed is an enum and a string table. The existing mechanism
using a custom Perl script wrapped around a module continues to be
available for any use case where this particular approach isn't
sophisticated enough.
Much of this patch comes from renaming "enum directives" to "enum
directive" as a result of the string hash generator expecting a set of
uniform naming conventions.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
The 2-operand form was inherently unsafe. Use the 3-operand form
instead, which guarantees that arbitrary filenames are supported.
This also means we can remove a few instances of sysopen() which was
used for exactly this reason, however, at least in theory sysopen()
isn't portable.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Remove the list file before running the first pass, so in case we
die before running pass 2 then there won't be a stale list file
sitting around.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Checkin c33d95fde9:
BR 3392370: {z} decorator allowed on MOVDQ* memory operands
... inadvertently broke broadcast operations, which only apply to
memory operands and therefore were only handled in one of the two
brace-parser implementations. Fix that.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Passing an object to nasm_zero() allows us to use it on arrays.
Otherwise the array will decay to a pointer and silently clear only
the first member of the array!
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
When we make an artificial RESB instructions (due to isolated
prefixes) we need to make sure there isn't any crap left in the
operands structure. The easiest way to guarantee that is to force it
to zero.
Reported-by: Henrik <henrik@gramner.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
The spec says very clearly the {z} decorator is allowed on memory
operands for the MOVDQ* instructions. Remove special cases from the
code to disallow this case, which had the unfortunate effect of
generating a very uninformative error message.
Reported-by: Agner <agner@agner.org>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
A raw data dump can potentially be very large, especially when
incbin is used. Allow a %pragma for setting the maximum dump
size (defaults to 128 bytes.)
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Update the debug output format to dump (most of) the information that
is available via the new backend format, as well as the legacy backend
format -- probably the only backend ever which will ever want both!
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
There is no reason to keep a private copy of the value of
"globalbits", which needs to be kept in sync anyway. With the move of
directive processing to a separate file, this variable wasn't kept up
to date, resulting in failures.
This resolves BR 3392390.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
If a displacement is as large as the address size currently in use
(which is the norm except for 64-bit code), then we should use
OUT_WRAP rather than OUT_UNSIGNED; the sign doesn't matter at all.
This resolves BR 3392391.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Implement the MachO do_dead_strip directive, which sets a flag on the
corresponding section. This as well as subsections_by_symbols are
reimplemented as pragmas; if someone uses the predefined macro they
still get the expected behavior.
However, this allows someone to write:
%pragma macho subsections_by_symbols
... and have it ignored if compiling for, say, ELF.
Also, implement the following section attributes:
zerofill, no_dead_strip, live_support, strip_static_syms
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
If the handler is NULL, then all pragmas are by definition unknown, so
treat them exactly as if we had received DIRR_UNKNOWN from the
handler.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Very few things have any desire to do its own string parsing, and the
directives hash is already a plain string-to-numbers O(1) hash. The
namespace is small enough that even if it makes some switch statements
compile a bit larger there is no real reason to have separate hashes,
even if the actual code as opposed to the data structure was shared.
So, for right now, just throw them together in one big happy pot.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Make -Werror possible to control on a per-warning-class basis. While
I was fixing up that code anyway, merge the handling of the -w, -W and
[warning] argument and directives.
Furthermore, make *all* warnings suppressible; any warning that isn't
categorized now belong to category "other". However, for cleanliness
sake an "other" option does not get listed in the warning messages.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
The "subsection_via_symbols" directive simply sets a flag in the
Mach-O file header.
Requested in BR 3392367.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
The directives code is already trying to do a bit more unified error
handling, so give ourselves a bit richer interface. At this point,
the conversion was pretty automatic so we probably return DIRR_OK
instead of DIRR_ERROR in a fair number of places, but that's okay.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Global variables need to be declared in a header file; "extern" in C
files should be used extremely rarely (it is OK at least for now for
macro tables as they are generally only ever used in one specific
location, but otherwise, no.)
In a few cases the global variables were actually function-local!
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Move directive processing to its own file, and move nasmlib/error.c to
asm/error.c (it was not used by the disassembler); remove some extern
declarations from .c files, and do some general code cleanups.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
We want to move the directive handling to a separate file, so change
the filename of the directive table handler to something a bit more
specific.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Move the directive parsing out of the main loop into a separate
function. It is much cleaner this way, and opens up for further
refactoring -- a bunch of the directives do the same thing or very
similar things.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
When we are generating a signed byte operand, we anyway have to do the
overflow check "manually". After doing so, output the result using
out_rawbyte() instead of out_imm(), so we don't end up doing a
redundant, and incorrect, second overflow check.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This reverts commit fbb07d6843.
This change was quite wrong; it is explicitly there to verify the
validity of the value as a 16/32/64-bit number, not it's
8-bit-worthiness.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
It is very rare that it makes sense to warn on pass 1. Instead, do
all the overflow warnings in pass 2.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
For byte immediates that are sign-extended to a wider operand size,
simplify the code and make the warning code behave as what is
expected.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Remove casts in switch statements that were intended to keep
OpenWatcom happy. It didn't work, and now we have a more general
solution for the problem, which also ought to be less dangerous.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Most of the time we don't need the dumping code, so move it to a
separate C file to the linker can exclude it.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
There is absolutely no reason to call reloc_value() twice while
processing an immediate. Doing so is both expensive and unnecessary.
Make some more deliberate decorations to try to avoid miscompilation
on OpenWatcom, but I'm not sure this will help enough.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Use PRId64 instead of %ld to print a 64-bit number. This is debugging
code, but as it is frequently useful I included it in mainline code
and, well, then it has to compile everywhere...
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
We can remove OUT_ADDRESS relocations for absolute addresses (NO_SEG),
but for OUT_RELADDR relocations we can remove them if they point into
*our own segment*, not NO_SEG.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
For expressions like [foo - $] or [bar - $$] our relocation base is
not the same as the end of the instruction. Make that explicit.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Handle, hopefully correctly, self-relative expressions (that is,
expressions of the form X - Y where Y is a symbol in the current
segment, possibly $ or $$) used as offsets or immediates, as opposed
to arguments to Dx statements (which have already been supported for a
while.)
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
In commits e1f985c167 and f7606613d0
we reordered macros handling, but ofmt specific
macros are to be handled after standart ones
are processed.
In particular __SECT__ handling must not change,
so the order of inclusion does matter.
https://bugzilla.nasm.us/show_bug.cgi?id=3392376
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
fixes pvs-studio error 'V707 Giving short names to global variables
is considered to be bad practice. It is suggested to rename 'sb' variable.
gorcunov@: Use local non-static variable.
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
fixes pvs-studio error 'V707 Giving short names to global variables
is considered to be bad practice. It is suggested to rename 'i' variable.
gorcunov@: Simply define it as local variable.
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
fixes pvs-studio error 'V507 Pointer to local array 'debugid' is
stored outside the scope of this array. Such a pointer will become invalid.'
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Fix pvs-studio error 'V501 There are identical sub-expressions
'(c) == '_'' to the left and to the right of the '||' operator.'. isnumchar()
is a macro defined as (nasm_isalnum(c) || (c) == '_')
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
fix pvs-studio error 'V501 There are identical sub-expressions '(c) == '_'' to
the left and to the right of the '||' operator.'. isnumchar() is a macro
defined as (nasm_isalnum(c) || (c) == '_')
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Instead of using hacks or compiler-specific features, if we have
standard features as defined in ISO C11, use them.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Allow constructs like:
dd foo - $
... where foo is an external symbol. Currently this is only
implemented for extops, i.e. dx opcodes.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Plumb the %pragma directive through the preprocessor and make it
generate an assembly directive unless given as %pragma preproc. So
far no actual pragmas are actually defined.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
We search the dependency list anyway (ouch...) so we might as well
use that instead of keeping track of a tail pointer.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Always return found_path as a constant string. We end up making an
internal copy of it anyway to put in the fullpath hash, so there is no
reason to make a duplicate of it.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Scan the command line twice, so we among other things can set up the
proper preprocessor before calling any of the preprocessor entry
points.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
We have been doing a pathname search every time we encounter a file,
which means every file in every pass. Instead, put the pathnames
found in a hash table.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
An INCBIN "instruction" can be enormous (up to an off_t size.) There
is no reason to burden the rest of the code by widening the inslen and
insoffs fields just for INCBIN, so set inslen == 0 to indicate fields
not valid.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
If we can't mmap a file and instead have to fread(), if the data is
small enough that we can reasonably accomodate it in a memory buffer,
then just read it once.
It seems rather unlikely that very large files would be used with
TIMES anyway.
Also note: the previous comment about nasm_file_size[_by_path]() being
invoked twice was spurious; it does not actually happen.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
A number of fairly common operations are invoked way too many times,
especially when using incbin. Drastically reduce the number of system
calls that need to be executed, and use memory mapping to reduce
unnecessary double buffering.
We could improve this further by leaving files open once used;
however, that might run into file count problems on some systems.
Still unclear is why we seem to invoke nasm_file_size() twice per pass
for incbin.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
For EVEX instructions, /is4 can contain a fifth register bit, encoded
in bit 3 of the imm8. Properly generate this case, and simplifiy the
/is4 generation code somewhat.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Cherry picked and ported from nasm-2.12.xx commit
976ba73062.
Resolved Conflicts:
asm/assemble.c
This provides the first pass of assembler internals for a new, richer,
backend interface. It also reduces the amount of data carried in
function parameters inside the assembler.
The new interface is in the form of a structure, which will contain
substantially more information that the previous interface. This will
allow things like ELF GOT32X and Mach-O X86_64_RELOC_BRANCH
relocations to be reliably emitted.
This provides the initial set of structures. Future additions should
include:
1. Pass down the base symbol, if any.
2. Segments should be a structure rather than a number, and the
horrible hack of adding one for a segment reference should be
removed (OUT_SEGMENT replaces it.)
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
The ordering of the macro sets ended up changing due to the recent
file reorganization. Instead of forcing the order again, handle
multiple macro sets (rather than just two) in a coherent manner.
macros/macros.pl could use a cleanup of duplicated code, however.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Make the source code easier to understand and keep track of by
organizing it into subdirectories depending on the function.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>