Move directive processing to its own file, and move nasmlib/error.c to
asm/error.c (it was not used by the disassembler); remove some extern
declarations from .c files, and do some general code cleanups.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Add a redundant cast in watcom_switch_hack() to quiet a Watcom
warning, and remove open-coded implementation of the Watcom switch
hack.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
HAVE_DECL_* are 0/1 not ifdef; use HAVE_DECL_STRNLEN to see if we need
to declare this, lest stdlib/strnlen.c fails to compile.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Avoid type promotion due to ?:, and put in a comment to explain what
the heck the purpose is of wrapping default in a macro.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Use sizeof() to prevent the compiler from invoking
watcom_switch_hack() unnecessarily. Hopefully the optimizer would be
smart enough to recognize this inherently, but this is an old compiler
we are dealing with, so make life a little easier for it.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
For expressions like [foo - $] or [bar - $$] our relocation base is
not the same as the end of the instruction. Make that explicit.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Handle, hopefully correctly, self-relative expressions (that is,
expressions of the form X - Y where Y is a symbol in the current
segment, possibly $ or $$) used as offsets or immediates, as opposed
to arguments to Dx statements (which have already been supported for a
while.)
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
OpenWatcom still doesn't have proper support for 64-bit switch
statements. Hack around it in a truly vile way.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Use an ugly hack to make nasm_delete() side effect free. This assumes
all pointers have the same internal NULL pointer representation as
void *, however, we already assume zero-initialized memory will
represent a NULL pointer, so hopefully this is okay on any platform we
actually care about.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
I have not figured out a way to make nasm_delete() side effect safe
without using compiler-specific hacks, which would defeat the whole
purpose.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
We do have a number of places where we had problems doing things like:
memset(foo, 0, sizeof foo) instead of sizeof *foo. Add a helper macro
nasm_zero() to the list of (sadly not yet well used) pointer-safe
helper macros.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
http://www.drdobbs.com/compile-time-assertions/184401873 describes a
number of possible implementations of static_assert() on compilers
that do not support it natively. Use their best recommendation.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
"Assertion failed" is likely to be redundant with static_assert().
__attribute__((error)) is only guaranteed to work while optimizing, so
do not use it unless __OPTIMIZE__ is defined.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Instead of using hacks or compiler-specific features, if we have
standard features as defined in ISO C11, use them.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Use autoconf to detect function attributes; some compilers like Sun CC
do support some gcc-style attributes, but don't define __GNUC__. Also
-U__STRICT_ANSI__ already in configure.ac so our tests match what we
might eventually encounter.
Add const_func and pure_func attributes.
Decorate functions in nasmlib.h with const_func and pure_func.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Allow constructs like:
dd foo - $
... where foo is an external symbol. Currently this is only
implemented for extops, i.e. dx opcodes.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Move the canned OpenWatcom configuration file to config/watcom.h.
Also exclude config/config.h from being a dependency for MSVC.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Apparently, at least on some OS/2 compilers, <sys/types.h> needs to be
included for off_t to be defined. This seems like a generically good
idea to include this header whenever it is available.
Remove reference to <types.h>. This was supposedly for MSVC, but
there is no actual evidence that it is useful beyond <sys/types.h>.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
For newer gcc attributes, we can use __has_attribute() to test for
attribute presence. This improves compatibility both with older gcc
and with clang, at least with -Werror enabled.
Reported-by: Daniel Lundqvist <daniel@malarhojden.nu>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
MSVS < 2005 doesn't have "long long", so use the MSVC-specific
__int64, I64, and ...[u]i64 constructs. nasmint.h makes this easy
enough that it is worth doing.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Instead of trying to do hacks in the Makefiles, define header files
for specific compilers if they can't use autoconf. Currently defined
for Microsoft Visual Studio, based on MSDN documentation. It is
currently untested.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
We search the dependency list anyway (ouch...) so we might as well
use that instead of keeping track of a tail pointer.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
We have been doing a pathname search every time we encounter a file,
which means every file in every pass. Instead, put the pathnames
found in a hash table.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
If we can't mmap a file and instead have to fread(), if the data is
small enough that we can reasonably accomodate it in a memory buffer,
then just read it once.
It seems rather unlikely that very large files would be used with
TIMES anyway.
Also note: the previous comment about nasm_file_size[_by_path]() being
invoked twice was spurious; it does not actually happen.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
A number of fairly common operations are invoked way too many times,
especially when using incbin. Drastically reduce the number of system
calls that need to be executed, and use memory mapping to reduce
unnecessary double buffering.
We could improve this further by leaving files open once used;
however, that might run into file count problems on some systems.
Still unclear is why we seem to invoke nasm_file_size() twice per pass
for incbin.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Move fseeko, ftello, and off_t definitions to nasmlib.h so that files
other than nasmlib/file.c can use them (already added to
asm/assemble.c).
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
This provides the first pass of assembler internals for a new, richer,
backend interface. It also reduces the amount of data carried in
function parameters inside the assembler.
The new interface is in the form of a structure, which will contain
substantially more information that the previous interface. This will
allow things like ELF GOT32X and Mach-O X86_64_RELOC_BRANCH
relocations to be reliably emitted.
This provides the initial set of structures. Future additions should
include:
1. Pass down the base symbol, if any.
2. Segments should be a structure rather than a number, and the
horrible hack of adding one for a segment reference should be
removed (OUT_SEGMENT replaces it.)
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
The ordering of the macro sets ended up changing due to the recent
file reorganization. Instead of forcing the order again, handle
multiple macro sets (rather than just two) in a coherent manner.
macros/macros.pl could use a cleanup of duplicated code, however.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
Make the source code easier to understand and keep track of by
organizing it into subdirectories depending on the function.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>