Commit graph

5692 commits

Author SHA1 Message Date
H. Peter Anvin (Intel)
6950581b35 NASM 3.02rc10 2026-06-25 15:16:19 -07:00
alexvoste
cfcfe9e701 asm/labels: fix memory leak in local label structures
Travis CI testing with AddressSanitizer (ASan) triggered a severe memory
leak in the assembler label tracking. Local label structures were not
properly freed during cleanup stages. This fix adds proper verification
and destruction of tracking labels, resolving the ASan memory leak.

Signed-off-by: alexvoste <alexvostedev@proton.me>
[ hpa: fixed indentation style and removed unnecessary { } ]
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-25 15:13:47 -07:00
alexvoste
3a33d83610 parser: fix invalid segment override on EQU FAR pointers
The parser incorrectly treated colons as memory segment overrides inside
EQU directives because of an inverted far_jmp_ok check. This regression
was introduced in commit 8981724. Removing the incorrect negation
restores proper parsing of FAR pointer constants.

Fixes #242

Signed-off-by: alexvoste <alexvostedev@proton.me>
2026-06-25 15:11:05 -07:00
H. Peter Anvin (Intel)
90ba5bbc23 doc: fix spelling of "syntactically"
Fix spelling error.

Fixes: https://github.com/netwide-assembler/nasm/issues/251
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-25 15:02:58 -07:00
H. Peter Anvin (Intel)
2b37c0ad75 directiv.c: include leading $ in a token if missing an identifier
When complaining about a valid token where an identifier was expected,
do include the leading $ if at all applicable to avoid confusing the
user.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-25 14:59:33 -07:00
H. Peter Anvin (Intel)
1fc631a173 directiv.c: $-hex requires nasm_isnumstart, not just nasm_isnumchar
For identifier-escapes beginning with $a-f to work, the $ hexadecimal
prefix cannot be used, nor could it ever be used, with A-F immediately
after the $. This is the main reason the $-hex has been deprecated.

When adding the non-dollarhex mode, this got accidentally promoted to
nasm_isnumchar() instead of nasm_isnumstart(), which broke using
$-escaped identifiers in directives.

To fix this properly, it would be a good thing to add a central
identifier-skipping function.

Fixes: https://github.com/netwide-assembler/nasm/issues/223
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-25 14:58:22 -07:00
H. Peter Anvin (Intel)
19125b6d46 builtin.mac: synchronize with the NASM binary
Update builtin.mac to match the current set of built-in NASM macros.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-24 15:56:50 -07:00
H. Peter Anvin (Intel)
08a369628e Rename emacstok.pl back to nasmtok.pl
This script can output more than just Emacs format these days; it is
already used to produce both Emacs and JSON output, and it seems
unlikely that we would want to create another script to output any
additional file formats.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-21 14:34:09 -07:00
H. Peter Anvin (Intel)
f0c3b0e6c7 NASM 3.02rc9
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-11 15:26:28 -07:00
H. Peter Anvin (Intel)
5e6a181fec insns.pl: fix unnecessary build reproducibility failure
Instead of sorting the list of flags by number, it sorted it by hash.

Reported-by: <bbhtt@bbhtt.in>
Fixes: https://github.com/netwide-assembler/nasm/issues/220
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-11 15:20:12 -07:00
H. Peter Anvin (Intel)
6f830c1c74 labels: handle the sequence EXTERN, GLOBAL, defined
The sequence EXTERN, GLOBAL, definition would fail, because the EXTERN
would create a pseudo-segment and consider it a definition, whereas
GLOBAL would set change it to a global definition, but leaving the
definition existing, which is not the normal case for a GLOBAL symbol
(define_label would not be called.)

Therefore, explicitly "undefine" the symbol by setting defn.defined to
0, as it would be after a GLOBAL statement, as as it is when an EXTERN
statement is followed by a definition (causing it to be implicitly
promoted to GLOBAL.)

