Commit graph

681 commits

Author SHA1 Message Date
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
Delan Azabani
5b730a197a out: maco64 -- Fix erroneously small write for OUT_REL4ADR
Ensure that the int64_t offset value, which ultimately comes from an
int64_t value in gencode() (assemble.c:1906), is completely written to
the temporary buffer, instead of merely its least significant 32 bits.

Prior to this change, WRITELONG was used instead of WRITEDLONG, which
resulted in add_reloc being passed an int64_t "reloff" whose least
significant 32 bits were those from the aforementioned offset value,
and whose most significant 32 bits were stack garbage from "mydata".

This led to get_closest_section_symbol_by_offset() attempting to search
for extremely large values of "offset" among the symbols in "syms",
which meant that the last symbol with a matching section number would
always win the symbol search.

In effect, this clobbered the resultant relocation information, such
that all entries would be resolved with the same symbol.

Test output can be found here

https://www.azabani.com/patch/2/output.txt

This patch fixes

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

Signed-off-by: Delan Azabani <delan@azabani.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-06-02 13:22:32 +03:00
Cyrill Gorcunov
4920a03243 output: outmac64 -- Fix the case when first hit matches the symbol
In case if we're looking up for a symbol and it's first
one in symbol table we might endup with error because of
using GE here (78f477b35f) ending cycle with @nearest = NULL.

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

Reprted-by: Benjamin Randazzo <benjamin@linuxcrashing.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-05-09 18:07:47 +03:00
Ed Maste
1f0cb0f2c1 output: elf64 -- increase .symtab and .rel* alignment to 8
Discovered while working on ELF Tool Chain elfcopy (strip),
which originally crashed on an assert while processing
a nasm-generated ELF object.

The .symtab and .rela.text sections report 4 byte alignment,
but require 8.

As an aside, see https://sourceforge.net/p/elftoolchain/tickets/485/ for a
discussion of the ELF Tool Chain issue that this bug exposed.

With my WIP elfcopy change and nasm-assembled jccolss2-64.o from libjpeg-turbo:

% strip -o /dev/null --strip-debug jccolss2-64.o
strip: section .symtab alignment 4 increased to 8
strip: section .rela.text alignment 4 increased to 8

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

Signed-off-by: Ed Maste <emaste@freebsd.org>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-04-16 01:02:55 +03:00
Cyrill Gorcunov
775153b1bf output: dbg,aout,elf32 -- Fix out for signed relocations
@size might be negative for signed relocations but its length
is abs value. This is rather a fix for future use because at
moment we can't hit this problems but better be on a safe side.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-02-21 21:14:28 +03:00
Cyrill Gorcunov
d72bec12bc output: bin -- Fix section length miscalc for OUT_ADDRESS
While we using proper @asize variable for relocation itself
we miss the fact that @size variable (which might be negative
for signed relocations since fd52c277dd) is used to calculate
section size increment.

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

Reported-by: Ben de Waal <ben@dewaals.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-02-15 18:18:57 +03:00
Cyrill Gorcunov
d4923fc6a2 output: maco 64 -- Fix data conversion
Looks like were a typo in first place

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

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-01-11 17:21:46 +03:00
Cyrill Gorcunov
78f477b35f output: maco 64 -- Fix get_closest_section_symbol_by_offset
- fixup comparision it should be GE
 - make sure we never return nil here

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2015-01-11 17:19:34 +03:00
H. Peter Anvin
d4184a0e0f Add missing static declarations in output/outobj.c
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-11-25 12:14:52 -08:00
H. Peter Anvin
895ac7e53f Add missing static declaration in output/outdbg.c
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-11-25 12:14:52 -08:00
H. Peter Anvin
443b8e9b5f Add missing static declaration in output/outieee.c
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-11-25 12:14:52 -08:00
H. Peter Anvin
aa433d738c Add missing static declaration in output/outcoff.c
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-11-25 12:14:52 -08:00
H. Peter Anvin
c0c67c67c8 Add missing header file in output/nulldbg.c
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2014-11-25 12:14:52 -08:00
H. Peter Anvin
e76a626055 Replace unchecked fwrite() calls
Instead of having unchecked fwrite() calls, introduce nasm_write()
which does error checking (and fatal errors if the write fails).

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-10-21 12:50:47 -07:00
Cyrill Gorcunov
8a076f4260 output: elf -- Use common elf_ structures
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-09-21 13:05:03 +04:00
Cyrill Gorcunov
c24568b0b0 output: elf -- Move common structures into outelf.h header
All Elf formats we're supporting at the moment have
are using same structures, move them into a header
and name then with elf_ prefix.

