aboutsummaryrefslogtreecommitdiffstats
path: root/include
Commit message (Collapse)AuthorAgeFilesLines
* preprocessor: major cleanups; inline text into Tokenpp-inlineH. Peter Anvin2019-09-231-2/+8
| | | | | | | | | | | | | 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>
* Change LBL_NONE to LBL_noneH. Peter Anvin2019-09-121-1/+1
| | | | | | | | | | | NASM convention is to use all-upper-case for "real" information, and mixed-case (upper case common prefix, lower case description) for meta-information. This is a highly useful distinction. Thus "LBL_NONE" implies an actual label of type "NONE", as opposed to no label at all. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* Drop unnecessary EXTERN symbolsH. Peter Anvin2019-09-121-4/+9
| | | | | | | | | | | | Currently, NASM always issues as an unknown symbol any symbol declared EXTERN. This is highly undesirable when using common header files, as it might cause the linker to pull in a bunch of unnecessary modules, depending on how smart the linker is. Add a new REQUIRED directive which behaves like the old EXTERN, for the use cases which might still need this behavior. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* error: replace nasm_verror() indirection with preproc callbackH. Peter Anvin2019-08-282-9/+4
| | | | | | | | | | Since pp_error_list_macros() was introduced, the only need for pp_verror() is to suppress error messages in certain contexts. Replace this function with a preprocessor callback, preproc->pp_suppress_error(), so we can drop the nasm_verror() function pointer entirely. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* errors: be more robust in handling unexpected fatal errorsH. Peter Anvin2019-08-281-2/+6
| | | | | | | | | | | | | 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>
* preproc: standard macros now C-safe, %aliases off, fix %? recursionH. Peter Anvin2019-08-271-4/+4
| | | | | | | | | | | | | | | | | | | | Enough users expect the namespace starting with underscore to be safe for symbols. Change our private namespace from __foo__ to __?foo?__. Use %defalias to provide backwards compatiblity (by using %defalias instead of %define, we handle the case properly where the user changes the value.) Add a preprocessor directive: %aliases off ... to disable all smacro aliases and thereby making the namespace clean. Finally, fix infinite recursion when seeing %? or %?? due to paste_tokens(). If we don't paste anything, the expansion is done. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* BR 3392597: the system malloc() can return NULLH. Peter Anvin (Intel)2019-08-161-1/+1
| | | | | | | | | | | | | | 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>
* config.h: separate function and function pointer attributes; automateH. Peter Anvin (Intel)2019-08-161-75/+22
| | | | | | | | | | | | Separate out function and function pointer attributes, as not all versions of all compilers support both. Have macros related to function attributes auto-generated by autoheader. As a result, rename config.h.in to unconfig.h, to make it more obvious that it is really intended to be included from some C programs. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* preproc: fix mmacro nesting preventionH. Peter Anvin (Intel)2019-08-151-0/+1
| | | | | | | BR 3392602: mmacros should not nest unless so explicitly specified. Reported-by: C. Masloch <pushbx@38.de> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* macros: can't use the __USE_*__ macro string anymore; fix comment strippingH. Peter Anvin (Intel)2019-08-151-1/+8
| | | | | | | | | | Since we use 127 not 0 for end of line in stdmac packages now, we can't simply use the __USE_*__ macro as a string to test for a %use package. Keep an internal array of state instead. Fix the stripping of comments from lines in macro files. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* masm.mac, parser: VERY limited MASM emulation packageH. Peter Anvin (Intel)2019-08-141-0/+2
| | | | | | | | | | Very limited MASM emulation. The parser has been extended to emulate the PTR keyword if the corresponding macro is enabled, and the syntax displacement[index] for memory operations is now recognized. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* LEA: allow immediate syntax; ignore operand size entirelyH. Peter Anvin (Intel)2019-08-141-1/+1
| | | | | | | The memory operand size of LEA doesn't matter in any way as it isn't "real memory". Add an ANYSIZE option to ignore sizes entirely. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* Clean up backend format namesH. Peter Anvin2019-08-101-1/+0
| | | | | | | The backend format names were rather redundant and not always helpful. Do some cleanup. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Additional listing options, improve help output, fix macro limitsH. Peter Anvin2019-08-101-1/+5
| | | | | | | | | | | | | | | | | | Additional listing options: -Ld to display counts in decimal -Lp to output a list file in every pass (to make sure one exists) Clean up the help output and make it comprehensive. The -hf and -y options are no longer necessary, although they are supported for backwards compatiblity. Fix macro-levels so it actually count descent levels; a new macro-tokens limit introduced for the actual token limit. Slightly simplify the limits code. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* compiler.h: fix bad typedef in case of HAVE__BOOLOzkan Sezer2019-08-091-1/+1
| | | | | | | | Fix stray # mark in typedef _Bool bool. What compiler has _Bool and not <stdbool.h>? Weird... Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* error.h: fix typo: nasm_intof -> nasm_infofH. Peter Anvin (Intel)2019-08-091-1/+1
| | | | | | | BR 3302593: nasm_infof() prototype misspelled as nasm_intof(). Reported-by: <pushbx@38.de> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* listing: add -L option for additional listing infoH. Peter Anvin (Intel)2019-08-091-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | Add an -L option for additional listing information. Currently supported is -Le, which emits each line after processing through the preprocessor, and -Lm, which displays each single-line macro defined or undefined. NASM doesn't preserve the names of unused arguments, nor does it have any technical reason to do so. Instead of adding complexity to save them, make unnamed parameters official by specifying an empty string in the argument list. This has the additional advantage that () is now simply considered a single empty argument, which means that NASM should now properly handle things like: %define myreg() eax mov edx,myreg() ... similar to how the C preprocessor allows an empty macro argument list which is distinct from a macro with no arguments whatsoever. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* Diagnostics: make debug more dynamic, note -> info, add listmsg levelH. Peter Anvin (Intel)2019-08-091-7/+24
| | | | | | | | | | | | | | | | Make debug messages more dynamic by making it easy to conditionalize the messages. Change ERR_NOTE to ERR_INFO which reflects the usage better. Other compilers use note: for additional information. Don't unwind the macro stack with ERR_HERE; it is only going to give confusing results as it will unwind the wrong macro stack. Add ERR_LISTMSG level which is *always* suppressed, but will still appear in the list file. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* 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>
* iflag.h: fix IF_CPU_LEVEL_MASK, add missing CPU definitionsH. Peter Anvin (Intel)2019-08-061-2/+2
| | | | | | | | | Fix the definition of IF_CPU_LEVEL_MASK (which was missing the top bit, IFM_ANY itself). Add CPU definitions that we actually have into directiv.c. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* iflag.h: simplify, fix iflag_cmp() when bit 31 is setH. Peter Anvin (Intel)2019-08-061-25/+14
| | | | | | | | | | Additional simplifications, including using the new IFM_ masks, and make IF_GENBIT() automatically mask the field number. When bit 31 in a field is set, iflag_cmp() could return the wrong ordering value. Fix. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* iflags: move definitions to a separate file; auto-generate moreH. Peter Anvin (Intel)2019-08-061-18/+5
| | | | | | | | | | Move the definitions to a separate file, in order to separate code from data better. We can auto-generate more information about the instruction flags, so let's do so. 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>
* warnings: add [warning push] and [warning pop]H. Peter Anvin (Intel)2019-01-111-0/+6
| | | | | | Add [warning push] and [warning pop] directives. Signed-off-by: H. Peter Anvin (Intel) <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-272-4/+3
| | | | | | | | 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-274-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>
* Merge tag 'nasm-2.14.03rc1'H. Peter Anvin2018-12-271-0/+1
|\ | | | | | | | | | | | | | | | | | | NASM 2.14.03rc1 Resolved Conflicts: asm/labels.c include/error.h Signed-off-by: H. Peter Anvin <hpa@zytor.com>
| * BR 3392539: some errors can "cascade". Allow suppressing if dead.H. Peter Anvin2018-12-271-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In BR 3392539, the error: helloW.s:18: error: label `rurt' changed during code generation [-w+error=label-redef-late] ... occurs a number of times after we have already issued an error. This is because the erroring instruction computes to a different size during code generation; this causes each subsequent label to cause a phase error. The phase error simply doesn't make much sense to report: if we are already committed to erroring out, it is more likely an error cascade rather than an error in its own right, so just suppress it in that case. Reported-by: <russvz@comcast.net> Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | compiler.h: need to cast a (void *) to (char *) before addingH. Peter Anvin2018-12-261-1/+1
| | | | | | | | | | | | | | | | | | In the implementation of mempcpy(): Doing arithmetic on (void *) isn't permitted, so we need to cast it to (char *); it then get automatically converted to void * by the return. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | nasmlib/ver.[ch]: add "compiler.h"H. Peter Anvin2018-12-261-0/+2
| | | | | | | | | | | | 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-263-2/+1
| | | | | | | | | | | | | | 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>
* | Test for the mempcpy() function and add alternative if missingH. Peter Anvin2018-12-261-0/+7
| | | | | | | | | | | | | | If memcpy() doesn't exist, then add an inline alternative using memcpy(). Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | Factor out size tokens and annotate with the corresponding sizeH. Peter Anvin2018-12-241-10/+26
| | | | | | | | | | | | | | There is space in the token table to explicitly encode the size corresponding to a size token. We might as well do so... Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | With buffered warnings, change the handling of error passesH. Peter Anvin (Intel)2018-12-181-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | Clean up the handling of various passesH. Peter Anvin (Intel)2018-12-181-17/+72
| | | | | | | | | | | | | | | | | | The use of pass0, pass1, pass2, and "pass" passed as an argument is really confusing and already caused a severe bug in the 2.14.01 release cycle. Clean them up and be far more explicit about what various passes mean. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | compier: Zap __builtin_constant_p on gcc 4.x seriesCyrill Gorcunov2018-12-151-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It is been discovered that on gcc-4.8.4 compiler can't properly evaluate __builtin_constant_p. | gcc (Ubuntu 4.8.4-2ubuntu1~14.04.3) 4.8.4 | | In file included from asm/nasm.c:38:0: | asm/nasm.c: In function ‘assemble_file’: | ./include/compiler.h:377:27: error: first argument to ‘__builtin_choose_expr’ not a constant | # define if_constant(x,y) __builtin_choose_expr(is_constant(x),(x),(y)) | ^ | ./include/nasmlib.h:145:23: note: in expansion of macro ‘if_constant’ | static_assert(if_constant(x, 1), #x); \ | ^ | ./include/nasmlib.h:167:9: note: in expansion of macro ‘nasm_try_static_assert’ | nasm_try_static_assert(x); \ | ^ | asm/nasm.c:1544:17: note: in expansion of macro ‘nasm_assert’ | nasm_assert(output_ins.times >= 0); | Zap it for 4.x series so we could run our tests. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* | nasmlib: Fix space/tabs messCyrill Gorcunov2018-12-151-28/+28
| | | | | | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* | compiler: Brace __builtin_constant_p argumentCyrill Gorcunov2018-12-151-1/+1
| | | | | | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* | nasm_assert(): try to run at compile time if possibleH. Peter Anvin (Intel)2018-12-142-17/+66
| | | | | | | | | | | | | | | | | | | | 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>
* | nasm_warnf() -> nasm_warn()H. Peter Anvin (Intel)2018-12-141-2/+1
| | | | | | | | | | | | | | | | We want to strongly encourage writers of warnings to create warning categories, so remove the flagless nasm_warn() and change nasm_warnf() to nasm_warn(). Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* | Restore the ability to have ? in identifiers, except ? itselfH. Peter Anvin (Intel)2018-12-142-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | ? 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-0/+7
| | | | | | | | | | | | | | | | 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-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>
* | strlist: can be unique or not, add printf functionsH. Peter Anvin (Intel)2018-12-132-3/+15
| | | | | | | | | | | | | | | | | | | | 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-132-51/+24
|\ \ | | | | | | | | | | | | | | | | | | 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-41/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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>