Commit Graph

39 Commits

Author SHA1 Message Date
H. Peter Anvin
b20bc733c9 asm/*: Move directive processing to its own file, refactor error handling
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>
2017-03-07 19:31:04 -08:00
H. Peter Anvin
e90a89abe4 compiler.h: add redundant cast to quiet Watcom warning
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>
2017-03-01 00:52:48 -08:00
H. Peter Anvin
e29c7bb241 include/compiler.h: change __WATCOM__ to __WATCOMC__
The correct macro to test for (Open)Watcom is __WATCOMC__ not
__WATCOM__.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-02-28 23:05:17 -08:00
H. Peter Anvin
2958bcc6c2 compiler.h: correctly handle HAVE_DECL_*, test HAVE_DECL_STRNLEN
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>
2017-02-23 19:23:10 -08:00
H. Peter Anvin
be01d496d4 compiler.h: watcom_switch_hack() improvements
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>
2017-02-23 17:25:31 -08:00
H. Peter Anvin
e3cd70bc46 compiler.h: only use watcom_switch_hack() if necessary
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>
2017-02-23 17:22:58 -08:00
H. Peter Anvin
90303022b4 nasmlib.h: add nasm_zeron()
Add a nasm_zeron() convenience macro to match nasm_zero(); compare
nasm_new() vs nasm_newn().

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-02-21 11:32:22 -08:00
H. Peter Anvin
8930a8fc15 Properly keep track of the base of relative relocations
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>
2017-02-21 11:30:22 -08:00
H. Peter Anvin
164d24677a Support self-relative expressions in offsets and immediates
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>
2017-02-20 02:39:56 -08:00
H. Peter Anvin
9b4b92b014 watcom.h: horrific hack to support OpenWatcom switch limitations
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>
2017-02-20 00:36:53 -08:00
H. Peter Anvin
a92a7dce5e nasm_delete(): ugly hack to make it side-effect-free
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>
2017-01-24 14:04:44 -08:00
H. Peter Anvin
75f2c1e131 Put in a comment that nasm_delete isn't side effect safe
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>
2017-01-24 12:42:37 -08:00
H. Peter Anvin
5d7fdc1962 nasmlib.h: add a nasm_zero() macro to the pointer helpers
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>
2017-01-24 12:28:40 -08:00
H. Peter Anvin
94e4052a8a nasm_build_assert() -> nasm_static_assert()
The C11 standard calls this concept a static assert, so go with that
terminology.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-01-24 12:26:09 -08:00
H. Peter Anvin
4eb7a1f089 nasm_build_assert(): use better fallback implementation
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>
2017-01-24 12:24:03 -08:00
H. Peter Anvin
fc427c6fab nasmlib.h: slightly tidy up the definition of nasm_build_assert()
"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>
2017-01-22 21:06:05 -08:00
H. Peter Anvin
abd28c9ab9 If we have new features introduced by C11, use them
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>
2016-12-20 02:29:58 -08:00
H. Peter Anvin
7294d62040 compiler.h: use the correct symbol to test for __builtin_expect()
__builtin_expect() has leading underscores, they need to be reflected
in the symbol.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-11-15 15:53:38 -08:00
H. Peter Anvin
8b19083483 Better support for function attributes, autoconf cleanups
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>
2016-11-15 14:01:37 -08:00
H. Peter Anvin
472a7c1d17 Allow relative references to external symbols in data
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>
2016-10-31 08:44:25 -07:00
H. Peter Anvin
f5287231c1 Move canned OpenWatcom config to config/watcom.h.
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>
2016-10-19 13:23:04 -07:00
H. Peter Anvin
4c9132e3a0 compiler.h: include <sys/types.h>
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>
2016-10-19 13:13:38 -07:00
H. Peter Anvin
44e3a11087 compiler.h: fix typo in the non-gcc case
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-10-14 15:05:28 -07:00
H. Peter Anvin
9b733a5845 compiler.h: for newer gcc attributes, we can use __has_attribute()
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>
2016-10-14 15:01:06 -07:00
H. Peter Anvin
194751404b nasmint.h: change header guards to NASM_NASMINT_H
Change the header guards for nasmint.h to NASM_NASMINT_H instead of
INTTYPES_H.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-10-04 18:11:57 -07:00
H. Peter Anvin
4b189f89d0 nasmint.h: add support for the MSVS < 2005 __int64 type
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>
2016-10-04 18:09:01 -07:00
H. Peter Anvin
276785a8ff config: add configuration file for unknown compilers
Add a config header file for the most conservative case of a totally
unknown compiler.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-10-04 17:13:50 -07:00
H. Peter Anvin
397c169736 Move config.h to a subdirectory, add MSVC-specific config file
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>
2016-10-04 17:01:59 -07:00
H. Peter Anvin
436e367874 Factor out common string list handling code
Simplify the preprocessor code by factoring out the common string list
handling code.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-10-04 01:12:28 -07:00
H. Peter Anvin
9924d1ea85 preproc: clean up handing of the dependency lists
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>
2016-10-04 00:59:39 -07:00
H. Peter Anvin
169ac7c152 Add a hash for pathname searches, instead of searching very pass
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>
2016-09-25 17:08:05 -07:00
H. Peter Anvin
fa803abc61 backend: move wrapper for legacy output functions to a library routine
Move the wrapper for legacy output into a library routine so the
backends can be ported one at a time.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-09-24 09:46:47 -07:00
H. Peter Anvin
04445364fc incbin: if we have to fread(), try to do it only once...
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>
2016-09-21 15:56:19 -07:00
H. Peter Anvin
d81a235f33 file: improve the file access interface
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>
2016-09-21 14:07:17 -07:00
H. Peter Anvin
c170089e7c nasmlib: move fseeko/ftello/off_t replacements to nasmlib.h
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>
2016-09-20 18:26:42 -07:00
H. Peter Anvin
a77692b34d New backend interface - assembler internals #1
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>
2016-09-20 16:05:09 -07:00
Cyrill Gorcunov
43bb293432 Merge branch 'nasm-2.12.xx'
* nasm-2.12.xx:
  codeview: Fix ill-formed "S_COMPILE2" record.
  rdoff: Add rdf2bin input dependency
  labels: Warn if new label created on pass two
  Add explicit void parameter to newmembuf() function declaration.
  compiler.h: always undefine __STRICT_ANSI__ for gcc

| Conflicts:
|	rdoff/Makefile.in

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-07-27 01:08:51 +03:00
H. Peter Anvin
f7606613d0 Handle multiple standard macro sets sanely
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>
2016-07-13 14:23:48 -07:00
H. Peter Anvin
e1f985c167 Reorganize the source code into subdirectories
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>
2016-05-25 12:06:29 -07:00