Commit graph

681 commits

Author SHA1 Message Date
Cyrill Gorcunov
20029a586c output: bin -- Use nasm_error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-01 21:32:15 +03:00
Cyrill Gorcunov
ba499c2ac7 output: as86 -- Use nasm_error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-01 21:29:59 +03:00
Cyrill Gorcunov
4dc5360b60 output: aout -- Use nasm_error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-01 21:29:14 +03:00
Cyrill Gorcunov
8525757a31 output: codeview -- Use nasm_error helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-12-01 21:26:18 +03:00
H. Peter Anvin
c77f5079e5 Merge remote-tracking branch 'origin/nasm-2.14.xx'
Resolved Conflicts:
	asm/nasm.c
	version

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-28 12:47:25 -08:00
H. Peter Anvin
4885cc2ba8 BR 3392532: outobj: fix forward references to the SEG of external symbols
External symbols are defined via deflabel(), but deflabel() is not
called until pass0 == 1. Until that happens, segbase has no way to
know what the proper segment base of the segment actually is.

Thus, testing for pass0 == 0 will always fail for a forward reference;
correct the test to test for pass0 < 2, i.e. the assert should fail
only for the final code-generation pass.

Reported-by: <stsp@list.ru>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-11-26 13:41:37 -08:00
Cyrill Gorcunov
f6b1720a2d version: Make them dynamic for regression tests sake
When we are running regression tests we compare binary
forms and the strings better to be the constants to not
trigger false positives.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-24 16:59:32 +03:00
Cyrill Gorcunov
b4e3f11931 output: obj -- Fix nil dereference if no deps needed
Occasionally sneaked in by f7106d06e4

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-11-11 21:42:40 +03:00
Cyrill Gorcunov
fa13a138ea stabs: Convert style and add comments
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-28 23:51:38 +03:00
Cyrill Gorcunov
f856a97707 elf: Convert header to linux style
No functional changes.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-28 23:51:31 +03:00
Cyrill Gorcunov
29a8299487 dwarf: Update header and drop redundant space
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-28 23:51:18 +03:00
Cyrill Gorcunov
218971e5ac dwarf: Update definitions for v4 and v5
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-28 23:51:10 +03:00
H. Peter Anvin (Intel)
f7106d06e4 strlist: use a hash table
Use a hash table to enforce uniqueness in a string list. It is still
an ordered list, however, and can be walked in insertion order.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2018-10-25 12:33:58 -07:00
Cyrill Gorcunov
c7922f95af output: macho -- Rename sect_attribs to macho_known_section_attr
To unify with macho_known_section in namings.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-25 00:14:08 +03:00
Cyrill Gorcunov
458c04eca4 output: macho -- Use lookup_known_section helper
To make it similar to elf code.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-25 00:13:54 +03:00
Cyrill Gorcunov
fbc92bdb66 output: macho -- Beautify known sections
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-24 22:49:03 +03:00
Cyrill Gorcunov
68de05ca79 output: macho -- Move constants into the header
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-24 22:31:07 +03:00
Cyrill Gorcunov
f7b44f6092 Merge branch 'nasm-2.14.xx'
* nasm-2.14.xx: (83 commits)
  NASM 2.14rc16
  doc: Update changes
  preproc: expand_smacro -- Fix nil dereference on error path
  eval: Eliminate division by zero
  doc: Update changes
  opflags: Convert is_class and is_reg_class to helpers
  preproc: Fix out of range access in expand mmacro
  doc: Update changes
  parser: Fix sigsegv on certain equ instruction parsing
  labels: Make sure nil label is never passed
  labels: Don't nil dereference if no label provided
  macho: Add warning message in macho_output()
  macho/reloc: Fix addr size sensitive conditions
  macho/reloc: Fix macho_output() to get the offset adjustments by add_reloc()
  macho/reloc: Fixed offset adjustment in add_reloc()
  macho/reloc: Allow absolute relocation when forcing a symbol reference
  macho/reloc: Adjust SUB relocation information
  macho/reloc: Fixed in handling GOT/GOTLOAD/TLV relocations
  macho/reloc: Simplified relocation for REL/BRANCH
  macho/sym: Record initial symbol number always
  ...

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-10-15 22:58:13 +03:00
Chang S. Bae
703e565849 macho: Add warning message in macho_output()
Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:23:13 +03:00
Chang S. Bae
7fcf32ba31 macho/reloc: Fix addr size sensitive conditions
TLVP relocation helps GOT that is 64-bit only.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:23:10 +03:00
Chang S. Bae
195e735a81 macho/reloc: Fix macho_output() to get the offset adjustments by add_reloc()
Unlike the relative relocations, OUT_ADDRESS had ignored the adjustments
made by add_reloc(), and writes the offset of the target symbol in the
target section.

