0
0
mirror of https://github.com/netwide-assembler/nasm.git synced 2025-07-24 10:25:42 -04:00

182 Commits

Author SHA1 Message Date
H. Peter Anvin (Intel)
cc843efa38 Merge tag 'nasm-2.15.04'
NASM 2.15.04

Conflicts:
	asm/listing.h
	asm/pptok.pl
	asm/preproc.c
	version

This doesn't pass travis test 3392711, which is using an extremely odd
construct of %?? in the middle of an argument sequence for an smacro
while not being in a macro itself, and expecting it to expand to the
macro name. This seems to *really* confuse the master branch.

Resolve this later...
2020-08-25 16:16:09 -07:00
H. Peter Anvin (Intel)
1227a5d7fb Merge remote-tracking branch 'github/master'
Resolved Conflicts:
	asm/preproc.c

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-08-25 15:56:05 -07:00
H. Peter Anvin (Intel)
16ab7aed21 debug: feed single-line macro definitions and include hierachy to dfmt
At least DWARF can encode C-style macros. In doing so, it wants the
file include hierarchy, so give the debug format backend the option of
receiving that information from the preprocessor.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-08-25 15:52:05 -07:00
Cyrill Gorcunov
7c88289e22 BR3392711: preproc: fix memory corruption in expand_one_smacro
The mempcpy helper returns *last* byte pointer thus when
we call set_text_free we have to pass a pointer to the
start of the string.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-08-18 11:27:03 +03:00
Cyrill Gorcunov
8806c3ca00 BR3392712: pp_tokline: fix double free
Make sure the data being freed get double
freed after -- the pointers must be zapped
(actually nasm_free and free_tlist support
being called with NULL pointer as an argument).

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-08-17 21:30:14 +03:00
H. Peter Anvin (Intel)
6299a3114c BR 3392708: fix NULL pointer reference for invalid %stacksize
After issuing an error message for a missing %stacksize argument, need
to quit rather than continuing to try to access the pointer.

Fold uses of tok_text() while we are at it.

Reported-by: Suhwan <prada960808@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-30 15:57:57 -07:00
H. Peter Anvin
6263a2a4c2 preproc: add %*? and %*??
The %? and %?? tokens are ambiguous when used inside a multi-line
macro. Add tokens %*? and %*?? that only expand during single-macro
expansion.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-18 13:47:59 -07:00
H. Peter Anvin
d6b8c53b8c Merge tag 'nasm-2.15.03'
NASM 2.15.03

Resolved Conflicts:
	asm/preproc.c

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-17 17:58:38 -07:00
H. Peter Anvin
e830e92b77 preproc: when printing errors, don't descent into unlisted macros
If macros are nolisted, *or* they don't have any filename associated
with them, it is absolutely pointless to try to descend into them for
error messages, so just don't, even if -Lb is provided.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2020-07-16 22:50:33 -07:00
H. Peter Anvin (Intel)
4c0bd9e736 preproc: BR 2292698: fix handling of whitespace around %+
The previous code to fix whitespace around and multiple %+ symbols in
a row (checkin 122c5fb75986adc37dfb147cc2a613e3ebc66e80) had some
seriously broken pointer handling when zapping tokens. This could
cause paste_tokens() to go into an infinite loop because it would
attach %+ to another token and then immediately break them apart
again, over and over.

Reported-by: <alexfru@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-15 16:16:57 -07:00
H. Peter Anvin (Intel)
64c7c763c2 Change dfmt->debug_macros to dfmt->debug_mmacros
... in preparation for adding dfmt->debug_smacros.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-14 12:05:03 -07:00
H. Peter Anvin (Intel)
ecd4ea94b6 preproc, doc: change a few remaining TOK_ -> TOKEN_ in comments only
A handful of comments still had TOK_ instead of TOKEN_.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-14 11:51:35 -07:00
H. Peter Anvin (Intel)
20e0d616dc preproc: unify token codes between the preprocessor and assembler
The different token codes between the preprocessor and the assembler
is a completely unnecessary headache. Furthermore, lumping all the
operators under TOK_OTHER in the preprocessor causes a whole bunch of
unnecessary headaches.

