Commit Graph

4359 Commits

Author SHA1 Message Date
H. Peter Anvin
18e87ce7bd doc: we really need a Fontmap file
It turns out that we need a Fontmap file after all, *and* -I. to make
gs find it. Inconsistent results came from stray Fontmap files from
previous debug attempts.

Now generate both fontpath and Fontmap, and hopefully at least one of
them should work. We might, in fact, need both, one for gs to know
where the files are and one for gs to know it is allowed to read them.

The core problem seems to be that gs will find OTF fonts by its normal
discovery mechanisms, but for some reason don't seem to use them
unless it can find them in a Fontmap, Font directory, of CIDFont
directory.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-10-04 13:09:30 -07:00
H. Peter Anvin
bef71a86b9 warnings: do a line break before enabled/disabled note
We need to create a separate paragraph if the help text had used \c
anyway. Putting the enabled/disabled separately for all entries makes
it read a lot cleaner anyway.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-10-03 23:47:08 -07:00
H. Peter Anvin
7ad824be7a warnings: make it possible to put blank lines in doc text
rdsrc.pl requires blank lines around \c paragraph, but warnings.pl
would strip them. Create a *!- prefix to force a blank line.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-10-03 22:18:35 -07:00
H. Peter Anvin
97ea4adcf0 config/unconfig.h: eliminate #undef directives
config/config.h as generated by autoconf has #undef directives
commented out, but the autoheader-generated template contains them,
and config/unconfig.h should not contain them. Re-introduce
config/config.h.in, and postprocess it to generate config/unconfig.h
by commenting out all the #undef directives, just as configure does.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-10-03 21:34:42 -07:00
H. Peter Anvin
fae1dd3d94 config/unconfig.h: add this autoconf-generated file to the tree
<config/unconfig.h> is generated by autoconf (autoheader), but just
like the autoconf/helpers directory contains files for people who
don't have the proper tools, check this file in.

It should even be less annoying change-wise than the helpers...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-10-03 21:05:12 -07:00
H. Peter Anvin
c6666be781 Win32: when converting filenames to UTF-16, don't add \\?\
\\?\ is supposed to override the hard-coded path limit, but it has
other effects as well, such as not working with relative paths and
paths containing /. On Windows 10 it is possible to set a registry key
to override this option anyway.

Maybe one day we can just use fopen() like on normal systems, even...

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Link: https://bugzilla.nasm.us/show_bug.cgi?id=3392614
Reported-by: Iouri Kharon <bc-info@styx.cabel.net>
2019-10-03 20:58:21 -07:00
H. Peter Anvin
0209ecb179 test: add a test for symbol prefixes via %pragma
Add a test for symbol prefixes via %pragma, including overlapping
directives.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-09-30 13:30:15 -07:00
H. Peter Anvin
fb2a2d6697 outcoff: add semi-generic pragma namespaces
Recognize the semi-generic pragma namespaces "coff" and "win" for
the win32 and win64 backends.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-09-30 13:30:15 -07:00
H. Peter Anvin
1dd926e8ce pragma: handle default name/fallback handler for NULL list; cleanups
The previous code would fail to process any directive if the directive
list was NULL. However, we also need to process the default name
passed to search_pragma_list() (e.g. "elf32"), as well as the global
name (e.g. "output") and call the default handler in that case.

In the process, improve the handling such that if one handler returns
DIRR_UNKNOWN, try calling subsequent handlers in the list.

Finally, factor out as much as possible to generic handlers.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-09-30 13:30:15 -07:00
H. Peter Anvin (Intel)
9781db8906 Merge branch 'pp-inline'
The inlining of preprocessor tokens has benchmarked about 15% faster in any
realistic scenario than the old code. For an artificial case where
over 50% of symbols are longer than 47 characters there was a slowdown
of about 15%, but that represents an incredibly unlikely scenario in
practice: even if labels are that long (e.g. C++ name mangling) the
majority of tokens should be instructions and registers, which are
uniformly short.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-24 11:15:04 -07:00
H. Peter Anvin (Intel)
01a67a1ba4 autogen.sh: don't update helpers unless there is a newer version
Updating the autoconf helpers unconditionally is very noisy and
probably the wrong thing to do anyway. Check the version numbers and
only update if the current machine has a newer version installed.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-24 11:13:43 -07:00
H. Peter Anvin
8571f06061 preprocessor: major cleanups; inline text into Token
Major cleanups of the preprocessor. In particular, the
block-allocation of Token is pretty ridiculous since nearly every
token requires a text allocation anyway. Change the definition of
Token so that only very long tokens (48+ characters on 64-bit systems)
need to be stored out of line.

