0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-09-22 10:43:39 -04:00
Commit Graph

98 Commits

Author SHA1 Message Date
H. Peter Anvin
276cbf9682 autoconf/Makefile.in: add include for local zlib
When using the internal zlib, need to make sure to add the appropriate
-I option for the header...

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-09-05 18:36:28 -07:00
H. Peter Anvin
6c105cea3b Improve misc/omfdump, add misc/Makefile, use -std=c23 if possible
- Add improvements to omfdump from Bernd Böckmann.

- Add misc/Makefile with option to install omfdump and auxiliary NASM
  data files.

- Use compiler.h and friends in the misc directory.

- Use -std=c23 if the C compiler supports it.

Cc: Bernd Boeckmann <bernd-github@boeckmann.io>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2025-09-03 10:05:21 -07:00
H. Peter Anvin
050c275c39 Makefile: factor out the disassembler
Factor the objects ONLY needed for the disassembler into a
separate library. This allows building the assembler even while
the disassembler is not yet buildable; this makes working on
the disassembler easier.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-29 13:26:44 -07:00
H. Peter Anvin
9f86275c74 Merge remote-tracking branch 'origin/master' into apx.wip
Resolved Conflicts:
	disasm/disasm.c

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-29 01:51:27 -07:00
H. Peter Anvin
7a5502142b bytesex, ilog2: use C23 <stdbit.h> if available; use in disassembler
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>
2025-08-29 01:46:57 -07:00
H. Peter Anvin
83534f1f37 Merge remote-tracking branch 'origin/master' into apx.wip
Resolved Conflicts:
	Makefile.in
	Mkfiles/msvc.mak
	Mkfiles/openwcom.mak
	asm/assemble.c
	asm/nasm.c
	asm/parser.c
	doc/Makefile.in
	include/nasm.h
	include/tables.h
	output/legacy.c
	travis/test/br3392531.stderr
	travis/test/br3392716.stderr
	travis/test/org.stderr
	x86/insns.dat

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-25 21:09:15 -07:00
H. Peter Anvin
df4555d68b preproc: compress standard macros with zlib
The very simple compression scheme used for the builtin macro sets no
longer works adequately, and in fact it generates incorrect output
now.

Drop the whole idea of an ad hoc compression scheme and just use
zlib. For the case where there is no system zlib available, include a
(subset of) the zlib distribution. The configure script can be set to
force this included zlib if desired (e.g. for testing.)

Unfortunately this turned out to be a pretty painful can of worms in
terms of complexity. On the other hand having zlib available might be
useful at some point in the future.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2025-08-15 16:51:39 -07:00
H. Peter Anvin
888d9ab550 configure.ac: enable some -Werror= warnings not included in -W -Wall -pedantic
For some reason, these warnings are not included in -W -Wall -pedantic, at least
not on gcc 14.2.1:

	-Wstrict-prototypes
	-Wmissing-prototypes
	-Wmissing-declarations

This caused a missing prototype error (because nasm_note[f]()
prototypes were missing from include/error.h) to get missed when
compiling with --enable-werror, which is ironic at best.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-11-04 10:30:14 -08:00
H. Peter Anvin
bff94fbd39 Major changes to a number of subsystems to improve matching
Work through a number of changes toward making matching a lot saner,
both to reduce the number of patterns to generate for APX but also to
make a number of code patterns simpler.

This replaces a fair number of byte codes.

Improve a number of error messages, especially related to overflows.

Move process_insn() from nasm.c to assemble.c, as it really is the
primary entry point to the assembler module.

Reorder some prefixes. In particular, F2/F3 override 66 when used as a
mandatory prefix, so it makes more sense for them to be closer to the
opcode.

Move a lot more information into struct insn. It is better to have it
in one place; memory consumption is not an issue because struct insn
is transient information.

Get rid of "optimization levels" and replace it with a mask of
flags. That was already halfway done; complete the job.

Replace seg:offset in struct out_data with a struct location. It would
be better to extend this to more places, too.

The ARx and SMx flags are now explicit bitmasks, instead of having a
couple of hard-coded ranges.

Add __func__ to assert or panic messages.

Because of prefix and message changes, a number of travis tests had to
be audited and updated.

