Commit Graph

4781 Commits

Author SHA1 Message Date
H. Peter Anvin
a131b1129c preproc: fix use of free() instead of nasm_free()
free() and nasm_free() are required to be compatible (as we may end up
having memory allocated on the heap by the C library), but that
doesn't mean we shouldn't use it whereever possible to allow for
better debugging.

Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392804
Reported-by: C. Masloch <pushbx@ulukai.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 12:09:04 -08:00
H. Peter Anvin
7b8cd67d51 preproc: add warning for empty %{} construct
An empty %{} becomes % which is simply the arithmetic
operator. Although that is consistent, it might be surprising for
users, to issue a warning.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 12:01:00 -08:00
H. Peter Anvin
baae422e61 preproc: an empty %[] construct generates a null token, drop
%[] amounts to an empty token; this needs to be handled specially so
that it gets properly dropped.

Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392806
Reported-by: C. Masloch <pushbx@ulukai.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 11:47:22 -08:00
H. Peter Anvin
2d4e695241 quote_for_pmake: fix counter underrun resulting in segfault
while (nbs--) { ... } ends with nbs == -1. Rather than a minimal fix,
introduce mempset() to make these kinds of errors less likely in the
future.

Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392815
Reported-by: <13579and24680@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 10:26:03 -08:00
H. Peter Anvin
7a2b5c9221 x86/insns.dat: fix VCVTNEPS2BF16
The VCVTNEPS2BF16 instruction was incorrectly specified as
VCVTNE2S2BF16. Fortunately, the correct opcode for the latter was
specified first, so it would emit the correct result when that
instruction was specified.

Fixes: https://bugzilla.nasm.us/show_bug.cgi?id=3392821
Reported-by: Agner <agner@agner.org>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 10:03:45 -08:00
H. Peter Anvin
7351302477 output/elf: remove efmt->rela_size
There are no use cases for of RELA on i386, and the intent has always been
that efmt->rel_size would be the size of the desired relocation
section type. Rename it from rel_size to relsize to make it more
obvious that it matches efmt->reltype rather than SHT_REL, and delete
efmt->rela_size to keep it from being misused again.

This should avoid a repeat of:

    https://bugzilla.nasm.us/show_bug.cgi?id=3392807

fixed in adf7507e29.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-11-07 09:54:33 -08:00
H. Peter Anvin
bb1233ccde Add FRED instructions
Add the FRED instructions: ERETU, ERETS, LKGS

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-10-05 13:31:30 -07:00
H. Peter Anvin
91580319bc Merge remote-tracking branch 'github/nasm-2.15.xx' 2022-10-05 12:31:33 -07:00
H. Peter Anvin
b6bcd3a6dc NASM 2.16rc1 2022-10-05 12:15:06 -07:00
H. Peter Anvin
b6151260a1 configure.ac: update to autoconf 2.71 standard
autoconf 2.71 changes some macros and obsolete others; fix to match
autoconf 2.71 standard.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-10-05 12:09:36 -07:00
H. Peter Anvin
8453bcfa6c autoconf: update macros and helper scripts
Update the autoconf macros and helper scripts to the current versions.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-10-05 12:03:33 -07:00
H. Peter Anvin
67fbb45816 rdoff/ldrdf.c: fix memory overflow errors causing build failures
The RDOFF tools are fundamentally broken to the core: they are
defining headers which contain misaligned structure members, which
cause the compiler to add padding, breaking the format.

This is just a build fix; remove RDOFF in 2.16.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-10-05 12:00:57 -07:00
Cyrill Gorcunov
a8ff6bf771
Merge pull request #37 from hjl-tools/hjl/dwarf32
Use REL relocation in DWARF sections for i386
2022-09-06 11:06:35 +03:00
H.J. Lu
adf7507e29 Use REL relocation in DWARF sections for i386
i386 should use REL relocation in DWARF sections with addend stored at
the relocation offset.  This fixes

