Commit Graph

38 Commits

Author SHA1 Message Date
H. Peter Anvin
892c4818ce Add support for backend-defined subsections and label hacks
MachO has this odd thing called "subsections via symbols", by which a
symbol can magically start what effectively is a new section. To
support this, add support for a calldown into the backend when a new
symbol is defined *at the current output location*, and allow it to
switch the current segment.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-05-30 14:48:18 -07:00
H. Peter Anvin
740ec3572b malloc: simplify nasm_malloc code, add nasm_strcatn()
Simplify the nasm_malloc() code by moving the pointer check into a
common subroutine.

We can now issue a filename error even for failures like malloc().

Add support for the gcc sentinel attribute (verify that a list ends
with NULL).

Add a handful of safe_alloc attributes.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-05-30 11:40:42 -07:00
H. Peter Anvin
281f5bd92c Merge branch 'master' of ssh://repo.or.cz/srv/git/nasm 2018-02-22 14:53:46 -08:00
H. Peter Anvin
6686fc627e Introduce cold function attribute
Attribute to deemphasize certain code paths.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-02-22 14:52:50 -08:00
Cyrill Gorcunov
53371ddd17 Merge branch 'nasm-2.13.xx'
* nasm-2.13.xx:
  nasmlib: Drop pure_func attrib from seg_alloc
  nasmlib: Drop unused seg_init
2018-02-10 00:44:07 +03:00
Cyrill Gorcunov
9f45a77f46 nasmlib: Drop pure_func attrib from seg_alloc
It not only reads static variable but writes it back as well.

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

Reported-by: Michael Šimáček <msimacek@redhat.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-02-10 00:40:46 +03:00
Cyrill Gorcunov
5eb1838b4d nasmlib: Drop unused seg_init
The helper has been eliminated in 2c4a4d5810

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-02-10 00:34:10 +03:00
H. Peter Anvin
81b62b9f54 Eliminate filename length restrictions, remote ofmt->filename()
Get rid of remaining dependencies on FILENAME_MAX, which ought to have
been removed a long time ago.

Remove ofmt->filename(); all implementations pretty much do the same
thing and there is absolutely no reason to duplicate that
functionality all over the place.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-12-20 13:38:20 -08:00
H. Peter Anvin
ece809789e Merge remote-tracking branch 'origin/nasm-2.13.xx'
Resolved conflicts:
	version

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-11-01 10:37:18 -07:00
H. Peter Anvin
aaefc7fe6b BR 3392442: correct vmin in overflow_general()
The calculation of vmin in overflow_general() was bogus, causing
silliness like ~80h being warned about in a byte context.

Reported-by: C. Masloch <pushbx@38.de>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-10-11 13:12:17 -07:00
H. Peter Anvin
0a126062fb ilog2(): inline functions if practical
For many (most?) targets these will be very small functions, so inline
them.  However, just in case make these external library functions.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-09-27 13:34:42 -07:00
H. Peter Anvin
fbce0bfb4e Merge remote-tracking branch 'origin/nasm-2.13.xx'
Resolved Conflicts:
	asm/directiv.dat
	asm/preproc.c
	misc/omfdump.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-08-16 22:41:40 -07:00
H. Peter Anvin
a771be85f4 outobj: emit file dependency information
Some OMF toolchain can make use of file dependency information
embedded in the object files.  As implemented here, we don't try to
absolutize the filenames, as that prevents moving around trees and is
OS-dependent.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-08-16 15:00:38 -07:00
H. Peter Anvin
20f6c253cd Merge remote-tracking branch 'origin/nasm-2.13.xx' 2017-05-01 21:25:14 -07:00
H. Peter Anvin
3e458a89d8 a) Fix handling of DZ/ZWORD; b) don't crash on TIMES JMP
a) Fix a number of missing instances of DZ and ZWORD.

b) NASM would crash if TIMES was used on an instruction which varies
   in size, e.g. JMP.  Fix this by moving the handling of TIMES at a
   higher level, so we generate the instruction "de novo" for each
   iteration.  The exception is INCBIN, so we can avoid reading the
   included file over and over.

c) When using the RESx instructions, just fold TIMES into the reserved
   space size; there is absolutely no point to iterate over it.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-05-01 21:13:15 -07:00
H. Peter Anvin
d3e22572b3 Clean up byteorder functions
Move byte order handling functions to their own header file, and try
to be more specific about how exactly to handle things.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-24 13:01:08 -07:00
H. Peter Anvin
e0172d5870 Merge branch 'master' into elf 2017-04-23 23:52:32 -07:00
H. Peter Anvin
11a07a7319 nasmlib: add function to splice pathnames
Add a function to splice a pathname consisting of a directory and a
filename.  It is worth noting that this function is limited to that
particular use case: in particular, it does NOT currently support
concatenating a filename which itself contains directory components to
a non-null directory.

Combining directory names is extremely system-dependent and probably
needs more than just parameterized code in many cases, for example,
on VMS combining "foo:[bar]" with "[baz]quux" should produce
"foo:[bar.baz]quux" whereas combining "foo:[bar]" and baz:quux" is an
outright error.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-23 23:01:00 -07:00
H. Peter Anvin
c4d75ddcbf Merge branch 'master' into elf
Resolved Conflicts:
	aclocal.m4
	output/outelf.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-18 16:08:54 -07:00
H. Peter Anvin
8dc965347d rdoff: use nasm-provided safe memory allocation and I/O
We already have abort-on-error memory allocation and I/O operations in
nasmlib, so use them for rdoff as well.

Delete long-since-obsolete rdoff Mkfiles directory.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-04-17 13:56:50 -07:00
H. Peter Anvin
5253f58c36 Add generic perfect string hashes, use for directives
Add a generic facility for generating perfect string hashes, where all
that is needed is an enum and a string table.  The existing mechanism
using a custom Perl script wrapped around a module continues to be
available for any use case where this particular approach isn't
sophisticated enough.

Much of this patch comes from renaming "enum directives" to "enum
directive" as a result of the string hash generator expecting a set of
uniform naming conventions.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-03 00:27:07 -07:00
H. Peter Anvin
e886c0e968 Change nasm_zero() to pass an object, not a pointer
Passing an object to nasm_zero() allows us to use it on arrays.
Otherwise the array will decay to a pointer and silently clear only
the first member of the array!

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-31 14:56:17 -07:00
Cyrill Gorcunov
2f038e9d5d nasmlib: Add _le helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-18 15:16:10 +03:00
H. Peter Anvin
b852d351f6 nasmlib.h: explicitly include <ctype.h>
There are macros in this file which depend on <ctype.h>, so treat them
that way.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-03-14 18:42:25 -07:00
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
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
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
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
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
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