Based-on-code-from: zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: Chang S. Bae <changseok.bae@gmail.com>
2018-10-09 10:23:05 +03:00
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
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
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
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
2c57d0a5ca RAA: make pointer vs integer RAAs type safe
Use pseudo-types to make it impossible to confuse RAAs made of
integers and RAAs made of pointers.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-18 17:11:54 -07:00
H. Peter Anvin
a5992a4c41 outmacho: don't use raa_read() for pointer values
If we write pointers, we have to read pointers.  This unbreaks
non-64-bit bigendian systems.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-18 16:00:48 -07:00
H. Peter Anvin
c51369067c errors: simplify nasm_fatal() and nasm_panic()
Nearly all instances of nasm_fatal() and nasm_panic() take a flags
argument of zero. Simplify the code by making nasm_fatal and
nasm_panic default to no flags, and add an alternate version if flags
really are desired. This also means that every call site doesn't have
to initialize a zero argument.

Furthermore, ERR_NOFILE is now often not necessary, as the error code
will no longer cause a null reference if there is no current
file. Therefore, we can remove many instances of ERR_NOFILE which only
deprives the user of information.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-06-15 18:20:17 -07:00
H. Peter Anvin
d3b1832c04 outbin: remove ERR_NOFILE
The current error interface fully supports the case where there is no
current filename, so specifying ERR_NOFILE just deprives the user of
information.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-06-15 18:04:54 -07:00
H. Peter Anvin
8f3a62f154 outelf: remove additional tests for [ABSOLUTE]
This test is now centralized, no reason to duplicate everywhere.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-06-15 18:02:08 -07:00
H. Peter Anvin
79561027a0 Make limits 64 bits, add globallines limit to configurable limits
Make all limit counters 64 bits, in case someone really has a usage
for an insanely large program. The globallines limit was omitted, add
it to the list of configurable limits.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-06-15 17:57:15 -07:00
H. Peter Anvin
a3d96d02b0 Make limits 64 bits, add globallines limit to configurable limits
Make all limit counters 64 bits, in case someone really has a usage
for an insanely large program. The globallines limit was omitted, add
it to the list of configurable limits.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-06-15 17:56:25 -07:00
H. Peter Anvin
ed859f72a1 output: remove ABSOLUTE handling, OUT_RAWDATA asserts
ABSOLUTE handling can be done centrally, and shouldn't need to be in
every backend.  Simply drop the call to ofmt->output().

Many backends have an assert for OUT_RAWDATA not having a target
segment; this doesn't make any sense as output/legacy.c will not allow
that to happen.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-15 00:03:53 -07:00
H. Peter Anvin
0125c446dd output: centralize the null definition of ofmt->segbase
Only two output formats (obj and ieee) actually need ofmt->segbase, so
move the common dummy definion into nullout.c.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 22:41:00 -07:00
H. Peter Anvin
b91b63d164 outmacho: don't do encoding magic in the segment index
Encoding magic (in this case, subsection number) by bitfields in the
segment index has several problems:

1. It limits the number of *external symbols* as well as
   segments/subsections.
2. It is inefficient for the assembler (creates a very large RAA).

This is also a really good opportunity for removing linear lookups in
the MachO backend. We now use an RAA to do look up segment by index,
and a hash table to look up segment by name. Subsections are simply
handled by allocating a new index using seg_alloc() but still point it
to the same section structure in the index RAA.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 17:14:36 -07:00
H. Peter Anvin
29695c85fb labels: add a subsection field available for backend use
Allow the subsection to store a subsection value directly in the
label, rather than having to do strange encoding hacks.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-14 17:04:32 -07:00
H. Peter Anvin
69f0551f6f macho: Turn off OFMT_KEEP_ADDR
OFMT_KEEP_ADDR seems to not work properly. Now when we have proper
subsections, there is no need for that anymore.

This reverts commit 69ed82447a.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-01 18:14:16 -07:00
H. Peter Anvin
98578071b9 Cleanup of label renaming infrastructure, add subsection support
In order to support Mach-O better, add support for subsections, as
used by Mach-O "subsections_via_symbols". We also want to add
infrastructure to support this by downcalling to the backend to
indicate if a new subsection is needed.