In combining them, the only tricky part is that PP_CONCAT_MASK() is no
longer usable, as the range of token codes is too large. Replace with
dedicated category masks.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-14 11:50:55 -07:00
H. Peter Anvin (Intel)
1d151a8558 preproc: when parsing a # marker, use C-style string unquoting
To handle escape codes in filename strings after # markers correctly,
we need nasm_unquote() to be aware that it is using C escapes;
otherwise things like "foo`bar" will break.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-13 14:14:28 -07:00
Cyrill Gorcunov
4c3798b7e6 BR 3392696: nasm_quote -- fixup callers
In 41e9682efed7cd1df133b1b4ac806e07723f1486 we've
changed the nasm_quote arguments still not all callers
were converted which could lead to nil dereference.

[hpa: no need to call strlen() for the asm/preproc.c chunk]

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2020-07-12 06:06:02 -07:00
H. Peter Anvin
6a9d1e56c6 Revert "BR 3392696: nasm_quote -- fixup callers"
This reverts commit 6c300aa4882bc1662df899501f23ff5a93a3547f.

Will apply a modified version from the nasm-2.15.xx branch instead.
2020-07-12 06:04:48 -07:00
H. Peter Anvin
d831915543 preproc: add %is...() function-like macros
Add the first "preprocessor functions". These are simply "magic"
single-line macros with a suitable expansion function. The first
application is functions equal to the %if directives, e.g.
%ifdef blah == %if %isdef(blah) except can be used anywhere (not just
in %if statements like defined() in C.)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2020-07-12 06:03:58 -07:00
Cyrill Gorcunov
65c6ba8716 BR 3392696: nasm_quote -- fixup callers
In 41e9682efed7cd1df133b1b4ac806e07723f1486 we've
changed the nasm_quote arguments still not all callers
were converted which could lead to nil dereference.

[hpa: no need to call strlen() for the asm/preproc.c chunk]

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2020-07-12 06:00:51 -07:00
Cyrill Gorcunov
6c300aa488 BR 3392696: nasm_quote -- fixup callers
In 41e9682efed7cd1df133b1b4ac806e07723f1486 we've
changed the nasm_quote arguments still not all callers
were converted which could lead to nil dereference.

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2020-07-11 19:18:30 +03:00
H. Peter Anvin (Intel)
10c9aa37a4 preproc: drop preproc_ops
There is only one preprocessor now, so drop the indirection through
preproc_ops.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-10 19:26:44 -07:00
H. Peter Anvin (Intel)
d9ea17fb47 preproc: saner handling of cpp-style line directives
NASM now supports a proper superset of cpp line number markers, so
there is no need to hack around them using the
"prepreprocessor". Instead, just put a quick test in do_directive()
treating it just like %line, except convert a "-quoted string into a
`-quoted string.

(This can break if there is a ` or \" sequence in the string... fix
that at some point. This is still much better than what there is now.)

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-10 18:44:15 -07:00
H. Peter Anvin (Intel)
fcd3cb8861 preproc: preserve %[...] in listings
When generating list output, preserve %[...] in the output if we list
a TOK_INDIRECT. The tokenization process removes these deliminators,
so we have to explicitly put them back.

This doesn't affect assembly output, which will only ever be generated
after all TOK_INDIRECT tokens have been removed, but it does affect
some of the listing modes.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-10 17:22:47 -07:00
H. Peter Anvin (Intel)
a79a700208 preproc: add a %null directive for the masm macro package
Instead of %pragma ignore, use a new %null directive which ignores the
rest of the line, without bothering to expand it.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-10 02:55:50 -07:00
H. Peter Anvin (Intel)
23abe9fe88 preproc: correctly handle %00 capturing a label
defining->dstk.mmac should point back to "defining" when the topmost
definition block is a %macro block.

Otherwise %00 will not inhibit label emission.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-10 01:52:49 -07:00
H. Peter Anvin (Intel)
1593c1dc60 preproc: don't call do_directive recursively
The hacky %arg and %local directives build directives as strings which
they then tokenize and call do_directive() recursively with. Factor
these out and remove the recursion.

It is too bad that %arg and %local didn't include the [] brackets in
the created macros; if so it would have been possible to do something
sane with 64-bit register operands. Sigh.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-10 01:21:44 -07:00
H. Peter Anvin (Intel)
72a555972f error: get rid of ERR_PASS1
ERR_PASS1 only remains in three places:

