HAVE_DECL_* are 0/1 not ifdef; use HAVE_DECL_STRNLEN to see if we need
to declare this, lest stdlib/strnlen.c fails to compile.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Move memory-mapping functions from file.c into a separate mmap.c.
This will be cleaner especially once (if) we end up doing a Windows
implementation, which is likely to look entirely different.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Use PRId64 instead of %ld to print a 64-bit number. This is debugging
code, but as it is frequently useful I included it in mainline code
and, well, then it has to compile everywhere...
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Avoid type promotion due to ?:, and put in a comment to explain what
the heck the purpose is of wrapping default in a macro.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Use sizeof() to prevent the compiler from invoking
watcom_switch_hack() unnecessarily. Hopefully the optimizer would be
smart enough to recognize this inherently, but this is an old compiler
we are dealing with, so make life a little easier for it.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
It is kind of sad and impressive at the same time how little of the
2.13 changes are actually user-visible at this point.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
The UD0 and UD1 opcodes are now officially documented, with UD1
officially documented to take a modr/m. Still permit the "UD2B" and
argument-less aliases, but not as preferred.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
We can remove OUT_ADDRESS relocations for absolute addresses (NO_SEG),
but for OUT_RELADDR relocations we can remove them if they point into
*our own segment*, not NO_SEG.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
For expressions like [foo - $] or [bar - $$] our relocation base is
not the same as the end of the instruction. Make that explicit.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Handle, hopefully correctly, self-relative expressions (that is,
expressions of the form X - Y where Y is a symbol in the current
segment, possibly $ or $$) used as offsets or immediates, as opposed
to arguments to Dx statements (which have already been supported for a
while.)
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
OpenWatcom still doesn't have proper support for 64-bit switch
statements. Hack around it in a truly vile way.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
This fixes disassembly of instructions like jmp/call when target address
is larger than 2^32-1, and also printing of current address when it's
large.
After this change ndisasm still assumes that the files to disassemble
will never reach 4GiB: only offsets are made 64 bit, but not lengths.
https://bugzilla.nasm.us/show_bug.cgi?id=3392349
Signed-off-by: Ruslan Kabatsayev <b7.10110111@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Use an ugly hack to make nasm_delete() side effect free. This assumes
all pointers have the same internal NULL pointer representation as
void *, however, we already assume zero-initialized memory will
represent a NULL pointer, so hopefully this is okay on any platform we
actually care about.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
I have not figured out a way to make nasm_delete() side effect safe
without using compiler-specific hacks, which would defeat the whole
purpose.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
We do have a number of places where we had problems doing things like:
memset(foo, 0, sizeof foo) instead of sizeof *foo. Add a helper macro
nasm_zero() to the list of (sadly not yet well used) pointer-safe
helper macros.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
http://www.drdobbs.com/compile-time-assertions/184401873 describes a
number of possible implementations of static_assert() on compilers
that do not support it natively. Use their best recommendation.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
"Assertion failed" is likely to be redundant with static_assert().
__attribute__((error)) is only guaranteed to work while optimizing, so
do not use it unless __OPTIMIZE__ is defined.
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Type long is not necessarily long enough to be valid to hold a 64-bit
number (e.g. 32-bit platforms or Win64), however, the output variable
newaddr is uint64_t.
Cc: Martin Lindhe <martin-commit@ubique.se>
Cc: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
In commits e1f985c167 and f7606613d0
we reordered macros handling, but ofmt specific
macros are to be handled after standart ones
are processed.
In particular __SECT__ handling must not change,
so the order of inclusion does matter.
https://bugzilla.nasm.us/show_bug.cgi?id=3392376
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
fixes pvs-studio error 'V530 The return value of function 'freopen'
is required to be utilized.'
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
fixes pvs-studio error 'V707 Giving short names to global variables
is considered to be bad practice. It is suggested to rename 'sb' variable.
gorcunov@: Use local non-static variable.
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
fixes pvs-studio error 'V707 Giving short names to global variables
is considered to be bad practice. It is suggested to rename 'i' variable.
gorcunov@: Simply define it as local variable.
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
pvs-studio error 'V629 Consider inspecting the '1 << s->align' expression.
Bit shifting of the 32-bit value with a subsequent expansion to the 64-bit type.'
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
fixes pvs-studio error 'V507 Pointer to local array 'debugid' is
stored outside the scope of this array. Such a pointer will become invalid.'
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
fixes pvs-studio 'V512 A call of the 'memset' function will lead to
underflow of the buffer 'ctx'.'
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
fixes pvs-studio error 'V502 Perhaps the '?:' operator works in a different way
than it was expected. The '?:' operator has a lower priority than the '!=' operator.'
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
fix pvs-studio error 'V581 The conditional expressions of the 'if'
operators situated alongside each other are identical.
Check lines: 170, 173.'
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
fix pvs-studio error 'V581 The conditional expressions of the 'if'
operators situated alongside each other are identical. Check lines: 304, 311.'
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
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>
Fix pvs-studio error 'V501 There are identical sub-expressions
'(c) == '_'' to the left and to the right of the '||' operator.'. isnumchar()
is a macro defined as (nasm_isalnum(c) || (c) == '_')
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
fix pvs-studio error 'V501 There are identical sub-expressions '(c) == '_'' to
the left and to the right of the '||' operator.'. isnumchar() is a macro
defined as (nasm_isalnum(c) || (c) == '_')
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
pvs-studio: V519 The 'mod' variable is assigned values twice successively.
Perhaps this is a mistake. Check lines: 398, 405.
Signed-off-by: Martin Lindhe <martin-commit@ubique.se>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Instead of using hacks or compiler-specific features, if we have
standard features as defined in ISO C11, use them.
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>