Commit Graph

4337 Commits

Author SHA1 Message Date
H. Peter Anvin
7ad25b2e18 Change LBL_NONE to LBL_none
NASM convention is to use all-upper-case for "real" information, and
mixed-case (upper case common prefix, lower case description) for
meta-information. This is a highly useful distinction.

Thus "LBL_NONE" implies an actual label of type "NONE", as opposed to
no label at all.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 20:26:23 -04:00
H. Peter Anvin
90b1ccff86 Drop unnecessary EXTERN symbols
Currently, NASM always issues as an unknown symbol any symbol declared
EXTERN. This is highly undesirable when using common header files,
as it might cause the linker to pull in a bunch of unnecessary
modules, depending on how smart the linker is.

Add a new REQUIRED directive which behaves like the old EXTERN, for
the use cases which might still need this behavior.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 20:21:03 -04:00
H. Peter Anvin
495fda6341 elf: support weak global and extern references
A global or extern definition can now contain the keyword "weak" (or
"strong", although that is the default) to create a weak symbol or a
weak external reference, respectively.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 14:27:50 -04:00
H. Peter Anvin
a73ccfebcc error: replace nasm_verror() indirection with preproc callback
Since pp_error_list_macros() was introduced, the only need for
pp_verror() is to suppress error messages in certain contexts. Replace
this function with a preprocessor callback,
preproc->pp_suppress_error(), so we can drop the nasm_verror()
function pointer entirely.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-28 19:02:47 -07:00
H. Peter Anvin
6a4353c4c2 errors: be more robust in handling unexpected fatal errors
Introduce a new error level, ERR_CRITICAL, beyond which we will
minimize the amount of code that will be executed before we die; in
particular don't execute any memory allocations, and if we somehow end
up recursing, abort() immediately.

Basically, "less than panic, more than fatal."

At this point this level is used by nasm_alloc_failed().

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-28 18:32:46 -07:00
H. Peter Anvin
f8a15a8ea3 Correct __ALIGN_ -> __?ALIGN_
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-27 17:21:28 -07:00
H. Peter Anvin
2201ceb238 nasm: avoid null pointer reference on VERY early memory allocation failure
If we get a memory allocation failure before preproc is initialized,
we could end up taking a NULL pointer reference while trying to unwind
macros.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-27 17:19:07 -07:00
H. Peter Anvin
d235408c65 preproc: standard macros now C-safe, %aliases off, fix %? recursion
Enough users expect the namespace starting with underscore to be safe
for symbols. Change our private namespace from __foo__ to
__?foo?__. Use %defalias to provide backwards compatiblity (by using
%defalias instead of %define, we handle the case properly where the
user changes the value.)

Add a preprocessor directive:

%aliases off

... to disable all smacro aliases and thereby making the namespace
clean.