Reported-by: E. C. Masloch <ecm-pushbx@github.com>
Reported-by: <roel-z@github.com>
Fixes: https://github.com/netwide-assembler/nasm/issues/224
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-11 15:08:27 -07:00
H. Peter Anvin (Intel)
022586090d changes.src: document %clear directive fix
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-11 14:42:55 -07:00
H. Peter Anvin (Intel)
0c9baa8f3a preproc: ensure forward process in %clear loop
The %clear loop was missing advancing to the next token. Also allow
the list to be comma-separated, like most other cases in NASM.
Reported-by: <magicelk235@gmail.com>
Fixes: https://github.com/netwide-assembler/nasm/issues/227
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-11 14:40:01 -07:00
H. Peter Anvin (Intel)
9052efaa63 preproc: warn if the user tries to use %rmacro
Unfortunately, the %rmacro and %irmacro directives were not disabled
when recursive macros were removed due to the implementation did not
work. Make them issue a warning and document that they might change in
the future.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-11 14:29:41 -07:00
Jiri Malak
8d1f35b78f open-watcom: fix Open Watcom build make file
Resolves Conflicts:
	Mkfiles/openwcom.mak
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-11 14:05:52 -07:00
H. Peter Anvin (Intel)
7b267445b6 preproc.src: document the limitations of case insensitivity
For the longest time, NASM has allowed non-ASCII characters is macros
and identifiers, but they have always been treated as opaque
bytes.

NASM has never done case insensitive matching of identifiers, only
keywords and macros. Keywords are compile-time-defined and are always
ASCII, but macros can be user-defined, so document the limitations.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-11 13:57:29 -07:00
H. Peter Anvin (Intel)
018406b870 SubmittingPatches: more up to date information about the patch format
It has not been considered valid to omit the long patch description
for a long time. Try to explain in more detail what the long patch
description is actually expected to contain.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-11 12:47:32 -07:00
H. Peter Anvin (Intel)
6015afc6d7 omfdump.c: add updates from Bernd Böckmann
Bernd Böcknann has been maintaining a fork of this tool on github:

      https://github.com/boeckmann/omfdump

Sync with his latest version. In the future it might be possible to
drop this tool from the NASM distribution entirely.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 21:00:04 -07:00
H. Peter Anvin (Intel)
ed8864e342 NASM 3.02rc8
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 20:56:10 -07:00
H. Peter Anvin (Intel)
d832776ccb Revert "parser: fix invalid segment override on EQU FAR pointers"
This reverts commit 35ffac3ea0.

This commit caused a regression, causing segment overrides to get
lost. Multiple travis tests failed as a result.

Revert this until a proper solution exists.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 20:54:47 -07:00
Joe Konno
6d8ea837c6 x86: fix {er} decorator placement for integer-source VCVT* instructions
For `VCVTUSI2SD`, `VCVTUSI2SS`, and `VCVTUSI2SH`, the `|er` flag in
`insns.dat` was attached to the XMM pass-through source (operand 2, the
vvvv field) rather than the integer source (operand 3, the rm field).
This caused NASM to require the embedded-rounding decorator before the
integer register rather than after it, which is wrong; the correct
syntax is `vcvtusi2ss xmm0,xmm1,eax,{rn-sae}`, not `vcvtusi2ss
xmm0,xmm1,{rn-sae},eax`.

Move `|er` to the integer source operand for all six affected entries,
and change the XMM source from `xmmreg|er` to `xmmreg*` (optional
duplicate of the destination, consistent with every other scalar
integer-to-float convert in the file).

Also fix a copy-paste error in `insns.dat` where the second `VCVTUSI2SH`
entry (W=1, rm64) was mis-labeled as `VCVTUSI2SS`.

Update `travis/test/avx512f.asm` to use the correct decorator syntax
(`reg,{rN-sae}` instead of `{rN-sae},reg`) for the ER forms of
`VCVTSI2SD`, `VCVTSI2SS`, `VCVTUSI2SD`, and `VCVTUSI2SS`; regenerate the
golden `avx512f.bin.t`. The encoded bytes are unchanged.

`travis/test/avx512f.json` had a trailing comma after the last field of
the JSON object, making it invalid JSON. Remove the trailing comma.

