"suffix" is the more common English term, but NASM used "postfix" for
a long time. Allow them as aliases, and tidy up the documentation
accordingly. While making these changes, tidy up the handling of
options in the index.
Fixes: https://github.com/netwide-assembler/nasm/pull/61
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
This is really just a shorthand for the --before option, but it is
really convenient for quickly writing multimode tests.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Generalize pp_pre_command() so that the first argument doesn't have to
be a preprocessor token. Instead, the two arguments are now both
turned into token streams, separated by a whitespace token.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Although one can implement this "manually" in terms of %sel(), this
function is *really* useful for making multi-mode tests and allows for
better error checking.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
If an instruction triggers an error (nasm_nonfatal) it is legitimate
for calcsize() to return 0; in that case no further processing is
needed.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The label-orphan warning is *way* more useful if it includes the
actual label name; this way the programmer can usually spot
immediately if it is a label or misspelled instruction.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
When compiled -fsanitize=undefined nasm produced this error message:
asm/preproc.c:2523:25: runtime error: member access within null pointer of type 'struct Token'
The problem is reproducible on tests avx512f, avx512cd, avx512pf
and avx512er in the test suite.
The problematic line was:
/* Advance to the next comma */
maybe_comma = &t->next; <<< HERE
while (tok_isnt(t, ',')) {
if (!tok_white(t))
comma = NULL; /* Non-empty parameter */
maybe_comma = &t->next;
t = t->next;
}
When t is NULL this line doesn't cause memory access, but it is still an
undefined behavior according to C standard.
I believe that the underlying problem is that this loop doesn't have a sound
invariant about maybe_comma:
* On first iteration: *maybe_comma == t->next
* On the following iterations: *maybe_comma == t
I don't know what the intended loop invariant is and I decided to just
mechanically fix the deferencing of NULL pointer, completely preserving
the existing behavior.
Signed-off-by: Ivan Sorokin <vanyacpp@gmail.com>
When running with -fsanitize=leak enabled nasm prints this error:
==19965==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 360 byte(s) in 90 object(s) allocated from:
#0 0x7faee9396867 in __interceptor_malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:145
#1 0x5645d39a401c in nasm_malloc nasmlib/alloc.c:55
#2 0x5645d3a41f9d in string_transform asm/strfunc.c:356
#3 0x5645d3a37d40 in eval_strfunc asm/eval.c:761
#4 0x5645d3a37d40 in expr6 asm/eval.c:906
#5 0x5645d3a3968d in expr5 asm/eval.c:627
#6 0x5645d3a39aca in expr4 asm/eval.c:602
#7 0x5645d3a39b72 in expr3 asm/eval.c:563
#8 0x5645d3a39db8 in expr2 asm/eval.c:537
#9 0x5645d3a39f38 in expr1 asm/eval.c:511
#10 0x5645d3a3a0b8 in expr0 asm/eval.c:485
#11 0x5645d3a3a242 in rexp3 asm/eval.c:422
#12 0x5645d3a3a508 in rexp2 asm/eval.c:396
#13 0x5645d3a3a6a8 in rexp1 asm/eval.c:369
#14 0x5645d3a3a838 in rexp0 asm/eval.c:342
#15 0x5645d3a3a838 in cexpr asm/eval.c:305
#16 0x5645d3a3ad08 in bexpr asm/eval.c:298
#17 0x5645d3a3ad08 in evaluate asm/eval.c:1032
#18 0x5645d39e4f20 in parse_line asm/parser.c:959
#19 0x5645d399e243 in assemble_file asm/nasm.c:1735
#20 0x5645d3998801 in main asm/nasm.c:719
#21 0x7faee8aaed8f in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
#22 0x7faee8aaee3f in __libc_start_main_impl ../csu/libc-start.c:392
#23 0x5645d399acd4 in _start (/home/ivan/d/nasm/nasm+0x2e5cd4)
SUMMARY: AddressSanitizer: 360 byte(s) leaked in 90 allocation(s).
This problem is reproducible on test utf.asm.
The problem was caused by the fact that eval_strfunc doesn't free the string
allocated by string_transform.
Signed-off-by: Ivan Sorokin <vanyacpp@gmail.com>
Signed-off-by: Elyes Haouas <ehaouas@noos.fr>
[ hpa: only one of the defined issues was valid, removed the rest. ]
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
When a line is suppressed there is no guarantee that it is
syntactically valid, so treat it exactly like a dead %if branch.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
With warnings disaggregated, there is no reason to play games with not
updating the output timestamp. Always write the files as usual.
Remove unnecessary Makefile rules.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
1# Please enter the commit message for your changes. Lines starting
The idea of putting the warnings in the source code was a nice one,
really, but it ended up being a nightmare from the perspective of
build dependencies. Disaggregate them, and tweak the documentation for
easier reading.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
pragma->tail is described as "anything after the operation", but
existing parsing passed just the first whitespace-delimited
word. Change the parsing to just strip leading and trailing
white space off the rest of the line, but keep interior spaces
if there are any.
This is preparation for a build_version pragma for Mach-O matching
the llvm-as .build_version syntax.
Signed-off-by: Fabian Giesen <fabian.giesen@epicgames.com>
This allows response files specified with -@ to reference other
response files. This keeps parity with many other common toolchains
such as MSVC, GCC, and Clang which all support nested response
files.
Signed-off-by: Zachary Turner <zturner@roblox.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>
- Document the [LIST] directive
- Add an option -LF to ignore the [LIST] directive
- Fix [LIST -] suppressing output on a following pass
- Minor other documentation fixes
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The assembler can't know if something is a colonless label or a
misspelled instruction, so print both when complaining about a missing
instruction.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
- Fix additional broken rules
- Add some more files to WARNOBJ
- $^ is not supported by POSIX, apparently
- Update warnings.pl to *actually* use the srcdir and list of
passed-in files.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
PF and CF are always set to the same value; allow the programmer to
specify either or both.
Allow EQU to take a {dfv} expression without needing parens.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
An earlier version of the AVX10.2 documentation had support for ER and
SAE in 256-bit vectors using a special encoding. This was never
implemented, and has since been removed from the spec.
Remove from NASM, too.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The control and debug registers are always using the default operand
size. It is probably easiest to just encode it explicitly for now.
Control registers are particularly weird because of the AMD "lock as
REX.R" hack...
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Using "extern" or "required" after the definition should be
interpreted as "global", just as if "extern" or "required" had been
specified before the definition.
Unfortunately the code did not correctly handle the case of upgrading
from LOCAL to GLOBAL via an EXTERN or REQUIRED directive, only from
EXTERN or REQUIRED to GLOBAL via definition or a GLOBAL or COMMON
directive.
Fix.
Reported-by: E. C. Masloch <pushbx@ulukai.org>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
ADC and SBB don't support using the {nf} prefix. They are the only one
in the arithmetic instructions group that are this way.
Add a flag that will warn when an instructions wants to use {nf} but
doesnt' support it.
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.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>
It is sometimes just too convenient to be able to convert between
strings and bytes at will. At one point I was considering making
something with the full power of the db (et al) directives, but that
is a much bigger change...
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>
Older versions of NASM would not try to match unknown %if directives
with a corresponding %endif, resulting in some very odd consequences
when it comes to trying to handle support for multiple NASM versions.
Document the problem.
Reported-by: E. C. Masloch <pushbx@ulukai.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
If an unknown preprocessor directive starting with %if or %elif is
encountered, assume it should be treated as a conditional directive
for the purpose of balancing %if...%endif.
This avoids some really ugly problems when dealing with code that is
intended to work across NASM versions that uses %if directives that
don't yet exist.
Reported-by: E. C. Masloch <pushbx@ulukai.org>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The message-generating functions appear to get expanded when they
shouldn't, resulting in errors. Disable them for now and remove them
from the documentation.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Add the %find() and %findi() functions to look for a string in a
list. This is useful with picking apart the contents of the
__?DEFAULT?__ macro, for example.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Create a __?DEFAULT?__ magic macro with the settings of the DEFAULT
directive.
The DEFAULT directive is complex enough that this is best done with a
magic macro.
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>
In at least one place, returned false instead of NULL, which caused
build failures on some platforms.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
There are currently six variations of each conditionals, and there may
be more in the future (e.g. %while). Stop trying to enumerate them all
everywhere.
Add support for index copying in the document processor.
Have pptok.pl auto-generate index metadata for conditional
preprocessor directives.
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>