Commit graph

681 commits

Author SHA1 Message Date
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
H. Peter Anvin
3d72e45a13 outmacho: Fix missing brace
Fix a missing brace introduced in checkin
84f6860ed5. This was a transcription
error of mine; Zenith432's original patch was correct.

Cc: Zenith432 <zenith432@users.sourceforge.net>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-09 11:36:55 -07:00
Zenith432
84f6860ed5 outmacho: Fix relative relocations for 32-bit Mach-O
IP-relative relocations were broken for 32-bit Mach-O when referencing
external symbols after the Mach-O backends were merged.

This fixes bug reports 3392348, 3392352, and 3392346.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-09 11:16:10 -07:00
Fabian Giesen
6503051dcc 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-04-30 16:01:30 +03:00
Fabian Giesen
5b838ef981 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-04-30 16:00:59 +03:00
Fabian Giesen
0bbc38dbd5 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-04-30 16:00:38 +03:00
Cyrill Gorcunov
3421a3f3f3 out: Elf -- Fix typo in section name
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:57:52 +03:00
Cyrill Gorcunov
4670887c4d out: Elf -- Merge Elf32, Elfx32 and Elf64 into single file
There is a bunch of common code here so merge them all into one file.
Unmergable parts are wrapped with is_elf() helpers.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:41 +03:00
Cyrill Gorcunov
855ec5aa2c out: Elf32, Elfx32, Elf64 -- Rename unmergable routines
Keep them separate for a while, and merge later.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:41 +03:00
Cyrill Gorcunov
6dfc0b2214 out: Elfx32 -- Unify dwarf_ types
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:41 +03:00
Cyrill Gorcunov
8348af4caf output: Elf32, Elfx32 -- Use 64 bit address
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:41 +03:00
Cyrill Gorcunov
239dfaa5b3 output: Elf32 -- Shuffle few lines to make it close to other code
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:41 +03:00
Cyrill Gorcunov
bff511937f output: Elf32, Elfx32 -- Unify elf_add_gsym_reloc
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:41 +03:00
Cyrill Gorcunov
b89fb8015c out: Elf32 -- A few more constants usage
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:41 +03:00
Cyrill Gorcunov
232788c549 output: Elf32, Elfx32, Elf64 -- Declare ofmt for all
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:41 +03:00
Cyrill Gorcunov
171af38cbc out: Elf64, Elfx32 -- Drop useless DEBUG
We rather need a trace engine.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:40 +03:00
Cyrill Gorcunov
a087d49f70 out: Elf32, Elfx32, Elf64 -- Unify elf_init and elf_deflabel
Note FIXMEs for address later.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:40 +03:00
Cyrill Gorcunov
8ba28bc20b out: Elf32 -- Unify dwarf_ nums
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:40 +03:00
Cyrill Gorcunov
d3ec4be590 out: Elf32, Elfx32, Elf64 -- more unifications
Some elf_ section numbers may be unused.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:40 +03:00
Cyrill Gorcunov
784d10cb9a out: Elf32, Elfx32 -- Unify elf_sect_write, elf_section_header and add elf_sect_writeaddr
elf_sect_writeaddr is unused by now.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:40 +03:00
Cyrill Gorcunov
6285d72efb out: Elf64, Elfx32 -- Style fix
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:40 +03:00
Cyrill Gorcunov
a541094beb out: Elf32, Elfx32 -- Unify struct ELF_SECTDATA and @elf_foffs
Use int64_t.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:40 +03:00
Cyrill Gorcunov
caa18da230 out: Elf32 -- Reuse TY_DEBUGSYMLIN
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:40 +03:00
Cyrill Gorcunov
fbbe8fe9e2 out: Elf32 -- Unify struct symlininfo
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:40 +03:00
Cyrill Gorcunov
583f505155 out: Elf64, Elf32, Elfx32 -- Style merge
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:40 +03:00
Cyrill Gorcunov
2bb791956e out: Elf32, Elfx32, Elf64 -- Use ofmt->maxbits
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:40 +03:00
Cyrill Gorcunov
e03bac6dbf out: Elf32 -- Add missing comment
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:40 +03:00
Cyrill Gorcunov
a65e0481c2 out: Elfx32, Elf32 -- Unify elf_add_reloc
Make offset being int64_t and use 0 for Elf32.
Thus it gonna be the same for all Elfs.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-04-24 20:02:40 +03:00
H. Peter Anvin
3ef4f00d5a lib: split library into stdlib and nasmlib; header handling fixes
Split lib/ into nasmlib/ (for nasm-specific functions) and stdlib/
(for replacements for C library functions which may be missing.)

