Commit Graph

3090 Commits

Author SHA1 Message Date
H. Peter Anvin
a648b90eab NASM 2.12rc4 2016-02-16 22:32:58 -08:00
H. Peter Anvin
dde34c51b3 outmacho: correct handling of GOT relocation, add TLVP relocations
Correct the handling of GOT relocations, as they need a symbol
reference.  Add handling of TLVP relocations; it is unclear to me
if non-local relocations in TLVP space is permitted.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-16 22:15:03 -08:00
H. Peter Anvin
085a4a9f98 outmacho: fix the .rodata -> __TEXT,__const mapping
For the mapping of .rodata to __TEXT,__const in the absence of
relocations, it would help if we changed the segment name *before* we
emit that part of the load command.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-16 18:04:39 -08:00
H. Peter Anvin
82a3082d64 raa: move private parts of the implementation into raa.c
Move the private aspects of the implementation into raa.c instead
of exposing it to raa.h.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-16 17:47:25 -08:00
H. Peter Anvin
ec62791d8c outmacho: sanitize the handling of sections
Sanitize the handling of sections in outmacho somewhat.  This should
bring further performance improvements.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-16 17:38:58 -08:00
H. Peter Anvin
2c4a4d5810 Simplify handling of segments and segalign
Slightly simplify the handling of segment number allocation.
If we are in absolute space, never push a segalign down to the backend.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-16 17:37:18 -08:00
H. Peter Anvin
6fc2b123af outmacho: if .rodata contains no relocations, change it to __TEXT,__const
If we specify .rodata as opposed to the explicit __DATA,__const, and
we end up with no relocations, change it to __TEXT,__const per the
Mach-O ABI.  However, it is generally better for the programmer to
explicitly specify the items that should go into __TEXT,__const as
otherwise a single relocatable item will force the whole thing into
__DATA.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-16 12:56:27 -08:00
H. Peter Anvin
d1da074b83 outmacho: Allow arbitrary MachO sections, avoid bss lookup
Allow specifying sections with arbitary MachO segment and section
names, as opposed to having a fixed list of supported sections
(especially __DATA,__const is wrong in some cases.)  Furthermore,
we do a completely unnecessary lookup of the bss section *for every
call to macho_output()* which is just plain crazy.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-16 12:39:26 -08:00
H. Peter Anvin
615ef1a6f8 outmacho: Only test for MAX_SECT at the point sections are laid out
Exceeding MAX_SECT is not a warning, it is a fatal error.  However,
there is no point to test for it until we already process all the
sections.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-16 11:42:13 -08:00
H. Peter Anvin
e1eb7b8880 outmacho: Fix the computation of non-external relocation offsets
When we clear the ext bit, creating section-relative relocations,
the resulting value is computed somewhat differently; we need to
adjust for that.

TODO: Need to make sure we do the right thing for ALL relocations.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-16 11:30:54 -08:00
H. Peter Anvin
4e5fbcb81b outmacho: use section table lookup for local symbol references
When generating local symbol references, don't loop over all the
sections like we used to...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-16 00:29:48 -08:00
H. Peter Anvin
c44bfaa054 Merge branch 'master' of git://repo.or.cz/nasm 2016-02-15 23:44:43 -08:00
Ozkan Sezer
ec3d426e36 configure.in: Add -Werror flags last (BR 2292332)
configure.in: Add the -Werror flags as the last thing. Otherwise, with
development versions of autoconf, all AC_CHECK_FUNCS calls fails with:
conftest.c:49: error: function declaration isn't a prototype
conftest.c:49: warning: conflicting types for built-in function 'strcspn'

Signed-off-by: Ozkan Sezer <sezero@users.sourceforge.net>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-12 23:49:56 -08:00
H. Peter Anvin
ddf424758c NASM 2.12rc3 2016-02-12 21:24:32 -08:00
H. Peter Anvin
2bc798a968 rdflib: actually get the time
sizeof(t = time(NULL)) doesn't ever actually call time().

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-12 21:21:57 -08:00
H. Peter Anvin
99276cc7d9 outmacho: rename outmac.c to outmacho.c
We already have outmacho.mac, so name this file outmacho.c.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-12 21:19:13 -08:00
H. Peter Anvin
941356b2ca outmac: generate section-relative relocations for local symbols
We generate section-relative relocations for local symbols for all
the other output formats, and we should do the same for MachO;
this was done in MachO-32 but not in MachO-64, presumably because
the MachO spec implies that such relocations shouldn't exist in
64-bit code.  They are indeed rare, but that is a programmer's
decision, and the spec is clear that they are legal.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-12 15:06:23 -08:00
H. Peter Anvin
ca351fa175 assemble.c: when converting an address to RAWDATA, need to update size
When converting an address to RAWDATA we have to copy the address size
into the size variable, as the size variable may be negative.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-12 13:49:45 -08:00
H. Peter Anvin
fc1a7ad662 outmac: correct the format name for macho32
The name for the macho32 output format was incorrectly set to
macho64, which means neither macho32 nor macho64 worked correctly.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-12 13:36:37 -08:00
Cyrill Gorcunov
f8d52b655e output: outmac -- Fix few nits during merge
- typo in @if statement
 - unused @originalIndex

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-02-12 21:50:38 +03:00
H. Peter Anvin
b13df02490 outmac: allow section alignment to be declared more than once
Allow section alignment to be declared more than once, with different
values.  The strictest alignment value via either a section or
sectalign directive becomes the controlling parameter.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-12 03:23:25 -08:00
H. Peter Anvin
7dcd1a1549 outmac: default to bits 32 for macho32 output format
Default to 32 bits for macho32; default to 64 bits for macho64.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-12 03:16:02 -08:00
H. Peter Anvin
09b56b421a outmac: move the format definitions down to the format-specific code
Move the format definitions down the to where the format-specific
initialization code lives.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-12 03:13:00 -08:00
H. Peter Anvin
c635497870 Merge the macho32 and macho64 (outmac32/64) backends
Merge the two Mach-O backends for cleanliness and maintainability.
This should also make the recent fixes to MachO-64 available in
MachO-32.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-12 03:04:41 -08:00
H. Peter Anvin
d7043da281 realpath: prefer the buffer size given by pathconf()
If realpath(..., NULL) doesn't work, we have to allocate a buffer
blindly.  Use the value returned from pathconf() in preference from
compile-time constants.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-12 01:32:57 -08:00
H. Peter Anvin
67db8184b1 macho64: remove -64 suffix from static variables
When the macho64 backend was forked, instead of fixing variables which
ought to have been static all along, the porter added a -64 suffix to
prevent namespace conflict.  Fix it by making those variables static.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-12 01:23:53 -08:00
H. Peter Anvin
797dc4f01e macho: make a bunch of global variables static
These variables should never have been anything but static in the
first place.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-12 01:21:15 -08:00
H. Peter Anvin
b03d91e6ab assemble.c: fix the handling of zero-extending unsigned relocations
First of all we printed the wrong error message, and second of all we
need to set the segments to NO_SEG before passing them to the output
format generator.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-11 21:13:54 -08:00
H. Peter Anvin
b64125022d assemble.c: handle oversized relative relocations
Handle the case of oversized (larger than permitted by the output
format) relative relocations.  Relative relocations are always signed,
and quite likely to actually have the sign bits set, so zero-extending
them is not an option.  Fortunately oversized relative relocations
are rare, as no CPU instruction support 64-bit relative addresses.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-11 21:07:40 -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
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