Finally, fix infinite recursion when seeing %? or %?? due to
paste_tokens(). If we don't paste anything, the expansion is done.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-27 16:42:41 -07:00
H. Peter Anvin
eaef851689 configure.ac: look for unconfig.h not uninit.h... 2019-08-27 15:13:15 -07:00
H. Peter Anvin (Intel)
7eb18213b7 preproc: make sure the mmacro params list is NULL-terminated
If we adjust nparams due to default or greedy arguments, we need to
re-terminate the params[] array.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-20 16:24:46 -07:00
H. Peter Anvin (Intel)
d4607846a4 preproc: smacro argument lists can't be preceded by space
The smacro argument list cannot be preceded by whitespace, or we
wouldn't be able to define no-argument smacros the expansion of which
starts with (.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-20 16:19:37 -07:00
H. Peter Anvin (Intel)
ffe89ddaed preproc: fix comment -La -> -Lm
The -Lm option was briefly called -Lm during development, fix.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-20 16:06:36 -07:00
H. Peter Anvin (Intel)
41d91a9273 preproc: mmacro argument fixes; listing option for mmacro args
Correctly handle empty mmacro arguments that still have preceding
whitespace tokens.

Default mmacro parameters are obtained by count_mmac_params() so they,
too, need to be shifted over by one.

Add an option to list mmacro calls with arguments. Name this -Lm;
remove the old -Lm option to -Ls since it is related to single-line
macros.

Trivially optimize the case where an mmacro is called from within
itself: if all possible mmacros are excluded by loop removal, there is
no need to delve into the mmac processing code.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-20 16:03:46 -07:00
H. Peter Anvin (Intel)
68075f8fa6 preproc: fix uninitialized variables
Fix uninitialized variables (not just warnings, actual bugs.)

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-20 12:28:05 -07:00
H. Peter Anvin (Intel)
a1a844697d preproc: fix varadic macros, add conditional comma operator
Fix the (severely broken handling of) varadic macros.

Add a conditional comma operator "%,". This expands to a comma unless
followed by a null expansion of some sort, which allows suppressing
the comma before an empty argument (usually varadic, but not
necessarily.)

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-20 01:32:28 -07:00
H. Peter Anvin (Intel)
62cf4aaef6 preproc: add suppport for stringify, nostrip, greedy smacro arguments
Add a few more types of smacro arguments, and clean stuff up in
process.

If declared with an &, an smacro parameter will be quoted as a string.
If declared with a +, it is a greedy/varadic parameter.
If declared with an !, don't strip whitespace and braces (useful with &).

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-20 00:05:41 -07:00
H. Peter Anvin (Intel)
de7acc3a46 preproc: defer %00, %? and %?? expansion for nested macros, cleanups
BR 3392603: When doing nested macro definitions, we need %00, %? and
%?? expansion to be deferred to actual expansion time, just as the
other parameters.

Do major cleanups to the mmacro expansion code.

Reported-by: Alexandre Audibert <alexandre.audibert@outlook.fr>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-19 18:24:02 -07:00
H. Peter Anvin (Intel)
41e9705054 assemble.c: fix signed/unsigned comparison warning
Ponderance: if data->bits < globalbits, should we actually use
OUT_UNSIGNED rather than OUT_WRAP here?

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-19 15:47:36 -07:00
H. Peter Anvin (Intel)
b83621350c listing: add the -L+ option to enable all listing options
-L+ or %pragma list options ++ will enable all possible listing
 options.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-19 13:11:34 -07:00
H. Peter Anvin (Intel)
2586cee21d BR 3392472: don't complain on wraparound for lower bit modes
If the address we are using is >= the size of the instruction, then
don't complain on overflow as we can wrap around the top and bottom of
the address space just fine.

Alternatively we could downgrade it to OUT_WRAP in that case.

Reported-by: C. Masloch <pushbx@38.de>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-16 01:44:49 -07:00
H. Peter Anvin (Intel)
7be54b3d0c Makefile.in: use $(ALL_LDFLAGS)
$(ALL_LDFLAGS) was defined but not used; might as well use it.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-16 01:29:49 -07:00
H. Peter Anvin (Intel)
93d41d8296 BR 3392576: don't segfault on a bad %pragma limit
Don't segfault on a bad %pragma limit. Instead treat a NULL pointer as
an empty string.

Reported-by: Ren Kimura <rkx1209dev@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-16 01:12:54 -07:00
H. Peter Anvin (Intel)
480d5e2c8b BR 3392601: allow the user to disable pedantic warnings
--disable-pedantic passed to configure will now disable
-W, -Wc90-c99-compat, and -pedantic.

Requested-by: Orzkan Sezer <sezeroz@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-16 00:52:26 -07:00
H. Peter Anvin (Intel)
5bb35772b3 BR 3392597: the system malloc() can return NULL
malloc(0) can legitimately return NULL; it does on some systems and
not others. Force the size to 1 byte if the size is 0 coming in,
except for realloc() where this is legitimate and equivalent to
free().

Since this is an abnormal case, and can't even happen with most C
libraries, handle it on the error path, after we already got back a
NULL pointer.

Reported-by: Ozkan Sezer <sezeroz@gmail.com>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-16 00:41:29 -07:00
H. Peter Anvin (Intel)
16a3e8ddb9 autoconf: update check for gcc inlines
Old versions of gcc didn't define either __GNUC_STDC_INLINE__ or
__GNUC_GNU_INLINE__, but imply the latter.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-16 00:14:17 -07:00
H. Peter Anvin (Intel)
8b6e6bf04f config.h: separate function and function pointer attributes; automate
Separate out function and function pointer attributes, as not all
versions of all compilers support both.

Have macros related to function attributes auto-generated by
autoheader. As a result, rename config.h.in to unconfig.h, to make it
more obvious that it is really intended to be included from some C
programs.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-16 00:08:27 -07:00
H. Peter Anvin (Intel)
9fbd9fb859 preproc: fix mmacro nesting prevention
BR 3392602: mmacros should not nest unless so explicitly specified.

Reported-by: C. Masloch <pushbx@38.de>
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-15 19:26:52 -07:00
H. Peter Anvin (Intel)
743c91855e macros.pl: remove a debugging print
Remove a stray debugging print statement from macros.pl.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-15 11:57:05 -07:00
H. Peter Anvin (Intel)
4b282d0503 macros: can't use the __USE_*__ macro string anymore; fix comment stripping
Since we use 127 not 0 for end of line in stdmac packages now, we
can't simply use the __USE_*__ macro as a string to test for a %use
package. Keep an internal array of state instead.

Fix the stripping of comments from lines in macro files.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-15 11:53:19 -07:00
H. Peter Anvin (Intel)
6d5c77c95f stdmac: handle up to 160 directives, make macros.c more readable
Handle up to 160 directives for stdmac compression.  This is done by
allowing the directive numbers to wrap around (128-255, 0-31), using
127 for end of line, and forcing any whitespace character to be space.

Make macros.c a bit more legible by using #defines for the byte codes;
strictly for the benefit of the human reader.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-15 02:29:40 -07:00
H. Peter Anvin (Intel)
566a0f2187 pptok.pl: don't leak internal codes into pptok.c
If we have internal codes in pptok.c, we may have false matches for
them as tokens, plus, there is no reason for them to exist there. Go
back to putting NULL in those slots.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-15 01:37:48 -07:00
H. Peter Anvin (Intel)
97cbdd34d0 preproc: simplify handling of conditionals and casesense
Simplify the handling of conditionals; remove the PPC_* types.

Automate the generation of case-sensitive versus case-insensitive
directives, and make it so the bulk of the code doesn't have to worry
about it.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-15 01:14:23 -07:00
H. Peter Anvin (Intel)
5e3d741b00 preproc: introduce alias smacros, cleanups
Introduce "alias smacros", which are the smacro equivalent of
symlinks; when used with the various smacro-defining and undefining
directives, they affect the macro they are aliased to. Only explicit
%defalias, %idefalias, and %undefalias affect them.

This is intended for being able to rename macros while retaining the
legacy names.

This patch also removes an *astonishing* amount of duplicated
code:

1. Every caller to defined_smacro() and undef_smacro() would call
   get_ctx() to mangle the macro name; push that into those functions.
2. Common code to get an smacro identifier.
3. Every code path that returns DIRECTIVE_FOUND also has to do
   free_tlist(origline); make it do so.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-14 23:50:37 -07:00
H. Peter Anvin (Intel)
522bcad4ae masm.mac: tbyte -> tword
Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-14 21:29:21 -07:00
H. Peter Anvin (Intel)
fe90f152d1 test: very simple test for MASM displacement syntax
Very trivial test of MASM package.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-14 15:46:01 -07:00
H. Peter Anvin (Intel)
8981724f17 masm.mac, parser: VERY limited MASM emulation package
Very limited MASM emulation.

The parser has been extended to emulate the PTR keyword if the
corresponding macro is enabled, and the syntax displacement[index] for
memory operations is now recognized.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-14 15:44:50 -07:00
H. Peter Anvin (Intel)
02b60ddd1c LEA: allow immediate syntax; ignore operand size entirely
The memory operand size of LEA doesn't matter in any way as it isn't
"real memory". Add an ANYSIZE option to ignore sizes entirely.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-08-14 15:23:00 -07:00
H. Peter Anvin
a635809620 list_option_mask(): return 0 (empty mask) for < '0'
Missing limit check at the bottom of the ASCII range.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 18:16:37 -07:00
H. Peter Anvin
d91519a107 listing: encapsulate the list_options encoding, make more comprehensive
Encapsulate the list_options() encoding in an inline function. We only
ever compute a mask with a non-constant input in two places (command
line and pragma parsing), so a slightly more complex mapping is of no
consequence; thus map a-z, A-Z and 0-9 as being the most likely
characters we may want to use as options. Space is left for two more :)

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 18:04:04 -07:00
H. Peter Anvin
59d4ccc2b0 Add %pragma list options
Add a %pragma to set (or clear) listing options. It only takes effect
on the next assembly pass, however!

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 06:45:12 -07:00
H. Peter Anvin
06335873ae preproc: avoid dropping the facility name in %pragma
tline got advanced a token too far, with the obvious results that the
facility name got truncated. Skip whitespace *after* expand_smacro(),
not before.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 06:42:55 -07:00
H. Peter Anvin
f5d7d90148 preproc: fix double free in the handling of %pragma
expand_smacro() consumes its input, so we need to truncate the input
list so we can call free_tline(origline) safely.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 06:21:00 -07:00
H. Peter Anvin
6686de2bab preproc: add listing options to override nolist; some cleanups
Add listing options:

    -Lb    to show builtin macro packages
    -Lf    to override .nolist