a. Unterminated %! string, an error
   - Should be signalled no matter which pass it is encountered in
b. Two cases of map file problems in outbin
   - The buffered warning system take care of that issue

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-10 01:10:30 -07:00
H. Peter Anvin (Intel)
fcb3d135ec preproc: a negative number is actually two tokens
A negative number is two tokens: a minus sign and a positive
number. For most uses we still want to generate signed numbers; for
specific uses there might be motivation for an unsigned output, but in
most cases it would be confusing.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-10 01:08:47 -07:00
H. Peter Anvin (Intel)
93dd437ac9 preproc: move reverse_tokens() into define_smacro()
The fact that smac->expansion is stored in reverse order is a detail
of the implementation, and should not be forced on the caller of
define_smacro().

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-10 00:56:03 -07:00
H. Peter Anvin (Intel)
32322a9a93 preproc: get rid of the prepreprocessor and the nop preprocessor
Fold the prepreprocessor and the nop preprocessor into the main
preprocessor. This means handling # cpp-like lines and TASM
compatibility tokens in the preprocessor proper, but that is really
not very hard to do.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-09 23:34:52 -07:00
H. Peter Anvin (Intel)
c36cdf8a55 Merge remote-tracking branch 'github/debug-macros'
Resolved Conflicts:
	version

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-09 21:16:49 -07:00
H. Peter Anvin (Intel)
7501601dbd preproc: pass macro debug information in invocation order
Reverse the invocation lists once each list is complete, so that the
lists passed to the macro backend are in true invocation order.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-08 10:13:46 -07:00
H. Peter Anvin (Intel)
942092e32a macro debug: use rb_search_exact()
We need the exact match in the rbtree for the current section. An
approximate match is not acceptable.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-08 09:53:49 -07:00
H. Peter Anvin (Intel)
50184c26c7 debug: collect macro information for the debug backend
Collect macro call/nesting information for the benefit of the debug
back end. So far, the only backend for which this is provided is the
debug back end, to show what information is present.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-08 09:28:44 -07:00
H. Peter Anvin
63769c588e Merge remote-tracking branch 'github/nasm-2.15.xx' 2020-07-05 15:27:04 -07:00
H. Peter Anvin (Intel)
122c5fb759 preproc: handle %+ pasting after empty expansions
%+ tokens can end up next to each other, or at the beginning or the
end of an expansion if we try to paste the output of empty
macros. This is perhaps particularly likely to happen in %[]
expressions.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-05 03:39:04 -07:00
H. Peter Anvin (Intel)
5b7369d7e0 Make debug info and error messages correctly reflect macros and reps
1. Error messages would issue with the line number of %endrep.
2. Debug line information would ignore both macros and reps.
   This is doubly wrong; macros are semantically equivalent to
   inline functions, and it is expected that debuggers trace
   into these functions.

These changes finishes the last parts of moving all responsibility for
the listing enable/disable into the preprocessor, so remove the
way over-complicated macro inhibit facility from the listing module
entirely.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-05 02:16:13 -07:00
H. Peter Anvin (Intel)
1939b69fdf Merge remote-tracking branch 'github/nasm-2.15.xx' 2020-07-02 20:44:57 -07:00
H. Peter Anvin (Intel)
b877708a83 Change unused -> unused_func to remove special case
The autoconf process automatically generates macros for function
attributes, including empty placeholders. Said empty placeholders also
propagate automatically into config/unconfig.h for the compilers which
don't support autoconf.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-07-01 20:49:04 -07:00
H. Peter Anvin (Intel)
8bc18080fe Merge tag 'nasm-2.15.02rc2'
NASM 2.15.02rc2
2020-06-30 17:53:13 -07:00
H. Peter Anvin (Intel)
c0d0f88261 preproc: expand_mmac_param_range() should be static
expand_mmac_params_range() lost its "static" in checkin
e99a946390e561804bf624a1e67f25ae34b13dfd. Put it back.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-30 17:33:39 -07:00
H. Peter Anvin (Intel)
a3db726f02 Merge remote-tracking branch 'github/nasm-2.15.xx'
Resolved Conflicts:
	version

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-30 17:14:36 -07:00
H. Peter Anvin (Intel)
e99a946390 preproc: fix %{:} macro operand ranges
Fix the handling of %{:} macro operands. Use the same code for
expanding the subarguments as for normal arguments.

