nodejs/node · error · ValueError

Unsupported libffi target

Error message

Unsupported libffi target {os_name}/{target_arch}.

What it means

libffi's generate-headers.py maps an (os_name, target_arch) pair to a preprocessor define and a source subdirectory (e.g. X86_64/x86_64). get_target() has explicit branches for the supported platforms/arches; any combination not listed falls through to this ValueError, signalling that no ffitarget header template exists for that target.

Solutions

  1. Confirm the (os, arch) pair is one libffi supports in get_target(); pick the closest supported target.
  2. If you must build for an unsupported arch, vendor the missing ffitarget.h template and extend get_target().
  3. Check that --target-arch / TARGET_ARCH env uses a recognized alias (x64 not 'amd64-intel').

Example fix

# before
python generate-headers.py --output-dir out --target-arch riscv64 --os linux
# after
python generate-headers.py --output-dir out --target-arch x86_64 --os linux
Defensive patterns

Strategy: type-guard

Validate before calling

SUPPORTED = {('linux','x86_64'),('linux','arm64'),('mac','arm64'),('win','x86_64')}
assert (os_name, target_arch) in SUPPORTED, f'unsupported libffi target {os_name}/{target_arch}'

Type guard

def is_supported_libffi_target(os_name, target_arch):
    pairs = {('linux','x86'),('linux','x86_64'),('linux','arm'),('linux','arm64'),
             ('mac','x86_64'),('mac','arm64'),('win','x86'),('win','x86_64'),
             ('freebsd','x86_64'),('aix','ppc64')}
    return (os_name, target_arch) in pairs

Prevention

When it happens

Trigger: Raised at the end of get_target() when target_arch is not one of x86/x86_64/arm/arm64/mips/mipsel/... or when a known arch is paired with an unsupported os_name (e.g. ppc64 only handled for aix/mac/freebsd/openbsd/linux).

Common situations: Cross-compiling for an architecture libffi's bundled headers don't ship (riscv, s390x, loongarch); exotic os/arch matrix cells in CI; a typo in --target-arch or an alias the normalizer doesn't recognize.

Related errors


AI-assisted analysis of nodejs/node@1b2de5e052 (2026-08-13). Data as JSON: /api/errors/3df01fc08a0e4a42. Report an issue: GitHub.

Appendix: source

Thrown at deps/libffi/generate-headers.py:64

    if target_arch == 'loong64':
        return ('LOONGARCH64', 'loongarch')

    if target_arch in ('mips', 'mipsel', 'mips64el'):
        if os_name in ('freebsd', 'linux', 'openbsd'):
            return ('MIPS', 'mips')

    if target_arch == 'ppc64':
        if os_name == 'aix':
            return ('POWERPC_AIX', 'powerpc')
        if os_name == 'mac':
            return ('POWERPC_DARWIN', 'powerpc')
        if os_name in ('freebsd', 'openbsd'):
            return ('POWERPC_FREEBSD', 'powerpc')
        if os_name == 'linux':
            return ('POWERPC', 'powerpc')

    raise ValueError(f'Unsupported libffi target {os_name}/{target_arch}.')


def has_long_double(os_name, target_arch):
    target_arch = normalize_arch(target_arch)

    if os_name == 'win':
        return '0'

    if os_name == 'mac' and target_arch == 'arm64':
        return '0'

    if target_arch == 'arm':
        return '0'

    return '1'


def uses_exec_trampoline_table(os_name, target_arch):

View on GitHub (pinned to 1b2de5e052)