Formalize the mechanism for storing mapped (non-filesystem) filenames
in the filenames array. These are not compared against input or output
files for overwrite checks.
Add the infrastructure for comparing more than one input filename
(future proofing.)
Move the Makefile dependency target name to the filenames system.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Add nasm_compare_paths(). At this point, the only effect is wide
character/case insensitivity canonicalization on Windows, but in the
future it might be doing things like comparing st_dev:st_inode pairs
on Unix or compare nasm_realpath().
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Adds an option to remap file prefixes in output object files. This is
analogous to the "-fdebug-prefix-map" option in GCC, and allows files to
be built in a reproducible manner regardless of the build directory.
[ hpa: this still needs to be documented in doc/running.src. ]
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
- Register the map file with the filename system.
- Check to see if the mapfile is clobbering the input.
- Remove the map file if the output file is also removed.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Replace the direct setting of variables for input and output variables
with accessors. This allows for properly tracking the lifetimes of the
data and allows for things like checking of the overwrite of the
primary input file to be centralized.
It isn't possible *in the general case* to check for overwrite of
*any* of the input files, although in the particularly important case
of the assembler proper it ought to be possible to do a bit better:
it should be able to guard for overwrites of non-primary input files
except for the error file or the list file if and only if -Lp is used.
That is, however, a latter project.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Add nasm_remove() to mangle a filename if necessary before calling
an OS-specific remove() function. This allows calling _wremove() on
Windows.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
It is common enough that one wants to set a string pointer to a newly
allocated string, freeing the old one if it is not NULL.
Add specific helper functions for this.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
filename_set_extension() always returns a newly allocated string
buffer, drop the "const" from the return type.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
nasm_assert_pointer() would fail with newer gcc when passed a void *,
because the construct sizeof(*(p)) is invalid for void pointers, as is
sizeof(&*(p)).
Instead, make use of the fact that the ternary operator ? : requires
type compatibility between the two sides, and const volatile void * is
type-compatible with any pointer.
Since some compilers are known to elide this check when one side is
NULL, make it a explicit pointer to an arbitrary
object cast to (const volatile void *). zero_buffer[] seems a logical
choice.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Allow limits to be queried via a %limit() preprocessor function and a
__?NASM_LIMITS?__ macro.
Reset limits at the top of each pass. Note that the pass number limits
are checked at the *end* of the pass, so a %pragma limit will be
properly honored anyway.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Revamp the limit processor to allow a limit to have an absolute
maximum other than LIMIT_MAX_VAL.
Use LIMIT_MAX as a final enum parameter == parameter count == final
actual value + 1, which is the more usual construct and doesn't need
manual updating.
Allow setting a limit to the default value by setting it to "0" or
"default".
Accept "max" or "maximum" instead of "unlimited", specifically to
better handle the case of a fixed maximum < LIMIT_MAX_VAL.
Change the mmacro limit parameter to a dynamic limit, in case someone
needs it.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Make saa_wleb128[us]() take uint64_t and int64_t, respectively, rather
than int.
Notably, if saa_wleb128u() were to receive negative int, it would have
looped forever.
Recode these functions in a style more consistent with NASM code in
general, and possibly a bit simpler.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
C2y adds \o for octal byte escapes, and allows \x, \o, or \u escape
sequences to be enclosed in braces to indicate their termination.
Add a \d sequence as a NASM extension to allow decimal bytes to be
specified.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
When using -LX to debug template selection, emit the specific template
number (as per insnsa.c) as well as the xda line number.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Adding information about the NASM internal state to the list file can
be useful for debugging purposes. Separate the list of options that
are "user" options and those that are "debugging" options. The latter
are not implied by -L+ and are intended for NASM developer use.
Introduce -LX, which lists which instruction patterns are matched by
each instruction.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Add the line number from insns.xda to struct itemplate. NASM itself
doesn't need this information, but it makes debugging matching *much*
easier; it is worth a few more bytes.
In theory it could be conditionalized on --enable-debug, but it is
probably not worth it.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
MOVDDUP tuple type uses a compression shift for the disp8 addressing
scheme. The shift depends on the vector lenght and is defined as 8 for
128 bits, 32 for 256 bits and 64 for 512 bits.
Current implementation doesn't work for the 128 bit vector case since
the expression used evaluates to 16 instead of 8. Fix it with a special
if check before the current expression is returned.
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
Move filename_set_extension() into path.c, so it has access to the
filesystem-specific character constants. This prevents something like:
nasm-code.d/foobar
... from getting truncated to ...
nasm-code.bin
... instead of producing ...
nasm-code.d/foobar.bin
Make the extension character (normally '.') configurable; this MIGHT
be usable on RISCOS at some point, although it is not entirely clear
that trying to make sense of RISCOS paths actually is meaningful,
because RISCOS compiler chains seem to do all kinds of path
translation magic trying to behave like other operating systems... it
might simply be more trouble than it is worth, especially for a
non-x86 platform.
As a side bonus, this removes the only use of strrchrnul(), so that
function can be dropped.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Tidy up a *lot* of code by moving error functions into separate source
files. This required breaking out some of the assembler-only files
into a separate library, as it conflicts with stubs in the
disassembler.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Re-introduce ERR_HOLD, which means that an error is treated like a
warning except for the last pass, but unlike ERR_PASS2 the error
message *will* be issued if another error happens on the same pass, just
like warnings.
This will be used to improve error messages on instruction mismatch.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
C23 defines unreachable() as a macro in <stddef.h>. For earlier
versions of gcc, __builtin_unreachable() is possible.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The test needs to test for neither nor; as it was it tested "(not C++)
or C23" which was not at all what was intended...
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The C++-style cast-to-bool hack was broken in concept that it doesn't help the
fundamental problem -- implicit conversions are broken for the
backwards compatibility enum definition -- as well as in
implementation, as it misspelled __STDC_VERSION__ as __STDC_VERSION.
The #ifdef bool test *should* have prevented this problem, but
apparently several compilers do define "bool" in <stdbool.h> even when
it is a keyword, in violation of the C23 spec.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Make the spellings for the label-mangling options and pragmas
consistent, and implement the directive forms which were documented
but never implemented.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The list_last() macro is a statement macro; wrap it in a
do { ... } while(0) block to prevent accidental misuse.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
You have to check that something that isn't standard C actually exists
before trying to use it...
Cc: Colin Ian King <colin.i.king@intel.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
SPDX is an international standard for documenting software license
requirements. Remove the existing headers and replace with a brief
SPDX preamble.
See: https://spdx.dev/use/specifications/
The script used to convert the files is added to "tools", and the
file header templates in headers/ are updated.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Add missing uses of PRI constants.
Create a PRI constant for size_t, since %z isn't available on all
platforms. Notably, the legacy Windows runtime needs %I instead of %z.
Use that on UCRT as well, since there doesn't seem to be a way to
determine if you are compiling for MSVCRT or UCRT.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
ISO C before C23 restricted enum ranges to type "int" (not even
"unsigned int"). This limits the usability of enums for bit fields,
but it still covers our main use cases.
On gcc/clang this just produces a warning, but who knows what other
compilers will do.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
When dealing with bitmasks/bitfields, definining them in macros tends
to cause a lot of desirable constants out because it is a pain to
create all of them. C macros can't create other macros, but they
*can* be used to create fields in an enum, so provide some neat
convenience macros for doing so.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Apparently the has_attribute() macro triggers false positives on at
least gcc 5.3, which is the version that the build server uses with
djgpp.
Drop using it, so much for trying to be standards-compliant...
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
- Add some features to autoconf that makes it cleaner and faster
- Modernize some of the autoconf macros
- Update compiler.h with some C23 features
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Convenience preprocessor functions that allows for efficient packing
of binary data in source code.
Move some functions that has previously been local but are more
generally useful into more accessible places.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The POSIX names for these functions are htole*(). Use those
preferentially.
Speed up autoconf by allowing early-out during alternative function
searches.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Making DEFAULT ABS the default for 64-bit mode was a real
mistake. Issue a warning so we can eventually change it.
Support making FS: and GS: references also be REL by default.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
If the shift amount is known, there is really no reason why we can't
accept "ROLX" as an alias for "RORX" with a modified shift operand.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Make the handling of messages saner. In particular, regularize the
handling of info and debug messages, so that nasm_info() and
nasm_debug() actually become useful.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Along with C and other languages, the current trend is to be able to
probe for features rather than relying on version numbers. This is
motivated in part by the intent of bumping the major version number to
3.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The use of $ prefixes for hexadecimal numbers conflicts with
the use of $ to escape symbols. Add a directive to disable
$ for hexadecimal numbers so that those escapes work OK.
As a result, allow escaped symbols to start with a digit.
Add a warning that this syntax is deprecated.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
If VEX.V is an immediate, it should not be subject to register range
checks.
If the WW flag is set, REX_W needs to be OR'd in, not XOR'd, because
the map might have the W bit set for matching purposes.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
- Significantly overhauled the disassembler internals to make
better use of the information already in the instruction template
and to reduce the implementation differences with the assembler
- Add APX support to the disassembler
- Fix problem with disassembler truncating addresses of jumps
- Fix generation of invalid EAs in 16-bit mode
- Fix array overrun for types in a few modules
- Fix invalid ND flag on near JMP
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Merge the macros used in the assembler and disassembler.
Simplify and slightly correct the byte order/unaligned handling macros.
Use <stdbit.h> from C23 if available for bytesex.h and ilog2.h.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>