Currently this supports a maximum of 2^14 subsections per section for
Mach-O; this can be addressed by adding a level of indirection (or
cleaning up the handling of sections so we have an actual data
structure.)

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-06-01 18:06:25 -07:00
H. Peter Anvin
892c4818ce Add support for backend-defined subsections and label hacks
MachO has this odd thing called "subsections via symbols", by which a
symbol can magically start what effectively is a new section. To
support this, add support for a calldown into the backend when a new
symbol is defined *at the current output location*, and allow it to
switch the current segment.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-05-30 14:48:18 -07:00
H. Peter Anvin
1ce81e10ef Revert "output: macho -- Check the actual size of 64-bit absolute address"
This reverts commit 69ed82447a.
2018-05-08 12:46:55 -07:00
Chang S. Bae
427d8e3e57 output: macho -- Avoid conversion of addresses to RAWDATA
Without relocation, the linker may do erroneous dead strip.
For the relocation, the conversion of addresses to RAWDATA
should be avoided for Mach-O.

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

Reported-by: Andrew Fish <afish@apple.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-05-05 23:44:33 +03:00
Chang S. Bae
69ed82447a output: macho -- Check the actual size of 64-bit absolute address
Even though the size is set to 64-bit, actual value can be
in 32-bit range. In that case, the use of such absolute
address is prevented.

The side effect of 58d2ab17 is resolved.

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

Reported-by: Richard Russell <rtrussell@gmail.com>
Reported-by: Michael Petch <mpetch@capp-sysware.com>
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-05-05 23:43:57 +03:00
Fabian Giesen
713fd1ffc8 output: codeview -- change version number written
Windows Store and Xbox One apps need to pass WACK, the Windows App
Certification Kit, and part of that process involves a tool named
BinScope that checks the debug info of all object files making up
the final executable against a list of minimum versions.

These minimum versions get increased periodically as new SDKs and
compilers are released. In a patch 2 years ago, I made NASM
pretend it was MASM and output a then-current MASM version number.

Well, the minimum version number has increased again, and
periodically hardcoding a new random MASM version to keep BinScope
happy doesn't seem like the way to go.

It turns out that BinScope does not impose any minimum version
requirements on object files listing a source language BinScope
doesn't know about.

I have no idea how to officially request a new CodeView language
ID (or whether there even is a way to do so for someone outside
MS). But experimentally, using 'N' (0x4e) for NASM seems to be
working just fine and is far away from the range of currently
allocated language IDs (which stop at 0x10).

Long story short, make NASM emit a source language ID of 0x4e,
with the actual NASM version in the version number fields.
BinScope is happy to accept that, and since the language ID field
is purely an informational field in an optional debug info record
that (as far as I can tell) is not used for anything else, this
seems reasonably safe and unlikely to cause trouble.

Signed-off-by: Fabian Giesen <fabiang@radgametools.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-04-20 11:27:19 +03:00
Matthieu Darbois
9adfd34b03 output: macho -- Add support for N_PEXT in macho output
This allows to mark global symbols as private external.
Similar to visibility hidden in ELF output.

Signed-off-by: Matthieu Darbois <mayeut@users.noreply.github.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-02-25 17:41:54 +03:00
Cyrill Gorcunov
fb9e00a1c3 output: outobj -- Fix typo in obj_init
In 51b453b097 occasionally
used wrong operand for sizeof.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-02-25 16:12:34 +03:00
Cyrill Gorcunov
51b453b097 output: elf,ieee,macho,obj -- Fix mofule name for commit 81b62b9f54
These modules need a reference to input filename.
For example elf put into symbol table

 | SYMBOL TABLE:
 | 0000000000000000 l    df *ABS*	0000000000000000 sha-64.asm

Otherwise this  become empty string.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-02-25 15:50:35 +03:00
H. Peter Anvin
281f5bd92c Merge branch 'master' of ssh://repo.or.cz/srv/git/nasm 2018-02-22 14:53:46 -08:00
H. Peter Anvin
6feef84f25 outbin: check the status of lookup_label()
Make sure we actually found the label we looked at, to avoid undefined
behavior.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-02-22 14:51:59 -08:00
H. Peter Anvin
7418883b62 outelf: fix possibly uninitialized variable
Fix possibly uninitialized variable "currfile".

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-02-22 14:51:26 -08:00
Cyrill Gorcunov
70c439b8de output: elf -- Add missing dwarf loc section
Lost during elf engine unification in
4670887c4d

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-01-28 00:56:18 +03:00
H. Peter Anvin
81b62b9f54 Eliminate filename length restrictions, remote ofmt->filename()
Get rid of remaining dependencies on FILENAME_MAX, which ought to have
been removed a long time ago.

Remove ofmt->filename(); all implementations pretty much do the same
thing and there is absolutely no reason to duplicate that
functionality all over the place.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-12-20 13:38:20 -08:00
H. Peter Anvin
ece809789e Merge remote-tracking branch 'origin/nasm-2.13.xx'
Resolved conflicts:
	version

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-11-01 10:37:18 -07:00
H. Peter Anvin
230db148a3 outelf.c: fix a typo in previous commit
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-09-27 15:12:03 -07:00
H. Peter Anvin
e4303ee7f1 BR 3392417: always end the DWARF .debug_abbrev section with a null
The DWARF spec specifies that the .debug_abbrev section always should
end with a null byte.  Existing tools don't seem to care, but some
issue a warning, and it is invalid according to spec.