This makes a few fields to carry 64 bit integers while
in former Elf32|x formats they can be 32 bit wide, but
I think it's acceptable tradeoff.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-09-21 13:03:26 +04:00
Cyrill Gorcunov
500dd5461c output: elf -- Move elf_directive into single instance
For all Elf32/32x/64 this routine is the same. So lets
merge it into one instance.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-08-29 20:30:57 +04:00
Cyrill Gorcunov
9b76c802ae output: elf -- Rename section_attrib to elf_section_attrib
Global section_attrib name is too general.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-08-29 20:24:24 +04:00
Cyrill Gorcunov
6ebe3bcd2e output: outbin -- Fix relocation size
In commit fd52c277dd
we've started handling negative address relocations
but support Elf format only and got a typo in bin
format which leaded to endless cycle of applying
relocation due to negative argument (make test
hangs).

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-06-28 22:31:06 +04:00
H. Peter Anvin
49de44e56d Merge remote-tracking branch 'origin/signrel' 2014-05-09 15:09:43 -07:00
H. Peter Anvin
0ace62cb6a outelf: Error out on "section align" without value
If someone specifies "section align" without =value, error out.

Reported-by: Ilya Albrekht <ilya.albrekht@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2014-02-18 13:30:44 -08:00
Cyrill Gorcunov
d0293d3392 BR3392274: output: Elf -- Don't crash on erronious syntax
Elf align section attribute requires syntax "align=value",
but in case if '=' is missed we pass nil pointer into
atoi function which cause libc to crash.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2014-02-15 18:40:12 +04:00
H. Peter Anvin
fd52c277dd output: Allow OUT_ADDRESS with a negative size to mean signed relocation
This only matters for ELF64/ELFx32, at least for now.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2013-11-26 18:12:39 -08:00
Marat Dukhan
29227125f0 coff: Better handling of section redefinition
Currently, if we try to define an already defined section and specify
section flags, NASM will output "warning: section attributes ignored
on redeclaration of section %SECTIONNAME%".

The patch modifies this behaviour:

1. If the previous section definition differs only in alignment flags,
   no warning is generated

2. If the new definition implies larger alignment, it overrides the
   previous section alignment

3. If the new definition specifies any section alignment, the content of
   the section will be aligned on the new boundary (i.e. the effect is the
   same as if there was ALIGN macro)

Signed-off-by: Marat Dukhan <maratek@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-10-03 16:55:50 +04:00
Marat Dukhan
91c43d789a coff: Support for section names longer than 8 bytes
http://bugzilla.nasm.us/show_bug.cgi?id=3392233

Signed-off-by: Marat Dukhan <maratek@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-09-21 13:09:03 +04:00
Philipp Kloke
91a2f99346 Fixed wrong format specifier in format string
Signed-off-by: Philipp Kloke <philipp.kloke@web.de>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-04-01 02:11:51 +04:00
Philipp Kloke
c51a224ceb Remove unnecessary calls to memset
The C standard guarantees that strncpy pads
the string with zeros if source string is smaller
than destination buffer.

Signed-off-by: Philipp Kloke <philipp.kloke@web.de>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-04-01 02:11:01 +04:00
Andrew Nayenko
57162eb084 Fix warnings generated by clang 3.0
Fix warnings like this:

output/outelf32.c:2120:33: warning: equality comparison with extraneous
      parentheses [-Wparentheses-equality]
            if ((match->section == index)) {
                 ~~~~~~~~~~~~~~~^~~~~~~~
output/outelf32.c:2120:33: note: remove extraneous parentheses around the
      comparison to silence this warning
            if ((match->section == index)) {
                ~               ^       ~
output/outelf32.c:2120:33: note: use '=' to turn this equality comparison into
      an assignment
            if ((match->section == index)) {
                                ^~
                                =
1 warning generated.

Signed-off-by: Andrew Nayenko <resver@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2013-02-25 01:08:00 +04:00
Keith Kanios
0863bc386b BR3392232: Fix relocations in MachO64
Signed-off-by: Keith Kanios <keith@kanios.net>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2012-11-28 20:05:20 +04:00
Cyrill Gorcunov
5fa17e8398 output: Add more Elf unification
One day the elf output routines would be abstracted
enough to be merged in one file. This patch simply
removes some differences from elf32/64 code.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2012-11-16 22:57:07 +04:00
Cyrill Gorcunov
7ce86b500c BR3392231: Fix get_closest_section_symbol_by_offset
This patch changes get_closest_section_symbol_by_offset
logic to lookup only the closest symbols which are at
or before the supplied offset.

Signed-off-by: Keith Kanios <keith@kanios.net>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2012-11-06 00:47:20 +04:00
H.J. Lu
04633d07b6 backend: add support for x32 ELF
Add an x32 ELF (32-bit code with the CPU in 64-bit mode) backend.
2012-02-03 12:08:59 -08:00
Cyrill Gorcunov
7add67f949 elf64: Make linelist to look the same as elf32
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-08-28 17:07:26 +04:00
Cyrill Gorcunov
5a8944af59 elf32: Drop holes in linelist structure
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-08-28 17:05:17 +04:00
Cyrill Gorcunov
e07bd499f8 outobj: Reorder Segment members to eliminate holes
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-08-28 17:03:21 +04:00
Cyrill Gorcunov
a30090b7e5 outieee: Reorder ieeeSection members to eliminate holes
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-08-28 17:00:04 +04:00
Cyrill Gorcunov
32af9d75f3 elf64: Drop unused 'zero' variable
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-07-17 14:04:44 +04:00
Keith Kanios
8052664433 BR3282788: Fix 64-bit Mach-O bug that crashes NASM due to NULL symbols 2011-04-11 21:38:50 -05:00
Cyrill Gorcunov
a4f98b3aab Merge branch 'nasm-2.09.xx'
Conflicts:
	nasm.h
	version

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-04-06 19:12:17 +04:00
Cyrill Gorcunov
c1936da942 ofmt: Alias shortname must be used for __OUTPUT_FORMAT__ macro
__OUTPUT_FORMAT__ must consist of shortname of output format
or its alias, otherwise userspace ABI gets broken.

For example source code still can refer to __OUTPUT_FORMAT__=elf,
instead of __OUTPUT_FORMAT__=elf32.

BR3246990

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-04-06 18:32:15 +04:00
Keith Kanios
e3f4780665 output/outbin.c: initialize section align/start attributes upon creation 2011-02-28 09:49:04 +03:00
Cyrill Gorcunov
befc631d04 elf64: Use nasm_zalloc helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-02-28 09:45:43 +03:00
Cyrill Gorcunov
efc249d8fc outelf32: Use nasm_zalloc helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-02-28 09:40:43 +03:00
Cyrill Gorcunov
b4af1ac765 outcoff: Use nasm_zalloc helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-02-28 09:33:08 +03:00
Cyrill Gorcunov
c13deef255 bin: Use nasm_zalloc for default section creation
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-02-28 09:28:25 +03:00
Cyrill Gorcunov
3bc3ff2fb6 bin: Use nasm_zalloc helper for section allocation in a sake of simplicity
Instead of opencoded zero assignments better to use nasm_zalloc
and set fields which are supposed to be non-nil. This simplifies
code and makes it more readable.

Also note the field 'ifollows' renamed to 'prev' as it should
be from the very beginning in terms of lists.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2011-02-28 01:26:24 +03:00
Keith Kanios
11db774a15 output/outbin.c: initialize section align/start attributes upon creation 2011-02-27 13:14:32 -06:00
Cyrill Gorcunov
cb9a459560 coff: Handle massive relocations
The backport of

4db724fdd7
359b63f897
01102ee8e6
2672af7379

so coff output target to be able to handle
massive relocations.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-11-20 14:18:23 +03:00
Cyrill Gorcunov
2672af7379 coff: Cover 'else' with cond compilation
It was a nit in first place.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-11-07 01:09:36 +03:00
Cyrill Gorcunov
01102ee8e6 coff: Handle massive relocations
In case if relocations number exceed 16bit values
we have to hande such case by a special way, as described
in COFF specification.

 "IMAGE_SCN_LNK_NRELOC_OVFL indicates that the count of
relocations for the section exceeds the 16 bits that are
reserved for it in the section header. If the bit is set
and the NumberOfRelocations field in the section header
is 0xffff, the actual relocation count is stored in the
32-bit VirtualAddress field of the first relocation. It
is an error if IMAGE_SCN_LNK_NRELOC_OVFL is set and
there are fewer than 0xffff relocations in the section."

[ BR3092924 ]

Reported-by: Robert Yates
Investigated-by: nasm64developer
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-11-06 18:38:00 +03:00
Cyrill Gorcunov
359b63f897 coff: Issue fatal signal on relocations more then 0xffff
Actually it's temporary action. We have to support more
relocations then that but it requires some more code rework.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-11-06 02:45:45 +03:00
Cyrill Gorcunov
4db724fdd7 coff: Add IMAGE_SCN_MAX_RELOC constant
We will need it to analyze if section relocations
are overflowed.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-11-05 13:50:04 +03:00
Cyrill Gorcunov
2c157002f2 BR3079550: NASM crash on run-time for OMF output format
We could have accessed malloc'ed data on external symbols
in obj and ieee output formats. Fix it by using nasm_zalloc.

Reported-by: Jiri Malak
Patch-by: Jiri Malak
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-10-27 21:41:11 +04:00
Cyrill Gorcunov
9e8f0ac460 BR3079550: NASM crash on run-time for OMF output format
We could have accessed malloc'ed data on external symbols
in obj and ieee output formats. Fix it by using nasm_zalloc.

Reported-by: Jiri Malak
Patch-by: Jiri Malak
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-10-02 01:21:00 +04:00
Cyrill Gorcunov
d7b654c73d elf: Move stabs symbol table format into outelf.h
Get rid of code duplication

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-30 00:51:44 +04:00
Cyrill Gorcunov
4cc1064328 outbin: Cleanup bin_cleanup
No need for 'q' variable.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-06 19:40:02 +04:00
Cyrill Gorcunov
faf23d1302 outbin: Simplify reverse address computing
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-06 19:08:28 +04:00
Cyrill Gorcunov
2b416c9def BR3025702: outbin -- Fix byte ordering
In commit 55ae12052c we occasionally broke byte ordering. Fix it.
Note that current stable version 2.08.01 is not affected by this bug.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-07-06 18:33:29 +04:00
H. Peter Anvin
5e2e8b9105 Rename filenames to 8.3 format
Apparently some people still care about compiling native on MS-DOS,
and we don't have a significant number of files which need adjustment.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-06-15 10:47:16 -07:00
H. Peter Anvin
b714cb27cb outobj: handle compilers without 64-bit switch() support
OpenWatcom, in particular, doesn't handle switch() statements with
64-bit expressions, sigh.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-06-07 11:34:28 -07:00
H. Peter Anvin
4dff757ba5 outelf32: handle compilers without 64-bit switch() support
OpenWatcom, in particular, doesn't handle switch() statements with
64-bit expressions, sigh.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-06-07 11:26:11 -07:00
Cyrill Gorcunov
a731924978 nasmlib: Rename elements() macro to ARRAY_SIZE
ARRAY_SIZE is a well known name pointing out that
we're dealing with array in macro argument.

Also to be on a safe side prefix_name helper should
check the index been in bounds more precisely.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-06-03 23:17:21 +04:00
H. Peter Anvin
62de275527 outobj: update error message
The possible sizes we can encounter are 1, 2, 4, 8... make sure we get
a proper error message.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-05-06 17:58:46 -07:00
H. Peter Anvin
931ce775cf outobj: properly error on unsupported relocations
Error out on any relocations not supported by the backend.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-05-06 17:52:57 -07:00
H. Peter Anvin
bce369022a outelf64: update copyright date
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-05-06 17:45:39 -07:00
H. Peter Anvin
32575e46ac ELF support for 8-bit relocations
Support 8-bit relocations (OUT_ADDRESS and OUT_REL1ADR) in ELF.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-05-06 16:14:00 -07:00
H. Peter Anvin
55ae12052c Add support for one-byte relocations
Add OUT_REL1ADR (one-byte relative address) and support for
OUT_ADDRESs with size == 1.  Add support for it in
outbin and outdbg.  *It still needs to be added to other backends*,
both the OUT_REL*ADR and OUT_ADDRESS codepaths need to be handled.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-05-06 15:33:24 -07:00
Cyrill Gorcunov
97ec06a16a MachO: Fix misprinted macho_sectalign
macho_sectalign was occasionally misprinted
with macho_setcalign, fix it. No change on functionality.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-28 23:17:13 +04:00
Cyrill Gorcunov
a20b668add obj: Implement sectalign helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-25 22:00:15 +04:00
Cyrill Gorcunov
573d25fe92 macho: Implement sectalign handler
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-25 21:35:09 +04:00
Cyrill Gorcunov
9868bfe80f ieee: Fix section index match in sectalign handler
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-25 17:55:52 +04:00
Cyrill Gorcunov
b9fd67b38e outieee: Implement sectalign handler
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-25 01:17:11 +04:00
Cyrill Gorcunov
bb196d4fd3 outbin: Drop current_section variable
There is no need for it anymore.

Reported-by: "H. Peter Anvin" <hpa@linux.intel.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-22 22:32:17 +04:00
Cyrill Gorcunov
4c45e83aac outbin: Prune ancient format_mode variable
format_mode is always set to 1 so there is no need to
keep this variable. "Old chicken bit" (c) :)

Reported-by: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-22 22:25:55 +04:00
Cyrill Gorcunov
630f221b01 bin: Implement sectalign handler
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-22 19:06:29 +04:00
Cyrill Gorcunov
279d8f146a coff: Use IMAGE_SCN_ALIGN_MASK macro
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-22 19:06:14 +04:00
Cyrill Gorcunov
3834305507 coff: Allow alignment greater then 64 bytes on win
On win32/64 we have no 64 bytes limit so hit it on
"coff" target only.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-22 19:06:03 +04:00
Cyrill Gorcunov
7c8c258cdd coff: Fix section alignment computation
Section alignment is broken due to not being
direct "align -> power of two set" mapping but
rather including second addition operation.

Fix it by introducing coff_sectalign_flags helper.
This also allow us to use this helper for getting
rid of open coded computation as well.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-22 19:05:50 +04:00
Cyrill Gorcunov
42017a6115 coff: Use predefined macros instead of numbers and style fix
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-22 19:03:56 +04:00
Cyrill Gorcunov
557a57bd55 pecoff.h: Complete header
Put in all constants pecoff v8 states. Most probably we
will never need most of them but lets have them here for
completeness.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-22 19:02:22 +04:00
H. Peter Anvin
35c30da61b Remove open-coded ilog2() implementations
When we need integer log2, use the new library routine.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2010-04-21 16:46:57 -07:00
Cyrill Gorcunov
83ffe8ca24 coff: Use predefined macro in common section flags
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 22:40:11 +04:00
Cyrill Gorcunov
d0c6dbe0fe coff: Use predefined macro and eliminate open coded constants
Not all are covered but process initiated.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 22:03:33 +04:00
Cyrill Gorcunov
d71d876f46 pecoff.h: Add more constants
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 21:47:03 +04:00
Cyrill Gorcunov
2ece71588c pecoff: Update machine types
Update up to pecoff v8

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 18:46:27 +04:00
Cyrill Gorcunov
8906629f4f output: Introduce pecoff.h
Better to have common constants grouped.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 18:10:04 +04:00
Cyrill Gorcunov
f8dc028c07 coff: Implement sectalign handler
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 18:10:00 +04:00
Cyrill Gorcunov
2ef5c27be7 Rename SEGALIGN to SECTALIGN
"sectalign" is preferred over "segalign"
since it operates over section attributes.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 18:09:54 +04:00
Cyrill Gorcunov
c56a7a2c82 Elf64: Implement segalign handler
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 01:15:28 +04:00
Cyrill Gorcunov
f68feb08c2 Elf-32: Implement segalign handling
Via elf_segalign helper

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 01:09:02 +04:00
Cyrill Gorcunov
2a587ab1c9 ofmt: Implement null_segalign stubs
Set stubs for all targets

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 01:08:36 +04:00
Cyrill Gorcunov
d807d911fe Elf: Rename SEG_ALIGN to SEC_FILEALIGN
It's Elf specifics. To not mess with segment alignment.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 01:06:44 +04:00
Cyrill Gorcunov
8d4d060104 Add "win" alias for "win32" output format
We already have "elf" and "macho" aliases for respective
32 bit output formats. Make the same for "win32" in a
sake of consistency.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-21 01:06:36 +04:00
Cyrill Gorcunov
ba3c0513dd Elf: switch section_attrib to a new nasm_opt_val interface
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-11 13:12:20 +04:00
Cyrill Gorcunov
c084467eba Elf: Use SHA_ANY constant instead of open coded number
SHA_ANY is not part of Elf specification but rather our own symbolic
definition for convenience.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-11 12:58:05 +04:00
Cyrill Gorcunov
6837749d85 ofmt: Introduce output format aliases
This allow us to keep compatibility layer without
needing the separated struct ofmt for this and
elf_init_hack routine.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-10 00:11:00 +04:00
Cyrill Gorcunov
f134cc63da Elf: Some unification snippets for 32/64 bit versions
Nothing serious, comments and style movements.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-10 00:10:38 +04:00
Cyrill Gorcunov
e3c4791300 Elf: Merge WRITE_STAB to outelf.h
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-10 00:10:20 +04:00
Cyrill Gorcunov
6620d1aa6d Elf: Drop never used SOC helper
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-10 00:10:07 +04:00
Cyrill Gorcunov
572dd0021c Elf: Introduce section_attrib helper
In a sake of removing code duplication.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-04-10 00:02:38 +04:00
Cyrill Gorcunov
6fe313a719 output/outbin.c: Fix misprinted alignment bound
Due to a misprint in commit
9b66d8e4c3

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2010-02-11 21:49:58 +03:00