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>
The bugs were found by Svace static analysis tool:
1. sym can be null in when exact is false, and sym is later dereferenced
by sym->symnum
2. asym can be null, no return from function is performed, and asym is
dereferenced by asym->symnum
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>
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>
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>
The GROUP directive can now be specified more than once for a group,
and the result is cumulative (the union of all specified groups.)
Signed-off-by: KO Myung-Hun <komh78@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Officially the syntax for TEST is "rm,reg"; however TEST is
commutative in every aspect, and as such "reg,mem" is an equivalent
form that NASM has also supported in the past.
Reinstate it properly.
Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392962
Reported-by: E. C. Masloch <pushbx@ulukai.org>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Merge PRs 127, 126, 125, 124 and 91. Document some of the most relevant
changes.
Signed-off-by: Maciej Wieczor-Retman <maciej.wieczor-retman@intel.com>
-- TCMMIMFP16PS, TCMMRLFP16PS instructions
-- AMX.asm fix: Similar to GATHER instructions, 3-operand AMX instructions cannot have the same operand more than once
Checked with XED version: [v2025.06.08]
see Intel® Architecture Instruction Set Extensions and Future Features Programming Reference, March 2025 319433-057
else (without this correction) it conflict with VPERMI2PS
If a line is suppressed, the %if or %rep condition must never be
evaluated. Test for it, and add the exitrep test to travis.
Signed-off-by: H. Peter Anvin (Intel) <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>
Looks like there are enough critical changes to justify a release
without a bunch of new development. Let's just call the new
release 3.01 and avoid a bunch of excess dottage.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
The column width really wasn't quite enough.
Make the text size in Appendix F which can be rather wide
smaller. There is also no real reason to put that in a background box.
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
Obj2 is an obj variation for OS/2.
Obj2 has the following differences from obj.
1. Default attributes for a segment are ALIGN=16 and USE32.
2. Add a segment to FLAT group implicitly if 32-bit segment.
3. Recognize Unix sections .text, .rodata, .data and .bss as TEXT32,
CONST32, DATA32 and BSS32 respectively for compatibility with other
Unix platforms.
4. Set default classes implicitly for known segments such as TEXT32,
CONST32, DATA32, BSS32 and so on.
Signed-off-by: KO Myung-Hun <komh78@gmail.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>