Do some cleanups in the process, in particular generalize read_line()
between stdmac and file alternatives.

When processing stdmac, create an istk entry for it. This means stdmac
can be identified by istk->fp == NULL. At some future date there could
even be a function pointer to an appropriate read function.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 05:33:14 -07:00
H. Peter Anvin
3f51082bcd listing: clean up before a restart
With the -Lp option, the listing generator gets invoked multiple times
in the same session. If we already have a list file open, call
list_cleanup() before reinitializing; otherwise we get stray output in
the updated file.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 05:31:51 -07:00
H. Peter Anvin
a2c1c7d0d4 listing: coalesce TIMES in non-final passes, print <len>, clarify hex
Merge TIMES in the nonfinal passes, there is no point in getting <len
...> an arbitrary number of times.

Actually print <len> (OUT_RAWDATA without a data pointer), not <res>
(OUT_RESERVE).

Dropping the zero-fill for the hex format made the listing more
manageable, but it also doesn't immediately look like hex, plus there
is now the -Ld option. Put an h after hex (shorter than leading 0x) to
make it obvious.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 02:45:41 -07:00
H. Peter Anvin
14b16442ce outelf: change debug format default to dwarf
DWARF is by far the predominant format on ELF platforms these
days. Catch up with the times.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 02:30:29 -07:00
H. Peter Anvin
9084beb1bb Clean up backend format names
The backend format names were rather redundant and not always
helpful. Do some cleanup.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 02:28:17 -07:00
H. Peter Anvin
355bfb879d Stylistic improvements to help text
Trivial stylistic improvements to the help text.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 01:55:00 -07:00
H. Peter Anvin
322bee0aac Additional listing options, improve help output, fix macro limits
Additional listing options:

   -Ld to display counts in decimal
   -Lp to output a list file in every pass (to make sure one exists)

Clean up the help output and make it comprehensive. The -hf and -y
options are no longer necessary, although they are supported for
backwards compatiblity.

Fix macro-levels so it actually count descent levels; a new
macro-tokens limit introduced for the actual token limit.

Slightly simplify the limits code.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-10 01:46:58 -07:00
H. Peter Anvin
ab6f831955 listing: when listing lines in macros and rep blocks, show the actual line
When printing lines coming from %rep blocks and macros, show the line
number corresponding to the line actually being printed.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-08-09 22:31:45 -07:00