Commit graph

3106 commits

Author SHA1 Message Date
Jim Kukunas
65a8afcaba preproc: for include files, include correct path in filename
The codeview backend needs to be able to open each source file passed in
so that it can calculate its checksum. In order to take into account
include paths, this patch updates the filename to include the path where
the file was found.

Signed-off-by: Jim Kukunas <james.t.kukunas@linux.intel.com>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>

[ hpa: resolved one conflict in preproc.c ]
2016-06-16 15:07:32 -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
H. Peter Anvin
5e0eb0c08b NASM 2.12.02rc7 2016-06-03 23:57:10 -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
9f9ba28043 NASM 2.12.02rc6 2016-05-25 03:11:02 -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
8794350751 NASM 2.12.02rc5 2016-05-24 23:06:11 -07:00
H. Peter Anvin
aa958b1ab6 ifunc.mac: the ilog2 warning may want to be both ceil and floor
There is no reason why the warning-generating ilog2 has to be only the
floor variant.  However, I am pretty sure we can simply implement the
ilog2cw() as a macro only; we can always fix that if that turns out to
be incorrect.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-24 23:03:17 -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
c9fd7b2aa5 configure: correctly discover -W options for clang
clang doesn't error out on unknown -W options unless
-Werror=unknown-warning-option is specified first, so do that so the
configure script can do its job.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-05-16 21:35:48 -07:00
H. Peter Anvin
acbf8f0e19 doc: remove obsolete references
We don't use comp.lang.asm.x86 or freshmeat for announements anymore.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-16 20:39:04 -07:00
H. Peter Anvin
407166001c Fix building in a separate directory from the source code
The code to handle building in a separate directory had seriously
bitrotted.  This contains a number of fixes to make it possible,
including bits like the documentation which never worked in the past.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-16 20:30:09 -07:00
H. Peter Anvin
b06736ae7e Unbreak building in a separate object directory
Fix bitrot in building in a separate object directory.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-16 13:20:01 -07:00
H. Peter Anvin
cba1aca466 autogen.sh: remove configure-generated files
Remove files generated by configure when running autogen.sh.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-16 13:05:04 -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
Cyrill Gorcunov
771d04e263 preproc: Don't dereference nil @istk
If not input was specified istk = NULL, so don't dereference it.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-05-10 23:27:03 +03:00
H. Peter Anvin
acb48602fc srcfile.c: remove unnecessary #include's
Remove #include's inherited from nasmlib.c which aren't needed in this
file.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-10 09:01:10 -07:00
H. Peter Anvin
cfbdc3c6fa NASM 2.12.02rc4 2016-05-10 03:12:28 -07:00
H. Peter Anvin
02f49f2c1e stdscan: put some error message strings in quotes
Put some error message strings inside `...' quotes to match existing
usage.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-05-10 03:08:09 -07:00
H. Peter Anvin
274cda81f8 Use a hash to keep exactly one copy of each filename around
The old code for keeping track of source file name and line was
confused as hell about ownership of the strings, and it is pretty
clear we leaked that information all over the place.

Instead, use a hash table to keep a copy of each string as necessary,
and simply make references to a string pool that we keep until the end
of the assembly session.

This pool probably should be unified with the list of dependency
files, and so on, but that is for the development branch.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-05-10 03:01:58 -07:00
H. Peter Anvin
b157701b17 quote: make the input argument to nasm_quote() const
Whereas nasm_unquote() unquotes the argument in place, nasm_quote()
has to allocate a new string (since the new string will *always* be
longer than the old string!)  Make the old string const since we're
making a copy anyway.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-05-10 02:59:04 -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
31c97fb89e NASM 2.12.02rc3 2016-05-09 14:37:39 -07:00
H. Peter Anvin
77511e32a7 doc: document warning improvements
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-09 14:36:59 -07:00
H. Peter Anvin
f43aedac23 .gitignore: add .s and .i files
.s and .i files can be generated during debugging.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-09 14:14:11 -07:00
H. Peter Anvin
3736895c07 Fix and clean up listing of macro expansion
Fix the printing of the macro stack: we need to follow the
mstk->next_active list, not mstk->next, and we need to reverse the
order so that the highest-level inclusion comes first.

Since this should be a rare or at least performance-insensitive
operation, do it using simple function recursion.

Finally, add an ellipsis before the "from macro" message; it greatly
enhances readability.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-09 14:10:32 -07:00
H. Peter Anvin
4def1a8db4 Show the expanded macro stack when displaying diagnostics
It can be hard to find errors inside potentially nested macros.
Show the mmacro expansion stack when printing diagnostics.
Note that a list file doesn't help for errors that are detected
before the code-generation pass.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-09 13:59:44 -07:00
H. Peter Anvin
b4f734fb84 Ignore unrecognized warning names
If we get an invalid warning name passed to the -w/-W option or the
[warning] directive, ignore it.  This may be a warning name enabled in
a future version of NASM, and it is rather pointless to error out on
it.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-09 12:13:08 -07:00
H. Peter Anvin
19bc9de9d0 doc/changes.src: document PTR warning
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-09 12:09:04 -07:00
H. Peter Anvin
69550eac55 Specifically if we encounter the PTR keyword
Issue a specific suppressible warning if we encounter the PTR keyword.
This usually indicates someone mistakenly using MASM syntax in NASM.

This introduces a generic infrastructure for issuing warnings for such
keywords.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-09 12:05:56 -07:00
H. Peter Anvin
934f0478d4 Fix the handling of pass1 warnings, display control option for warnings
Fix pass1 warnings so they actually display.

When issuing suppressible warnings, display the option that controls
them, as gcc has been doing for a while.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-09 12:00:19 -07: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
H. Peter Anvin
3c27bdcaee NASM 2.12.02rc2 2016-05-09 11:21:04 -07:00
H. Peter Anvin
ff7ff12b1c changes.src: update as of the current time
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-05-09 11:19:58 -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
H. Peter Anvin
ccb16787d5 NASM 2.12.02rc1 2016-04-05 13:25:50 -07:00
H. Peter Anvin
8494cc82c5 changes.src: document %if error fix
Document the fix for errors inside live %if branches.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-04-05 13:06:14 -07:00
H. Peter Anvin
eb6653f9e4 preproc: correct the logic in the suppression of preproc errors
The logic for suppressing preprocessor errors was missing an !, which
was present before checkin 215186fe82.

Reported-by: Knut St. Osmundsen <bird-nasm@anduin.net>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-04-05 13:03:10 -07:00
H. Peter Anvin
d2238e2286 changes.src: fix old typo
arror -> error

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-04-05 12:49:07 -07:00
Cyrill Gorcunov
138e3f6699 insns.dat: Bring back rax for 64 bit mode of MONITORX
Previously in d3be338017 i ripped off @rax but this
is due to misinterpretation of

https://sourceware.org/ml/binutils/2015-06/msg00041/mwaitx.patch

so move it back.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-03-27 13:19:13 +03:00
Cyrill Gorcunov
d3be338017 insns.dat: Fix monitorx instruction
It accepts rax|ax registers instead of rax.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-03-27 13:06:58 +03:00
Cyrill Gorcunov
b7636a8a56 insns.dat: Allow MONITORX, MWAITX and CLZERO in 32bit mode as well
Reported-by: Paul Blinzer <apblinzer@gmail.com>
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-03-23 00:07:55 +03:00
H. Peter Anvin
86d4acea57 NASM 2.12.01 2016-03-17 17:15:36 -07:00
H. Peter Anvin
4bef68a84e msvc.mak: /Ox and /Oy are redundant with /O2
Per the MSVC++ docs, /Ox and /Oy are redundant with /O2, and the docs
recommend that they do not be used together.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-08 00:50:13 -08:00
H. Peter Anvin
134874848c nasmdoc.src: remove unimplemented %comment directive
%comment..%endcomment were never implemented, remove from the
documentation.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-07 23:58:11 -08:00
H. Peter Anvin
8da30d0266 Makefiles: run "make alldeps"
Automatic update of dependencies.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2016-03-07 23:23:19 -08:00