Commit Graph

3374 Commits

Author SHA1 Message Date
H. Peter Anvin
be01d496d4 compiler.h: watcom_switch_hack() improvements
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>
2017-02-23 17:25:31 -08:00
H. Peter Anvin
e3cd70bc46 compiler.h: only use watcom_switch_hack() if necessary
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>
2017-02-23 17:22:58 -08:00
H. Peter Anvin
4d32674144 NASM 2.13rc2 2017-02-23 17:21:12 -08:00
H. Peter Anvin
f805cdebe2 changes.src: update to fit current 2.13 branch status
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>
2017-02-23 17:19:56 -08:00
H. Peter Anvin
1a3314f64b insns.dat: use the officially documented UD0 and UD1 forms
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>
2017-02-23 17:10:19 -08:00
H. Peter Anvin
c5cbb97db4 assemble: for relative addresses, convert *this segment* to fixed
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>
2017-02-21 11:53:15 -08:00
H. Peter Anvin
90303022b4 nasmlib.h: add nasm_zeron()
Add a nasm_zeron() convenience macro to match nasm_zero(); compare
nasm_new() vs nasm_newn().

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-02-21 11:32:22 -08:00
H. Peter Anvin
d97cceed61 We can have a WRT for a relative reference
It isn't illegal to have WRT for a relative reference.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-02-21 11:31:35 -08:00
H. Peter Anvin
8930a8fc15 Properly keep track of the base of relative relocations
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>
2017-02-21 11:30:22 -08:00
H. Peter Anvin
ed71316e2b test/pcrel.asm: make test output a bit easier to understand
Make the output of the test a bit easier to pick apart.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-02-20 13:06:02 -08:00
H. Peter Anvin
164d24677a Support self-relative expressions in offsets and immediates
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>
2017-02-20 02:39:56 -08:00
H. Peter Anvin
9b4b92b014 watcom.h: horrific hack to support OpenWatcom switch limitations
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>
2017-02-20 00:36:53 -08:00
H. Peter Anvin
2902fbc1d8 assemble.c: don't use a case for get_broadcast_num()
Instead of using a case, use a conditional shift.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-02-20 00:35:58 -08:00
Ruslan Kabatsayev
3ebed50146 disasm: Add support for 64-bit origin
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>
2017-02-12 20:19:34 +03:00
H. Peter Anvin
a92a7dce5e nasm_delete(): ugly hack to make it side-effect-free
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>
2017-01-24 14:04:44 -08:00
H. Peter Anvin
75f2c1e131 Put in a comment that nasm_delete isn't side effect safe
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>
2017-01-24 12:42:37 -08:00
H. Peter Anvin
5d7fdc1962 nasmlib.h: add a nasm_zero() macro to the pointer helpers
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>
2017-01-24 12:28:40 -08:00
H. Peter Anvin
94e4052a8a nasm_build_assert() -> nasm_static_assert()
The C11 standard calls this concept a static assert, so go with that
terminology.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-01-24 12:26:09 -08:00
H. Peter Anvin
4eb7a1f089 nasm_build_assert(): use better fallback implementation
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>
2017-01-24 12:24:03 -08:00
H. Peter Anvin
fc427c6fab nasmlib.h: slightly tidy up the definition of nasm_build_assert()
"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>
2017-01-22 21:06:05 -08:00
H. Peter Anvin
cd0c7ddc40 NASM 2.13rc1 2017-01-22 20:57:39 -08:00
H. Peter Anvin
6d20c1f894 output/outmacho.c: use UINT64_C() instead of 1L
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>
2017-01-22 20:53:03 -08:00
Cyrill Gorcunov
dc9c312c97 insns.dat: Fix SHA256RNDS2 optional xmm0 argument
In commit 1eef781594 we allowed xmm0
to be implicit, then in dcaef4b095 it
occasionally got ripped off. Move it back.

https://bugzilla.nasm.us/show_bug.cgi?id=3392379

Reported-by: ig <glucksmann@avast.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-01-08 16:51:41 +03:00
Cyrill Gorcunov
15ce78fc5b macros: Define ofmt specific macros late
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>
2017-01-06 20:22:36 +03:00
Cyrill Gorcunov
c7b0fe6bbe macros: standart -- Shift endmacro left
Fix code imbalance.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-01-06 13:37:05 +03:00
Cyrill Gorcunov
4ff8c63ab6 preproc: Use found path when opening include
It's a typo in 169ac7c152

