Commit graph

71 commits

Author SHA1 Message Date
H. Peter Anvin
9084beb1bb Clean up backend format names
The backend format names were rather redundant and not always
helpful. Do some cleanup.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 02:28:17 -07:00
H. Peter Anvin (Intel)
38ddb19977 Warnings: move zeroing reserved space to a separate warning class
Zeroing reserved space in a progbits section really should be a
separate warning class, so it can be controlled independently.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-01-11 12:27:02 -08:00
H. Peter Anvin
8960e1bc83 Remove #includes already provided by "compiler.h"
"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>
2018-12-27 12:45:44 -08:00
H. Peter Anvin
c2f3f26015 Replace <ctype.h> includes with "nctype.h"
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>
2018-12-27 12:37:25 -08:00
H. Peter Anvin
2e53f27e9d Move <string.h> inclusion to compiler.h
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>
2018-12-26 06:32:37 -08:00
H. Peter Anvin (Intel)
e55d03dd47 Clean up the handling of various passes
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>
2018-12-18 11:14:59 -08:00
H. Peter Anvin (Intel)
80c4f23c52 nasm_warnf() -> nasm_warn()
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>
2018-12-14 13:33:24 -08:00
Cyrill Gorcunov
4dc5360b60 output: aout -- Use nasm_error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-01 21:29:14 +03:00
H. Peter Anvin
ed859f72a1 output: remove ABSOLUTE handling, OUT_RAWDATA asserts
ABSOLUTE handling can be done centrally, and shouldn't need to be in
every backend.  Simply drop the call to ofmt->output().

Many backends have an assert for OUT_RAWDATA not having a target
segment; this doesn't make any sense as output/legacy.c will not allow
that to happen.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-15 00:03:53 -07:00
H. Peter Anvin
0125c446dd output: centralize the null definition of ofmt->segbase
Only two output formats (obj and ieee) actually need ofmt->segbase, so
move the common dummy definion into nullout.c.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 22:41:00 -07:00
H. Peter Anvin
98578071b9 Cleanup of label renaming infrastructure, add subsection support
In order to support Mach-O better, add support for subsections, as
used by Mach-O "subsections_via_symbols". We also want to add
infrastructure to support this by downcalling to the backend to
indicate if a new subsection is needed.

Currently this supports a maximum of 2^14 subsections per section for
Mach-O; this can be addressed by adding a level of indirection (or
cleaning up the handling of sections so we have an actual data
structure.)

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-01 18:06:25 -07:00
H. Peter Anvin
892c4818ce Add support for backend-defined subsections and label hacks
MachO has this odd thing called "subsections via symbols", by which a
symbol can magically start what effectively is a new section. To
support this, add support for a calldown into the backend when a new
symbol is defined *at the current output location*, and allow it to
switch the current segment.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-05-30 14:48:18 -07:00
H. Peter Anvin
81b62b9f54 Eliminate filename length restrictions, remote ofmt->filename()
Get rid of remaining dependencies on FILENAME_MAX, which ought to have
been removed a long time ago.

