infix
A JIT-Powered FFI Library for C
Loading...
Searching...
No Matches
infix_config.h File Reference

Platform, architecture, and ABI detection macros. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define _POSIX_C_SOURCE   200809L
 
#define INFIX_COMPILER_NFI
 
#define INFIX_TRAMPOLINE_HEADROOM   128
 Extra bytes to allocate in a trampoline's private arena.
 

Detailed Description

Platform, architecture, and ABI detection macros.

Copyright (c) 2025 Sanko Robinson

This source code is dual-licensed under the Artistic License 2.0 or the MIT License. You may choose to use this code under the terms of either license.

SPDX-License-Identifier: (Artistic-2.0 OR MIT)

The documentation blocks within this file are licensed under the Creative Commons Attribution 4.0 International License (CC BY 4.0).

SPDX-License-Identifier: CC-BY-4.0

This header is the first to be included by infix_internals.h and is responsible for defining a consistent set of INFIX_* macros that describe the build environment. It is the central point of configuration for the entire library, adapting the build to different operating systems, compilers, and CPU architectures.

Its most critical function is to select the correct Application Binary Interface (ABI) implementation to use for JIT code generation. This is achieved through a cascade of preprocessor checks that can be overridden by the user for cross-compilation. By the end of this file, exactly one INFIX_ABI_* macro must be defined, which determines which abi_*.c file is included in the unity build.

Macro Definition Documentation

◆ _POSIX_C_SOURCE

#define _POSIX_C_SOURCE   200809L

These macros are defined to ensure that standard POSIX and other necessary function declarations (like dlopen, dlsym, snprintf, shm_open) are made available by system headers in a portable way across different C library implementations (glibc, musl, BSD libc, etc.). Failing to define these can lead to compilation failures due to implicitly declared functions on stricter build environments.

◆ INFIX_COMPILER_NFI

#define INFIX_COMPILER_NFI

This section defines INFIX_OS_* macros based on compiler-provided preprocessor definitions. It also defines the broader INFIX_ENV_POSIX for systems that follow POSIX conventions, which simplifies later #ifdef logic.

Defines INFIX_COMPILER_* macros. The order is important, as Clang often defines __GNUC__ for compatibility, so it must be checked for first.

◆ INFIX_TRAMPOLINE_HEADROOM

#define INFIX_TRAMPOLINE_HEADROOM   128

Extra bytes to allocate in a trampoline's private arena.

Defines INFIX_ARCH_* for the two currently supported architectures. The library will fail to compile if the architecture is not one of these, as the JIT code emitters are architecture-specific.

This is the most critical section of the configuration. It determines which ABI implementation will be compiled and used by the JIT engine.

It supports two modes:

  1. Forced ABI: A user can define INFIX_FORCE_ABI_* (e.g., via a compiler flag like -DINFIX_FORCE_ABI_SYSV_X64) to override automatic detection. This is essential for cross-compilation, where the host compiler's macros would not reflect the target environment.
  2. Automatic Detection: If no ABI is forced, it uses the INFIX_ARCH_* and INFIX_OS_* macros to deduce the correct ABI for the current build target.

When a trampoline handle is created, it deep-copies all type information from a source (like the parser's temporary arena) into its own private arena. The size of the source arena is used as a hint for the new arena's size, but the copy process itself requires a small amount of extra memory for its own bookkeeping (e.g., the memoization list in _copy_type_graph_to_arena_recursive). This headroom provides that extra space to prevent allocation failures during the copy.