Commit Graph

3851 Commits

Author SHA1 Message Date
Chang S. Bae
f63d211bcf macho/reloc: Fixed offset adjustment in add_reloc()
If the target symbol is in the same file, add_reloc() emits an
internal reloc for the target section, and the offset written
is the offset in the target section.  If the target symbol is
external, its offset is zero (or an explicit addend), and
add_reloc() emits an external reloc for the symbol.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:23:01 +03:00
Chang S. Bae
960efc3ff2 macho/reloc: Allow absolute relocation when forcing a symbol reference
The (fake) section for absolute symbols is not in the linked list. So,
when the section is not found from the index, now it simply points to
the special section.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:22:57 +03:00
Chang S. Bae
625ea1ca47 macho/reloc: Adjust SUB relocation information
As SUB relocation getting deprecated, reset external reference seems to
be enough. Also, print a warning message for this.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:22:53 +03:00
Chang S. Bae
e859ece378 macho/reloc: Fixed in handling GOT/GOTLOAD/TLV relocations
- Changed to search all symbols, instead of only global symbols.

- Will do immediate exits when unsupported use of WRT

- Fixed to mark (got)pcrel flag only for macho64 output. GOT is
supported only for 64-bit.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:22:49 +03:00
Chang S. Bae
4cbbb3940d macho/reloc: Simplified relocation for REL/BRANCH
It seems like the relocation for the relative reference
to absolute addresses only cares external reference info.
Instead of exiting, reset the external reference flag.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:22:45 +03:00
Chang S. Bae
bffd2b7def macho/sym: Record initial symbol number always
The special segment may need this information for future fix-ups.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:22:40 +03:00
Cyrill Gorcunov
0bdd7f1546 opflags: Style unification
No func change.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-01 01:09:43 +03:00
Cyrill Gorcunov
c713b5f994 preproc: parse_size -- Check for string provided
In case if the string is nil we will have sigsegv.

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-09-29 14:31:26 +03:00
H. Peter Anvin
ab2c4dfff9 pspdf.pl: GhostScript font integration seems broken with -dSAFER
-dSAFER seems to break font integration on some systems.  Furthermore,
once given -dSAFER seems to not be possible to override, so instead of
calling via the ps2pdf script, call GhostScript explicitly with the
equivalent options, sans -dSAFER.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-09-24 18:02:22 -07:00
Cyrill Gorcunov
10c0f66570 doc: changes -- Add a few more bullets
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-09-23 23:30:44 +03:00
Cyrill Gorcunov
da3780dc22 Fix small typo in comment
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-09-22 14:10:36 +03:00
Cyrill Gorcunov
69bb052e00 asm: Restore showing output for preproc mode in stdout
Before the commit 81b62b9f54
we've been always putting -E,-e results into stdout if no
output file provded. So bring this backward compatibility
back.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-09-22 13:46:45 +03:00
Chang S. Bae
17ffc1704b obj: Fix to initialize segment list
Recent labeling mechanism changes seem to bring the case,
where segment() procedure is called when the segment list
is empty. Now, it will simply check and initalize the
segment list.

Reported-by: Ozkan Sezer <sezeroz@gmail.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2018-09-15 23:04:30 +03:00
Chang S. Bae
b10435f06e macho: Fix relocation type for relative direct branch
Previously, X86_64_RELOC_BRANCH is only set for external
relocations. Internal relocation also needs this type to be
set, instead of the default (X86_64_RELOC_SIGNED) or
anything.

Reported-by: <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2018-08-24 11:21:58 +03:00
Chang S. Bae
1fd4c45c96 doc: Fix macho section name for code
While today's manual lists "text" as the code section name,
"code" has been effectively named from d1da074.

Reported-by: <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2018-08-24 11:21:53 +03:00
Cyrill Gorcunov
55d09bbf6f disasm: Fix buffer overread in ndisasm
https://nvd.nist.gov/vuln/detail/CVE-2018-10254
https://sourceforge.net/p/nasm/bugs/561/

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-08-16 01:20:01 +03:00
Chang S. Bae
b8d153eb4d macho: Turn off jump-match optimization for subsections_via_symbols
The jump-match optimization tends to remove labels. When the
"subsections_via_symbols" pragma is declared, all the labels
should be emitted. Disabling the optimization (only) makes
the pragma effective.

