Commit Graph

97 Commits

Author SHA1 Message Date
H. Peter Anvin
5507ad585f Merge branch 'machofix'
This fixes the macho64 output.  However, macho32 has the same problems and the
code either needs to be backported or, better yet, unified.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-11 20:24:53 -08:00
H. Peter Anvin
d24dd5fecc Remove the --allow-64-bits option and make it a warning
Remove the --allow-64-bits relocation, and instead make it a
suppressible warning in the case of a zero-extended relocation, and an
error in the case of a sign-extended relocation.

Relocations which can be losslessly represented in the output format
do not issue any diagnostic at all, as there is no problem in that
case.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-08 10:32:13 -08:00
H. Peter Anvin
0c11e123b2 nasmlib.h: Add #undef for ZERO_BUF_SIZE
If we are redefining ZERO_BUF_SIZE, add an #undef to avoid nuisance
compiler warnings.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-08 10:12:37 -08:00
H. Peter Anvin
50fe0b5904 nasmlib: Factor out common code from the panic() macro
There is no reason to pass a constant and a string from each call
site.  Move that into a separate out of line function.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-08 10:10:57 -08:00
H. Peter Anvin
c2f6baabc3 Merge branch 'master' of ssh://repo.or.cz/srv/git/nasm 2016-02-08 10:05:49 -08:00
H. Peter Anvin
25e2b40ac2 nasmlib.h: remove system definitions of ALIGN and ALIGN_MASK
Apparently some BSD flavors define these macros in a system header
file; this includes MacOS X.  Assume we can just #undef them without
causing any additional issues; otherwise we may need to rename them.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-05 11:30:11 -08:00
H. Peter Anvin
f0d92fd19a nasmlib: Add generic panic() macro, and no-return nasm_panic()
Add a generic panic() macro which we can simply insert where an
internal error happens.  Also, create a nasm_panic() function
the only purpose of which is to let the compiler know that we will
never return after a panic.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-02 16:01:43 -08:00
H. Peter Anvin
c5123e9482 nasmlib.h: If BUFSIZ is bigger than the default ZERO_BUF_SIZE, adjust
If BUFSIZ exists and is bigger than the default ZERO_BUF_SIZE, expand
ZERO_BUF_SIZE so we don't end up unnecessarily double buffering in the
stdio library.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-01-28 20:44:33 -08:00
Jim Kukunas
c9b3b8af41 nasmlib: Add nasm_realpath()
Converts a relative pathname to an absolute pathname.

Signed-off-by: Jim Kukunas <james.t.kukunas@linux.intel.com>
Acked-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-01-24 14:12:56 +03:00
Cyrill Gorcunov
6377180e08 nasmlib: Plcate undefined behaviour in signed_bits
http://bugzilla.nasm.us/show_bug.cgi?id=3392320

Reported-by: Dingbao Xie <xiedingbao@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-10-11 18:06:30 +03:00
H. Peter Anvin
e76a626055 Replace unchecked fwrite() calls
Instead of having unchecked fwrite() calls, introduce nasm_write()
which does error checking (and fatal errors if the write fails).

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-10-21 12:50:47 -07:00
Cyrill Gorcunov
07f0a8dbc9 debug: Drop LOGALLOC usage
There are special tools (like valgrind and etc)
to track memory leaks, no need for own trivial
tracker.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-05-09 22:22:34 +04:00
Jin Kyu Song
bb8cf3fa77 bnd: Show warning when bnd prefix is dropped
When bnd prefix is dropped as jmp is encoded as jmp short,
nasm shows a warning message, which can be suppressed with a new
command line option, -w-bnd.

Signed-off-by: Jin Kyu Song <jin.kyu.song@intel.com>
2013-12-04 20:06:23 -08:00
H. Peter Anvin
5a24fdd547 Make the LOCK and HLE warnings suppressable.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2012-02-25 15:11:11 -08:00
Cyrill Gorcunov
0e754dcafe Add WARN_IDX helper and ERR_WARN_TERM named constant
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-12-05 01:01:06 +04:00
Cyrill Gorcunov
396b5dfe95 nasmlib: Add list_reverse helper
There is no way to make it as a helper function
for a while, we need to unify list processing
in general (ie to use abstract list type).

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-06-25 18:15:41 +04:00
Cyrill Gorcunov
87225da76d nasmlib: Add list_last helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-06-25 18:15:21 +04:00
Cyrill Gorcunov
a39912dcd9 Move numvalue herleper into nasmlib.h
No need to duplicate implementation.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-06-25 12:10:40 +04:00
Keith Kanios
918317c4ce Revert "nasmlib: added string replace (strrep) utility function"
This reverts commit dd9c9752ea.
2011-04-09 10:33:06 -05:00
Keith Kanios
dd9c9752ea nasmlib: added string replace (strrep) utility function 2011-04-08 00:23:21 -05:00
Cyrill Gorcunov
a731924978 nasmlib: Rename elements() macro to ARRAY_SIZE
ARRAY_SIZE is a well known name pointing out that
we're dealing with array in macro argument.