Fix a number of instruction patterns which had .128 when they ought to
be .lig. This is no longer a minor issue with the disassembler: for
AVX10, the pattern vector length determines how SAE/RC are encoded,
and there is no valid 128-bit encoding. However, with .lig the 512-bit
encoding can be used.

Separate "o64nw" into two pieces: opsize 64 and "nw" = "REX.w not necessary". The
latter can be included in non-64-bit patterns. "o64" still set REX.W
since that is still the common thing.

New "osz" bytecode: emit an OSP *or* REX.W depending on the current
mode and operand size. Useful for special cases like "nop" where "o64
nop" probably wants to be encoded as "48 90".

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-08-07 17:13:44 -07:00
H. Peter Anvin
2d2ae91d7a autoconf: unbreak --enable-lto, fix some language macros
PA_ADD_LANGFLAGS() was broken, resulting in among other things
--enable-lto not working.

Make autogen.sh fail if aclocal return error.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-04-16 16:31:28 -07:00
H. Peter Anvin
1e965e30ff windows host: add embedded manifest file
Without a manifest, Windows applications force a fixed PATH_MAX limit
to any pathname; this is unnecessary.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-01-29 17:19:32 -08:00
H. Peter Anvin
a315659957 autoconf: more aggressively avoid cross-compilation problems
We could end up invoking WINE even when we didn't want to.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2024-01-04 23:21:44 -08:00
H. Peter Anvin
0e7eae99e8 autoconf: add detection of variadic macros support
Variadic macros are really useful, even if we can only use them
conditionally.

Unfortunately this means removing -Wc90-c99-compat, because apparently
-Wno-variadic-macros is broken in gcc 13.2. Fortunately it is 2023...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2023-10-11 13:32:52 -07:00
H. Peter Anvin
0e96487608 autoconf: modernize autoconf and update a lot of m4 macros 2023-10-11 10:47:09 -07:00
H. Peter Anvin
5a2d629501 autoconf: a much of macro fixes... not sure how this ever worked?
Exposed a bunch of problems with the autoconf m4 macro
library. Hopefulyy fix it, and tidy it up in the process.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2023-02-19 21:26:15 -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
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 (Intel)
50200cc0d3 configure.ac: add option to compile with suggestion warnings
Add a configure option to enable suggestion warnings, currently a set
of -Wsuggest-attribute=* warnings.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-30 17:37:42 -07:00
H. Peter Anvin (Intel)
e1f0b35af0 configure.ac: also try -std=c99
If -std=c17 and -std=c11 don't work, try -std=c99 as well.
-std=c90 is unlikely to work because of the requirement for "long
long" on L32 platforms, which isn't likely to be supported on a pure
C90 compiler.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-09 19:33:26 -07:00
H. Peter Anvin (Intel)
5c90a7c237 autoconf: use -std=c17 or -std=c11 if available
If the compiler supports it, use -std=c17 or -std=c11. Hopefully, this
will give us more predictable behavior in some cases.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-09 19:26:27 -07:00
H. Peter Anvin (Intel)
e8d6bbacd4 configure.ac: if we have a C17/C11-compatible compiler, use it
Enable -std=c17 or -std=c11 for compilers that handle them.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-09 19:12:25 -07:00
H. Peter Anvin (Intel)
abcdf8356a configure.ac: better tests for typeof, snprintf, vsnprintf
With some combinations of options tests for typeof, snprintf, and
vsnprintf end up with warnings promoted to errors, which then trigger
incorrect results for these tests. Move the typeof test to the end,
and write specific tests for snprintf and vsnprintf.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-09 19:04:28 -07:00
H. Peter Anvin (Intel)
30844a4c62 offsetin(): use typeof() if the compiler supports it
If the C compiler has typeof(), we can use a safer implementation of
the offsetin() macro by using typeof(). Since typeof() isn't standard
(yet?) autoconf has to test for it.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-06 12:39:14 -07:00
H. Peter Anvin (Intel)
70f0d04ee5 configure.ac: -enable-... breaks other compilers, so hope for clang 10
The -enable-... option to enable -ftrivial-auto-var-init=zero breaks
linking not just on clang but on other compilers (gcc) too. Drop it;
this feature is enabled by default in clang 10.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-06 11:30:22 -07:00
H. Peter Anvin (Intel)
e2040291ec config/unconfig.h: generate by Makefile, not autogen.sh
config/unconfig.h really is no different than the other perlreq files,
so move it into the Makefile. This has the extra advantage that
config/unconfig.h no longer needs to be kept in the source repository.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-06 11:12:03 -07:00
H. Peter Anvin (Intel)
0da8a88c62 clang: add -ftrivial-auto-var-init=zero
The clang behavior is sometimes really weird, and extremely hard to
debug, when uninitialized variables are used even if the value cancels
out in an expression. It also depends on optimization level, etc.