Rename the ersatz inttypes.h to nasmint.h so we can use a simple test
in compiler.h instead of dealing with include path magic.

Remove tests in configure.in for ancient missing functions (which will
break the build anyway.)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-08 12:20:02 -08:00
H. Peter Anvin
2bc0ab38a2 Move version strings to a separate header
Move version strings to a separate header, instead of needing to
include nasm.h in places where it probably really doesn't belong.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-08 02:17:36 -08:00
H. Peter Anvin
1917f45ec2 Merge remote-tracking branch 'origin/nasm-2.12.xx'
Resolved Conflicts:
	output/codeview.c
	output/outelf32.c
	output/outelf64.c
	output/outelfx32.c
	output/outform.c
	output/outform.h
	output/outieee.c
	output/outobj.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-08 01:08:53 -08:00
H. Peter Anvin
283b3fb15a Defer debug format search until after command line parsing
Avoid funnies with ordering of debug format selection by deferring
debug format search until after command line processing.  Also permit
the -gformat syntax used by many C compilers.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-07 23:20:00 -08:00
H. Peter Anvin
477ae4419c ofmt: get rid of the debuginfo parameter to ofmt->cleanup()
Get rid of the completely pointless "debuginfo" parameter to
ofmt->cleanup().  Most backends completely ignore it, and the two that
care (obj, ieee) can simply test dfmt instead.

Also, dfmt is never NULL, so any test for a NULL dfmt is bogus.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-07 22:55:43 -08:00
H. Peter Anvin
c941a35e58 outelf*: remove null debug functions
Instead of duplicating empty functions, use the corresponding
null_debug_* functions.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-07 22:12:19 -08:00
H. Peter Anvin
bc42cbe363 codeview: remove hack for handling local labels
Now when labels are properly concatenated in common code, there is no
reason for the debugging backend to need to be aware of local
symbols.  We don't have to consider ..[^@] special symbols either, as
they are now filtered in labels.c.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Debugged-by: Jim Kukunas <james.t.kukunas@linux.intel.com>
2016-03-07 22:06:16 -08:00
H. Peter Anvin
3def9fcb59 outieee: no need to filter .. symbols in the debug format anymore
labels.c now filter ..[^@] special symbols from the debug backend,
so we don't have to open-code that everywhere.

In the actual output format, don't treat ..@ symbols as special.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Jim Kukunas <james.t.kukunas@linux.intel.com>
2016-03-07 22:04:54 -08:00
H. Peter Anvin
5686a65fe9 outobj: no need to filter .. symbols in the debug format anymore
labels.c now filter ..[^@] special symbols from the debug backend, so
we don't have to open-code that everywhere.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Jim Kukunas <james.t.kukunas@linux.intel.com>
2016-03-07 22:03:50 -08:00
Jim Kukunas
63c42f08f7 codeview: Don't treat labels starting with .. as local labels
For local labels, starting with '.', the label name is concatenated with
the previous non-local label to produce a label that can be accessed from
elsewhere. This is the name we want to generate debug info for.

Labels starting with ".." are special and shouldn't be concatenated.

Fix Bugzilla #3392342

Signed-off-by: Jim Kukunas <james.t.kukunas@linux.intel.com>
2016-03-07 19:36:41 -05:00
H. Peter Anvin
6224033738 Merge remote-tracking branch 'origin/nasm-2.12.xx'
Resolved Conflicts:
	.gitignore
	Makefile.in
	assemble.c
	configure.in
	eval.c
	float.c
	listing.c
	nasm.c
	nasmlib.c
	output/outform.h
	preproc.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-07 12:15:40 -08:00
H. Peter Anvin
335c4857ce Remove ofmt->current_dfmt indirection
Move ofmt->current_dfmt into a separate global variable.  This
should allow us to make ofmt readonly and removes some additional
gratuitious differences between backends.

From master branch checkin a7bc15dd0a

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-03-07 12:07:50 -08:00
H. Peter Anvin
0b7969e9a9 Merge branch 'nasm-2.12.xx'
Resolved Conflicts:
	compiler.h

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-07 11:50:38 -08:00
H. Peter Anvin
215186fe82 Get rid of a bunch of unnecessary indirections
We pass around a whole bunch of function pointers in arguments,
which then just get stashed in static variables.  Clean this mess
up and in particular handle the error management in the preprocessor
using nasm_set_verror() which already exists.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>