Remove ofmt->filename(); all implementations pretty much do the same
thing and there is absolutely no reason to duplicate that
functionality all over the place.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-12-20 13:38:20 -08:00
H. Peter Anvin
ac06133ed2 output: remove the completely unused set_info method
Every single backend has this method set to NULL.  It is also a
rather strange interface.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-31 11:41:16 -07:00
H. Peter Anvin
a6e26d9cca Add a generic pragma-handling infrastructure
Add infrastructure for handling %pragmas with a variety of namespaces,
etc., etc...

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 21:32:37 -08:00
H. Peter Anvin
b20bc733c9 asm/*: Move directive processing to its own file, refactor error handling
Move directive processing to its own file, and move nasmlib/error.c to
asm/error.c (it was not used by the disassembler); remove some extern
declarations from .c files, and do some general code cleanups.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 19:31:04 -08:00
Martin Lindhe
42aa10c985 output,aout: Improve aout_section_names
fix pvs-studio error 'V581 The conditional expressions of the 'if'
operators situated alongside each other are identical.
Check lines: 246, 249.'

Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-01-05 22:38:41 +03:00
H. Peter Anvin
fa803abc61 backend: move wrapper for legacy output functions to a library routine
Move the wrapper for legacy output into a library routine so the
backends can be ported one at a time.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-09-24 09:46:47 -07:00
H. Peter Anvin
e1f985c167 Reorganize the source code into subdirectories
Make the source code easier to understand and keep track of by
organizing it into subdirectories depending on the function.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-05-25 12:06:29 -07:00
H. Peter Anvin
3ef4f00d5a lib: split library into stdlib and nasmlib; header handling fixes
Split lib/ into nasmlib/ (for nasm-specific functions) and stdlib/
(for replacements for C library functions which may be missing.)

Rename the ersatz inttypes.h to nasmint.h so we can use a simple test
in compiler.h instead of dealing with include path magic.

Remove tests in configure.in for ancient missing functions (which will
break the build anyway.)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-08 12:20:02 -08:00
H. Peter Anvin
1917f45ec2 Merge remote-tracking branch 'origin/nasm-2.12.xx'
Resolved Conflicts:
	output/codeview.c
	output/outelf32.c
	output/outelf64.c
	output/outelfx32.c
	output/outform.c
	output/outform.h
	output/outieee.c
	output/outobj.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-08 01:08:53 -08:00
H. Peter Anvin
477ae4419c ofmt: get rid of the debuginfo parameter to ofmt->cleanup()
Get rid of the completely pointless "debuginfo" parameter to
ofmt->cleanup().  Most backends completely ignore it, and the two that
care (obj, ieee) can simply test dfmt instead.

Also, dfmt is never NULL, so any test for a NULL dfmt is bogus.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-07 22:55:43 -08:00
H. Peter Anvin
6224033738 Merge remote-tracking branch 'origin/nasm-2.12.xx'
Resolved Conflicts:
	.gitignore
	Makefile.in
	assemble.c
	configure.in
	eval.c
	float.c
	listing.c
	nasm.c
	nasmlib.c
	output/outform.h
	preproc.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-07 12:15:40 -08:00
H. Peter Anvin
215186fe82 Get rid of a bunch of unnecessary indirections
We pass around a whole bunch of function pointers in arguments,
which then just get stashed in static variables.  Clean this mess
up and in particular handle the error management in the preprocessor
using nasm_set_verror() which already exists.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>

From master branch checkin 130736c0cf

Resolved Conflicts:
	nasm.c
	preproc-nop.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-03 15:22:03 -08:00
H. Peter Anvin
41087068aa Replace nasm_error(ERR_FATAL/ERR_PANIC) with nasm_fatal/nasm_panic
Replace all instances of ERR_FATAL or ERR_PANIC with nasm_fatal or
nasm_panic so the compiler knows that these functions cannot return,
*and* we trigger abort() if we were to ever violate that constraint.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-03 15:22:02 -08:00
H. Peter Anvin
338656c1de output: make all instances of struct ofmt readonly
With current_dfmt gone, we can make all instances of struct ofmt
const (read-only).

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-17 20:59:22 -08:00
H. Peter Anvin
130736c0cf Get rid of a bunch of unnecessary indirections
We pass around a whole bunch of function pointers in arguments,
which then just get stashed in static variables.  Clean this mess
up and in particular handle the error management in the preprocessor
using nasm_set_verror() which already exists.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-17 20:27:41 -08:00
H. Peter Anvin
33814133bd Replace global maxbits variable with field in struct ofmt
maxbits is strictly a property of the output format, so get rid of
this ad hoc method of reporting.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-11 20:40:07 -08:00
H. Peter Anvin
ae01785d87 LLVM portability fix for abs(size)
size is actually an uint64_t, and LLVM drops the abs() on the
principle that the uint64_t should always be positive.  Make it
explicit that we are converting to a signed integer first, by using
abs((int)size) instead.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-05 11:34:07 -08:00
Cyrill Gorcunov
94b4a2c819 output: aout -- Use nasm_x_space helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-07-26 16:42:27 +03:00
Cyrill Gorcunov
2e6297ff1b out: Zeroify temp buffer before use
This is a a buffer on stack big enough to hold
bigger object we might need (address, number and
etc) but it's defined as an array of bytes and
we treat it as different types depending on context,
which may lead to situation where data from stack
been treated as meaningful.

In particular in commit 5b730a197 we've fixed such
problem simply using a "big" write to zeroify stack
data before use.

Lets simply zeroify this buffer explicitly to escape
such problems in future.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-07-19 14:24:26 +03:00
Cyrill Gorcunov
775153b1bf output: dbg,aout,elf32 -- Fix out for signed relocations
@size might be negative for signed relocations but its length
is abs value. This is rather a fix for future use because at
moment we can't hit this problems but better be on a safe side.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-02-21 21:14:28 +03:00
H. Peter Anvin
fd52c277dd output: Allow OUT_ADDRESS with a negative size to mean signed relocation
This only matters for ELF64/ELFx32, at least for now.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2013-11-26 18:12:39 -08: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
9b66d8e4c3 Use ALIGN helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-02-11 21:28:30 +03:00
Cyrill Gorcunov
54e94a56e2 Remove outdated comments
From Frank Kotler:
| ...
| > -                stdscan_bufptr = saveme;        /* bugfix? fbk 8/10/00 */
| > +                stdscan_set(saveme);            /* bugfix? fbk 8/10/00 */
|
| While you're at it, you could remove my comment(s - it seems to have
| reproduced). It *is* a bugfix (apparently). "saveme" might have a better
| name, too...

So get rid of the comments.

Reported-by: Frank Kotler <fbkotler@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-31 20:03:14 +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
Cyrill Gorcunov
a95a76a868 outaout.c -- use list helpers
Note that we use list_for_each(var,var) sometime
which actually brings in at least one redundant
assignment in case of NULL being passed but save
us a few lines of code.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-07-28 23:26:12 +04: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
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
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
d7392ad814 Add new copyright headers to the output modules
Add new copyright headers to the new output modules.  As far as I
know, the only module which we still don't have a green light to
release under 2-BSD is outmacho.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-28 17:25:15 -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
03c4f90afa output: add common file outlib.c for common functions; realsize()
Add a common file, outlib.c, for output formats.  Add the function
realsize() instead of open-coded variants in almost every backend.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-27 22:19:59 -07:00
H. Peter Anvin
bda7a6e371 ctype.h: wrapper ctype functions with a cast to (unsigned char)
ctype functions take an *int*, which the user is expected to have
taken the input character from getc() and friends, or taken a
character and cast it to (unsigned char).

We don't care about EOF (-1), so use macros that cast to (unsigned
char) for us.
2008-06-21 10:23:17 -07:00
H. Peter Anvin
cfb7176ca2 Move the output format macros into the macros.pl mechanism
Move the handling of "extra" macros (i.e. output format macros) into
the macros.pl mechanism.  This allows us to change the format of the
internal macro store in the future - e.g. to a single byte store
without redundant pointers.

Also, stop using indicies into a long array when there is no good
reason to not just use different arrays.
2008-06-20 15:20:16 -07:00
H. Peter Anvin
fcb8909749 Move all the RAA code out of nasmlib
The RAA code doesn't have to be in nasmlib; it is only used by nasm
itself, and is better handled in a separate module.
2008-06-09 17:40:16 -07:00