Reported-by: Darren Sylvain <sylvaindarren@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-09-27 15:05:03 -07:00
H. Peter Anvin
621603da26 BR 3392418: MachO: support 16-character section names, debug flag
Support 16-character section names, and support the debug section
flag.

Reported-by: Andrey Timofeyev <timofeyev@bk.ru>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-09-27 14:42:08 -07:00
H. Peter Anvin
0a126062fb ilog2(): inline functions if practical
For many (most?) targets these will be very small functions, so inline
them.  However, just in case make these external library functions.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-09-27 13:34:42 -07:00
H. Peter Anvin
fbce0bfb4e Merge remote-tracking branch 'origin/nasm-2.13.xx'
Resolved Conflicts:
	asm/directiv.dat
	asm/preproc.c
	misc/omfdump.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-08-16 22:41:40 -07:00
H. Peter Anvin
a771be85f4 outobj: emit file dependency information
Some OMF toolchain can make use of file dependency information
embedded in the object files.  As implemented here, we don't try to
absolutize the filenames, as that prevents moving around trees and is
OS-dependent.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-08-16 15:00:38 -07:00
H. Peter Anvin
24f7b5c3e4 timestamp: centralize handing of compilation timestamp
Do all the generation and conversion of the compiler timestamp in one
place and make it available to modules.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-08-02 18:37:54 -07:00
H. Peter Anvin
aac369d5b0 Merge remote-tracking branch 'origin/nasm-2.13.xx'
Resolved Conflicts:
	common/common.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-06-23 14:48:08 -07:00
H. Peter Anvin
58d2ab176f outmacho: always use symbol-relative relocations for MachO64
It seems that the MachO64 linker really doesn't like segment-relative
relocations under certain circumstances, so force relocations to be converted
to "external" (symbol-relative); error out if no symbol is available
(if this is a problem, we can consider inserting a synthetic symbol if
necessary.)

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-06-22 23:36:34 -07:00
H. Peter Anvin
1669cb04a5 outdbg: make the output for relative relocations more clear
Make the output for relative relocations more clear, so it can be
actually comprehended.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-06-22 23:00:38 -07:00
H. Peter Anvin
a7b6bfca68 Sanitize the handling of segments a bit
Make the internal handling of segment numbers just a little more
sane.  The whole use of when we have done ofmt->segbase or not is
crazy, though...

In the meantime, add a few more hacks to the dbg output format to make
it more useful.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-05-03 17:33:04 -07:00
H. Peter Anvin
20f6c253cd Merge remote-tracking branch 'origin/nasm-2.13.xx' 2017-05-01 21:25:14 -07:00
H. Peter Anvin
3e458a89d8 a) Fix handling of DZ/ZWORD; b) don't crash on TIMES JMP
a) Fix a number of missing instances of DZ and ZWORD.

b) NASM would crash if TIMES was used on an instruction which varies
   in size, e.g. JMP.  Fix this by moving the handling of TIMES at a
   higher level, so we generate the instruction "de novo" for each
   iteration.  The exception is INCBIN, so we can avoid reading the
   included file over and over.

c) When using the RESx instructions, just fold TIMES into the reserved
   space size; there is absolutely no point to iterate over it.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-05-01 21:13:15 -07:00
H. Peter Anvin
217e714e6b output/legacy.c: OUT_SEGMENT -> OUT_ADDRESS with a zero addend
The legacy output doesn't distinguish between segments and other
addresses, so we need to force the offset to zero before passing it
down to the output layer.

This addresses BR 3392406.

Reported-by: <rugxulo@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-05-01 15:10:47 -07:00
H. Peter Anvin
97408d67dd Merge remote-tracking branch 'origin/elf' 2017-04-29 13:28:12 -07:00
Chang S. Bae
375f452813 outmacho: fix dwarf line number information (debug_line section)
Create directory table in prologue and file name indicates index
of the table for its directory

Now bring back included file names

Signedoff-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-27 20:04:15 -07:00
Chang S. Bae
961d8670bf outmacho: add dir list
Separate dir info from the file list to align with dwarf format
in debug_line section

Signedoff-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-27 20:03:53 -07:00
Chang S. Bae
1d73d14eb0 outmatch: fix file info and cleanup in dwarf generation
In debug info and line, only main source is showed up. Header files
will be laid out via TAG_subprogram

Included missing memory cleanups