From master branch checkin 130736c0cf

Resolved Conflicts:
	nasm.c
	preproc-nop.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-03 15:22:03 -08:00
H. Peter Anvin
41087068aa Replace nasm_error(ERR_FATAL/ERR_PANIC) with nasm_fatal/nasm_panic
Replace all instances of ERR_FATAL or ERR_PANIC with nasm_fatal or
nasm_panic so the compiler knows that these functions cannot return,
*and* we trigger abort() if we were to ever violate that constraint.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-03 15:22:02 -08:00
H. Peter Anvin
c5b2de0964 codeview: be a bit more explicit about the nature of a panic
When we have to die due to an assertion violation, then show the
missing symbol.  Also, use nasm_panic() rather than nasm_assert() for
this purpose.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-03 14:15:41 -08:00
H. Peter Anvin
54469e27d0 outmacho: remove unused debugging functions
Remove unused debugging functions, and the _unused macro which turned
out to cause compilation problems on Linux/PowerPC.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-03 12:29:25 -08:00
H. Peter Anvin
53f1559c06 Remove unnecessary C99-isms
In order to make it more likely to compile cleanly with "C90 plus long
long" style compilers, remove existing constructs (mostly commas at
the end of enums) that aren't compliant.

Ironically enough this was most likely an unintentional omission in
C90...

From master branch checkin 7214d18b40

Resolved Conflicts:
	output/outelf32.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-02 10:48:53 -08:00
H. Peter Anvin
7214d18b40 Remove unnecessary C99-isms
In order to make it more likely to compile cleanly with "C90 plus long
long" style compilers, make gcc warn for incompatible constructs.
Remove existing constructs (mostly commas at the end of enums) that
aren't compliant.

Ironically enough this was most likely an unintentional omission in
C90...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-01 22:43:51 -08:00
H. Peter Anvin
b9c1ca7e8d Merge branch 'nasm-2.12.xx'
Resolved Conflicts:
	configure.in
	output/codeview.c

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-01 21:51:40 -08:00
Knut St. Osmundsen
52ae33a2cb Remove unnecessary C99 features which break Visual C++ 2010
Fixes Visual C++ 2010 breakage in recently added Codeview 8 code;
these are C99 features which were not necessary to introduce.

Signed-off-by: Knut St. Osmundsen <bird-nasm@anduin.net>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-02-26 23:44:10 -08:00
H. Peter Anvin
8aba13b51f Merge branch 'master' into elfmerge
Resolved Conflicts:
	output/outmacho.c

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-26 20:51:46 -08:00
H. Peter Anvin
ed8eb56546 outmacho: correctly handle references between sections
Correctly generate references between sections.  The previous
version would work correctly as long as all relative references
came from the first section, which is usually __TEXT,__text and
so it usually worked.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-23 00:13:49 -08:00
H. Peter Anvin
95b43676c3 Merge branch 'master' into elfmerge 2016-02-21 21:24:38 -08:00
H. Peter Anvin
a222d21138 outmacho: make a best effort at separating SIGNED from BRANCH relocs
For 64 bits, a BRANCH reloc is sometimes needed to fix up PIC
problems.  Make a best effort at generating BRANCH relocs just as
we make a best effort at distinguishing GOTLOAD from GOT.

This needs to be replaced with information from the assembler to
the backend.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-21 20:56:19 -08:00
H. Peter Anvin
28ec7d1ddf Merge branch 'master' into elfmerge
Resolved Conflicts:
	configure.in

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-18 13:57:03 -08:00
H. Peter Anvin
4afa730c03 outmacho: default section flags should depend on section name only
The __TEXT segment in particular contains both code and data.  The
most consistent thing is to look only at the section name, and have
the same behavior across sections.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-18 10:55:00 -08:00
H. Peter Anvin
2530a10b56 Make a few more data items static and const
A few more data items that should be static and const.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-18 02:28:15 -08:00
H. Peter Anvin
a4973cf997 A few more debugging format arrays to mark const
Making more debugging format array const.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-18 02:25:26 -08:00
H. Peter Anvin
2be1050f93 codeview: make struct dfmt df_cv8 const
This one was not declared const; fix that.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-18 02:22:50 -08:00
H. Peter Anvin
7e3b12d6da More constification, mostly of struct dfmt
Make struct dfmt and the struct dfmt arrays const across the board,
and make them static whereever possible.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-18 02:16:36 -08:00
H. Peter Anvin
f9be8c3179 outelf64: fix comment
Fix comment that refer to R_386_* to avoid hiding similarities
versus outelfx32.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-17 22:01:33 -08:00
H. Peter Anvin
e3e2f1bbc2 outelf64: symtabsection is defined but never set, change to sec_symtab
The variable symtabsection is defined but it is never actually set and
so was always zero.  For both the 32-bit output format this is
sec_symtab defined in elf.h.