https://bugzilla.nasm.us/show_bug.cgi?id=3392807

Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
2022-09-01 09:04:47 -07:00
Cyrill Gorcunov
3aebb20f12
Merge pull request #28 from Zildj1an/patch-1
Fix warning on ; outside of function
2022-05-10 23:59:32 +03:00
Carlos Bilbao
c0d902c6c2
Fix warning on ; outside of function
Fix "warning ISO C does not allow extra ‘;’ outside of a function" when using gcc v8.5. 
Signed-off-by: Carlos Bilbao <carlos.bilbao@amd.com>
2022-04-04 10:25:58 -05:00
Igor Glucksmann
3f9fc2a3a7 docs: Update comdat section attribute
Signed-off-by: "Glücksmann, Igor" <igor.glucksmann@avast.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-12-17 23:45:51 +03:00
Igor Glucksmann
27e17c913c output/coff: Possibility to define the associated comdat sections in any order
Signed-off-by: "Glücksmann, Igor" <igor.glucksmann@avast.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-12-17 23:45:39 +03:00
Igor Glucksmann
ed2c609976 output/coff: Support for COMDAT sections
Signed-off-by: "Glücksmann, Igor" <igor.glucksmann@avast.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-12-17 23:45:25 +03:00
Cyrill Gorcunov
4b5224ba8f test: add dbxsize test
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-11-20 23:57:49 +03:00
Marco Bonelli
d167b3d4f3 Fix wrong size calculation for "Dx ?" larger than DB
The size calculation done in len_extops() (called by insn_size()) for
EOT_DB_RESERVE (i.e. uninitialized storage "?" token) does not take
into account the element size (e->elem), thus calculating a wrong
size for any Dx larger than DB (DW, DQ, etc).

