summaryrefslogtreecommitdiff
path: root/include/nasmlib.h
Commit message (Collapse)AuthorAgeFilesLines
* preproc: fix parsing of single-line macro arguments, cleanupsH. Peter Anvin (Intel)2019-08-091-3/+15
| | | | | | | | | | | | | | | | | | | | The single-line macro argument parsing was completely broken as a comma would not be recognized as an argument separator. In the process of fixing this, make a fair bit of code cleanups. Note: reverse tokens for smacro->expansion doesn't actually make any sense anymore, might reconsider that. This checkin also removes the distinction between "magic" and plain smacros; the only difference is which specific expand method is being invoked. Finally, extend the allocating-string functions such that *all* the allocating string functions support querying the length of the string a posteori. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* nasmlib.h: fix indentation in nasm_try_static_assert()H. Peter Anvin2019-06-061-1/+1
| | | | | | | Fix missing indentation in nasm_try_static_assert() which made the code hard to read. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Merge branch 'master' of ssh://repo.or.cz/nasmH. Peter Anvin2019-06-061-0/+13
|\ | | | | | | | | | | | | Resolved Conflicts: asm/preproc.c Signed-off-by: H. Peter Anvin <hpa@zytor.com>
| * preproc: massive cleanup of smacro expansionH. Peter Anvin (Intel)2019-04-251-0/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The smacro expansion code was virtually impossible to understand, and was leading to very strange failures. Clean it up, and do much better handling of magic macros. This should also allow for recursive macros, but recursive macros are extremely tricky in that it is very hard to keep them from recursing forever, unless there is at least one argument which is never expanded. They are not currently implemented. Even so, I believe token pasting makes it possible to create infinite loops; e.g.: %define foo foo %+ Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | quote: disallow control characters in C strings; concatendate; cleanupsH. Peter Anvin2019-04-221-2/+6
|/ | | | | | | | | | | | In nasm_unquote_cstr(), disallow any control character, not just NUL. This will matter when allowing quoting symbols. Merge nasm_unquote() and nasm_unquote_cstr(). Strings can now be concatenated, C style: adjacent quoted strings (including whitespace-separated) are merged into a single string. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* nasmlib.h: clarify the semantics of nasm_aprintf_size()H. Peter Anvin2018-12-271-1/+2
| | | | | | | nasm_aprintf_size() does include the final NUL byte, but does not include any prefix storage allocated by nasm_[v]axprintf(). Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Move <strings.h> inclusion to "compiler.h"H. Peter Anvin2018-12-271-4/+0
| | | | | | | | Move the inclusion of <strings.h> from nasmlib.h to compiler.h Try to centralize compiler dependences as much as possible. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Remove #includes already provided by "compiler.h"H. Peter Anvin2018-12-271-1/+0
| | | | | | | | "compiler.h" already includes a bunch of common include files. There is absolutely no reason to duplicate them in individual files, and in fact it robs us of central control of how these files are used. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Move <string.h> inclusion to compiler.hH. Peter Anvin2018-12-261-1/+0
| | | | | | | There is absolutely no reason not to include <string.h> globally, and with the inline function for mempcpy() we need it there anyway. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* nasmlib: Fix space/tabs messCyrill Gorcunov2018-12-151-28/+28
| | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* nasm_assert(): try to run at compile time if possibleH. Peter Anvin (Intel)2018-12-141-17/+45
| | | | | | | | | | 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>
* strlist: can be unique or not, add printf functionsH. Peter Anvin (Intel)2018-12-131-1/+8
| | | | | | | | | | 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>
* asprintf: add "axprintf" functions that allocate extra storageH. Peter Anvin (Intel)2018-12-131-4/+10
| | | | | | | | Add a set of variants on the asprintf functions, "axprintf", which allocate extra storage for metadata at the head of the allocated buffer. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* nasmlib: Add nasm_(v)asprintf()H. Peter Anvin (Intel)2018-12-121-5/+13
| | | | | | | | | 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>
* Move srcfile.c to asm/H. Peter Anvin2018-12-101-17/+1
| | | | | | srcfile.c is not used by anything outside asm/, so move it there. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* ctype: create our own ctype tableH. Peter Anvin2018-11-281-18/+0
| | | | | | | | 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>
* segalloc: DO NOT reset segment numbersH. Peter Anvin2018-06-141-2/+0
| | | | | | | | | | We are not supposed to reset the segment numbers; this was an attempted fix for a convergence bug that didn't actually exist. The backend is required to return the same segment number for the same segment; if it does not, the front end will not converge, but that is in fact the correct behavior. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
* Make any execution limit configurable, add eval limitH. Peter Anvin2018-06-121-1/+1
| | | | | | | Make any "deadman"-style execution limit configurable on the command line (--limit-foo) or via a pragma (%pragma limit foo). Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
* Unbreak special segment symbols, unbreak COMMONH. Peter Anvin2018-06-111-1/+2
| | | | | | | | | | | | Recent changes broke: 1. Backend-provided special segments, due to seg_alloc() getting reset. 2. COMMON; the old code would pass size in the "offset" *without* setting it in the label structure. Containing all this information in the label structure requires another field. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
* Add support for backend-defined subsections and label hacksH. Peter Anvin2018-05-301-0/+1
| | | | | | | | | | 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>
* malloc: simplify nasm_malloc code, add nasm_strcatn()H. Peter Anvin2018-05-301-2/+2
| | | | | | | | | | | | | | 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>
* Merge branch 'master' of ssh://repo.or.cz/srv/git/nasmH. Peter Anvin2018-02-221-3/+1
|\
| * Merge branch 'nasm-2.13.xx'Cyrill Gorcunov2018-02-101-3/+1
| |\ | | | | | | | | | | | | | | | * nasm-2.13.xx: nasmlib: Drop pure_func attrib from seg_alloc nasmlib: Drop unused seg_init
| | * nasmlib: Drop pure_func attrib from seg_allocCyrill Gorcunov2018-02-101-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| | * nasmlib: Drop unused seg_initCyrill Gorcunov2018-02-101-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | The helper has been eliminated in 2c4a4d5810d0a59b033a07876a2648ef5d4c2859 https://bugzilla.nasm.us/show_bug.cgi?id=3392461 Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* | | Introduce cold function attributeH. Peter Anvin2018-02-221-1/+1
|/ / | | | | | | | | | | Attribute to deemphasize certain code paths. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | Eliminate filename length restrictions, remote ofmt->filename()H. Peter Anvin2017-12-201-3/+2
| | | | | | | | | | | | | | | | | | | | | | 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>
* | Merge remote-tracking branch 'origin/nasm-2.13.xx'H. Peter Anvin2017-11-011-1/+1
|\ \ | |/ | | | | | | | | | | Resolved conflicts: version Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
| * BR 3392442: correct vmin in overflow_general()H. Peter Anvin2017-10-111-1/+1
| | | | | | | | | | | | | | | | 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>
* | ilog2(): inline functions if practicalH. Peter Anvin2017-09-271-12/+0
| | | | | | | | | | | | | | 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>
* | Merge remote-tracking branch 'origin/nasm-2.13.xx'H. Peter Anvin2017-08-161-0/+1
|\ \ | |/ | | | | | | | | | | | | | | Resolved Conflicts: asm/directiv.dat asm/preproc.c misc/omfdump.c Signed-off-by: H. Peter Anvin <hpa@zytor.com>
| * outobj: emit file dependency informationH. Peter Anvin2017-08-161-0/+1
| | | | | | | | | | | | | | | | | | 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>
* | Merge remote-tracking branch 'origin/nasm-2.13.xx'H. Peter Anvin2017-05-011-2/+0
|\ \ | |/
| * a) Fix handling of DZ/ZWORD; b) don't crash on TIMES JMPH. Peter Anvin2017-05-011-2/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Clean up byteorder functionsH. Peter Anvin2017-04-241-128/+2
| | | | | | | | | | | | | | 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>
* | Merge branch 'master' into elfH. Peter Anvin2017-04-231-1/+8
|\ \ | |/
| * nasmlib: add function to splice pathnamesH. Peter Anvin2017-04-231-1/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Merge branch 'master' into elfH. Peter Anvin2017-04-181-2/+7
|\ \ | |/ | | | | | | | | | | | | Resolved Conflicts: aclocal.m4 output/outelf.c Signed-off-by: H. Peter Anvin <hpa@zytor.com>
| * rdoff: use nasm-provided safe memory allocation and I/OH. Peter Anvin2017-04-171-1/+3
| | | | | | | | | | | | | | | | | | 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>
| * Add generic perfect string hashes, use for directivesH. Peter Anvin2017-04-031-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
| * Change nasm_zero() to pass an object, not a pointerH. Peter Anvin2017-03-311-1/+1
| | | | | | | | | | | | | | | | 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>
* | nasmlib: Add _le helpersCyrill Gorcunov2017-03-181-0/+31
|/ | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* nasmlib.h: explicitly include <ctype.h>H. Peter Anvin2017-03-141-0/+1
| | | | | | | 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>
* asm/*: Move directive processing to its own file, refactor error handlingH. Peter Anvin2017-03-071-75/+0
| | | | | | | | 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>
* nasmlib.h: add nasm_zeron()H. Peter Anvin2017-02-211-0/+1
| | | | | | | 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>
* nasm_delete(): ugly hack to make it side-effect-freeH. Peter Anvin2017-01-241-3/+14
| | | | | | | | | | 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>
* Put in a comment that nasm_delete isn't side effect safeH. Peter Anvin2017-01-241-0/+4
| | | | | | | | 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>
* nasmlib.h: add a nasm_zero() macro to the pointer helpersH. Peter Anvin2017-01-241-0/+1
| | | | | | | | | | 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>
* nasm_build_assert() -> nasm_static_assert()H. Peter Anvin2017-01-241-3/+3
| | | | | | | The C11 standard calls this concept a static assert, so go with that terminology. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* nasm_build_assert(): use better fallback implementationH. Peter Anvin2017-01-241-2/+4
| | | | | | | | 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>