Commit graph

84 commits

Author SHA1 Message Date
H. Peter Anvin
c8af731120 outieee: fix segfault on empty input
Fix the IEEE backend crashing if the input file is empty.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2022-12-07 10:24:14 -08:00
Elyes HAOUAS
cdf7ad02c2 Fix some typos
while on it, remove unneeded white spaces.

Signed-off-by: Elyes HAOUAS <ehaouas@noos.fr>
2022-01-09 17:34:35 +01:00
Cyrill Gorcunov
93c774d482 BR3392637: output/outieee: Fix nil dereference
The handling been broken in commit 98578071.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-11-04 13:08:06 +03:00
H. Peter Anvin (Intel)
cc843efa38 Merge tag 'nasm-2.15.04'
NASM 2.15.04

Conflicts:
	asm/listing.h
	asm/pptok.pl
	asm/preproc.c
	version

This doesn't pass travis test 3392711, which is using an extremely odd
construct of %?? in the middle of an argument sequence for an smacro
while not being in a macro itself, and expecting it to expand to the
macro name. This seems to *really* confuse the master branch.

Resolve this later...
2020-08-25 16:16:09 -07:00
H. Peter Anvin (Intel)
16ab7aed21 debug: feed single-line macro definitions and include hierachy to dfmt
At least DWARF can encode C-style macros. In doing so, it wants the
file include hierarchy, so give the debug format backend the option of
receiving that information from the preprocessor.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-08-25 15:52:05 -07:00
H. Peter Anvin (Intel)
c9467688b4 Add [v]printf_func() attributes where appropriate
Add a new macro vprintf_func() for vprintf-style functions, and add
printf_func() and vprintf_func() attribute arguments whereever
meaningful.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-30 17:30:20 -07:00
H. Peter Anvin (Intel)
64c7c763c2 Change dfmt->debug_macros to dfmt->debug_mmacros
... in preparation for adding dfmt->debug_smacros.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-14 12:05:03 -07:00
H. Peter Anvin (Intel)
50184c26c7 debug: collect macro information for the debug backend
Collect macro call/nesting information for the benefit of the debug
back end. So far, the only backend for which this is provided is the
debug back end, to show what information is present.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-08 09:28:44 -07: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)
5df6ca712d With buffered warnings, change the handling of error passes
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>
2018-12-18 12:25:11 -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
f8d9bf9d83 output: ieee -- Use nasm_error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-02 11:41:06 +03:00
Cyrill Gorcunov
f6b1720a2d version: Make them dynamic for regression tests sake
When we are running regression tests we compare binary
forms and the strings better to be the constants to not
trigger false positives.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-24 16:59:32 +03:00
H. Peter Anvin
c51369067c errors: simplify nasm_fatal() and nasm_panic()
Nearly all instances of nasm_fatal() and nasm_panic() take a flags
argument of zero. Simplify the code by making nasm_fatal and
nasm_panic default to no flags, and add an alternate version if flags
really are desired. This also means that every call site doesn't have
to initialize a zero argument.

Furthermore, ERR_NOFILE is now often not necessary, as the error code
will no longer cause a null reference if there is no current
file. Therefore, we can remove many instances of ERR_NOFILE which only
deprives the user of information.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-06-15 18:20:17 -07: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
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
Cyrill Gorcunov
51b453b097 output: elf,ieee,macho,obj -- Fix mofule name for commit 81b62b9f54
These modules need a reference to input filename.
For example elf put into symbol table

 | SYMBOL TABLE:
 | 0000000000000000 l    df *ABS*	0000000000000000 sha-64.asm

Otherwise this  become empty string.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-02-25 15:50:35 +03: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
24f7b5c3e4 timestamp: centralize handing of compilation timestamp
Do all the generation and conversion of the compiler timestamp in one
place and make it available to modules.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-08-02 18:37:54 -07:00
H. Peter Anvin
5253f58c36 Add generic perfect string hashes, use for directives
Add a generic facility for generating perfect string hashes, where all
that is needed is an enum and a string table.  The existing mechanism
using a custom Perl script wrapped around a module continues to be
available for any use case where this particular approach isn't
sophisticated enough.

Much of this patch comes from renaming "enum directives" to "enum
directive" as a result of the string hash generator expecting a set of
uniform naming conventions.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-03 00:27:07 -07: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
e562b70cea output: make the return value from the directives method more meaningful
The directives code is already trying to do a bit more unified error
handling, so give ourselves a bit richer interface.  At this point,
the conversion was pretty automatic so we probably return DIRR_OK
instead of DIRR_ERROR in a fair number of places, but that's okay.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 22:42:39 -08: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
H. Peter Anvin
09dff8b257 Remove casts in switch statements only meant to keep OpenWatcom happy
Remove casts in switch statements that were intended to keep
OpenWatcom happy.  It didn't work, and now we have a more general
solution for the problem, which also ought to be less dangerous.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-03-01 01:01:37 -08: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
2bc0ab38a2 Move version strings to a separate header
Move version strings to a separate header, instead of needing to
include nasm.h in places where it probably really doesn't belong.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-08 02:17:36 -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
3def9fcb59 outieee: no need to filter .. symbols in the debug format anymore
labels.c now filter ..[^@] special symbols from the debug backend,
so we don't have to open-code that everywhere.

In the actual output format, don't treat ..@ symbols as special.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Jim Kukunas <james.t.kukunas@linux.intel.com>
2016-03-07 22:04:54 -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
335c4857ce Remove ofmt->current_dfmt indirection
Move ofmt->current_dfmt into a separate global variable.  This
should allow us to make ofmt readonly and removes some additional
gratuitious differences between backends.

From master branch checkin a7bc15dd0a

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-03-07 12:07:50 -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
a4973cf997 A few more debugging format arrays to mark const
Making more debugging format array const.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-18 02:25:26 -08:00
H. Peter Anvin
7e3b12d6da More constification, mostly of struct dfmt
Make struct dfmt and the struct dfmt arrays const across the board,
and make them static whereever possible.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-18 02:16:36 -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
a7bc15dd0a Remove ofmt->current_dfmt indirection
Move ofmt->current_dfmt into a separate global variable.  This
should allow us to make ofmt readonly and removes some additional
gratuitious differences between backends.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-17 20:55:08 -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
H. Peter Anvin
443b8e9b5f Add missing static declaration in output/outieee.c
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-11-25 12:14:52 -08: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
a30090b7e5 outieee: Reorder ieeeSection members to eliminate holes
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-08-28 17:00:04 +04:00
Cyrill Gorcunov
9e8f0ac460 BR3079550: NASM crash on run-time for OMF output format
We could have accessed malloc'ed data on external symbols
in obj and ieee output formats. Fix it by using nasm_zalloc.

Reported-by: Jiri Malak
Patch-by: Jiri Malak
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-10-02 01:21:00 +04:00
Cyrill Gorcunov
9868bfe80f ieee: Fix section index match in sectalign handler
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-25 17:55:52 +04:00