-ftrivial-auto-var-init=zero makes the behavior
predictable. Unfortunately it also needs a really weird "enable"
option, and it issues a warning about an unused command line option on
link, which may get promoted to error, so silence the warning before
doing anything else.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-06 10:19:38 -07:00
H. Peter Anvin (Intel)
65ab3ab197 clang: mark inline functions unused and add warning options
clang, unlike gcc, will warn on inline functions which are
unused. This can happen if a function is either intended to be used in
the future, or it is only used under certain config options. Mark
those functions with the "unused" attribute; not only does it quiet
the warning, but it also documents it for the user.

Shuffle around the warning options in configure and add a few more
that are specific to clang.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-30 10:14:21 -07:00
H. Peter Anvin (Intel)
5b4de52083 BR 3392667: more reasonable limit for expression descent
Set an expression descent limit to 8192, which is more reasonable to
expect to work on most platforms. Furthermore, if getrlimit() exists,
then try to use it to see if we need to further limit the size.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-01 13:21:05 -07:00
H. Peter Anvin (Intel)
941c75a2b2 Makefile portability improvement, build nasmdoc.pdf.xz
Significantly improve the portability/reliability of a general
make command. Build a .pdf.xz version of the documentation,
using an uncompressed pdf as basis.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-05-26 14:13:31 -07:00
H. Peter Anvin
97ea4adcf0 config/unconfig.h: eliminate #undef directives
config/config.h as generated by autoconf has #undef directives
commented out, but the autoheader-generated template contains them,
and config/unconfig.h should not contain them. Re-introduce
config/config.h.in, and postprocess it to generate config/unconfig.h
by commenting out all the #undef directives, just as configure does.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-10-03 21:34:42 -07:00
H. Peter Anvin
eaef851689 configure.ac: look for unconfig.h not uninit.h... 2019-08-27 15:13:15 -07:00
H. Peter Anvin (Intel)
480d5e2c8b BR 3392601: allow the user to disable pedantic warnings
--disable-pedantic passed to configure will now disable
-W, -Wc90-c99-compat, and -pedantic.

Requested-by: Orzkan Sezer <sezeroz@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-16 00:52:26 -07:00
H. Peter Anvin (Intel)
8b6e6bf04f config.h: separate function and function pointer attributes; automate
Separate out function and function pointer attributes, as not all
versions of all compilers support both.

Have macros related to function attributes auto-generated by
autoheader. As a result, rename config.h.in to unconfig.h, to make it
more obvious that it is really intended to be included from some C
programs.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-16 00:08:27 -07:00
H. Peter Anvin (Intel)
471120f485 file.c: handle long pathnames on Windows
Windows supports pathnames up to 32767 UTF-16 characters, but using
the standard interfaces only up to 260 characters. Wrap the functions
that take filenames on Windows.

Clean up the compatiblity layers some more for reduced #ifdefs.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-05-15 13:07:21 -07:00
H. Peter Anvin (Intel)
9bb55bd127 Merge branch 'evalmacro'
Resolved Conflicts:
	asm/preproc.c
	output/elf.h
	output/outelf.c
	output/outelf.h
	version

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-04-24 11:14:43 -07:00
H. Peter Anvin
efee3ea312 configure.ac: add --enable-profiling option
Add option to enable profiling without having to modify Makefile.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-02-25 21:00:43 -08:00
H. Peter Anvin
0bddd0f1b1 autoconf: move aux directory, define AC_CONFIG_AUX_DIR()
The name "aux" is reserved on Windows platforms, a legacy from CP/M
via MS-DOS. Rename it to "helpers".

