Commit Graph

2961 Commits

Author SHA1 Message Date
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
ecc9e0ecd7 Set warning name to zext-reloc and fix the warning message
Adjustment to the warning about zero-extended relocations.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-11 20:29:34 -08:00
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
f30d96d1c0 outmac64.c: Fix memory clobber bug, clean up memory free
Fix an array that was way too small resulting in memory overwrite
errors, and free a few more dynamic data structures.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-11 20:20:10 -08:00
H. Peter Anvin
97577e82d7 macho64: remove LC_DATA_IN_CODE, change reloc type to 1
Change the relocation type to SIGNED instead of BRANCH, this is
probably more correct.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-11 19:25:33 -08:00
H. Peter Anvin
5eebc6bc2b macho64: fix alignment problems, add LC_DATA_IN_CODE
Hopefully actually fix the issues with alignment this time.
Avoid a linear search of segments for each symbol emitted.
Issue an empty LC_DATA_IN_CODE command since that seems to be
expected.

With this, ffmpeg builds but still crashes on startup, which seems
very strange.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-11 17:51:37 -08:00
H. Peter Anvin
1c10ad65fe nasmdoc.src: update copyright date 2016-02-08 10:34:09 -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
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
5482a15e17 codeview.c: remove superfluous pointer test
A pointer to a field in a structure can never be NULL so remove
the test.  There is no reason to test the field for an empty string
either, since we immediately thereafter do a strcmp().

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-05 11:31:46 -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
def81d5c71 outmac64: Fix the handling of section data alignment
Fix a number of places which failed to account for padding to
alignment of section data.  Also, fix confusion between aligning
section data in the linkable object code and final address alignment;
LLVM/Xcode always align section data to 4 bytes (with a comment saying
that it probably should be 8 bytes for 64-bit output) independent of the
section alignment.

This will need to be ported to the macho32 backend, as well; ideally
the two should be merged as they are really very similar and we don't
want to have these kinds of cross-porting problems.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-05 11:19:29 -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
5a8c424d0c Use a more optimal value for the UNUSED slot
Instead of ~1/4 the range we can use ~1/3 the range for better
distance.  It is possible that using ~1/2 - 1 might be even better,
but this is a trivial tweak.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-01-29 12:05:27 -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
H. Peter Anvin
02237cbfe8 NASM 2.12rc2 2016-01-27 14:48:04 -08:00
H. Peter Anvin
e8677d6818 compiler.h: disable __STRICT_ANSI__ for djgpp
Undefine __STRICT_ANSI__ for djgpp; it removes the prototypes for
non-ANSI functions which is not at all what this symbol is intended
for.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-01-27 14:29:40 -08:00
H. Peter Anvin
064af69d62 realpath.c: remove testing #ifdef unintentionally left in
Remove the #if 0 for canonicalize_file_name().  This was added to
test the realpath() code, and inadvertently left in.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-01-27 14:28:32 -08:00
Knut St. Osmundsen
3c72a1b3b3 Add option to allow 64-bit code in any output format
Add the option --allow-64-bit to permit the generation of 64-bit code
even for a 16/32-bit output format.

Using NASM to do some boot strapping code and ran into trouble when
trying to emit a few 64-bit instructions in the OMF object file doing
the mode switching.  While I can see how the "error: obj output format
does not support 64-bit code" message can be a useful reality check
for application programmers, it prevents low-level programmers from
doing what they want.  It if was just a harmless warning, it wouldn't
be so bad, but it turns BITS 64 into BITS 16. The main trick to mixing
64-bit code into OMF and other 32-bit output formats is to avoid
64-bit sized fixups, which normally isn't too hard.

[hpa: shortened the option name to --allow-64-bit, minor code cleanups]

Signed-off-by: Knut St. Osmundsen <bird-nasm@anduin.net>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-01-26 12:34:41 -08:00
H. Peter Anvin
ad790a2e39 make alldeps to remove unnecessary dependencies for realpath.c
The previous commit contained unnecessary dependencies for realpath.c
so run make alldeps to remove those.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-01-26 12:07:58 -08:00
H. Peter Anvin
2ad64d6974 NASM 2.12rc1 2016-01-26 12:04:49 -08:00
H. Peter Anvin
4627e695a5 Portability improvements to nasm_realpath()
Try harder to nasm_realpath() to be as portable as possible.  Move it
to a separate file since it has gotten complex enough that it is
cleaner that way.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-01-26 12:01:34 -08:00
Jim Kukunas
3115e789d6 coff: Add support for the Codeview 8 debug format
Codeview is a debug format for win32/win64 PE/COFF files. It adds two sections,
.debug$S (symbols) and .debug$T (types), to the generated object file. These
sections are then used by the linker to generate a PDB file which can be used
by various debuggers (WinDbg, Visual Studio, etc).

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:14:39 +03:00
Jim Kukunas
ba754eec03 Add a MD5 implementation
This implementation was written by Colin Plumb and
is in the public domain.

I've updated it to use stdint.h and the standard C types rather than
sys/types.h for portability.

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:14:00 +03: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
H. Peter Anvin
7faf605ca5 NASM 2.11.09rc2 2016-01-15 11:09:42 -08:00
H. Peter Anvin
f29123b936 smartalign.mac: Ignore smartalign in preprocess-only mode
When running in preprocess-only mode generate the equivalent of
standard alignment using nops.  This at the very least allows some
kind of reasonable output and allows for dependency generation to
proceed; the only way to *really* address this problem is to move
alignment generation into the assembler proper; this would also allow
the align/alignb distinction to be removed and handle padding with
instructions which are more than one byte.

