Commit Graph

34 Commits

Author SHA1 Message Date
H. Peter Anvin
36e2a0c887 mempool: define standard mempools, fixes to the mempool allocator
Define standard mempools reclaimed at various stages. Fix various
problems with the mempool allocator.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-06-03 02:47:06 -07:00
H. Peter Anvin
740ec3572b malloc: simplify nasm_malloc code, add nasm_strcatn()
Simplify the nasm_malloc() code by moving the pointer check into a
common subroutine.

We can now issue a filename error even for failures like malloc().

Add support for the gcc sentinel attribute (verify that a list ends
with NULL).

Add a handful of safe_alloc attributes.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-05-30 11:40:42 -07:00
Cyrill Gorcunov
dd6a2cdcf4 Revert "compiler: Add fallthrough() helper"
This reverts commit 8ba28e13ea.
2018-02-25 22:25:57 +03:00
Cyrill Gorcunov
8ba28e13ea compiler: Add fallthrough() helper
https://bugzilla.nasm.us/show_bug.cgi?id=3392465

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-02-25 17:09:11 +03:00
Cyrill Gorcunov
fff27ab229 compiler: Fix typo in 6686fc6
https://bugzilla.nasm.us/show_bug.cgi?id=3392464

Reported-by: sezeroz@gmail.com
Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2018-02-24 15:11:32 +03:00
H. Peter Anvin
281f5bd92c Merge branch 'master' of ssh://repo.or.cz/srv/git/nasm 2018-02-22 14:53:46 -08:00
H. Peter Anvin
6686fc627e Introduce cold function attribute
Attribute to deemphasize certain code paths.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2018-02-22 14:52:50 -08:00
H. Peter Anvin
99d45c850e Fix problem with C99 inlines and -Werror=missing-prototypes
Some older versions of gcc (gcc 4.2.1 at least) produce a warning,
promoted to error, on C99 inlines.  Do some work to figure out if we
need to fall back to GNU inline syntax.

Fix some issues with GNU inline syntax.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2018-02-20 12:34:17 -08:00
H. Peter Anvin
81b62b9f54 Eliminate filename length restrictions, remote ofmt->filename()
Get rid of remaining dependencies on FILENAME_MAX, which ought to have
been removed a long time ago.

Remove ofmt->filename(); all implementations pretty much do the same
thing and there is absolutely no reason to duplicate that
functionality all over the place.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-12-20 13:38:20 -08:00
H. Peter Anvin
b533f545e4 compiler.h: HAVE___BUILTIN_CONSTANT_P has 3 underscores
HAVE_ + __BUILTIN_CONSTANT_P makes 3 underscores...

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-11-29 16:48:27 -08:00
H. Peter Anvin
03a5187c59 compiler.h: indentation cleanup
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-11-29 16:36:14 -08:00
H. Peter Anvin
cb7da7e7f6 compiler.h: add is_constant()
Add macro is_constant() to return true if and only if the value is a
compile-time constant.  It may never return true, however.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-11-29 16:05:05 -08:00
H. Peter Anvin
0a126062fb ilog2(): inline functions if practical
For many (most?) targets these will be very small functions, so inline
them.  However, just in case make these external library functions.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-09-27 13:34:42 -07:00
H. Peter Anvin
53cd7c7bf0 bytesex: more endianness detection hacks
A few more tricks for sussing out endinanness, and add an ultimate
fallback option.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-25 12:51:17 -07:00
H. Peter Anvin
573112ee86 endian.h: can be called sys/endian.h or machine/endian.h
On some platforms, endian.h may exist but be called sys/endian.h or
machine/endian.h.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-24 13:28:14 -07:00
H. Peter Anvin
d3e22572b3 Clean up byteorder functions
Move byte order handling functions to their own header file, and try
to be more specific about how exactly to handle things.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-04-24 13:01:08 -07:00
H. Peter Anvin
c01af0967e msvc: define no_return
The syntax for no_return on MSVC is "__declspec(noreturn) void".