Signed-off-by: Joe Konno <joe.konno@intel.com>
Fixes: https://github.com/netwide-assembler/nasm/pull/229
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 20:23:45 -07:00
xmoezzz
d2541cb884 nasm.c: response file (-@) option parsing UAF affecting debug format selection (-F / -g)
Fixes: https://github.com/netwide-assembler/nasm/pull/189
[ hpa: added necessary cast to nasm_free() ]
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 20:21:09 -07:00
SEt
dee2d13f2c Proper handling of several code sections in Codeview debug information
Current Codeview implementation assumes there is only one actual code
section and all line number information is pulled there. With support
of comdat that assumption becomes incorrect, so proper generation of
line number information table per code section is required.

Also solved an issue with incorrect relocation for symbol with the
same name as some section.

New code assumes that coff_nsects doesn't change during generation of
debug information.

Fixes: https://github.com/netwide-assembler/nasm/pull/183
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 20:17:36 -07:00
Kacper Michajłow
1c9e16a03f output/codeview: don't panic when there is not code section
Simply skip the tables that require code section and source information.

Fixes: https://github.com/netwide-assembler/nasm/issues/216
Fixes: https://github.com/netwide-assembler/nasm/pull/178#issuecomment-4156226648
Signed-off-by: Kacper Michajłow <kasper93@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 20:13:27 -07:00
knut st. osmundsen
05ad1e46b2 doc/outfmt.src: Documented 'function' win32/64 symbol type.
Documented the 'function' win32/64 extension to the global, extern
and static directives.

Resolved Conflicts:
	doc/outfmt.src

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 20:10:15 -07:00
knut st. osmundsen
c8be7b7a3f outcoff.c: Added support for 'function' type on global symbols.
Setting the symbol type is necessary for the control flow guard (CFG)
stuff on windows.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 20:08:03 -07:00
knut st. osmundsen
3ad8e6c533 outcoff.c: Prevent elimination of extern safeseh symbol.
Do a lookup of the symbol given to safeseh to prevent out_symdef() from
thinking it is unused.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 20:06:49 -07:00
knut st. osmundsen
251b9c6825 test/wrtsymtab.asm: reproducible
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 20:05:20 -07:00
knut st. osmundsen
06d2606b06 outcoff.c: fix warnings
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 20:05:20 -07:00
knut st. osmundsen
f1e4e6fe16 outcoff.c: dd symbol wrt ..symtab
Added a special symbol ..symtab for emitting the COFF symbol table
index of a symbol rather than some kind of address.  For use with ehcont
metadata and possible other stuff.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 20:05:20 -07:00
H. Peter Anvin (Intel)
f216d5b65d editors: rename nasmtok.pl to emacstok.pl
Rename this script to reflect its function within the NASM tree. The
output file is still called nasmtok.el, however, as it reflects its
function within an Emacs environment.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 20:04:50 -07:00
H. Peter Anvin (Intel)
5b4d5cf2a7 editors/nasmtok.pl: don't overquote nasm-token-lists
The definition of nasm-token-lists was double quoted: both the list
itself and the tokens inside were quoted, which is not the right
thing.

Remove the unnecessary inner quoting.

Reported-by: 8dcc <8dcc@github.com>
Fixes: https://github.com/netwide-assembler/nasm/issues/231
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 19:56:20 -07:00
H. Peter Anvin (Intel)
dc68633fa3 Fix tuple type for V{MOV,ADD,SUB,MUL,DIV}SH to t1s16
These use a 16-bit tuple type, not one derived from EVEX.W. All of
this is really messy... it would be better to have a much more
explicit handling of the displacement type than relying on "tuples".

Reported by: MSander-OptiCode <msander-opticode@gmail.com>
Fixes: https://github.com/netwide-assembler/nasm/issues/245
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 19:51:54 -07:00
H. Peter Anvin (Intel)
93bb528742 Remove nroff from configure.ac and Makefile.in
Converting nroff man pages to other formats was obsoleted with the use
of asciidoc. No need to check for them.

