summaryrefslogtreecommitdiff
path: root/nasmlib
Commit message (Collapse)AuthorAgeFilesLines
* rbtree: add rb_search_exact()HEADmasterH. Peter Anvin (Intel)2020-07-081-0/+8
| | | | | | | | Sometimes we want to search for an exact key only, and reject the case when tree->key < key. Add rb_search_exact() for this purpose, rather than forcing the caller to perform the comparison in open code. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* rbtree: implement rb_first(), rb_last() operationsH. Peter Anvin (Intel)2020-07-081-10/+26
| | | | | | | | | | | | | | | | | | Add operations to get the first and last entry in the tree, respectively. Searching for 0 or ~UINT64_C(0) is not sufficient in the presence of duplicated keys, and is more inefficient anyway. rb_first() followed by rb_next() until NULL, or equivalently rb_last() followed by rb_prev() until NULL, can be used to walk the tree in key order (ascending or descending), including all duplicate key entries. Since this is a *threaded* tree now, this walk can safely free entires as it goes along, as long as the whole tree is destroyed; once any one entry has been freed, the tree is no longer valid for anything other than proceeding with the same tree walk. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* Merge remote-tracking branch 'github/nasm-2.15.xx'H. Peter Anvin (Intel)2020-06-302-5/+6
|\ | | | | | | | | | | | | Resolved Conflicts: version Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
| * BR 3392687: clang miscompiles offsetin() for uninitialized pointerH. Peter Anvin (Intel)2020-06-301-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The actual pointer value in offsetin() cancels out, but clang still miscompiles offsetin() for an uninitialized pointer, considering the value to be completely undefined. Initialize pointer being passed to offsetin() to make clang happy; both the gcc and clang optimizers discover later in the code that the initialization is unused and removes it from the code. Although technically undefined behavior, this is in my opinion a severe quality of implementation bug in clang, and I will file a bug report accordingly. Reported-by: Jasper Lievisse Adriaanse <r+nasm@jasper.la> Reported-by: David Bohman <debohman@gmail.com> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
| * hash generators: rename UNUSED to UNUSED_HASH_ENTRYH. Peter Anvin (Intel)2020-06-301-3/+3
| | | | | | | | | | | | | | | | The name UNUSED is too generic and may conflict with future macro definitions. This is machine-generated code anyway, so rename UNUSED to UNUSED_HASH_ENTRY. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | rbtree: implement a "threaded LLRB tree"H. Peter Anvin (Intel)2020-06-291-48/+164
|/ | | | | | | | | | | | | | Change the left-leaning red-black (LLRB) trees into left-leaning threaded red-black trees. Instead of NULL pointers at leaf nodes, use the otherwise unused field as a pointer to the lexical predecessor (left) or successor (right). This allows fast previous/next interator operation without needing to keep track of the root of the tree at all times. The additional metadata that needs to be kept can be done for "free" simply by changing "bool red" into a flag field. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* hashtbl.c: don't call nasm_free() for a null pointerH. Peter Anvin (Intel)2020-06-081-2/+3
| | | | | | | There really isn't much point in calling nasm_free() everywhere, even with a null pointer... Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* BR 3392667: more reasonable limit for expression descentH. Peter Anvin (Intel)2020-06-011-0/+78
| | | | | | | | 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>
* disam: explicitly change stdin to binary modeChang S. Bae2020-04-222-0/+27
| | | | | | | | | | | | | | | | | | | The binary mode has no difference from text mode in POSIX-compliant operating systems. The two modes are distinguishable from each other on Windows, and perhaps on other systems as well. The binary stream has scalability and other advantages. Windows treats the standard input stream as text mode by default. So the code changes it to binary mode. Also, add a helper function, nasm_set_binary_mode(), that is OS-agnostic, in the library. Reported-by: Didier Stevens <didier.stevens@gmail.com> Suggested-by: Didier Stevens <didier.stevens@gmail.com> Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392649 Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
* listing: make it possible to flush the listing output after every lineH. Peter Anvin (Intel)2019-10-231-0/+14
| | | | | | | Add the -Lw option to flush the list file after every line output. This is handy for debugging if nasm hangs. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* Win32: when converting filenames to UTF-16, don't add \\?\H. Peter Anvin2019-10-031-13/+10
| | | | | | | | | | | | | \\?\ is supposed to override the hard-coded path limit, but it has other effects as well, such as not working with relative paths and paths containing /. On Windows 10 it is possible to set a registry key to override this option anyway. Maybe one day we can just use fopen() like on normal systems, even... Signed-off-by: H. Peter Anvin <hpa@zytor.com> Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392614 Reported-by: Iouri Kharon <bc-info@styx.cabel.net>
* preprocessor: major cleanups; inline text into Tokenpp-inlineH. Peter Anvin2019-09-231-15/+11
| | | | | | | | | | | | | Major cleanups of the preprocessor. In particular, the block-allocation of Token is pretty ridiculous since nearly every token requires a text allocation anyway. Change the definition of Token so that only very long tokens (48+ characters on 64-bit systems) need to be stored out of line. If malloc() preserves alignment (XXX: glibc doesn't) then this means that each Token will fit in a cache line. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* errors: be more robust in handling unexpected fatal errorsH. Peter Anvin2019-08-282-19/+3
| | | | | | | | | | | | | Introduce a new error level, ERR_CRITICAL, beyond which we will minimize the amount of code that will be executed before we die; in particular don't execute any memory allocations, and if we somehow end up recursing, abort() immediately. Basically, "less than panic, more than fatal." At this point this level is used by nasm_alloc_failed(). Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* BR 3392597: the system malloc() can return NULLH. Peter Anvin (Intel)2019-08-161-6/+41
| | | | | | | | | | | | | | malloc(0) can legitimately return NULL; it does on some systems and not others. Force the size to 1 byte if the size is 0 coming in, except for realloc() where this is legitimate and equivalent to free(). Since this is an abnormal case, and can't even happen with most C libraries, handle it on the error path, after we already got back a NULL pointer. Reported-by: Ozkan Sezer <sezeroz@gmail.com> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* perl files: clean up warningsH. Peter Anvin (Intel)2019-08-091-3/+3
| | | | | | | | | | | | Clean up some perl warnings, some of which were legitimate (apparently undef doesn't actually take a list of arguments, a common enough mistake that it is mentioned in the man page!, and a list of variables after "my" can be cantankerous), and some of which were nuisance but were easy enough to clean up. Maybe this can resolve the problems with very old version of Perl? Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* preproc: fix parsing of single-line macro arguments, cleanupsH. Peter Anvin (Intel)2019-08-094-12/+24
| | | | | | | | | | | | | | | | | | | | 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>
* update watcom config file.Ozkan Sezer2019-08-071-1/+3
| | | | | | | also a tiny change to nasm_file_exists() so that it builds with c89 compilers. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* Replace nasm_error(ERR_WARNING|...) with nasm_warn()H. Peter Anvin (Intel)2019-08-061-1/+1
| | | | | | Remove a few remaining instances of nasm_error(ERR_WARNING). Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* file.c: the "rb" os_fopen() flags are static in two places, simplifyH. Peter Anvin (Intel)2019-05-151-8/+5
| | | | | | | We can still allocate these as a static array, just not a static string. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* file.c: handle long pathnames on WindowsH. Peter Anvin (Intel)2019-05-152-101/+295
| | | | | | | | | | 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>
* preproc: massive cleanup of smacro expansionH. Peter Anvin (Intel)2019-04-251-5/+0
| | | | | | | | | | | | | | | | 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>
* Merge branch 'evalmacro'H. Peter Anvin (Intel)2019-04-241-4/+10
|\ | | | | | | | | | | | | | | | | | | | | 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>
| * SAA: allow seeking beyond the end of the arrayH. Peter Anvin2019-02-251-4/+10
| | | | | | | | | | | | | | If putting the file pointer past the end of the array, expand the array with zeroes. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
| * errfile.c: add file missing from previous checkinH. Peter Anvin (Intel)2018-12-131-0/+5
| | | | | | | | | | | | File was missing from checkin Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | Remove #includes already provided by "compiler.h"H. Peter Anvin2018-12-273-4/+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>
* | Replace <ctype.h> includes with "nctype.h"H. Peter Anvin2018-12-271-1/+1
| | | | | | | | | | | | | | For almost everything we should use "nctype.h". Right now we don't have a nasm_toupper() to use <ctype.h> for things that need toupper(). Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | nasmlib/ver.[ch]: add "compiler.h"H. Peter Anvin2018-12-261-2/+0
| | | | | | | | | | | | We should use "compiler.h", not just include <stdlib.h> explicitly. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | Move <string.h> inclusion to compiler.hH. Peter Anvin2018-12-264-4/+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>
* | With buffered warnings, change the handling of error passesH. Peter Anvin (Intel)2018-12-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With buffered warnings, most warnings *must* be issued on every pass, so ERR_PASS1 is simply wrong in most cases. ERR_PASS1 now means "force this warning to be output even in pass_first(). This is to be used for the case where the warning is only executed in pass_first() code; this is highly discouraged as it means the warnings will not appear in the list file and subsequent passes may make the warning suddenly vanish. ERR_PASS2 just as before suppresses an error or warning unless we are in pass_final(). Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | Restore the ability to have ? in identifiers, except ? itselfH. Peter Anvin (Intel)2018-12-141-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | ? in identifiers turns out to be used in the field even in non-TASM mode. Resolve this by allowing it in an identifier still, but treat '?' by itself the same as we would a keyword, meaning that it needs to be separated from other identifier characters. In other words: a ? b : c ; conditional expression a?b:c ; seg:off expression seg = a?b, off = c Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | Define and use offsetin() instead of offsetof()H. Peter Anvin (Intel)2018-12-141-1/+1
| | | | | | | | | | | | | | | | New macro which defines the offset on an object rather than a type. This macro, as far as I know, ought to be fully portable, unlike the fallback version of offsetof(). Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | strlist, warnings: improve strlist, buffer warnings until errorH. Peter Anvin (Intel)2018-12-141-10/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Make strlist_free() take a pointer to a pointer, so we can set it to NULL. Buffer warnings on a strlist until we either get an error or we are in pass 2. Hopefully this should let us get rid of a lot of the ERR_PASS* bullshit, which far too often causes messages to get lost. asm/labels.c contains one example of a warning that cannot be made correct with a specific pass number. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | hashtbl: fix errors in hash_iterate() and hash_free()H. Peter Anvin (Intel)2018-12-141-13/+10
| | | | | | | | | | | | | | Both of these functions were apparently subtly broken after the revamp to the new interfaces. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | strlist: make sure strlist_free() works for a non-uniqizing list tooH. Peter Anvin (Intel)2018-12-131-1/+8
| | | | | | | | | | | | We can't rely on hash_free_all() when using a non-uniqizing list. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | strlist: can be unique or not, add printf functionsH. Peter Anvin (Intel)2018-12-132-20/+82
| | | | | | | | | | | | | | | | | | | | 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>
* | Merge branch 'mkwarnings'H. Peter Anvin (Intel)2018-12-131-1/+7
|\ \ | | | | | | | | | | | | | | | | | | Resolved conflicts: asm/nasm.c Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
| * | warnings: define warning classes at point of usemkwarningsH. Peter Anvin (Intel)2018-12-131-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is extremely desirable to allow the user fine-grained control of warnings, but this has been complicated by the fact that a warning class has had to be defined in no less than three places (error.h, error.c, nasmdoc.src) before it can be used in source code. Instead, use a script to define these via magic comments at the point of use. This hopefully will encourage creating new classes as needed. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | | asprintf: add "axprintf" functions that allocate extra storageH. Peter Anvin (Intel)2018-12-131-14/+32
| | | | | | | | | | | | | | | | | | | | | | | | 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>
* | | asprintf: actually include asprintf.cH. Peter Anvin (Intel)2018-12-131-0/+70
|/ / | | | | | | | | | | File missing from earcier checkin... Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | Merge remote-tracking branch 'origin/nasm-2.14.xx'H. Peter Anvin (Intel)2018-12-132-1/+22
|\ \ | |/ | | | | | | | | | | | | | | | | | | Resolved Conflicts: Makefile.in Mkfiles/msvc.mak Mkfiles/openwcom.mak asm/nasm.c nasmlib/alloc.c Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
| * malloc: handle potential infinite loop in nasm_alloc_failed()H. Peter Anvin (Intel)2018-12-131-1/+17
| | | | | | | | | | | | | | | | | | It is possible on memory exhaustion that nasm_fatal() might cause another allocation error, thus calling nasm_alloc_failed() again. If we find us in nasm_alloc_failed() for a second time, try to get a message out and then call abort(). Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
| * warnings: rename ERR_WARN_* to WARN_*H. Peter Anvin (Intel)2018-12-121-1/+1
| | | | | | | | | | | | | | | | The prefix ERR_WARN_ is unnecessarily long and may be a disincentive to create new warning categories. Change it to WARN_*, it is still plenty distinctive. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | warnings: Make WARN_ constants consistent with -w optionsH. Peter Anvin (Intel)2018-12-121-1/+1
| | | | | | | | | | | | Not only does this make it consistent, but allows for automation. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | warnings: rename ERR_WARN_* to WARN_*H. Peter Anvin (Intel)2018-12-121-1/+1
| | | | | | | | | | | | | | | | | | | | The prefix ERR_WARN_ is unnecessarily long and may be a disincentive to create new warning categories. Change it to WARN_*, it is still plenty distinctive. This is equivalent to nasm-2.14.xx checkin 77f53ba6d4cb90e5a7e09b33357ed7c1fe9f6b9d. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | nasmlib: Add nasm_(v)asprintf()H. Peter Anvin (Intel)2018-12-122-11/+50
| | | | | | | | | | | | | | | | | | 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>
* | strlist: merge the strtbl and strlist interfacesH. Peter Anvin (Intel)2018-12-111-6/+42
| | | | | | | | | | | | | | | | The currently-unused strtbl was basically a slightly different version of strlist, with the find and linearize capabilities. Merge these two together by augmenting strlist to have the same capabilities. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | hashtbl: revamp the hash table interface, support binary keysH. Peter Anvin (Intel)2018-12-113-102/+156
| | | | | | | | | | | | | | Add binary key support to the hash table interface. Clean up the interface to contain less extraneous crud. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | Move srcfile.c to asm/H. Peter Anvin2018-12-101-122/+0
| | | | | | | | | | | | srcfile.c is not used by anything outside asm/, so move it there. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | nctype: add nasm_isquote()H. Peter Anvin2018-11-281-7/+10
| | | | | | | | | | | | Add nasm_isquote() to test for a NASM quoted string. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | ctype: create our own ctype tableH. Peter Anvin2018-11-283-20/+114
| | | | | | | | | | | | | | | | 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>