Signed-off-by: H. Peter Anvin <h.peter.anvin@intel.com>
2017-04-06 13:51:32 -07:00
H. Peter Anvin
e90a89abe4 compiler.h: add redundant cast to quiet Watcom warning
Add a redundant cast in watcom_switch_hack() to quiet a Watcom
warning, and remove open-coded implementation of the Watcom switch
hack.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-03-01 00:52:48 -08:00
H. Peter Anvin
e29c7bb241 include/compiler.h: change __WATCOM__ to __WATCOMC__
The correct macro to test for (Open)Watcom is __WATCOMC__ not
__WATCOM__.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2017-02-28 23:05:17 -08:00
H. Peter Anvin
2958bcc6c2 compiler.h: correctly handle HAVE_DECL_*, test HAVE_DECL_STRNLEN
HAVE_DECL_* are 0/1 not ifdef; use HAVE_DECL_STRNLEN to see if we need
to declare this, lest stdlib/strnlen.c fails to compile.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-02-23 19:23:10 -08:00
H. Peter Anvin
be01d496d4 compiler.h: watcom_switch_hack() improvements
Avoid type promotion due to ?:, and put in a comment to explain what
the heck the purpose is of wrapping default in a macro.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-02-23 17:25:31 -08:00
H. Peter Anvin
e3cd70bc46 compiler.h: only use watcom_switch_hack() if necessary
Use sizeof() to prevent the compiler from invoking
watcom_switch_hack() unnecessarily.  Hopefully the optimizer would be
smart enough to recognize this inherently, but this is an old compiler
we are dealing with, so make life a little easier for it.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-02-23 17:22:58 -08:00
H. Peter Anvin
9b4b92b014 watcom.h: horrific hack to support OpenWatcom switch limitations
OpenWatcom still doesn't have proper support for 64-bit switch
statements.  Hack around it in a truly vile way.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2017-02-20 00:36:53 -08:00
H. Peter Anvin
abd28c9ab9 If we have new features introduced by C11, use them
Instead of using hacks or compiler-specific features, if we have
standard features as defined in ISO C11, use them.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-12-20 02:29:58 -08:00
H. Peter Anvin
7294d62040 compiler.h: use the correct symbol to test for __builtin_expect()
__builtin_expect() has leading underscores, they need to be reflected
in the symbol.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-11-15 15:53:38 -08:00
H. Peter Anvin
8b19083483 Better support for function attributes, autoconf cleanups
Use autoconf to detect function attributes; some compilers like Sun CC
do support some gcc-style attributes, but don't define __GNUC__.  Also
-U__STRICT_ANSI__ already in configure.ac so our tests match what we
might eventually encounter.

Add const_func and pure_func attributes.

Decorate functions in nasmlib.h with const_func and pure_func.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-11-15 14:01:37 -08:00
H. Peter Anvin
f5287231c1 Move canned OpenWatcom config to config/watcom.h.
Move the canned OpenWatcom configuration file to config/watcom.h.
Also exclude config/config.h from being a dependency for MSVC.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-10-19 13:23:04 -07:00
H. Peter Anvin
4c9132e3a0 compiler.h: include <sys/types.h>
Apparently, at least on some OS/2 compilers, <sys/types.h> needs to be
included for off_t to be defined.  This seems like a generically good
idea to include this header whenever it is available.

Remove reference to <types.h>.  This was supposedly for MSVC, but
there is no actual evidence that it is useful beyond <sys/types.h>.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-10-19 13:13:38 -07:00
H. Peter Anvin
44e3a11087 compiler.h: fix typo in the non-gcc case
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-10-14 15:05:28 -07:00
H. Peter Anvin
9b733a5845 compiler.h: for newer gcc attributes, we can use __has_attribute()
For newer gcc attributes, we can use __has_attribute() to test for
attribute presence.  This improves compatibility both with older gcc
and with clang, at least with -Werror enabled.

Reported-by: Daniel Lundqvist <daniel@malarhojden.nu>
Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-10-14 15:01:06 -07:00
H. Peter Anvin
276785a8ff config: add configuration file for unknown compilers
Add a config header file for the most conservative case of a totally
unknown compiler.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-10-04 17:13:50 -07:00
H. Peter Anvin
397c169736 Move config.h to a subdirectory, add MSVC-specific config file
Instead of trying to do hacks in the Makefiles, define header files
for specific compilers if they can't use autoconf.  Currently defined
for Microsoft Visual Studio, based on MSDN documentation.  It is
currently untested.

Signed-off-by: H. Peter Anvin <hpa@linux.intel.com>
2016-10-04 17:01:59 -07:00
Cyrill Gorcunov
43bb293432 Merge branch 'nasm-2.12.xx'
* nasm-2.12.xx:
  codeview: Fix ill-formed "S_COMPILE2" record.
  rdoff: Add rdf2bin input dependency
  labels: Warn if new label created on pass two
  Add explicit void parameter to newmembuf() function declaration.
  compiler.h: always undefine __STRICT_ANSI__ for gcc

| Conflicts:
|	rdoff/Makefile.in

Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com>
2016-07-27 01:08:51 +03: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