Removed unnecessary null assertions

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-25 12:54:25 -07:00
H. Peter Anvin
d3e22572b3 Clean up byteorder functions
Move byte order handling functions to their own header file, and try
to be more specific about how exactly to handle things.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-24 13:01:08 -07:00
H. Peter Anvin
bbb39579ec hashtbl, strtbl: add hash_free_all(), split strtbl_find()
Add hash_free_all() to factor common code of iterating over all
members of a hash to free them with a single nasm_free().

Split strtbl_find() into strtbl_find() and strtbl_add().  It is very
unlikely that the same call site will want to have both of these
functionalities, and in the end the code for the two functions are
surprisingly different.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-24 00:54:51 -07:00
H. Peter Anvin
bf0bcef3d4 output: generic string table implementation
Several output formats use "string tables", which is a collection of
null-terminated (C) strings which are referenced by a byte offset into
the string table.  A single string can be referenced an arbitrary
number of times.

As this is quite simple to implement with a hash table, we do exactly
that.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-24 00:23:03 -07:00
H. Peter Anvin
e0172d5870 Merge branch 'master' into elf 2017-04-23 23:52:32 -07:00
H. Peter Anvin
4b177bfb03 outmacho: clean up list walks, use nasm_basename/nasm_dirname
Use the new nasm_basename() and nasm_dirname() functions to split a
pathname.

Use nasm_wcstring() to write a C string to an SAA.

Use list_for_each() to walk linked lists.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-23 23:46:41 -07:00
H. Peter Anvin
3e555483b3 labels, outelf: remove casts for allocations
Remove casts from allocations.  This is simply Not How To Do Things:
every cast carries a potential risk of being a toxic type misuse
(e.g. pointer as integer) and so any unnecessary cast is actively
harmful.

Note that a lot of allocations here are completely unnecessary: the
core code now guarantees that all filenames are permanently allocated
for the duration of the assembly, and so should be turned into const
char * without any further allocation.  Any remaining malloc+strcpy
should be turned into nasm_strdup(), and nasm_new[n]() used whereever
possible.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-23 17:02:46 -07:00
Chang S. Bae
4dfbd9aec5 macho: add file path to the dwarf debugging output
Apple's linker requires file path along with file name to produce
debug notes.

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-04-23 16:46:45 -07:00
H. Peter Anvin
c4d75ddcbf Merge branch 'master' into elf
Resolved Conflicts:
	aclocal.m4
	output/outelf.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-18 16:08:54 -07:00
Chang S. Bae
5431732560 Fix errors uncovered by clang warnings
1. One incorrect variable use(!)
2. One possibly uninitialized variable.

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-04-17 14:01:33 -07:00
Chang S. Bae
d685bdd65c outmacho: dwarf debug (4/4)
line information added in dwarf output

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-04-17 14:00:20 -07:00
Chang S. Bae
2c2272a86d outmacho: dwarf debug (3/4)
debug information sections now generated.

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-04-17 14:00:20 -07:00
Chang S. Bae
6d14596476 outmacho: dwarf debug (2/4)
file and section list added for managing debug line info
also, now macho parts get to call debug interfaces

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-04-17 14:00:18 -07:00
Chang S. Bae
6a912a3c90 outmacho: dwarf debug (1/4)
skeletion interfaces

MachO Dwarf is basically porting of ELF's DWARF implementations
and it includes debug line information and some debug meta data

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-04-17 14:00:16 -07:00
Chang S. Bae
3b26c45e7f outmacho: align filesize together with vmsize
According to the Mach-O spec this should not be necessary for .o
files, but it seems that we get problems with extracted dsyms if this
is not done, so do this for now -- we might be able to troubleshoot
this later.

Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-04-17 14:00:07 -07:00
H. Peter Anvin
5253f58c36 Add generic perfect string hashes, use for directives
Add a generic facility for generating perfect string hashes, where all
that is needed is an enum and a string table.  The existing mechanism
using a custom Perl script wrapped around a module continues to be
available for any use case where this particular approach isn't
sophisticated enough.

Much of this patch comes from renaming "enum directives" to "enum
directive" as a result of the string hash generator expecting a set of
uniform naming conventions.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-03 00:27:07 -07:00
H. Peter Anvin
17df43c8f2 outdbg: add %pragma for maximum size of a raw data dump
A raw data dump can potentially be very large, especially when
incbin is used.  Allow a %pragma for setting the maximum dump
size (defaults to 128 bytes.)

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-31 12:03:57 -07:00
H. Peter Anvin
ac06133ed2 output: remove the completely unused set_info method
Every single backend has this method set to NULL.  It is also a
rather strange interface.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-31 11:41:16 -07:00
H. Peter Anvin
31a14699fb outdbg: update to dump new backend interface data
Update the debug output format to dump (most of) the information that
is available via the new backend format, as well as the legacy backend
format -- probably the only backend ever which will ever want both!

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-31 11:32:53 -07:00
Cyrill Gorcunov
5fe4eff8c4 output: elf -- Make elf_section_attrib static
After elf files have been merged into one
no need to keep it global.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-25 22:15:04 +03:00
Cyrill Gorcunov
ee1fc45ee1 dwarf: Update dwarf_line_number_extended
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-25 22:15:04 +03:00
Cyrill Gorcunov
de03b2b831 dwarf: Update dwarf_calling_conversion
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-25 22:15:04 +03:00
Cyrill Gorcunov
c95c2536b4 dwarf: Update dwarf_language
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-25 20:55:48 +03:00
Cyrill Gorcunov
495b6352d8 output: elf,dwarf -- Fix lookup over existing files
We are missing @next access here so in result we
might allocate same name several times.