This (hopefully) resolves the following bug reports:
  BR 3392611, BR 3392686, BR 3392688

Reported-by: <coconutfaistoslimeregistry@gmail.com>
Reported-by: Jasper Lievisse Adriaanse <r+nasm@jasper.la>
Reported-by: Jason Hood <jadoxa@yahoo.com.au>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-30 11:51:41 -07:00
H. Peter Anvin (Intel)
65ab3ab197 clang: mark inline functions unused and add warning options
clang, unlike gcc, will warn on inline functions which are
unused. This can happen if a function is either intended to be used in
the future, or it is only used under certain config options. Mark
those functions with the "unused" attribute; not only does it quiet
the warning, but it also documents it for the user.

Shuffle around the warning options in configure and add a few more
that are specific to clang.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-30 10:14:21 -07:00
H. Peter Anvin (Intel)
de8817ddbc doc: clean up warnings formatting
When a warning documentation message contains more than one paragraph,
we have to indent the subsequent paragraphs using \> unless they are a
code paragraph (\c).

Improve a few warnings doc messages.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-27 22:30:50 -07:00
H. Peter Anvin (Intel)
2383281768 Merge tag 'nasm-2.15rc8'
NASM 2.15rc8
2020-06-14 23:02:53 -07:00
H. Peter Anvin (Intel)
b292748d9f preproc, srcfile: much saner handling of %line directives
%line directives really need to be preprocessed early, before normal
directive processing. In particular, they are *not* affected by such
thing as smacro expansion, or deferred into an mmacro expansion.

The %line directive is special because it is explicitly indented to be
inserted by an external preprocessor, which can happen at any point.

For mmacro and rep expansions, store the current file and line for
each expansion line. Similarly, let each istk entry contain such
information.

Don't emit empty lines in preprocessing-only mode when we are
already required to issue a %line directive anyway. This cuts down on
clutter a fair bit.

Quote filenames in %line directives (and accept quoted filenames in
%line directives) if and only if it is necessary for
disambiguation. This is required if:

1. The filename contains control characters;
2. The filename begins or ends with whitespace or a quotation mark;
3. The filename is empty.

Otherwise issue the filename as-is, for backwards compatibility.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-14 20:09:11 -07:00
H. Peter Anvin (Intel)
4ed23c8f85 preproc.c: make extra sure we always have a null-terminated token
tok_set_text() and tok_set_text_free() take a length argument, which
could at least theoretically mean that we don't have a null-terminated
string. Directly enforce a null-terminated string in all cases.

In the future this means that it is legal to intentionally use these
functions to tokenize a substring.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-14 19:55:49 -07:00
H. Peter Anvin (Intel)
00335e43ef preproc.c: make extra sure tokens are always null-terminated
In tok_set_text() and tok_set_text_free(), don't trust that
the caller has given us a zero-terminated string.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-14 19:49:19 -07:00
H. Peter Anvin (Intel)
42894381c9 preproc: even more handling of backwards compatibility for mmacros
Legacy multi-line macro argument expansion really is very
complicated. With these changes, all legacy tests seem to pass, and
the only differences with NASM 2.14.xx are that some macros which
should have been expanded and were not now are.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-14 19:42:22 -07:00
H. Peter Anvin (Intel)
ee0e3ec5a4 preproc: %clear options, backwards compatibility hack for x264
The handling of empty arguments in NASM 2.14 and below was at best
"interesting"; a single whitespace token expansion, which can happen
during macro expansion, would sometimes be counted as an argument and
sometimes not.

One really weird effect of this was that %0 doesn't always match the
permitted range in the macro specification!

Add some backwards compatibility code to make x264/ffmpeg compile.

Add override via:

    %pragma preproc sane_empty_expansion true

Add support for %clear to clear specific subsets of the macro
definitions. In particular:

    %clear defalias

... can be used to wipe the __FOO__ backwards macro compatibility
aliases which may interfere with the C namespace.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2020-06-08 19:01:48 -07:00