If malloc() preserves alignment (XXX: glibc doesn't) then this means
that each Token will fit in a cache line.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-09-23 16:40:03 -07:00
H. Peter Anvin (Intel)
f7dbdb2e13 preproc: fix multiple memory corruption issues
paste_tokens() would not null-terminate the buffer before passing it
to tokenize(), resulting in garbage or a memory overwrite.

In several places the next pointers got confused; sometimes causing a
circular list and sometimes an invalid pointer.

Some minor code cleanups while fixing things, too...

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-18 21:20:52 -07:00
H. Peter Anvin (Intel)
f24d975008 preproc: fix list corruption bug; clean up token handling
expand_one_smacro() would corrupt the end of the list if a macro
expanded to another macro with arguments, which was also the last part
of the expansion.

Instead of doing all that testing with ttail, just scan forward at the
end to find the tail pointer; it is O(n) regardless.

Clean up the handling of tokens: use inline functions rather than odd
macros that sometimes modify their arguments and sometimes don't, and
fold some common code into new functions.

The tok_is() and tok_isnt() functions always are used with single
characters, so make it explicitly so (and remove the local hacks used
in some places.)

Allow using nasm_malloc() rather than blocked Tokens; this makes tools
like valgrind more useful in their reports.

For the future, consider making Tokens a separate memory allocation
immediately followed by the text, instead of using a pointer; we
allocate space for the string in almost every case anyway. Also
consider making it a doubly linked list...

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-18 18:17:26 -07:00
H. Peter Anvin
dd88aa9a1b preproc: add %ifusable and %ifusing directives
%ifusable tests to see if a certain %use package is available in this
version of NASM.

%ifusing tests if a certain %use packages is already loaded.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 19:39:48 -07:00
H. Peter Anvin
a039fcdb46 preproc: move %use package parsing to a separate routine
Move the parsing of %use package names to a separate routine, and stop
using get_id() for that purpose -- get_id() is wrong in a number of
ways.

This also means we can drop the error string argument to get_id().

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-09-12 19:27:42 -07:00
H. Peter Anvin
02d68d3da0 travis utf-error test: update error messages
Update error messages to match the new __?*?__ namespace.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 18:36:18 -07:00
H. Peter Anvin
14f0328aa1 eval: don't try to poke *opflags if opflags is NULL
While changing this code around to not do redundant lookups, dropped
this NULL pointer check. Oops.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 18:34:14 -07:00
H. Peter Anvin
d626f355f6 preproc: correct handling of %ifdef for aliases
Correctly handling %ifdef when operating on aliases; we had an
infinite loop going...

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 18:31:29 -07:00
H. Peter Anvin
86b2e93081 assemble: fix too aggressive dropping of overflow warnings
Drop down to OUT_WRAP when the size is big enough, as opposed to not
doing any tests at all.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 18:20:07 -07:00
H. Peter Anvin
82c5cb1704 outelf: use "symbols" not "variables" in error messages
Many symbols are variables, but others are labels, etc. Use the common
term "symbol".

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2019-09-12 17:48:16 -07:00
H. Peter Anvin
e47f4b7ad5 elf: fix "object" symbol keyword
The "object" symbol keyword would incorrectly generate STT_NOTYPE
instead of STT_OBJECT. Add test for weak object references; they are
different from plain weak references in that they are guaranteed to
resolve to zero if the symbol is not found.

Signed-off-by: H. Peter Anvin (Intel) <hpa@zytor.com>
2019-09-12 17:45:11 -07:00
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