Reported-by: Ross Burton <rossburton@github.com>
Fixes: https://github.com/netwide-assembler/nasm/issues/236
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 18:27:49 -07:00
H. Peter Anvin (Intel)
471073c0d0 changes.src: update release notes
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 18:25:57 -07:00
alexvoste
6e8cdf8d59 x86: Fix VCVTPD2PH and add missing VMINPH/VMAXPH AVX512-FP16 instructions
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 18:21:52 -07:00
alexvoste
35ffac3ea0 parser: fix invalid segment override on EQU FAR pointers
The parser incorrectly treated colons as memory segment overrides inside
EQU directives because of an inverted far_jmp_ok check. This regression
was introduced in commit 8981724. Removing the incorrect negation restores
proper parsing of FAR pointer constants.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-07 18:21:39 -07:00
H. Peter Anvin (Intel)
de7a94e884 asm/preproc.c: remove unused variable bad_bracket
This variable was assigned but never used.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-04 10:52:15 -07:00
H. Peter Anvin (Intel)
0114c92101 asm/assemble.c: remove unused variable this_good
This variable was assigned but never used.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-04 10:51:49 -07:00
H. Peter Anvin (Intel)
ea675d0af7 autoconf: sync with upstream pa_option_lto.m4
This change has no effect on NASM, but syncs with the upstream
collection. RANLIB should be defaulting to : if not present.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-04 10:50:54 -07:00
H. Peter Anvin (Intel)
3ee140842f autoconf: separate -g3 and -ggdb
The -g3 and -ggdb options are really separate, treat them as
such. Trying -ggdb3 -g3 is not only inefficient, it is wrong when the
compiler supports only -ggdb.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-04 10:42:01 -07:00
H. Peter Anvin (Intel)
ccb73b72b2 autoconf: fix up search for "gcc-ar" and "gcc-ranlib"
The detection for "gcc-ar" and "gcc-ranlib" when building with LTO for
gcc was broken, fix it.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-04 10:40:50 -07:00
H. Peter Anvin (Intel)
113191195b configure.ac: if "strip" isn't found, dummy it out
There is no reason to error out if "strip" is missing.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-06-04 10:40:06 -07:00
H. Peter Anvin (Intel)
aa12d3381a NASM 3.02rc7 2026-04-22 09:10:32 -07:00
Yongjie2017
498afdba1b output/outelf.c: fix address sanitizer findings in elf output format
In elf_init, cur_path is a malloced one, and should be freed.

This patch adds a free operation by the end of the elf_init.

Signed-off-by: Yongjie Sheng (Intel) <sheng.yongjie@outlook.com>
2026-04-17 06:38:10 +08:00
Yongjie2017
b5235c49f0 asm/preproc.c: fix https://nvd.nist.gov/vuln/detail/CVE-2025-8842
When there is an ill formed assembly (e.g. a macro without a correct
ending), the assembly processing will end with a defining->refcnt
in non-zero value that further causes a nasm_assert in free_mmacro,
the nasm_assert causes a panic.

Force the defining->refcnt to zero in pp_clean_pass as a bailout.

Signed-off-by: Yongjie Sheng (Intel) <sheng.yongjie@outlook.com>
2026-04-17 06:35:57 +08:00
Yongjie2017
8c3f3fbe36 asm/preproc.c: fix https://nvd.nist.gov/vuln/detail/CVE-2025-8844
When there is an invalid radix specifier, the parse_smacro_template
set the current char pointer (cp) to NULL, but the tailing processing
of the for loop increases the cp so its value is 0x1 that deceives
the for loop condition check.

Add a NULL pointer checking on the cp after the switch statement
to quit the for loop because of the invalid radix specifier.

Signed-off-by: Yongjie Sheng (Intel) <sheng.yongjie@outlook.com>
2026-04-17 06:33:06 +08:00
H. Peter Anvin (Intel)
3cb6231581 asm/preproc.c: remove git merge crap in comment
A comment accidentally was left with a merge resolution
annotation. This was of course harmless, being in a comment, but it
shouldn't be there.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-04-10 13:21:41 -07:00
H. Peter Anvin (Intel)
97db0b96c2 NASM 3.02rc6 2026-04-10 13:18:31 -07:00
H. Peter Anvin (Intel)
e1e03770f7 asm/preproc.c: remove dead code, improve comment
ppscan() had a break; statement followed immediately by a return
statement. The latter was left over from code restructuring and is
dead code.

Remove it.

Fix a nearby comment indicating that we should not need to strip a
const from a string pointer. Probably Token::t_charptr should be
const, but it might need additional work.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2026-04-10 13:10:16 -07:00