Commit graph

163 commits

Author SHA1 Message Date
H. Peter Anvin
ab5bd05d82 Revert "Improve process_ea and introduce -OL"
This reverts commit ac732cb6a5.

Resolved Conflicts:

	doc/nasmdoc.src

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2010-07-25 12:43:30 -07:00
Victor van den Elzen
ac732cb6a5 Improve process_ea and introduce -OL
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.
2010-07-24 22:00:12 +02:00
H. Peter Anvin
31387b2d04 Make -Ox the default
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>
2010-07-15 18:30:18 -07:00
Cyrill Gorcunov
69ce75076c No need for \n at __OUTPUT_FORMAT__ macro end
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-13 21:16:57 +04:00
Cyrill Gorcunov
2ef5c27be7 Rename SEGALIGN to SECTALIGN
"sectalign" is preferred over "segalign"
since it operates over section attributes.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 18:09:54 +04:00
Cyrill Gorcunov
2a587ab1c9 ofmt: Implement null_segalign stubs
Set stubs for all targets

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 01:08:36 +04:00
Cyrill Gorcunov
d5f2aef30a Introduce SEGALIGN directive
No real handling yet though. Definition only.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 01:07:47 +04:00
Cyrill Gorcunov
66206e7bd8 nasm.c: Delete redundant goto
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 01:06:27 +04:00
H. Peter Anvin
a36a4f2f1d nasm.c: smarter handling of missing directives
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>
2010-04-07 16:54:56 -07:00
H. Peter Anvin
888964a880 Distinguish no directive present from unknown directive
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>
2010-04-06 17:00:12 -07:00
Cyrill Gorcunov
d879900c5a nasm.c: Restore strings broken by indent
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>
2010-01-09 20:36:18 +03:00
Cyrill Gorcunov
416bd78bae nasm.c: Use copy_filename to set error message file
To prevent errname buffer overwrite we should
use copy_filename instead of strcpy.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-12-04 19:44:20 +03:00
Cyrill Gorcunov
917117ff69 stdscan: switch to stdscan_get/set routines
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>
2009-10-31 20:02:43 +03:00
H. Peter Anvin
ff800417a1 nasm: rename nasm_zap_spaces() to nasm_zap_spaces_fwd()
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>
2009-10-13 12:03:37 -07:00
Cyrill Gorcunov
d61debfc91 nasm.c: use string helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-13 19:42:14 +04:00
Cyrill Gorcunov
bd416c6860 nasm.c: getkw -- use string helpers
This allow us to shrink code a bit and
make it easy to read.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-13 19:42:05 +04:00
H. Peter Anvin
8bec2c788f nasm.c: fix stack overrun in assemble_file
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>
2009-08-08 13:49:00 -07:00
H. Peter Anvin
f46c0d6733 nasm.c: consistently use the 'murrican spelling "optimize"
"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>
2009-07-31 08:03:32 -07:00
Cyrill Gorcunov
73b87c68b1 nasm.c -- update info on -O cmdline option
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-07-31 10:26:55 +04:00
H. Peter Anvin
e873c9b16b Merge commit 'cyr/hpa-list' 2009-07-30 15:06:47 -07:00
Cyrill Gorcunov
984c4db12f nasm.c -- update help message
Show all options we support at moment
via "nasm -h" invoked.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-07-31 00:32:17 +04:00
Cyrill Gorcunov
fcd0a74330 nasm.c -- use list helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-07-27 16:26:26 +04:00
H. Peter Anvin
dbb640b846 Drop efunc and evalfunc as input to the preprocessor
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>
2009-07-18 18:57:16 -07:00
H. Peter Anvin
00444ae04e Drop efunc and evaluate argument to parse_line()
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>
2009-07-18 18:49:55 -07:00
H. Peter Anvin
605f5155ee Drop the ofmt and errfunc arguments to label definition functions
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>
2009-07-18 18:43:58 -07:00
H. Peter Anvin
9bd1506d59 Remove function pointers in output, simplify error handling
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>
2009-07-18 18:43:12 -07:00
H. Peter Anvin
159178f2aa Merge commit 'nasm-2.07rc7' into new-preproc 2009-07-17 00:55:17 -04:00
H. Peter Anvin
8a962b3efd BR 2822263: don't re-invoke ofmt->symdef() in pass2 unless "special"
Before checkin aeb0e0e9f1 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>
2009-07-16 22:35:25 -04:00
H. Peter Anvin
bf0247af7a Don't try to fclose() the output if ofile is NULL
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>
2009-07-14 14:47:41 -04:00
H. Peter Anvin
afa06137fa Hash even backend-specific directives, unify null functions
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>
2009-07-12 12:55:24 -07:00
H. Peter Anvin
d0fbb7f0ab Don't fclose() the output in the backend
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>
2009-07-12 12:15:35 -07:00
H. Peter Anvin
323fcff32b Use a phash to decode directives
We can use a perfect hash to decode directives as well.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-12 12:04:56 -07:00
H. Peter Anvin
a23aa4a3e9 listing: preserve list file on error, include errors
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>
2009-07-07 12:04:12 -07:00
H. Peter Anvin
8ee2e244eb NASM: relicense under the 2-clause BSD license
*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>
2009-07-06 11:09:11 -07:00
H. Peter Anvin
0cba107579 Make it possible for outputs to be either text or binary
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>
2009-07-05 14:45:12 -07:00
H. Peter Anvin
48ef41957a Fix early report_error(); avoid nuisance phase warnings
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>
2009-07-01 22:12:59 -07:00
H. Peter Anvin
9e6747ccac Add copyright headers to the *.c/*.h files in the main directory
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>
2009-06-28 17:13:04 -07:00
H. Peter Anvin
31b707bef0 Move backend-specific code to output/; break out null debug stuff
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>
2009-06-27 22:07:33 -07:00
H. Peter Anvin
2d115448b4 output: call debug init from a central location
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>
2009-06-27 21:55:31 -07:00
H. Peter Anvin
aeb0e0e9f1 BR 2781900: handle common labels while optimizing
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>
2009-06-27 16:30:00 -07:00
H. Peter Anvin
f7a9ecaffa nasm.c: clean up pass exit logic
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>
2009-06-27 15:34:32 -07:00
H. Peter Anvin
e5a352516c BR 2672117: handle long lines for db/dw/etc.
Handle long arrays on a single line in db/dw/etc.
2009-03-07 21:54:31 -08:00
H. Peter Anvin
3213a57740 nasm.c: another readability cleanup
Yet another change for readability
2009-02-26 14:36:19 -08:00
H. Peter Anvin
7219198d72 nasm.c: readability cleanup for seg:off parsing
The code to pick apart seg:off in nasm.c was virtually unreadable due
to mechanized line breaking.
2009-02-26 14:34:48 -08:00
H. Peter Anvin
2186415f01 BR 2593349: Move version message back to stdout
Checkin 4b9358928b 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.
2009-02-13 09:36:47 -08:00
H. Peter Anvin
f1e46600d2 Fix the [warning] directive
Fix multiple bugs in the [warning] directive:

- Only parsed on pass 1
- "-" was interpreted as "+"
2009-01-05 09:08:06 -08:00
Victor van den Elzen
f568613c2a Fix BR #916647
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.
2008-11-05 14:19:15 +01:00
Charles Crayne
e2dea103db Prevent erroneous extra "final" pass
Specifically check for end of final pass.
2008-11-03 18:21:24 -08:00
H. Peter Anvin
4b9358928b Move all version strings to a single compilation unit (ver.c)
Move all the version strings to a single compilation unit, ver.c; this
does not include the version macros, which are fed into macros.c.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-31 16:53:49 -07:00
H. Peter Anvin
9a65f71d64 Better description of the number-overflow warning
Better grammar and fix incorrect description of the number-overflow
warning (it is not just limited to 64-bit arithmetic overflow, it also
triggers when trying to squeeze in a value which is too large into an
immediate.)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-26 08:59:04 -07:00