* 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>
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>
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>
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>
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>
- 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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>