It might be cleaner to extend the OFMT interface to support
callback function. In this case, the reconfiguration can be
done through the callback interface, rather than direct
access to the global variable.

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2018-08-16 00:01:38 +03:00
Chang S. Bae
a578634b61 optimization: Introduce new flag to turn-off selectively
While configuring optimization in a level is conventional,
a certain optimization tends to conflict with some pragma.

For example, jump match conflicts with Mach-O's
"subsections-via-symbols" macro.

This configurability will workaround such conflicts.

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
2018-08-16 00:01:31 +03:00
H. Peter Anvin
ccd2d5c542 NASM 2.14rc15 2018-07-06 03:14:31 -07:00
H. Peter Anvin
af59af466a float: fix bogus pass flags for errors and warnings
Formatting errors -- syntax errors -- are errors, no matter which pass
they end up in.  ERR_PASS1 is just plain crazy: if we end up with a
formatting error on the code-generation pass, we are in a world of
hurt.

Defer warnings to the code-generation pass; that's the pass which
matters value-wise, and that way we get the warnings in the list file,
too.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-07-06 03:11:52 -07:00
Adam Majer
c7c28357c8 asm/float.c: fix buffer underflow in float parsing
When we suffer an underflow that cross limb boundaries, it is possible
to end up with a stack underflow.  Put in an explicit check for this
case (the mantissa will be zero in this case.)

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

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
diff --git a/asm/float.c b/asm/float.c
index dcf69fea..2965d3db 100644
--- a/asm/float.c
+++ b/asm/float.c
@@ -608,6 +608,8 @@ static void ieee_shr(fp_limb *mant, int i)
         if (offs)
             for (j = MANT_LIMBS-1; j >= offs; j--)
                 mant[j] = mant[j-offs];