Reported-by: "Bae, Chang Seok" <chang.seok.bae@intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-23 19:19:38 +03:00
Cyrill Gorcunov
8f1d6b0ed8 output: elf -- Use Elf64_Ehdr into section offset
Same as we do in e_shoff.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-18 16:25:49 +03:00
Cyrill Gorcunov
b074501887 output: elf -- Use ElfX_Relx in elf_build_reltab
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-18 15:16:10 +03:00
Cyrill Gorcunov
a95a8e6d7f output: elf -- Add ELF32_R_INFO, ELF64_R_INFO helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-18 15:16:10 +03:00
Cyrill Gorcunov
bb6daa408e output: elf -- Start using ElfX_Sym in elf_build_symtab
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-18 15:16:10 +03:00
Cyrill Gorcunov
c2df71b3ae elf: Switch writting sections with Elf structs
The target of all this code rework is to
start using general backend engine with
native Elf types behind.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-18 15:16:10 +03:00
Cyrill Gorcunov
3a994a92cc output: Elf -- Start using ElfX_Ehdr instead of opencoded writes
This should be more convenient. At least both headers
are well documented in specifications so we simply
follow them.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-18 15:16:10 +03:00
H. Peter Anvin
e74fd4b7b8 outelf: claim %pragma elf as our namespace
We don't have any elf pragmas yet, but we want to be able to do
"%pragma elf" and have it work for any of the elf formats.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-03-14 18:58:35 -07:00
H. Peter Anvin
6e4ceb7ba1 Merge remote-tracking branch 'origin/master' 2017-03-14 18:48:21 -07:00
H. Peter Anvin
9f16cfde4c macho: implement do_dead_strip, make subsections_by_symbols a pragma
Implement the MachO do_dead_strip directive, which sets a flag on the
corresponding section.  This as well as subsections_by_symbols are
reimplemented as pragmas; if someone uses the predefined macro they
still get the expected behavior.

However, this allows someone to write:

%pragma macho subsections_by_symbols

... and have it ignored if compiling for, say, ELF.

Also, implement the following section attributes:

      zerofill, no_dead_strip, live_support, strip_static_syms

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-03-14 18:46:31 -07:00
Cyrill Gorcunov
fa38564c49 output: elf -- Fix typo in ELF32_ST_INFO
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-12 11:40:52 +03:00
Cyrill Gorcunov
bcf0389481 elf: Drop code duplication in elf_section_header
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-12 11:37:41 +03:00
Cyrill Gorcunov
660101a02e elf: Align members for file format defs
For readability sake.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-12 11:37:23 +03:00
Cyrill Gorcunov
37034f1cc8 elf: Add EI_ constants
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2017-03-12 11:37:15 +03:00
H. Peter Anvin
fc7c5c3967 outmacho.mac: fix typo in subsections_via_symbols
subsections_via_symbols is plural for both nouns.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 23:02:31 -08:00
H. Peter Anvin
b786f66c2e output: output format macros should be case insensitive
Use %imacro instead of %macro for ELF "osabi" and Mach-O
"subsections_by_symbols".

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 22:53:48 -08:00
H. Peter Anvin
8e1cb8e594 outmacho: support the "subsections_via_symbols" directive
The "subsection_via_symbols" directive simply sets a flag in the
Mach-O file header.

