Commit message (Collapse)AuthorAgeFilesLines
* BR 3392601: allow the user to disable pedantic warningsH. Peter Anvin (Intel)2019-08-161-3/+6
| | | | | | | | --disable-pedantic passed to configure will now disable -W, -Wc90-c99-compat, and -pedantic. Requested-by: Orzkan Sezer <sezeroz@gmail.com> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* BR 3392597: the system malloc() can return NULLH. Peter Anvin (Intel)2019-08-162-7/+42
| | | | | | | | | | | | | | 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>
* autoconf: update check for gcc inlinesH. Peter Anvin (Intel)2019-08-161-1/+1
| | | | | | | Old versions of gcc didn't define either __GNUC_STDC_INLINE__ or __GNUC_GNU_INLINE__, but imply the latter. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* config.h: separate function and function pointer attributes; automateH. Peter Anvin (Intel)2019-08-169-100/+104
| | | | | | | | | | | | 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-153-16/+47
| | | | | | | 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.pl: remove a debugging printH. Peter Anvin (Intel)2019-08-151-2/+0
| | | | | | Remove a stray debugging print statement from macros.pl. 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-153-25/+41
| | | | | | | | | | 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>
* stdmac: handle up to 160 directives, make macros.c more readableH. Peter Anvin (Intel)2019-08-152-36/+68
| | | | | | | | | | | Handle up to 160 directives for stdmac compression. This is done by allowing the directive numbers to wrap around (128-255, 0-31), using 127 for end of line, and forcing any whitespace character to be space. Make macros.c a bit more legible by using #defines for the byte codes; strictly for the benefit of the human reader. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* pptok.pl: don't leak internal codes into pptok.cH. Peter Anvin (Intel)2019-08-151-1/+1
| | | | | | | | If we have internal codes in pptok.c, we may have false matches for them as tokens, plus, there is no reason for them to exist there. Go back to putting NULL in those slots. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* preproc: simplify handling of conditionals and casesenseH. Peter Anvin (Intel)2019-08-153-169/+140
| | | | | | | | | | Simplify the handling of conditionals; remove the PPC_* types. Automate the generation of case-sensitive versus case-insensitive directives, and make it so the bulk of the code doesn't have to worry about it. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* preproc: introduce alias smacros, cleanupsH. Peter Anvin (Intel)2019-08-142-314/+276
| | | | | | | | | | | | | | | | | | | | | Introduce "alias smacros", which are the smacro equivalent of symlinks; when used with the various smacro-defining and undefining directives, they affect the macro they are aliased to. Only explicit %defalias, %idefalias, and %undefalias affect them. This is intended for being able to rename macros while retaining the legacy names. This patch also removes an *astonishing* amount of duplicated code: 1. Every caller to defined_smacro() and undef_smacro() would call get_ctx() to mangle the macro name; push that into those functions. 2. Common code to get an smacro identifier. 3. Every code path that returns DIRECTIVE_FOUND also has to do free_tlist(origline); make it do so. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* masm.mac: tbyte -> twordH. Peter Anvin (Intel)2019-08-141-0/+2
| | | | Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* test: very simple test for MASM displacement syntaxH. Peter Anvin (Intel)2019-08-141-0/+36
| | | | | | Very trivial test of MASM package. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* masm.mac, parser: VERY limited MASM emulation packageH. Peter Anvin (Intel)2019-08-144-142/+256
| | | | | | | | | | 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-144-4/+11
| | | | | | | 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>
* list_option_mask(): return 0 (empty mask) for < '0'H. Peter Anvin2019-08-101-0/+2
| | | | | | Missing limit check at the bottom of the ASCII range. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* listing: encapsulate the list_options encoding, make more comprehensiveH. Peter Anvin2019-08-103-18/+36
| | | | | | | | | | Encapsulate the list_options() encoding in an inline function. We only ever compute a mask with a non-constant input in two places (command line and pragma parsing), so a slightly more complex mapping is of no consequence; thus map a-z, A-Z and 0-9 as being the most likely characters we may want to use as options. Space is left for two more :) Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Add %pragma list optionsH. Peter Anvin2019-08-106-18/+90
| | | | | | | Add a %pragma to set (or clear) listing options. It only takes effect on the next assembly pass, however! Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* preproc: avoid dropping the facility name in %pragmaH. Peter Anvin2019-08-101-6/+14
| | | | | | | | tline got advanced a token too far, with the obvious results that the facility name got truncated. Skip whitespace *after* expand_smacro(), not before. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* preproc: fix double free in the handling of %pragmaH. Peter Anvin2019-08-101-0/+3
| | | | | | | expand_smacro() consumes its input, so we need to truncate the input list so we can call free_tline(origline) safely. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* preproc: add listing options to override nolist; some cleanupsH. Peter Anvin2019-08-102-37/+102
| | | | | | | | | | | | | | | | Add listing options: -Lb to show builtin macro packages -Lf to override .nolist Do some cleanups in the process, in particular generalize read_line() between stdmac and file alternatives. When processing stdmac, create an istk entry for it. This means stdmac can be identified by istk->fp == NULL. At some future date there could even be a function pointer to an appropriate read function. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* listing: clean up before a restartH. Peter Anvin2019-08-101-23/+24
| | | | | | | | | With the -Lp option, the listing generator gets invoked multiple times in the same session. If we already have a list file open, call list_cleanup() before reinitializing; otherwise we get stray output in the updated file. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* listing: coalesce TIMES in non-final passes, print <len>, clarify hexH. Peter Anvin2019-08-102-13/+10
| | | | | | | | | | | | | | | Merge TIMES in the nonfinal passes, there is no point in getting <len ...> an arbitrary number of times. Actually print <len> (OUT_RAWDATA without a data pointer), not <res> (OUT_RESERVE). Dropping the zero-fill for the hex format made the listing more manageable, but it also doesn't immediately look like hex, plus there is now the -Ld option. Put an h after hex (shorter than leading 0x) to make it obvious. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* outelf: change debug format default to dwarfH. Peter Anvin2019-08-101-3/+3
| | | | | | | DWARF is by far the predominant format on ELF platforms these days. Catch up with the times. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Clean up backend format namesH. Peter Anvin2019-08-1011-43/+30
| | | | | | | The backend format names were rather redundant and not always helpful. Do some cleanup. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Stylistic improvements to help textH. Peter Anvin2019-08-101-9/+6
| | | | | | Trivial stylistic improvements to the help text. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Additional listing options, improve help output, fix macro limitsH. Peter Anvin2019-08-107-154/+275
| | | | | | | | | | | | | | | | | | 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>
* listing: when listing lines in macros and rep blocks, show the actual lineH. Peter Anvin2019-08-094-21/+25
| | | | | | | When printing lines coming from %rep blocks and macros, show the line number corresponding to the line actually being printed. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* warnings.pl: remove one more instance of "scalar(%hash)"H. Peter Anvin (Intel)2019-08-091-1/+1
| | | | | | | scalar(%hash) is broken on old versions of Perl, use scalar(keys %hash). Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* travis: update warning outputH. Peter Anvin (Intel)2019-08-094-111/+111
| | | | | | | Update warning formatting after verifying that the new output is indeed still correct. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* preproc.c: make sure we have the correct token lengthsH. Peter Anvin (Intel)2019-08-091-48/+66
| | | | | | | | | | | | | | | | It turns out that in tokenize() we would sometimes truncate a token string by inserting a NUL into the input string, expecting new_Token() to pick it up using strlen(). With explicit lengths, that no longer works, but there is a better solution anyway: instead of inserting NUL characters, keep track of where the token actually ends and feed the correct length to new_Token(). This triggered a buffer overflow in detoken(), add a debug level 2 assert for this condition. Use a relatively high debug level, because strlen() is fairly expensive, and this is an extremely performance-critical path. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* asm/nasm.c: make --debug=level actually workH. Peter Anvin (Intel)2019-08-091-24/+43
| | | | | | Turns out there was no support for optional arguments at all. [ Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* obsolete: make the message clearer in the case of NEVER,!NOPH. Peter Anvin (Intel)2019-08-091-1/+1
| | | | | | | | | | | | | "instruction never implemented and removed from the target CPU" ... doesn't really make sense, so change it to ... "instruction never implemented and invalid on the target CPU" (still may seen redundant, but it is to distingush it from "and is a noop on...") Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* obsolete handing: handle a few more subcases in a useful wayH. Peter Anvin (Intel)2019-08-095-15/+46
| | | | | | | | | Distinguish instructions which have once been valid (OBSOLETE) from those that never saw the light of day (NEVER). Futhermore, flag instructions which devolve to an architectural noop from those with undefined behavior and possibly recycled opcodes. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* BR 3392590: add warning for valid but obsolete instructionsH. Peter Anvin (Intel)2019-08-092-6/+25
| | | | | | | | | | | Just becase one is compiling for an old CPU doesn't mean one wants to use obsolete instructions that would not be forward compatible. Rename the "obsolete" warning to "obsolete-removed" and create a new "obsolete-valid" warning to go with it (-w[+-]obsolete controls both options, as usual.) Suggested-by: C. Masloch <pushbx@38.de> Signed-off-by: H. Peter Anvin (Intel) <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>
* warnings.pl: BR 3392585: don't use scalar(%hash)H. Peter Anvin (Intel)2019-08-091-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | The idiom scalar(%hash) seems similar to scalar(@array), and in fact is in current versions of Perl. However, in older versions of Perl, the former is totally useless: Prior to Perl 5.25 the value returned was a string consisting of the number of used buckets and the number of allocated buckets, separated by a slash. This is pretty much useful only to find out whether Perl's internal hashing algorithm is performing poorly on your data set. For example, you stick 10,000 things in a hash, but evaluating %HASH in scalar context reveals "1/16", which means only one out of sixteen buckets has been touched, and presumably contains all 10,000 of your items. This isn't supposed to happen. As of Perl 5.25 the return was changed to be the count of keys in the hash. If you need access to the old behavior you can use "Hash::Util::bucket_ratio()" instead. Use scalar(keys %hash) instead. Reported-by: Orkan Sezer <sezeroz@gmail.com> Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* perl files: clean up warningsH. Peter Anvin (Intel)2019-08-0910-38/+38
| | | | | | | | | | | | 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>
* 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-096-46/+218
| | | | | | | | | | | | | | | | | | | | | | | | 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-096-51/+86
| | | | | | | | | | | | | | | | 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>
* labels.c: don't use ERR_NOTE for additional informationH. Peter Anvin (Intel)2019-08-091-5/+4
| | | | | | | | | ERR_NOTE just confuses things, especially in the case of a suppressed warning. The preprocessor doesn't use it for unwinding macros, either. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* Add implicitly sized versions of the K instructionsH. Peter Anvin (Intel)2019-08-093-5/+233
| | | | | | | | | This allows the K instructions to be specified without a size suffix as long as the operands are sized; this matches the way most other x86 instructions work. As this is not the syntax specified in the SDM, don't use it for disassembly. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* insns.pl: use less cantankerous string expansion; better error infoH. Peter Anvin (Intel)2019-08-092-43/+52
| | | | | | | | | | | The flags massaging in insns.pl could end up with things like double commas in some pathological cases, which would make insns_flag_index() very unhappy due to the appearance of an empty argument. Fix this by processing the flags as a list already in insns.pl. Be more explicit and consistent in error messages. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* preproc: fix parsing of single-line macro arguments, cleanupsH. Peter Anvin (Intel)2019-08-096-198/+323
| | | | | | | | | | | | | | | | | | | | 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>
* msvc.h: Allow building with MSVC versions older than 1700Iouri Kharon2019-08-071-1/+5
| | | | | | Bug report 3392570. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* update watcom config file.Ozkan Sezer2019-08-072-1/+18
| | | | | | | 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>
* autogen.sh: allow overriding autotools location, and handle missingH. Peter Anvin (Intel)2019-08-071-11/+25
| | | | | | | | | | Allow overriding the autotools install location via environment variables. Handle missing aclocal or automake, which aren't mandatory as we cache the files we get from them. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* fix pa_add_headers.m4 for development versions of autoconf (bug 3392471)Ozkan Sezer2019-08-071-1/+2
| | | | Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
* br3392586: add test case for smacro descentH. Peter Anvin (Intel)2019-08-071-0/+8
| | | | | | Add test case for smacro descent from bug 3392586. Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>