+    } else if (MANT_LIMBS-1-offs < 0) {
+        j = MANT_LIMBS-1;
     } else {
         n = mant[MANT_LIMBS-1-offs] >> sr;
         for (j = MANT_LIMBS-1; j > offs; j--) {
2018-07-06 03:08:15 -07:00
Cyrill Gorcunov
70d429676b labels: Add missing backend type for extern symbols
Typo in 98578071b9

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-07-01 02:00:12 +03:00
Cyrill Gorcunov
a8e3d6a836 labels: Shrink declare_label
No need to pass unused 'created', find_label can
handle nil here.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-06-30 20:02:24 +03:00
H. Peter Anvin (Intel)
5ce549c354 NASM 2.14rc14 2018-06-28 02:26:09 -07:00
H. Peter Anvin (Intel)
e8ceba5979 assemble: defer MERR_OPSIZEMISSING
In order for the machinery that deduces memory operand sizes when they
are not provided to work correctly, we need to make sure that
MERR_OPSIZEMISSING is only issued by matches() as the last resort;
that way all other error conditions will have been filtered out and we
know at the very end if we have exactly one option left.

This is a partial revert of cd26fccab4,
but does not affect the functionality introduced by that patch.

Reported-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-28 02:22:55 -07:00
H. Peter Anvin (Intel)
94acb7b5d0 NASM 2.14rc13 2018-06-27 21:05:18 -07:00
H. Peter Anvin (Intel)
b45c03ab42 asm: add a default-off warning for phase error in pass 1
Add a default-off warning for phase error in pass 1.  This is default
off because of the lateness in the release cycle, but cases where we
have such instability should be investigated further.  For now, the
warning is here so we can debug these problems in the field.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-27 21:03:38 -07:00
H. Peter Anvin (Intel)
b28ff3a51f NASM 2.14rc12 2018-06-27 20:25:52 -07:00
H. Peter Anvin (Intel)
d644119ded subsections: don't lose the offset in the parent section
We don't want to lose the offset into the parent section when we
create a subsection, at least not for the MachO backend which is
currently the only user of subsections. Allow ofmt->herelabel() to set
a flag to copy the section offset from the previous section.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-27 20:20:21 -07:00
H. Peter Anvin (Intel)
12810fac92 nasm.c: min 2 optimization passes, don't re-run pass 1
We may not even have the most basic stabilization done unless we run
at least two optimization passes, e.g. in the case of subsections.
However, we cannot run more than one stabilization pass (pass0 == 1);
for one thing we'll call ofmt->symdef() multiple times on the same
symbol, which is not allowed.  If we haven't achieved stability by the
time we decide to run a stabilization pass, plod on and hope for the
best.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-27 20:17:33 -07:00
H. Peter Anvin (Intel)
58a275c3e9 doc/rdsrc.pl: fix unescaped brace
The latest version of Perl complains about an unescaped brace in a
regexp and states that it will be a fatal error in Perl 5.30.  Fix it
now before it becomes a problem.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 23:13:59 -07:00
H. Peter Anvin (Intel)
f388b4d862 NASM 2.14rc11 2018-06-25 23:11:46 -07:00
H. Peter Anvin (Intel)
8df822f79f insns.dat: add Intel Software Guard Extensions (SGX) instructions
Add SGX instructions ENCLS, ENCLU, ENCLV.

Bug report: https://bugzilla.nasm.us/show_bug.cgi?id=3392492

Reported-by: ff_ff <qqqqqqqqqfffffffff@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 23:09:38 -07:00
H. Peter Anvin (Intel)
d558598ebe doc: add a few more updates
In particular, document the new behavior of EXTERN, GLOBAL and COMMON.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 18:19:15 -07:00
H. Peter Anvin (Intel)
70c09f0aac insns.dat: V4F(N)MADDSS are .lig not .512
These instructions ignore vector length.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 18:06:40 -07:00
H. Peter Anvin
717d878314 NASM 2.14rc10 2018-06-25 17:24:10 -07:00
H. Peter Anvin
bac9023d1c insns.dat: fix the opcodes for the V4FNM* instructions
The two V4FNM* instructions had the wrong opcodes.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 17:22:41 -07:00
H. Peter Anvin
01192c0c4e NASM 2.14rc9 2018-06-25 17:17:02 -07:00
H. Peter Anvin
cd26fccab4 asm: support the +n syntax for register sets
Support the +n syntax for multiple contiguous registers, and emit it
in the output from ndisasm as well.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 17:15:08 -07:00
H. Peter Anvin (Intel)
2bf35e0b02 insns.dat: add support for the V4* and VP4* 4-way instructions
New instructions which do four full iterations of a data-reduction
operation (FMA, dot product.)

Bug report: https://bugzilla.nasm.us/show_bug.cgi?id=3392492

Reported-by: ff_ff <qqqqqqqqqfffffffff@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 14:51:15 -07:00
H. Peter Anvin (Intel)
26b810176f insns.dat: add PTWRITE instruction
Add PTWRITE instruction.  It is worth noting that we should
be able to do "ptwrite [eax]" in 32-bit mode, but the instruction
selector doesn't currently handle that well in a way that doesn't make
64-bit mode very confusing.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 14:35:05 -07:00
H. Peter Anvin (Intel)
b6b4b5d546 changes.src: cleanup and fixes
Clean up the language somewhat, and fix a couple of confusing
statements.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 14:19:39 -07:00
Chang S. Bae
ef21926ec2 doc: 2.14 change log
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 14:15:10 -07:00
Chang S. Bae
754edd85ee doc: document new feature from version 2.14
Added descriptions about new commandline options, STATIC
directive, symbol mingling, and some output format
specifics.

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 14:15:04 -07:00
Chang S. Bae
1af6ef4e14 nasm: fix some typo and description for the option help
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 14:14:44 -07:00
H. Peter Anvin (Intel)
ff6faf6134 NASM 2.14rc8 2018-06-25 14:13:20 -07:00
H. Peter Anvin (Intel)
415b6b3df1 absolute: in absolute space, need to use absolute.segment
We can be in absolute space and still end up with segment-relative
references.  This is in fact the meaning of absolute.segment.  Make
sure we define the labels appropriately.

Reported-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 14:09:52 -07:00
H. Peter Anvin, Intel
6bc18f1978 test: make absolute.asm buildable even when not in binary mode
absolute.asm is useful even for other backends, so explicitly test to
see if ORG is possible for this format.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 13:24:51 -07:00
H. Peter Anvin, Intel
59242bd10a test: add test for context-local labels and extern label promotion
Add a simple test case for context-local (%$) labels not disturbing
the local variable namespace, and extern labels getting promoted to
global.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 13:19:32 -07:00
H. Peter Anvin, Intel
c5e45f6b70 labels: auto-promote EXTERN labels to GLOBAL if defined
If we define a label which was previously declared EXTERN, then
automatically treat is as GLOBAL.

Previously, we would fail to converge and loop forever, which is
obviously not what we want.  This is more user-friendly anyway.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-06-25 13:16:53 -07:00