Commit graph

451 commits

Author SHA1 Message Date
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