Requested in BR 3392367.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 22:43:00 -08:00
H. Peter Anvin
e562b70cea output: make the return value from the directives method more meaningful
The directives code is already trying to do a bit more unified error
handling, so give ourselves a bit richer interface.  At this point,
the conversion was pretty automatic so we probably return DIRR_OK
instead of DIRR_ERROR in a fair number of places, but that's okay.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 22:42:39 -08:00
H. Peter Anvin
a6e26d9cca Add a generic pragma-handling infrastructure
Add infrastructure for handling %pragmas with a variety of namespaces,
etc., etc...

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 21:32:37 -08:00
H. Peter Anvin
b20bc733c9 asm/*: Move directive processing to its own file, refactor error handling
Move directive processing to its own file, and move nasmlib/error.c to
asm/error.c (it was not used by the disassembler); remove some extern
declarations from .c files, and do some general code cleanups.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-07 19:31:04 -08:00
H. Peter Anvin
f786ef7371 outelf.c: char * -> const char *
Make the arguments to add_sectname() constant.  There are definitely
more things about this that ought to be cleaned up, including not
relying on magic offsets for the section numbers, but this is a
trivial cleanup that really needed to be done anyway.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-03-01 21:17:45 -08:00
H. Peter Anvin
09dff8b257 Remove casts in switch statements only meant to keep OpenWatcom happy
Remove casts in switch statements that were intended to keep
OpenWatcom happy.  It didn't work, and now we have a more general
solution for the problem, which also ought to be less dangerous.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-03-01 01:01:37 -08:00
H. Peter Anvin
e90a89abe4 compiler.h: add redundant cast to quiet Watcom warning
Add a redundant cast in watcom_switch_hack() to quiet a Watcom
warning, and remove open-coded implementation of the Watcom switch
hack.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-03-01 00:52:48 -08:00
H. Peter Anvin
3fa2558a69 output/codeview.c: remove C99-ism
Remove a C99-ism, specifically the use of a variable declaration
inside a for loop statement.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-02-23 18:43:31 -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
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
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
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
Hilmar Ackermann
ed347369ae output: outelf,dwarf -- Add missing DW_LNS_copy
https://bugzilla.nasm.us/show_bug.cgi?id=3392325

Signed-off-by: Hilmar Ackermann <hilmar.ackermann@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-11-05 15:12:45 +03:00
H. Peter Anvin
9df6b4c8c2 output/legacy.c: include outlib.h
Add outlib.h for the prototype of nasm_do_legacy_output().

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-10-06 14:19:02 -07:00
H. Peter Anvin
fa803abc61 backend: move wrapper for legacy output functions to a library routine
Move the wrapper for legacy output into a library routine so the
backends can be ported one at a time.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-09-24 09:46:47 -07:00
H. Peter Anvin
9938bb6333 outelf: add panic() for unknown output types
If we get an output type we don't know how to handle, do a panic()
rather than a compile-time error; this will be necessary in the short
time pending a change to the backend interface.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-09-20 14:00:56 -07:00
Fabian Giesen
0cb6739ba4 output: elf -- Generate SHT_RELA relocs for elfx32/elf64 stabs
stabs is the default debug format and GNU gold dies with an assertion
failure when it encounters a SHT_REL section in an x64 ELF file.

Signed-off-by: Fabian Giesen <fabiang@radgametools.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-08-18 00:51:36 +03:00
Fabian Giesen
f47f451a85 output: elf -- Fix debug info.
df_dwarf and df_stabs were orphans of the elf32/64 merge; clean up.

Signed-off-by: Fabian Giesen <fabiang@radgametools.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-08-18 00:51:20 +03:00
Fabian Giesen
bb0fa088fb codeview: Fix ill-formed "S_COMPILE2" record.
write_symbolinfo_properties didn't match the S_COMPILE2 record it's
supposed to be writing (the "compiler version" string was emitted
starting in the final "version" field); fix that.

Write version 8.0.50727; the Windows App Certification Kit (WACK)
checks compiler versions as given in app debug info and complains
when the toolchain is too old. 8.0.50727 is the lowest permitted
"MASM" version for WACK to be happy, so that's what we write.

Signed-off-by: Fabian Giesen <fabiang@radgametools.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-07-18 14:55:55 +03:00
H. Peter Anvin
66d561f2d9 Merge tag 'nasm-2.12.02rc9'
NASM 2.12.02rc9

Resolved Conflicts:
	asm/preproc.c
	version

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-06-16 15:47:46 -07:00
H. Peter Anvin
b41952986b outmacho: Fix relative relocations for 32-bit Mach-O (fix typo)
This unbreaks checkin 84f6860ed5, which
was broken due to a transcription error of mine.  Zenith432 was
faultless in this case.

This fixes bug report 3392355.

Reported-by: Zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-06-14 18:04:46 -07:00
knut st. osmundsen
8e6feefb3b outobj.c: Fix for RIP relative addressing relocation.
For 16-bit and 32-bit x86 code, the size and realsize() always
matches as only jumps, calls and loops uses PC relative
addressing and the address isn't followed by any other opcode
bytes.  In 64-bit mode there is RIP relative addressing which
means the fixup location can be followed by an immediate value,
meaning that size > realsize().

When the CPU is calculating the effective address, it takes the
RIP at the end of the instruction and adds the fixed up relative
address value to it.

The linker's point of reference is the end of the fixup location
(which is the end of the instruction for Jcc, CALL, LOOP[cc]).
It is calculating distance between the target symbol and the end
of the fixup location, and add this to the displacement value we
are calculating here and storing at the fixup location.

To get the right effect, we need to _reduce_ the displacement
value by the number of bytes following the fixup.

Example:
 data at address 0x100; REL4ADR at 0x050, 4 byte immediate,
 end of fixup at 0x054, end of instruction at 0x058.
 => size = 8.
 => realsize() -> 4
 => CPU needs a value of:   0x100 - 0x058 = 0x0a8
 => linker/loader will add: 0x100 - 0x054 = 0x0ac
 => We must add an addend of -4.
 => realsize() - size = -4.

The code used to do size - realsize() at least since v0.90,
probably because it wasn't needed...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-06-03 23:54:12 -07:00
H. Peter Anvin
e1f985c167 Reorganize the source code into subdirectories
Make the source code easier to understand and keep track of by
organizing it into subdirectories depending on the function.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-05-25 12:06:29 -07:00
H. Peter Anvin
3e83cec90e Add wrappers around fopen(), use mmap on glibc
Add wrappers to fopen().  The intent is to replace references to
FILE * with an internal structure which can also cache things like the
filename and, when needed, the full pathname and checksums.

Also, add the "m" flag if we are compiling for glibc, for speed.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-05-25 04:34:00 -07:00
H. Peter Anvin
794688c21c Merge remote-tracking branch 'origin/nasm-2.12.xx'
Resolved Conflicts:
	version

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-24 23:48:38 -07:00
H. Peter Anvin
0183894895 codeview: use nasm_realpath() to find the canonical name of the outfile
Concatenating the cwd with the name of the output file is incorrect
for filenames which are specified as absolute.  We already have
nasm_realpath() for this purpose, use it.

Cc: Jim Kukunas <james.t.kukunas@intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-24 23:35:57 -07:00
H. Peter Anvin
57a0581394 codeview: don't walk the file list for every line
Instead of walking a linear list of files for every line, make a
simple comparison for the common case of the same file, and otherwise
use a hash table.

Cc: Jim Kukunas <james.t.kukunas@intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-24 23:00:23 -07:00
Jim Kukunas
4de0e93677 codeview.c: register all filenames
This essentially reverts 6503051dcc since
that workaround is no longer needed thanks to support for multiple source
files

Signed-off-by: Jim Kukunas <james.t.kukunas@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-17 11:35:44 -07:00
Jim Kukunas
f8259c662a codeview.c: Add support for multiple source files
Handle the existence of multiple source files, as is normal when using
include files.

Signed-of-by: Jim Kukunas <james.t.kukunas@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-17 11:35:44 -07:00
H. Peter Anvin
a87c5e4c87 Merge remote-tracking branch 'origin/nasm-2.12.xx'
Resolved Conflicts:
	.gitignore
	Makefile.in
	Mkfiles/msvc.mak
	Mkfiles/netware.mak
	Mkfiles/openwcom.mak
	Mkfiles/owlinux.mak
	preproc-nop.c
	preproc.c
	version

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-05-16 21:27:33 -07:00
H. Peter Anvin
6a5b3ecb16 codeview: use nasm_free() instead of plain free()
We want to consistently use our allocator wrapper functions whereever
possible.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-10 15:40:24 -07:00
Fabian Giesen
c74a709885 codeview: Call register_file only when producing line numbers
Previously, debug info would refer to the first file seen, even
when it did not actually generate line numbers (e.g. segto=-1).

Fix it so we only lock in the file name the first time we actually
produce a line number record. Not as good as proper support for
debug info referencing multiple source files but much more useful
than the current behavior.

Signed-off-by: Fabian Giesen <fabiang@radgametools.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-05-10 12:01:32 +03:00
Fabian Giesen
142285ddd8 codeview: Make md5sum calc read file in 'binary' mode
When assembling on Windows machines with CRLF line endings, computing
the MD5 hash from the file read in "text" mode (transforms CRLF->LF)
gives incorrect results.

Signed-off-by: Fabian Giesen <fabiang@radgametools.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-05-10 12:01:22 +03:00
Fabian Giesen
86d8756f0c codeview: Look up %include path when determining files to hash.
The hash calculation in calc_md5 tries to open the source file via
"filename" again. For %includes, this is the file name that was
specified in the %include directive, not the actual name of the file
that was opened by the preprocessor. In other words, this fails if the
include file is not in the current working directory.

Add pp_input_fopen that uses the preprocessor include path lookup
code to resolve a file name and open it, and use that in codeview.c.

Signed-off-by: Fabian Giesen <fabiang@radgametools.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-05-10 12:01:08 +03:00