The bug is silent, but it makes NASM error out if a "Dx ?" (larger
than DB) is followed by any label because the label offset gets
mismatched in the final code generation stage:

    $ cat test.asm
    [section .bss]
    DW ?
    x:

    $ nasm test.asm
    test.asm:3: error: label `x' changed during code generation [-w+error=label-redef-late]

See also: https://stackoverflow.com/q/70012188/3889449

Signed-off-by: Marco Bonelli <marco@mebeim.net>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-11-20 23:53:40 +03:00
Cyrill Gorcunov
00c6490620 BR3392776: parser: parse_line -- fix unitialized memory access
Andrew reported that we may access unitialized memory

> SUMMARY: MemorySanitizer: use-of-uninitialized-value nasm/asm/parser.c:982:41 in parse_line

It turns out that in case of malformed data the expression is terminator
itself so we should not "lookup ahead" for next one. Thus test for first
expression initially and if test passes check for terminator.

Reported-by: Andrew Bao <xiaobaozidi@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-10-18 00:21:05 +03:00
Cyrill Gorcunov
3a81150867
Merge pull request #15 from astiob/libass
preproc: fix misparsing of << as right shift
2021-09-22 21:33:40 +03:00
Oleg Oshmyan
80a4e8e454 preproc: fix misparsing of << as right shift
Regression in commit 20e0d616dc.

Independently discovered and fixed by C. Masloch:
https://bugzilla.nasm.us/show_bug.cgi?id=3392747

Signed-off-by: Oleg Oshmyan <chortos@inbox.lv>
2021-09-21 23:30:53 +03:00
Cyrill Gorcunov
e2ed7b7e12 x86/insns: add VMGEXIT
The instruction supports two forms with [f2] and [f3].
I guess we might add aliases as VMGEXIT2 and VMGEXIT3.
For now simly leave a second form for ndisasm sake.

https://bugzilla.nasm.us/show_bug.cgi?id=3392755

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-13 09:14:10 +03:00
Cyrill Gorcunov
c4babdf2db x86/insns: add RMPADJUST
https://bugzilla.nasm.us/show_bug.cgi?id=3392754

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-13 01:29:32 +03:00
Cyrill Gorcunov
1430995095 x86/insns: add PVALIDATE
https://bugzilla.nasm.us/show_bug.cgi?id=3392753

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-13 01:27:07 +03:00
Cyrill Gorcunov
984761f924 travis: add vmx test
To test VMX instructions.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-13 01:25:04 +03:00
Cyrill Gorcunov
39bb9d71a3 output/outelf: drop unused structure
The erel structure left from times when we've
been merging separate elf32/32x/64 files.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-09 00:59:38 +03:00
Marco Vanotti
f2a6eb4aac Add DW_AT_comp_dir to elf files.
This commit adds the compilation directory debug information for ELF files.
This feature helps debuggers locate the source file when debugging.
The feature is already present for Mach-O files.

Signed-off-by: Marco Vanotti <mvanotti@dc.uba.ar>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-08 23:59:09 +03:00
turekt
a9faae3e0b ndisasm: Stack buffer overflow fix
Changing the type of `to_read` from `uint32_t` to
`int32_t` makes it aware of negative numbers and fixes
the buffer overflow in ndisasm.

Signed-off-by: T Turek <tureqsec@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-05 00:30:55 +03:00
Cyrill Gorcunov
aa2dcdec09 travis: add br3392751
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-03 17:59:08 +03:00
Cyrill Gorcunov
02641a3c84 assemble: process_ea - fix unitialized read
In commit 2469b8b6 we occasionally bring the ability
to read unitialized memory due to refactoring. Fix it
doing needed test inside the function and setting up
an error message if needed.

Side note: passing 7 arguments into the function means
we have to decompose this helper somehow, such number
of arguments is a way over the top.

Bugzilla: https://bugzilla.nasm.us/show_bug.cgi?id=3392751
Reported-by: Marco <mvanotti@protonmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-05-03 17:55:32 +03:00
H. Peter Anvin
2469b8b66e Add {rex} prefix, simplify prefix handling, better error messages
Add a {rex} prefix to force REX encoding (typically a redundant 40h
prefix).

For prefix parsing, we can use t_inttwo to encode the prefix slot
number.

Give more verbose error messages for encoding mismatches.
2021-04-27 11:37:42 -07:00
H. Peter Anvin (Intel)
5368e45794 preproc: fix pasting of TOKEN_HERE, TOKEN_BASE and TOKEN_QMARK
Make the pasting behavior of TOKEN_QMARK, TOKEN_HERE and TOKEN_BASE
match the NASM 2.15 behavior: ? is a keyword and pastes as an ID, $
and $$ are treated as operators (which doesn't seem to make much
sense, but it is the current legacy behavior.)

Reported-by: C. Masloch <pushbx@ulukai.org>
Bugzilla: https://bugzilla.nasm.us/show_bug.cgi?id=3392733
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2021-03-24 10:46:45 -07:00
Cyrill Gorcunov
6d95cc8d29 travis: add br3392739
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-02-21 01:10:05 +03:00
Cyrill Gorcunov
8c735c58d1 BR3392739: output/outbin: fix nil dereference for self following sections
In case if section follows itself we should yield
an error, otherwise we hit nil dereference because
there won't be any group of sections.

After all "follow" attribute is rather to group
sections other than self.



Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2021-02-21 01:05:28 +03:00
Cyrill Gorcunov
79ac0d686d Merge branch 'nasm-2.15.xx'
* nasm-2.15.xx:
  preproc: prohibit unmacro while macro expansion
2020-12-31 16:50:25 +03:00
Igor Munkin
f95c7e983c preproc: prohibit unmacro while macro expansion
If macro is undefined while it's being expanded, use after free occurs,
since the MMacro instance is released, but it is still used to proceed
the expansion.

This change forbids macro undefinition: non-fatal error is raised and
the MMacro instance is not released if it is being processed by NASM
preprocessor.

Consider the following example:
| $ cat test.asm
| %macro m 0
| %unmacro m 0
| %endmacro
| m
| $ ./nasm test.asm
| test.asm:4: error: `%unmacro' can't undefine the macro being expanded
| test.asm:2: ... from macro `m' defined here

Fixes BR3392531 and BR3392716.

Signed-off-by: Igor Munkin <imun@cpan.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-12-31 16:42:31 +03:00
Cyrill Gorcunov
dc4a619426 travis: add br3392637
Code for testcase provided by Suhwan.

Reported-by: Suhwan <prada960808@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-11-04 13:15:52 +03:00
Cyrill Gorcunov
93c774d482 BR3392637: output/outieee: Fix nil dereference
The handling been broken in commit 98578071.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-11-04 13:08:06 +03:00
Cyrill Gorcunov
e24e18e6b9 travis: add rdpid
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 23:06:45 +03:00
Cyrill Gorcunov
b3233c77fc travis: update avx
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 23:02:45 +03:00
Cyrill Gorcunov
4431776fc0 travis: add imm
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 22:12:02 +03:00
Cyrill Gorcunov
8ff5cecc29 travis: add ilog
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 22:01:21 +03:00
Cyrill Gorcunov
daa534e55c travis: add hle
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 00:54:10 +03:00
Cyrill Gorcunov
9d68a8babd travis: add hexfp
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 00:54:10 +03:00
Cyrill Gorcunov
32efe62b81 travis: add gather
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 00:54:10 +03:00
Cyrill Gorcunov
0137027911 travis: add floatx
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 00:54:06 +03:00
Cyrill Gorcunov
ecd704d846 travis: update float test
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-10-15 00:40:36 +03:00