Turns out that that directory wasn't actually used properly, because
AC_CONFIG_AUX_DIR was never defined, and there was a redundant copy of
install-sh checked into the base of the source tree.

Reported-by: Ehsan Alem Mohammad Ghasemlou <e.ghasemloo@gmail.com>
NASM-Bugzilla: https://bugzilla.nasm.us/show_bug.cgi?id=3392560
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-02-22 01:18:04 -08:00
H. Peter Anvin
06f72bb968 Test for the mempcpy() function and add alternative if missing
If memcpy() doesn't exist, then add an inline alternative using
memcpy().

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-26 06:22:47 -08:00
Cyrill Gorcunov
8274623093 build: Add missing PA_ADD_LDFLAGS helper
Fixes b0121dc312

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-23 17:22:44 +03:00
H. Peter Anvin
b0121dc312 autoconf: use librarized autoconf setup
I have been setting up a cross-project librarized autoconf setup; use
it for NASM as well.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-12-22 18:17:16 -08:00
H. Peter Anvin (Intel)
b7f24e7715 nasm_assert(): try to run at compile time if possible
Try to make nasm_assert() do a static assert if the argument can be
evaluated at compile time by any particular compiler. We also provide
nasm_try_static_assert() which will assert a compile-time expression
if and only if we can determine we have a constant at compile time
*and* we know that the compiler has a way to handle it.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-14 15:42:03 -08:00
H. Peter Anvin (Intel)
7dc5b23920 configure: make section garbage collect the default
Section garbage collect really is quite useful, and it makes managing
library source code management a little bit less stressful. It has
been used by the official builds for a while now, turn it on by
default.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-13 22:51:22 -08:00
H. Peter Anvin (Intel)
7bb13eac11 strlist: can be unique or not, add printf functions
Make it a selectable option at allocation time if a strlist should
contain only unique strings or not. If not, we omit the hash table and
strlist_find() will not do anything.

Add printf()-style functions to a strlist.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-13 22:48:14 -08:00
H. Peter Anvin (Intel)
8e08fb6da7 Merge remote-tracking branch 'origin/nasm-2.14.xx'
Resolved Conflicts:
	asm/assemble.c
	asm/directiv.c
	asm/error.c
	asm/float.c
	asm/labels.c
	asm/listing.c
	asm/nasm.c
	asm/parser.c
	asm/preproc.c
	asm/stdscan.c
	include/error.h
	output/outelf.c
	version

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-12 18:05:52 -08:00
H. Peter Anvin (Intel)
64b56eaa39 configure: add -Wno-shift-negative-value
Shifting negative values is undefined in standard C, but we have tons
of dependencies that signed arithmetic is 2's-complement in the code
anyway, and on gcc-like compilers we pass the -fwrapv option to
indicate exactly that. Therefore, this is not a valid warning in our
case and should be suppressed.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-12 15:56:28 -08:00
H. Peter Anvin (Intel)
eb5b3ae0d3 nasmlib: Add nasm_(v)asprintf()
Add a version of (v)asprintf(), which allocates a string on the
heap. Unlike the standard version of (v)asprintf(), we return the
pointer; if one wants the length of the string then one can simply use
the %n pattern.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-12-12 14:34:34 -08:00
H. Peter Anvin
1350620bf1 ctype: create our own ctype table
Create our own ctype table where we can do the tests we want to do
cheaply, instead of calling ctype functions and then adding additional
tests all over the code.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-28 14:55:58 -08:00
H. Peter Anvin
cd133a6f2d Merge remote-tracking branch 'origin/nasm-2.14.xx'
Fixes for various build problems.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-06-15 17:44:30 -07:00
H. Peter Anvin
48fd154d1c configure.ac: drop -O3; it is excessive and produces huge code
There is no reason to use -O3; it causes code to be insanely
duplicated. Simplify the configure.ac file too.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 19:19:09 -07:00
H. Peter Anvin
c4e16f7e7c gcc: newer gcc trip on -Wstringop-truncation for valid uses of strncpy()
strncpy() is correctly used to fill in a zero-*padded* (not
zero-terminated) field in several places.  Make gcc not complain about
those uses.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-06-02 23:47:57 -07:00