https://bugzilla.nasm.us/show_bug.cgi?id=3392378

Reported-by: Ryan Prichard <ryan.prichard@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-01-06 00:36:23 +03:00
Martin Lindhe
a6ccf005a5 rdoff: check return value of freopen
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>
2017-01-05 22:38:41 +03:00
Martin Lindhe
8cc93f5232 assemble_file: Get rid of global variable @sb
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>
2017-01-05 22:38:41 +03:00
Martin Lindhe
58f37c1736 parser: Get rid of global variable
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>
2017-01-05 22:38:41 +03:00
Martin Lindhe
ec8b2081d3 macho: Improve macho_calculate_sizes
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>
2017-01-05 22:38:41 +03:00
Martin Lindhe
d551b431a1 Move @debugid declaration to same level as @q
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>
2017-01-05 22:38:41 +03:00
Martin Lindhe
058782948d nasmlib: md5c -- Use size of struct ctx for memset
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>
2017-01-05 22:38:41 +03:00
Martin Lindhe
3478078c5f disasm: matches -- fix operator priority error with parenthesis
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>
2017-01-05 22:38:41 +03:00
Martin Lindhe
f172526697 outas86: Shrink as86_section_names
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>
2017-01-05 22:38:41 +03:00
Martin Lindhe
5b85276196 outcoff: Shrink coff_section_names
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>
2017-01-05 22:38:41 +03: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
Martin Lindhe
b150e386ae Drop redundant test with isnumchar
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>
2017-01-05 22:38:41 +03:00
Martin Lindhe
9b5aa2e6d0 Drop redundant test with isnumchar
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>
2017-01-05 22:38:41 +03:00
Martin Lindhe
e29e321e62 Dont set @mod twice
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>
2017-01-05 22:38:41 +03:00
H. Peter Anvin
abd28c9ab9 If we have new features introduced by C11, use them
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>
2016-12-20 02:29:58 -08:00
Cyrill Gorcunov
fd610f27d6 asm/parser.c -- Fix typo in testing for register
It should be EXPR_REG_END referred when testing
for register present.

A typo in 472a7c1d17

https://bugzilla.nasm.us/show_bug.cgi?id=3392375

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-11-29 01:17:33 +03:00
H. Peter Anvin
7294d62040 compiler.h: use the correct symbol to test for __builtin_expect()
__builtin_expect() has leading underscores, they need to be reflected
in the symbol.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-11-15 15:53:38 -08:00
H. Peter Anvin
8d4fb26ad4 Various fixes to the ilog2 functions
Fix several bugs in the ilog2 functions.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-11-15 14:23:54 -08:00
H. Peter Anvin
069ad5fc18 nasmlib: we need the exact size for the clz functions
We need to use the exact size for the clz functions, otherwise we will
generate the wrong result.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-11-15 14:05:53 -08:00
H. Peter Anvin
8b19083483 Better support for function attributes, autoconf cleanups
Use autoconf to detect function attributes; some compilers like Sun CC
do support some gcc-style attributes, but don't define __GNUC__.  Also
-U__STRICT_ANSI__ already in configure.ac so our tests match what we
might eventually encounter.

Add const_func and pure_func attributes.

Decorate functions in nasmlib.h with const_func and pure_func.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-11-15 14:01:37 -08:00
H. Peter Anvin
70d0458050 Merge remote-tracking branch 'origin/nasm-2.12.xx'
Resolved Conflicts:
	output/outelf32.c
	output/outelf64.c

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-11-15 12:00:23 -08:00
H. Peter Anvin
456b1c46f8 doc/changes.src: document the RDPID instruction
Add RDPID to changes.src.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-11-15 11:56:42 -08:00
H. Peter Anvin
c7ea29b247 Add rdpid instruction
Add the RDPID instruction, documented in the Intel SDM October 2016.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-11-15 11:55:14 -08:00
Cyrill Gorcunov
48fe2eea27 output: outelf,dwarf -- Add missing DW_LNS_copy
Backport of master commit ed347369ae

https://bugzilla.nasm.us/show_bug.cgi?id=3392325

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-11-06 18:38:34 +03:00
Cyrill Gorcunov
4d79eed7b7 x86/insns.dat -- Fix typo in VMOVDQA instruction
https://bugzilla.nasm.us/show_bug.cgi?id=3392369

Reported-by: Agner <agner@agner.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-11-05 16:39:27 +03:00