libffi (original) (raw)
A Portable Foreign Function Interface Library
libffi-3.4.5 was released on February 15, 2024. You can download it from github here: https://github.com/libffi/libffi/releases/download/v3.4.5/libffi-3.4.5.tar.gz.
libffi is Free Software. It has a very liberal license.
What is libffi?
Compilers for high level languages generate code that follows certain conventions. These conventions are necessary, in part, for separate compilation to work. One such convention is the "calling convention". The "calling convention" is a set of assumptions made by the compiler about where function arguments will be found on entry to a function. A "calling convention" also specifies where the return value for a function is found.
Some programs may not know at the time of compilation what arguments are to be passed to a function. For instance, an interpreter may be told at run-time about the number and types of arguments used to call a given function. Libffi can be used in such programs to provide a bridge from the interpreter program to compiled code.
The libffi library provides a portable, high level programming interface to various calling conventions. This allows a programmer to call any function specified by a call interface description at run-time.
FFI stands for Foreign Function Interface. A foreign function interface is the popular name for the interface that allows code written in one language to call code written in another language. The libffi library really only provides the lowest, machine dependent layer of a fully featured foreign function interface. A layer must exist above libffi that handles type conversions for values passed between the two languages.
Who uses it?
The libffi library is useful to anyone trying to build a bridge between interpreted and natively compiled code. Some notable users include:
- CPython - the default, most-widely used implementation of the Python programming language uses libffi in the standard ctypes library.
- OpenJDK - the open-source implementation of the Java Platform Standard Edition uses libffi to bridge between the interpreter and native code for some platforms.
- js-ctypes - a foreign function interface for javascript that Mozilla will be shipping in Firefox 3.6.
- Dalvik - Dalvik is the virtual machine which runs the Java platform on Android mobile devices. libffi is used on Android ports for which no custom bridging code has been written.
- Java Native Access (JNA) - the JNI-free way to call native code from Java.
- Ruby-FFI - a Foreign Function Interface extension for Ruby.
- fsbv - Foreign Structure By Value is a foreign function interface library forCommon Lisp that extends the standard CFFI package to include support for passing structure arguments by value.
- JSCocoa - call Objective-C code from javascript on Mac OSX and the iPhone (via the libffi-iphone port).
- PyObjC - call Objective-C code from Python on Mac OSX.
- RubyCocoa - call Objective-C code from Ruby on Mac OSX.
- The Glasgow Haskell Compiler - call C code from this popular Haskell implementation.
- Racket - call C code from this popular Scheme implementation.
- gcj - the runtime library for the GNU Compiler for the Java Programming Language uses libffi to handle calls back and forth between interpreted and natively compiled code. gcj is part of the GCC, the GNU Compiler Collection.
Supported Platforms
Libffi has been ported to many different platforms. For specific configuration details and testing status, please refer to the README file. At the time of release, the following basic configurations have been tested:
Architecture | Operating System |
---|---|
AArch64 (ARM64) | iOS |
AArch64 | Linux |
AArch64 | Windows |
Alpha | Linux |
Alpha | Tru64 |
ARC | Linux |
ARM | Linux |
ARM | iOS |
ARM | Windows |
AVR32 | Linux |
Blackfin | uClinux |
CSKY | Linux |
HPPA | HPUX |
IA-64 | Linux |
KVX | Linux |
LoongArch64 | Linux |
M68K | FreeMiNT |
M68K | Linux |
M68K | RTEMS |
M88K | OpenBSD/mvme88k |
Meta | Linux |
MicroBlaze | Linux |
MIPS | IRIX |
MIPS | Linux |
MIPS | RTEMS |
MIPS64 | Linux |
Moxie | Bare metal |
Nios II | Linux |
OpenRISC | Linux |
PowerPC 32-bit | AIX |
PowerPC 64-bit | AIX |
PowerPC | AMIGA |
PowerPC | Linux |
PowerPC | Mac OSX |
PowerPC | FreeBSD |
PowerPC 64-bit | FreeBSD |
PowerPC 64-bit | Linux ELFv1 |
PowerPC 64-bit | Linux ELFv2 |
RISC-V 32-bit | Linux |
RISC-V 64-bit | Linux |
S390 | Linux |
S390X | Linux |
SPARC | Linux |
SPARC | Solaris |
SPARC | Solaris |
SPARC64 | Linux |
SPARC64 | FreeBSD |
SPARC64 | Solaris |
TILE-Gx/TILEPro | Linux |
VAX | OpenBSD/vax |
X86 | FreeBSD |
X86 | GNU HURD |
X86 | Interix |
X86 | kFreeBSD |
X86 | Linux |
X86 | Mac OSX |
X86 | OpenBSD |
X86 | OS/2 |
X86 | Solaris |
X86 | Solaris |
X86 | Windows/Cygwin |
X86 | Windows/MingW |
X86-64 | FreeBSD |
X86-64 | Linux |
X86-64 | Linux/x32 |
X86-64 | OpenBSD |
X86-64 | Solaris |
X86-64 | Windows/Cygwin |
X86-64 | Windows/MingW |
X86-64 | Mac OSX |
Xtensa | Linux |
Please send additional platform test results tolibffi-discuss@sourceware.organd feel free to update the wiki page above.
How to get it
You can download the latest version from github here: https://github.com/libffi/libffi/releases/download/v3.4.5/libffi-3.4.5.tar.gz.
You can also check out the very latest version from the development git repository at http://github.com/libffi/libffi. Here's how:
git clone git://github.com/libffi/libffi.git
You can also browse the sources at http://github.com/libffi/libffi.
Mailing lists
For such a small piece of software, there are plenty of mailing lists available.
- libffi-announce is a low volume mailing list for libffi release announcements
- libffi-discuss is a mailing list for asking questions, reporting bugs, etc.
Authors and Credits
libffi was originally written by Anthony Green
The developers of the GNU Compiler Collection project have made innumerable valuable contributions. See this ChangeLog files in the source distribution for details.
Some of the ideas behind libffi were inspired by Gianni Mariani's free gencall library for Silicon Graphics machines.
The closure mechanism was designed and implemented by Kresten Krab Thorup.
Major processor architecture ports were contributed by the following developers:
aarch64 Marcus Shawcroft, James Greenhalgh
alpha Richard Henderson
arc Hackers at Synopsis
arm Raffaele Sena
avr32 Bradley Smith
blackfin Alexandre Keunecke I. de Mendonca
cris Simon Posnjak, Hans-Peter Nilsson
csky Ma Jun, Zhang Wenmeng
frv Anthony Green
ia64 Hans Boehm
kvx Yann Sionneau
loongarch64 Cheng Lulu, Xi Ruoyao, Xu Hao,
Zhang Wenlong, Pan Xuefeng
m32r Kazuhiro Inaoka
m68k Andreas Schwab
m88k Miod Vallat
metag Hackers at Imagination Technologies
microblaze Nathan Rossi
mips Anthony Green, Casey Marshall
mips64 David Daney
moxie Anthony Green
nios ii Sandra Loosemore
openrisc Sebastian Macke
pa Randolph Chung, Dave Anglin, Andreas Tobler
powerpc Geoffrey Keating, Andreas Tobler,
David Edelsohn, John Hornkvist
powerpc64 Jakub Jelinek
riscv Michael Knyszek, Andrew Waterman, Stef O'Rear
s390 Gerhard Tonn, Ulrich Weigand
sh Kaz Kojima
sh64 Kaz Kojima
sparc Anthony Green, Gordon Irlam
tile-gx/tilepro Walter Lee
vax Miod Vallat
x86 Anthony Green, Jon Beniston
x86-64 Bo Thorsen
xtensa Chris Zankel
Jesper Skov and Andrew Haley both did more than their fair share of stepping through the code and tracking down bugs.
Thanks also to Tom Tromey for bug fixes, documentation and configuration help.
Thanks to Jim Blandy, who provided some useful feedback on the libffi interface.
Andreas Tobler has done a tremendous amount of work on the testsuite.
Alex Oliva solved the executable page problem for SElinux.
The list above is almost certainly incomplete and inaccurate. I'm happy to make corrections or additions upon request.
If you have a problem, or have found a bug, please file and issue on our issue tracker at https://github.com/libffi/libffi/issuesThe author can be reached at green@moxielogic.com.