Also to be on a safe side prefix_name helper should
check the index been in bounds more precisely.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-06-03 23:17:21 +04:00
H. Peter Anvin
084b13227e Add generic ilog2 functions
Add ilog2_{32,64}() and alignlog2_{32,64}() ... the latter is intended
for alignment statements and return -1 for non-power-of-2 other than 0
(which returns 0).

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-04-21 16:43:20 -07:00
Cyrill Gorcunov
6702d93c10 nasmlib.c: Introduce nasm_get_word helper
For easier space separated words extraction
from a text stream.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-11 12:58:09 +04:00
Cyrill Gorcunov
bb0745f432 nasmlib: Introduce nasm_trim_spaces and nasm_opt_val helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-10 00:02:32 +04:00
Victor van den Elzen
0d268fb78c BR 2496848: Tighten ea checks
Check if the offset and the representation are equivalent.

Disallow REL on absolute addresses.
I'm not sure what that would mean and the output formats don't support it.

Warn about ignored displacement size modifiers.
2010-03-12 23:52:04 +01:00
Cyrill Gorcunov
89fe355ad0 nasmlib.h: Introduce ALIGN helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-02-11 21:28:27 +03:00
Victor van den Elzen
b9856a266e Don't boundcheck 64-bit numbers, it gives problems due to overflows 2009-11-11 07:39:21 +01:00
Cyrill Gorcunov
09e2895fbe Introduce is_power2 helper
We will need it for hash tables

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-11-06 21:01:45 +03:00
Cyrill Gorcunov
acf256f4db nasmlib.h: Introduce nasm_build_assert
It's useful to protect our self from some
errors at build time.

For this sake we should use nasm_build_assert
if needed.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-11-05 23:35:04 +03:00
Cyrill Gorcunov
bafd877d48 nasmlib: Introduce idata_bytes helper
This allow us to eliminate code duplication

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-31 20:02:14 +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
c7e8f1bf6f nasmlib: introduce string helpers
To make code more compact we introduce the
following string helpers:

1) nasm_scip_spaces - skip leading spaces
2) nasm_skip_word - skip leading non-spaces
3) nasm_zap_spaces - zap leading spaces with zero
4) nasm_zap_spaces_rev - zap spaces in reverse order

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-13 19:42:01 +04:00
Cyrill Gorcunov
4b67cc371e introduce "overflow" helpers
Suggested-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-13 19:41:53 +04:00
Cyrill Gorcunov
1598a23ba3 style cleanup
Convert tabs to spaces.
Eliminate empty comments.

No change on binary level.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-10-13 19:41:37 +04:00
Victor van den Elzen
15bb233036 Fix some format strings for nasm_error
Added a format attribute to nasm_error (only for GCC) and
used the resulting warnings to fix some format strings.
2009-08-11 02:43:41 +02:00
Cyrill Gorcunov
2a75829452 nasmlib.h - introduce list iterator helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2009-07-20 17:59:00 +04: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
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
84280bbf88 Change noreturn macro to no_return to avoid header file problems
Change the "noreturn" macro to "no_return", to avoid problems with
system header files which use __attribute__((noreturn)) rather than
__attribute__((__noreturn__)) as is appropriate for system headers.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-05 19:22:28 -07:00
H. Peter Anvin
fe1ca5a09f nasmlib.h: add unlikely() to nasm_assert()
We explicitly want the compiler to pessimize the taken case of the
assert, so unlikely() is appropriate here.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-03 22:55:51 -07:00
H. Peter Anvin
807bed5ffd nasmlib: add nasm_assert(); use const char * for filenames
Add new nasm_assert() function, and add "const" to the declarations
which take filenames, as well as to the nasm_strdup/strndup functions.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-07-01 22:02:54 -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
69925e5b78 Move prototypes for null_debug to outform.h and outlib.h
Move the prototypes for the null debugging format to outform.h (for
the top-level structure declaration only) and outlib.h (for the
internal routines.)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-27 22:15:25 -07:00
H. Peter Anvin
2b1f51f1ca debug: make *all* the null debug routines available as a library
Make all the null debug routines available as a library, so we can use
them whenever appropriate.  We really don't need to have a bunch of
dummy functions scattered all over the code.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2009-06-27 21:58:21 -07:00
H. Peter Anvin
00bf04f742 nasmlib: make nasm_strcat() take const arguments
None of the strings passed to nasm_strcat() are modified, to
make them const.
2009-02-21 17:54:31 -08:00
H. Peter Anvin
999868f06f Unify all-zero buffers; add fwritezero()
We have a number of all-zero buffers in the code.  Put a single
all-zero buffer in nasmlib.c.  Additionally, add fwritezero()
which can be used to write an arbitrary number of all-zero bytes;
this prevents the situation where the all-zero buffer is simply
too small.
2009-02-21 17:24:08 -08:00
H. Peter Anvin
e9d7f1a074 Better warnings for out-of-range values
Issue better warnings for out-of-range values.  This is not yet
complete.

In particular, note we may have out-of-range for values that end up
being subject to optimization.  That is because the optimization takes
place on the *truncated* value, not the pre-truncated value.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-10-06 18:47:29 -07:00
H. Peter Anvin
2f16043879 Allow %warning output to be suppressed
Allow the user to suppress user-specified warnings.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-09-30 16:39:17 -07:00
Victor van den Elzen
22343c2c72 Add macro-defaults warning class and documentation. 2008-08-06 14:48:55 +02:00
H. Peter Anvin
f221b9ee08 Fix a few more <ctype.h> instances
A few isolated instances of isalpha() and isxdigit().
2008-06-21 11:03:51 -07:00