Identifying the environment
In SPRAAK, the following macros will be set to allow the code to adapt itself to the properties of the platform it is compiled for.
- SPR_OS
- The operating system. Possible values are:
Linux, Windows, OSX, Solaris
- SPR_OS_xxx
- Defined for xxx equaling 'SPR_OS'.
- SPR_CPU
- The CPU-family. Possible values are:
i686, x86_64, power, sparc, mips, arm
- SPR_CPU_xxx
- Defined for xxx equaling 'SPR_CPU'.
- SPR_COMPILER
- The compiler. Possible values are: gcc, visual_c, icc, sun_studio
- SPR_COMPILER_xxx
- Defined for xxx equaling 'SPR_COMPILER'.
- SPR_ENDIAN
- Set to 01 on little endian platforms and 10 on big endian platforms. Mixed endian platforms (e.g. 2310) are not supported.
- SPR_PTR_SZ
- Number of bits in a pointer (32 or 64).
- SPR_INT_SZ
- Number of bits in a standard integer (int) – typically 32.
- SPR_LONG_SZ
- Number of bits in a long – typically equal to SPR_PTR_SZ or SPR_INT_SZ.
- SPR_SIZE_SZ
- Number of bits in a size_t element – typically equal to SPR_PTR_SZ.
- SPR_MT_NPROC
- Estimate of the typical number of concurrent threads (core's) the software will use. 0 means that the software will never be used in multithreading mode (even not on a single core). The estimate is used to optimize the size of some internal tables.
- SPR_NULL_NOT_0
- Defined if the NULL pointer does not correspond with a binary 0 (all bits set to 0). If so, initialization of structures that contain pointers cannot be done by just zeroing the memory area.
- SPR_LIB_XXX
- Set to the version number (xx.yy) if the library and header files for 'XXX' are available and to 0 otherwise.
- SPR_VECEXT_XXX
- with XXX the convention used in the vector extension (currently either GCC or CLANG); see also vector extensions in Optional C-extensions
These macro's are set automatically by the build process.
Identifying bugs in the environment
General remarks
The next subsection gives a list of external bugs (bugs beyond the scope of SPRAAK such as bugs in the compiler, the operating systems or external libraries) and annoyances (conventions which are allowed by C99 but are unhandy to work with) which have been identified in SPRAAK. Each bug/annoyance is idenitified by means of a macro. All bug/annoyance indicating macro's have the form
SPR_BUG_<id>
When a 'bug macro' is not specified, the platform is not susceptible to the bug/annoyance and hence no work-around is needed. In special cases (see the specific comments for each bug below), the value of the macro provides additional information about how to circumvent the bug/annoyance.
All bug-related macro's are set automatically by the build process using appropriate test code. See the file 'sysdep.py' for the actual code (and to add newly detected bugs/annoyances).
List of external bugs and annoyances
- SPR_BUG_STAT_xxx
- The header files that define the data-layout of the 'stat' structure in Linux is not robust w.r.t. some optimization options. If this macro is set, the 'xxx' field in the 'stat' structure should be accessed as follows:
struct stat file_stat;
...
st_size file_sz = SPR_BUG_STAT_st_size(&file_stat);
- SPR_BUG_MALLOC_0_NULL
- Malloc returns NULL when requesting a chunk of memory of 0 bytes.
- SPR_BUG_REALLOC_0_NULL
- Realloc returns NULL when requesting a chunk of memory of 0 bytes.
- SPR_BUG_SSHIFT_IS_USHIFT
- A signed right shift acts like an unsigned right shift (this is allowed in C99, but it makes efficient coding quite difficult).
- SPR_BUG_USHIFT_IS_SSHIFT
- An unsigned right shift acts like a signed right shift (this is allowed in C99, but it makes efficient coding quite difficult).
- SPR_BUG_ILOGB
- The ilogb() instruction returns incorrect values for 0.0, Inf or Nan
- SPR_BUG_X86_TWIN48_18
- See atomic.c
- SPR_BUG_X86_NO_TWIN64
- See atomic.c
- SPR_BUG_X86_GOT_BX
- The 'bx' register on Linux_i686 tends to be locked down for the global offset table, and that is problematic for the twincas atomic operation.
- SPR_BUG_NO_BACKTRACE
- No support for stack dumping (backtracing), see core/sig_handler.c