summaryrefslogtreecommitdiff
path: root/nasm.c
Commit message (Collapse)AuthorAgeFilesLines
* ofmt: Alias shortname must be used for __OUTPUT_FORMAT__ macroCyrill Gorcunov2011-04-061-3/+9
| | | | | | | | | | | | __OUTPUT_FORMAT__ must consist of shortname of output format or its alias, otherwise userspace ABI gets broken. For example source code still can refer to __OUTPUT_FORMAT__=elf, instead of __OUTPUT_FORMAT__=elf32. BR3246990 Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* BR3200749: Fix "use after close" file pointerCyrill Gorcunov2011-03-071-1/+4
| | | | | | | Cleanup routine might be called several times so be ready for that. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* Revert "Improve process_ea and introduce -OL"H. Peter Anvin2010-07-251-16/+7
| | | | | | | | | | This reverts commit ac732cb6a599836bf4c988e59ac6de4498758c72. Resolved Conflicts: doc/nasmdoc.src Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Improve process_ea and introduce -OLVictor van den Elzen2010-07-241-7/+16
| | | | | | | | | | | | | | | | | | | Two fixes: 1. Optimization of [bx+0xFFFF] etc 0xFFFF is an sbyte under 16-bit semantics, so make sure to check it right. 2. Don't optimize displacements in -O0 Displacements that fit into an sbyte or can be removed should *not* be optimized in -O0. Implicit zero displacements are still optimized, e.g.: [eax] -> 0 bit displacement, [ebp] -> 8 bit displacement. However explicit displacements are not optimized: [eax+0] -> 32 bit displacement, [ebp+0] -> 32 bit displacement. Because #2 breaks compatibility with 0.98, I introduced a new optimization level: -OL, legacy.
* Make -Ox the defaultpreproc-paste-fixH. Peter Anvin2010-07-151-5/+14
| | | | | | | | Make -Ox the default; it's the optimization level expected by most users, and it is clearly still causing confusion that it has to be specified manually. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* No need for \n at __OUTPUT_FORMAT__ macro endCyrill Gorcunov2010-07-131-1/+1
| | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* Rename SEGALIGN to SECTALIGNCyrill Gorcunov2010-04-211-3/+3
| | | | | | | "sectalign" is preferred over "segalign" since it operates over section attributes. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* ofmt: Implement null_segalign stubsCyrill Gorcunov2010-04-211-0/+2
| | | | | | Set stubs for all targets Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* Introduce SEGALIGN directiveCyrill Gorcunov2010-04-211-1/+13
| | | | | | No real handling yet though. Definition only. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* nasm.c: Delete redundant gotoCyrill Gorcunov2010-04-211-2/+2
| | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* nasm.c: smarter handling of missing directivesH. Peter Anvin2010-04-071-4/+7
| | | | | | | If we get D_unknown, we definitely don't need to pass it to the backend for analysis. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
* Distinguish no directive present from unknown directiveH. Peter Anvin2010-04-061-4/+4
| | | | | | | | | | | Distinguish the case of no directive present (D_none) from the case of an unknown specified directive (D_unknown). This is reflected in different error messages. Furthermore, change the special case symbols to lower case in case we ever have a directive called [none] or [unknown]. Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
* nasm.c: Restore strings broken by `indent`Cyrill Gorcunov2010-01-091-30/+14
| | | | | | | | | | | | A number of strings are broken by nindent passed over the nasm.c. Though the compiler doesn't care about this fact it's really unpleasant to have a string split at "dot" symbol. Lets restore it in a sake of readability. (No change on binary level) Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* nasm.c: Use copy_filename to set error message fileCyrill Gorcunov2009-12-041-1/+1
| | | | | | | To prevent errname buffer overwrite we should use copy_filename instead of strcpy. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* stdscan: switch to stdscan_get/set routinesCyrill Gorcunov2009-10-311-2/+2
| | | | | | | | | | Instead of manipulating stdscan buffer pointer directly we switch to a routine interface. This allow us to unify stdscan access: ie caller should "talk" to stdscan via stdscan_get/set routines. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* nasm: rename nasm_zap_spaces() to nasm_zap_spaces_fwd()H. Peter Anvin2009-10-131-1/+1
| | | | | | | | | By analogy with nasm_zap_spaces_rev() have nasm_zap_spaces_fwd(). The forward version isn't a super-common operation, and it might be possible to think the reverse one is the "normal" version... therefore we might as well be explicit. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* nasm.c: use string helpersCyrill Gorcunov2009-10-131-19/+7
| | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* nasm.c: getkw -- use string helpersCyrill Gorcunov2009-10-131-36/+27
| | | | | | | This allow us to shrink code a bit and make it easy to read. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* nasm.c: fix stack overrun in assemble_fileH. Peter Anvin2009-08-081-15/+31
| | | | | | | | | | | | If [DEBUG id] has id longer then 80 symbols (well, 79 actually plus EOS) then stack will be just overwritten. Fix it with explicit check for identifier being too long. Based on an initial version by Cyrill Gorcunov <gorcunov@gmail.com>. Signed-off-by: H. Peter Anvin <hpa@zytor.com> Cc: Cyrill Gorcunov <gorcunov@gmail.com>
* nasm.c: consistently use the 'murrican spelling "optimize"H. Peter Anvin2009-07-311-1/+1
| | | | | | | | "Optimise" (and other -ise words) is en_GB, "optimize" (and other "-ize" words) is en_US. Stick to en_US since that is what we seens to be using more already. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* nasm.c -- update info on -O cmdline optionCyrill Gorcunov2009-07-311-1/+4
| | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* Merge commit 'cyr/hpa-list'H. Peter Anvin2009-07-301-4/+2
|\
| * nasm.c -- use list helpersCyrill Gorcunov2009-07-271-4/+2
| | | | | | | | Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* | nasm.c -- update help messageCyrill Gorcunov2009-07-311-3/+11
|/ | | | | | | Show all options we support at moment via "nasm -h" invoked. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
* Drop efunc and evalfunc as input to the preprocessorH. Peter Anvin2009-07-181-13/+8
| | | | | | | We only ever invoked the preprocessor with fixed values for efunc and evalfunc, so call nasm_error() and evaluate() directly. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Drop efunc and evaluate argument to parse_line()H. Peter Anvin2009-07-181-3/+1
| | | | | | | | We never invoked the parser with anything but the default definitions for evaluate and efunc. Unlike the backend, though, we sometimes invoke parse_line() with redefine_label() instead of define_label(). Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Drop the ofmt and errfunc arguments to label definition functionsH. Peter Anvin2009-07-181-15/+9
| | | | | | | | We never set ofmt and errfunc to anything but the global values. Dropping them from the label definition function command line simplifies the code. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Remove function pointers in output, simplify error handlingH. Peter Anvin2009-07-181-102/+86
| | | | | | | | | | | | | | | Remove a bunch of function pointers in the output stage; they are never changed and don't add any value. Also make "ofile" a global variable and let the backend use it directly. All we ever did with these variables were stashing it in locals and using them as-is anyway for no benefit. Also change the global error function, nasm_error() into a true function which invokes a function pointer internally. That lets us use direct calls to it. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Merge commit 'nasm-2.07rc7' into new-preprocH. Peter Anvin2009-07-171-1/+2
|\
| * BR 2822263: don't re-invoke ofmt->symdef() in pass2 unless "special"H. Peter Anvin2009-07-161-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | Before checkin aeb0e0e9f1e7e9b32a8f17f2259311f6e9207aa6 we would only invoke ofmt->symdef() for a common variable during pass 2 if that variable had "special" in the declaration. That checkin unintentionally changed that behavior. That doesn't mean that the pre-existing behavior is right, but this should at least fix the resulting regressions. This really warrants more investigation. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | Don't try to fclose() the output if ofile is NULLH. Peter Anvin2009-07-141-4/+6
| | | | | | | | | | | | | | ofile == NULL means no output file is open, so don't try to close the output file if that is true. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | Hash even backend-specific directives, unify null functionsH. Peter Anvin2009-07-121-2/+2
| | | | | | | | | | | | | | | | | | Hash all directives, even the ones that are backend-specific, and instead pass the backend an already-parsed directive number. Furthermore, unify null functions across various backends. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | Don't fclose() the output in the backendH. Peter Anvin2009-07-121-8/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We fopen() the output file in common code but fclose() it in the backend. This is bad for a variety of reasons: 1. it is generally an awkward interface to change ownership. 2. we should use ferror() to test for write errors, and that is better done in common code. 3. it requires more code. 4. we still need to fclose() in common code during error handing. Thus, move the fclose() of the output out of the backends, and add fflush() so we can test ferror() on output. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* | Use a phash to decode directivesH. Peter Anvin2009-07-121-18/+10
|/ | | | | | We can use a perfect hash to decode directives as well. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* listing: preserve list file on error, include errorsH. Peter Anvin2009-07-071-9/+15
| | | | | | | | | Instead of removing the list file on error, keep the list file and include the errors in the list file. This makes it actually possible to debug things that involve deep macro recursion, where the line number is pretty much meaningless. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* NASM: relicense under the 2-clause BSD licenseH. Peter Anvin2009-07-061-12/+0
| | | | | | | | *To the best of my knowledge*, we now have authorization from everyone who has significantly contributed to NASM in the past. As such, change the license to the 2-clause BSD license. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Make it possible for outputs to be either text or binaryH. Peter Anvin2009-07-051-1/+1
| | | | | | | | | | | Allow the backend to specify that an output format is either text or binary. For future uses, define this as a flag word so we can define other flags in the future if it would make sense. Currently, the ieee and dbg formats are text; all the others are binary. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Fix early report_error(); avoid nuisance phase warningsH. Peter Anvin2009-07-011-14/+19
| | | | | | | | | | | Fix report_error() to (hopefully) not fault if used without ERR_NOFILE if no filename is available. Avoid nuisance phase error between passes warnings if we have detected other errors. In those case, the phase error is almost certainly spurious. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Add copyright headers to the *.c/*.h files in the main directoryH. Peter Anvin2009-06-281-5/+46
| | | | | | | | | | Add copyright headers to the *.c/*.h files in the main directory. For files where I'm sure enough that we have all the approvals, I have given them the 2-BSD license, the others have been given the "LGPL for now" license header. Most of them can probably be changed after auditing. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* Move backend-specific code to output/; break out null debug stuffH. Peter Anvin2009-06-271-1/+1
| | | | | | | | Move backend-specific code into the output/ directory, and make the null debugging backend a separate file (it certainly isn't needed for ndisasm...) Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* output: call debug init from a central locationH. Peter Anvin2009-06-271-0/+1
| | | | | | | | | | | We already call current_dfmt->init in the same place (at the very end of ofmt->init) in all the backends that do it; instead call it centrally in nasm.c after ofmt->init. This fixes invalid ELF files with when compiling with -F dwarf, since the dwarf initialization routine never got called. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* BR 2781900: handle common labels while optimizingH. Peter Anvin2009-06-271-55/+56
| | | | | | | | | | | When optimizing, we have to keep track of common labels, since a common symbol cannot be optimized -- only the linker will know where it will end up. In that sense it is similar to an EXTERN symbol. Thus, allow them to be entered in the symbol table but make sure we don't holler too hard on redefinition. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* nasm.c: clean up pass exit logicH. Peter Anvin2009-06-271-26/+25
| | | | | | | | Clean up the pass exit logic. In particular, we had a whole routine to do the same thing that the normal exit logic would do anyway if we only would actually get there. Signed-off-by: H. Peter Anvin <hpa@zytor.com>
* BR 2672117: handle long lines for db/dw/etc.H. Peter Anvin2009-03-071-13/+13
| | | | Handle long arrays on a single line in db/dw/etc.
* nasm.c: another readability cleanupH. Peter Anvin2009-02-261-3/+2
| | | | Yet another change for readability
* nasm.c: readability cleanup for seg:off parsingH. Peter Anvin2009-02-261-14/+8
| | | | | The code to pick apart seg:off in nasm.c was virtually unreadable due to mechanized line breaking.
* BR 2593349: Move version message back to stdoutH. Peter Anvin2009-02-131-2/+2
| | | | | | | | | | | | | Checkin 4b9358928b114caaf34a69d6fdfd3b285b7a72cc changed the version message from stdout to stderr, but: a) doesn't motivate the change in the commit log; b) bundles that with other changes; c) is inconsistent with other programs; d) was done by me and I can't remember any reason for it. Hence conclude it was unintentional and therefore a bug. Since this commit was done after 2.05.01 no stable release has been affected.
* Fix the [warning] directiveH. Peter Anvin2009-01-051-30/+28
| | | | | | | Fix multiple bugs in the [warning] directive: - Only parsed on pass 1 - "-" was interpreted as "+"
* Fix BR #916647Victor van den Elzen2008-11-051-2/+0
| | | | | | | | nasm.c should respect the default debug format of the output format, instead of replacing it with the first format in the list. This is cleaner and allows the list to be sorted normally. This commit rewrites commit 116994111b which was very fragile.
* Prevent erroneous extra "final" passCharles Crayne2008-11-031-1/+1
| | | | Specifically check for end of final pass.