If this is not correct for the 64-bit format, then we should define
sec_symtab as a variable instead of having a gratuitious format
difference.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-17 21:03:13 -08:00
H. Peter Anvin
338656c1de output: make all instances of struct ofmt readonly
With current_dfmt gone, we can make all instances of struct ofmt
const (read-only).

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-17 20:59:22 -08:00
H. Peter Anvin
a7bc15dd0a Remove ofmt->current_dfmt indirection
Move ofmt->current_dfmt into a separate global variable.  This
should allow us to make ofmt readonly and removes some additional
gratuitious differences between backends.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-17 20:55:08 -08:00
H. Peter Anvin
130736c0cf Get rid of a bunch of unnecessary indirections
We pass around a whole bunch of function pointers in arguments,
which then just get stashed in static variables.  Clean this mess
up and in particular handle the error management in the preprocessor
using nasm_set_verror() which already exists.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-17 20:27:41 -08:00
H. Peter Anvin
0e8fcf1b6c outelf*: remove type prefix from debugging functions
The debugging functions currently have unique prefix, which is good
for debuggability but hides real code differences.  Convert them to
have the same name across files.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-17 15:51:08 -08:00
H. Peter Anvin
86e31129f7 outelf32: remove unused header file
Remove unused instance of <limits.h>.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-17 14:44:19 -08:00
H. Peter Anvin
4b70bc2504 outelf32: move stabs32_linenum() so that it matches the other files
Move the function stabs32_linenum() so that it is in the same location
as in the other ELF backends; this eliminates a gratuitous difference.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-17 14:37:26 -08:00
H. Peter Anvin
43e0c3cf8d outmacho: make a copy of "fmt" instead of making it a pointer
Make a point of the output format constants instead of making it
a pointer.  The output format is set only once, but it is accessed
all the time.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-02-17 13:28:19 -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
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
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
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
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
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
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
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
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
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
Jim Kukunas
3115e789d6 coff: Add support for the Codeview 8 debug format
Codeview is a debug format for win32/win64 PE/COFF files. It adds two sections,
.debug$S (symbols) and .debug$T (types), to the generated object file. These
sections are then used by the linker to generate a PDB file which can be used
by various debuggers (WinDbg, Visual Studio, etc).

Signed-off-by: Jim Kukunas <james.t.kukunas@linux.intel.com>
Acked-by: H. Peter Anvin <hpa@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-01-24 14:14:39 +03:00
Cyrill Gorcunov
8aa9c2eb91 output: macho64 -- Fix OUT_REL4ADR on bigendians
We're converting address value into bigendian
(on BE machine) and then continue doing arithmetics
on top, which is of course incorrect.

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

Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-11-05 00:43:29 +03:00
Mark Scott
be8a5c8f2d out: elf,stabs -- Fix @n_value attribute for HdrSym entry
Each stabs entry is 12 bytes in size, for some reason we've
been pasing wrong attribute here in @n_value.

Signed-off-by: Mark Scott <nasm@mscott.cx>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-11-03 01:14:14 +03:00
Cyrill Gorcunov
94b4a2c819 output: aout -- Use nasm_x_space helpers
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-07-26 16:42:27 +03:00
Martin Storsjö
561242bd43 out: maco64 -- Properly update the full 64 bit value when adding relocations
Previously only the first byte was updated (since @mydata
is a an uint8_t[]).

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

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

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-07-19 14:24:32 +03:00
Cyrill Gorcunov
2e6297ff1b out: Zeroify temp buffer before use
This is a a buffer on stack big enough to hold
bigger object we might need (address, number and
etc) but it's defined as an array of bytes and
we treat it as different types depending on context,
which may lead to situation where data from stack
been treated as meaningful.

In particular in commit 5b730a197 we've fixed such
problem simply using a "big" write to zeroify stack
data before use.

Lets simply zeroify this buffer explicitly to escape
such problems in future.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-07-19 14:24:26 +03:00