This should resolve bug 3392319.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-01-15 11:03:40 -08:00
Cyrill Gorcunov
dcc2cbce8d disasm: Drop unused variable
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-11-05 01:16:09 +03:00
Cyrill Gorcunov
a2a2d19f43 disasm: Fix disassembling of evex prefix
As been pointed by @hpa evex is pretty fine in ia-32.

Quoting Peter

 | This is wrong, though; EVEX is permitted in 32-bit mode just as VEX is.
 | The key thing is that bits [7:5] have to be 1 in 32-bit mode.  It is
 | unclear what happens if these bits are 110 as that depends on if it is
 | decoded using the modr/m decoder or not.  For VEX prefixes we accept
 | them as VEX in that case, which may not match the CPU.

This is a fix for commit db6ecf9b76

Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-11-05 01:14:45 +03:00
Cyrill Gorcunov
8aa9c2eb91 output: macho64 -- Fix OUT_REL4ADR on bigendians
We're converting address value into bigendian
(on BE machine) and then continue doing arithmetics
on top, which is of course incorrect.

Instead do all operations first then convert
to BE and write it into image.

Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-11-05 00:43:29 +03:00
H. Peter Anvin
03f229c74f Restore AC_C_INLINE
Checkin 7729edf722 removed AC_C_INLINE,
presumably inadvertently.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2015-11-04 11:41:33 -08:00
Mark Scott
db6ecf9b76 disasm: Fix for disassembly of BOUND
The opcode for BOUND, 62h, has a different meaning in long mode - it is the
prefix for EVEX instructions. ndisasm did not take this into account and always
tried to disassemble 62h back to an EVEX instruction.

Attached patch only permits EVEX disassembly if bitness is 64.
In 16/32 bit mode 62h will be not be a prefix and so disassemble
to BOUND.

Signed-off-by: Mark Scott <nasm@mscott.cx>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-11-03 23:09:05 +03:00
Mark Scott
be8a5c8f2d out: elf,stabs -- Fix @n_value attribute for HdrSym entry
Each stabs entry is 12 bytes in size, for some reason we've
been pasing wrong attribute here in @n_value.

Signed-off-by: Mark Scott <nasm@mscott.cx>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-11-03 01:14:14 +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
Cyrill Gorcunov
b0b969eec4 disasm: Fix segment prefix name
http://bugzilla.nasm.us/show_bug.cgi?id=3392322

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-09-13 17:16:06 +03:00
Cyrill Gorcunov
8ab77b59e2 insns.dat: Add SMSW for 64 bit mode
http://bugzilla.nasm.us/show_bug.cgi?id=3392323

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-09-13 16:30:21 +03: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
373583c6c8 insns.dat: Add PKU instructions
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-07-26 15:32:59 +03:00
Cyrill Gorcunov
8b4ef2d1d6 doc: Update changes list
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-07-26 14:42:30 +03:00
Cyrill Gorcunov
abe67eea15 NASM 2.11.09rc1
- Fix symbol alignment for Elf64
 - Fix symbol lookup for Macho64
 - Fix relocation records for Macho64
 - Fix potential stack overwrite in Macho32

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.org>
2015-07-25 00:39:42 +03:00
Martin Storsjö
561242bd43 out: maco64 -- Properly update the full 64 bit value when adding relocations
Previously only the first byte was updated (since @mydata
is a an uint8_t[]).

Signed-off-by: Martin Storsjö <martin@martin.st>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-07-24 00:45:59 +03:00
Cyrill Gorcunov
6f05b8008c output: outmacho32 -- Fix stack overwrite
The size of address migh be up to 8 bytes here
so allocate enough stack space.

http://bugzilla.nasm.us/show_bug.cgi?id=3392317

Reported-by: Kyle Brodie <kylecbrodie@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-07-21 22:51:34 +03:00
Cyrill Gorcunov
bd628dedea output: outmach64 -- Use back WRITELONG for OUT_REL4ADR
Because of 74a08cc3f we no longer need to write all
8 bytes here, revert it back as it were before
5b730a197

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-07-19 14:24:32 +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
Jim Kukunas
ce28db6b68 macros.pl: expand file wildcards in arguments
Whereas Unix shells automatically globs wildcard arguments, Windows leaves it
up to application. This commit fixes the build for perl implementations that
don't handle wildcards.

Signed-off-by: Jim Kukunas <james.t.kukunas@linux.intel.com>
2015-07-01 11:35:39 -07:00
Delan Azabani
5b730a197a out: maco64 -- Fix erroneously small write for OUT_REL4ADR
Ensure that the int64_t offset value, which ultimately comes from an
int64_t value in gencode() (assemble.c:1906), is completely written to
the temporary buffer, instead of merely its least significant 32 bits.

Prior to this change, WRITELONG was used instead of WRITEDLONG, which
resulted in add_reloc being passed an int64_t "reloff" whose least
significant 32 bits were those from the aforementioned offset value,
and whose most significant 32 bits were stack garbage from "mydata".

This led to get_closest_section_symbol_by_offset() attempting to search
for extremely large values of "offset" among the symbols in "syms",
which meant that the last symbol with a matching section number would
always win the symbol search.

In effect, this clobbered the resultant relocation information, such
that all entries would be resolved with the same symbol.

Test output can be found here

https://www.azabani.com/patch/2/output.txt

This patch fixes

http://bugzilla.nasm.us/show_bug.cgi?id=3392306

Signed-off-by: Delan Azabani <delan@azabani.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-02 13:22:32 +03:00
Ciro Santilli
668e58dc69 doc: typo occationally
Signed-off-by: Ciro Santilli <ciro.santilli@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-05-24 12:59:11 +03:00