summaryrefslogtreecommitdiff
path: root/Makefile.am
Commit message (Collapse)AuthorAgeFilesLines
* Add new files for distributionAnthony Green2022-09-191-1/+2
|
* Makefile: enable target overridings. (#661)Clément Chigot2022-09-011-0/+2
| | | | | | | | | | This patch allows target to provide extra files enabling the override of Makefile rules. This patch is not needed for libffi itself but only for GCC on AIX. The t-aix file which is here empty will be replaced in GCC repository. We cannot include GCC version directly here because it has no sense for a standalone libffi. Co-authored-by: Clement <clement.chigot@atos.net>
* Support loongarch64 (#678)zhangwenlong2022-05-241-2/+3
| | | | | | | | | | | | | | | * update config.{guess,sub} * Support loongarch64 Co-Authored-By: Cheng Lulu <chenglulu@loongson.cn> Co-Authored-By: Xi Ruoyao <xry111@mengyan1223.wang> Co-Authored-By: Xu Hao Co-Authored-By: Zhang Wenlong <zhangwenlong@loongson.cn> Co-Authored-By: Pan Xuefeng <panxuefeng@loongson.cn> Co-authored-by: panxuefeng <panxuefeng@loongson.cn> Co-authored-by: Cheng Lulu <chenglulu@loongson.cn> Co-authored-by: Xi Ruoyao <xry111@mengyan1223.wang>
* Makefile: Add missing kvx/asm.h to dist headers (#660)Jules Maselbas2021-09-221-1/+1
| | | | | | The header kvx/asm.h is required to build libffi and is missing from the dist tarball. Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
* Static tramp v5 (#624)Madhavan T. Venkataraman2021-03-051-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Static Trampolines Closure Trampoline Security Issue ================================= Currently, the trampoline code used in libffi is not statically defined in a source file (except for MACH). The trampoline is either pre-defined machine code in a data buffer. Or, it is generated at runtime. In order to execute a trampoline, it needs to be placed in a page with executable permissions. Executable data pages are attack surfaces for attackers who may try to inject their own code into the page and contrive to have it executed. The security settings in a system may prevent various tricks used in user land to write code into a page and to have it executed somehow. On such systems, libffi trampolines would not be able to run. Static Trampoline ================= To solve this problem, the trampoline code needs to be defined statically in a source file, compiled and placed in the text segment so it can be mapped and executed naturally without any tricks. However, the trampoline needs to be able to access the closure pointer at runtime. PC-relative data referencing ============================ The solution implemented in this patch set uses PC-relative data references. The trampoline is mapped in a code page. Adjacent to the code page, a data page is mapped that contains the parameters of the trampoline: - the closure pointer - pointer to the ABI handler to jump to The trampoline code uses an offset relative to its current PC to access its data. Some architectures support PC-relative data references in the ISA itself. E.g., X64 supports RIP-relative references. For others, the PC has to somehow be loaded into a general purpose register to do PC-relative data referencing. To do this, we need to define a get_pc() kind of function and call it to load the PC in a desired register. There are two cases: 1. The call instruction pushes the return address on the stack. In this case, get_pc() will extract the return address from the stack and load it in the desired register and return. 2. The call instruction stores the return address in a designated register. In this case, get_pc() will copy the return address to the desired register and return. Either way, the PC next to the call instruction is obtained. Scratch register ================ In order to do its job, the trampoline code would need to use a scratch register. Depending on the ABI, there may not be a register available for scratch. This problem needs to be solved so that all ABIs will work. The trampoline will save two values on the stack: - the closure pointer - the original value of the scratch register This is what the stack will look like: sp before trampoline ------> -------------------- | closure pointer | -------------------- | scratch register | sp after trampoline -------> -------------------- The ABI handler can do the following as needed by the ABI: - the closure pointer can be loaded in a desired register - the scratch register can be restored to its original value - the stack pointer can be restored to its original value (the value when the trampoline was invoked) To do this, I have defined prolog code for each ABI handler. The legacy trampoline jumps to the ABI handler directly. But the static trampoline defined in this patch jumps tp the prolog code which performs the above actions before jumping to the ABI handler. Trampoline Table ================ In order to reduce the trampoline memory footprint, the trampoline code would be defined as a code array in the text segment. This array would be mapped into the address space of the caller. The mapping would, therefore, contain a trampoline table. Adjacent to the trampoline table mapping, there will be a data mapping that contains a parameter table, one parameter block for each trampoline. The parameter block will contain: - a pointer to the closure - a pointer to the ABI handler The static trampoline code would finally look like this: - Make space on the stack for the closure and the scratch register by moving the stack pointer down - Store the original value of the scratch register on the stack - Using PC-relative reference, get the closure pointer - Store the closure pointer on the stack - Using PC-relative reference, get the ABI handler pointer - Jump to the ABI handler Mapping size ============ The size of the code mapping that contains the trampoline table needs to be determined on a per architecture basis. If a particular architecture supports multiple base page sizes, then the largest supported base page size needs to be chosen. E.g., we choose 16K for ARM64. Trampoline allocation and free ============================== Static trampolines are allocated in ffi_closure_alloc() and freed in ffi_closure_free(). Normally, applications use these functions. But there are some cases out there where the user of libffi allocates and manages its own closure memory. In such cases, static trampolines cannot be used. These will fall back to using legacy trampolines. The user has to make sure that the memory is executable. ffi_closure structure ===================== I did not want to make any changes to the size of the closure structure for this feature to guarantee compatibility. But the opaque static trampoline handle needs to be stored in the closure. I have defined it as follows: - char tramp[FFI_TRAMPOLINE_SIZE]; + union { + char tramp[FFI_TRAMPOLINE_SIZE]; + void *ftramp; + }; If static trampolines are used, then tramp[] is not needed to store a dynamic trampoline. That space can be reused to store the handle. Hence, the union. Architecture Support ==================== Support has been added for x64, i386, aarch64 and arm. Support for other architectures can be added very easily in the future. OS Support ========== Support has been added for Linux. Support for other OSes can be added very easily. Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com> * x86: Support for Static Trampolines - Define the arch-specific initialization function ffi_tramp_arch () that returns trampoline size information to common code. - Define the trampoline code mapping and data mapping sizes. - Define the trampoline code table statically. Define two tables, actually, one with CET and one without. - Introduce a tiny prolog for each ABI handling function. The ABI handlers addressed are: - ffi_closure_unix64 - ffi_closure_unix64_sse - ffi_closure_win64 The prolog functions are called: - ffi_closure_unix64_alt - ffi_closure_unix64_sse_alt - ffi_closure_win64_alt The legacy trampoline jumps to the ABI handler. The static trampoline jumps to the prolog function. The prolog function uses the information provided by the static trampoline, sets things up for the ABI handler and then jumps to the ABI handler. - Call ffi_tramp_set_parms () in ffi_prep_closure_loc () to initialize static trampoline parameters. Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com> * i386: Support for Static Trampolines - Define the arch-specific initialization function ffi_tramp_arch () that returns trampoline size information to common code. - Define the trampoline code table statically. Define two tables, actually, one with CET and one without. - Define the trampoline code table statically. - Introduce a tiny prolog for each ABI handling function. The ABI handlers addressed are: - ffi_closure_i386 - ffi_closure_STDCALL - ffi_closure_REGISTER The prolog functions are called: - ffi_closure_i386_alt - ffi_closure_STDCALL_alt - ffi_closure_REGISTER_alt The legacy trampoline jumps to the ABI handler. The static trampoline jumps to the prolog function. The prolog function uses the information provided by the static trampoline, sets things up for the ABI handler and then jumps to the ABI handler. - Call ffi_tramp_set_parms () in ffi_prep_closure_loc () to initialize static trampoline parameters. Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com> * arm64: Support for Static Trampolines - Define the arch-specific initialization function ffi_tramp_arch () that returns trampoline size information to common code. - Define the trampoline code mapping and data mapping sizes. - Define the trampoline code table statically. - Introduce a tiny prolog for each ABI handling function. The ABI handlers addressed are: - ffi_closure_SYSV - ffi_closure_SYSV_V The prolog functions are called: - ffi_closure_SYSV_alt - ffi_closure_SYSV_V_alt The legacy trampoline jumps to the ABI handler. The static trampoline jumps to the prolog function. The prolog function uses the information provided by the static trampoline, sets things up for the ABI handler and then jumps to the ABI handler. - Call ffi_tramp_set_parms () in ffi_prep_closure_loc () to initialize static trampoline parameters. Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com> * arm: Support for Static Trampolines - Define the arch-specific initialization function ffi_tramp_arch () that returns trampoline size information to common code. - Define the trampoline code mapping and data mapping sizes. - Define the trampoline code table statically. - Introduce a tiny prolog for each ABI handling function. The ABI handlers addressed are: - ffi_closure_SYSV - ffi_closure_VFP The prolog functions are called: - ffi_closure_SYSV_alt - ffi_closure_VFP_alt The legacy trampoline jumps to the ABI handler. The static trampoline jumps to the prolog function. The prolog function uses the information provided by the static trampoline, sets things up for the ABI handler and then jumps to the ABI handler. - Call ffi_tramp_set_parms () in ffi_prep_closure_loc () to initialize static trampoline parameters. Signed-off-by: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
* Add support for cskyMa Jun2020-06-291-57/+45
|
* Makefile: increase compatibility with bmake (#551)M. Herdiansyah2020-06-111-1/+1
|
* Add support for Kalray KVX architecture (#559)Yann Sionneau2020-05-011-2/+4
|
* x86: Add indirect branch tracking support (#540)hjl-tools2020-02-211-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Intel Control-flow Enforcement Technology (CET): https://software.intel.com/en-us/articles/intel-sdm contains shadow stack (SHSTK) and indirect branch tracking (IBT). When CET is enabled, ELF object files must be marked with .note.gnu.property section. When Intel CET is enabled, include <cet.h> in assembly codes to mark Intel CET support. Also when IBT is enabled, all indirect branch targets must start with ENDBR instruction and notrack prefix can be used to disable IBT on indirect branch. <cet.h> defines _CET_ENDBR which can be used in assembly codes for ENDBR instruction. If <cet.h> isn't included, define _CET_ENDBR as empty so that _CET_ENDBR can be used in assembly codes. Trampoline must be enlarged to add ENDBR instruction unconditionally, which is NOP on non-CET processors. This is required regardless if libffi is enabled with CET since libffi.so will be marked in legacy bitmap, but trampoline won't. Update library version for larger FFI_TRAMPOLINE_SIZE. This fixed: https://github.com/libffi/libffi/issues/474 Tested with $ CC="gcc -Wl,-z,cet-report=error -fcf-protection" CXX="g++ -Wl,-z,cet-report=error -fcf-protection" .../configure on Linux CET machines in i686, x32 and x86-64 modes.
* Manual clean-ups, and include the PDF in the source distribution.Anthony Green2019-11-221-1/+3
|
* Adapt for new old ChangeLog fileAnthony Green2019-11-181-2/+1
|
* Add make_sunver.pl to distribution.Anthony Green2019-10-261-1/+1
|
* Add missing build script, make_sunver.pl.Anthony Green2019-10-261-2/+2
|
* Strip build status from README.md at 'make dist' time.Anthony Green2019-10-241-0/+1
|
* Add missing dist files.Anthony Green2019-10-241-38/+27
|
* fix mingw build and crashing bugs for Python Windows ARM64 (#496)Paul Monson2019-08-071-0/+1
| | | | | | * fix mingw build and crashing bugs for Python Windows ARM64 * Fix issues found in PR review
* add support for 32-bit ARM on Windows (#477)Paul Monson2019-04-261-0/+1
| | | | | | | | | | | | | | | | | | | | * add support for 32-bit ARM on Windows * fix mismatched brace in appveyor.yml * remove arm platform from appveyor.yml for now * fix arm build * fix typo * fix assembler names * try Visual Studio 2017 * add windows arm32 to .appveyor.yml * update README.md
* Don't set AM_MAKEFLAGSAnthony Green2018-03-271-44/+0
|
* Add libffi.map.in to extra dist filesAnthony Green2018-03-231-1/+2
|
* Fix travis badge. Add REAME.md to dist filesAnthony Green2018-03-131-1/+1
|
* New RISC-V port (#281)Stef O'Rear2018-03-111-0/+2
| | | | | | | | | | | | | | | | | | | | | * Add RISC-V support This patch adds support for the RISC-V architecture (https://riscv.org). This patch has been tested using QEMU user-mode emulation and GCC 7.2.0 in the following configurations: * -march=rv32imac -mabi=ilp32 * -march=rv32g -mabi=ilp32d * -march=rv64imac -mabi=lp64 * -march=rv64g -mabi=lp64d The ABI currently can be found at https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md . * Add RISC-V to README * RISC-V: fix configure.host
* Makefile.am: add 'src/s390/internal.h' to source tarballSergei Trofimovich2017-11-051-1/+1
| | | | | | | | | | | | | | | | | | | commit 2f530de168e0253ac06e044c832132c496e8788b ("s390: Reorganize assembly") introduced new header (similar to other arches) but did not add it to source tarball. As a result build from 'make dist' tarballs failed as: ``` ../src/s390/ffi.c:34:10: fatal error: internal.h: No such file or directory #include "internal.h" ^~~~~~~~~~~~ ``` To fix it the change adds file to 'Makefile.am'. Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
* Merge pull request #319 from angerman/patch-5Tom Tromey2017-10-011-0/+2
|\ | | | | Adds `local.exp` to DISTCLEANFILES
| * Change CLEANFILES to DISTCLEANFILESMoritz Angermann2017-10-021-1/+1
| |
| * Adds `local.exp` to CLEANFILESMoritz Angermann2017-10-011-0/+2
| | | | | | | | | | | | | | With #315, #316, #317, #318 and this patch, running ``` AM_DISTCHECK_CONFIGURE_FLAGS=--disable-docs make distcheck ``` should complete successfully.
* | Merge pull request #316 from angerman/patch-2Tom Tromey2017-10-011-1/+1
|\ \ | | | | | | Add `configure.host` and `libtool-version` to the `EXTRA_DIST` files
| * \ MergedMoritz Angermann2017-10-011-1/+1
| |\ \
| | * | Include `libtool-version` in the EXTRA_DIST files.Moritz Angermann2017-10-011-1/+1
| | |/
| * | Add `configure.host` to the `EXTRA_DIST` filesMoritz Angermann2017-10-011-1/+1
| |/ | | | | When running `make dist`, `configure.host` would not result in the distribution tarball, however `configure` would try to read it, and as such the tarball would not be buildable.
* | Add src/x86/asmnames.h to noinst_HEADERSMoritz Angermann2017-10-011-1/+1
|/ | | In eaa59755fcbb692a8cb763c7f9f24a350aadbd30, macros from `unix64.S` were extracted into `asmnames.h` to be used with `win64.S` as well. As such these are required by `unix64.S`, which fails to build without them.
* Use ELF symbol versioningRichard Henderson2016-05-041-2/+26
| | | | | | At the same time, we must bump the (major) ABI version. This needed to be done anyway due to ABI breakage in the AArch64 port (see 12cf89ee and the corresponding GCC PR70024).
* fix documentation buildingTom Tromey2016-02-221-5/+8
| | | | | | | | | | | | An earlier patch added --disable-docs, but went too far, making it impossible to build the docs. It turns out that Automake seemingly has a bug preventing the conditional build of an info file. So, this patch works around the bug by putting the info_TEXINFOS rule into a new doc/Makefile.am. Tested by building with and without --disable-docs and looking for the existence of doc/libffi.info.
* Add configure-option to disable building docsHavard Graff2015-05-121-1/+5
|
* x86: Best guess at update for DarwinRichard Henderson2015-01-051-1/+0
|
* configure: Move target source selection into configure.hostRichard Henderson2014-11-141-161/+84
| | | | | | | | This eliminates the AM_CONDITIONAL ugliness, which eliminates just a bit of extra boilerplate for a new target. At the same time, properly categorize the EXTRA_DIST files into SOURCES and HEADERS, for the generation of ctags.
* sparc: Rewrite everythingRichard Henderson2014-11-121-2/+2
| | | | | | | | | It's impossible to call between v8 and v9 ABIs, because of the stack bias in the v9 ABI. So let's not pretend it's just not implemented yet. Split the v9 code out to a separate file. The register windows prevent ffi_call from setting up the entire stack frame the assembly, but we needn't make an indirect call back to prep_args.
* arm: Rewrite ffi_closureRichard Henderson2014-11-121-5/+2
| | | | | Move the push of the argument registers into ffi_closure_SYSV, reducing the size of the trampoline.
* x86: Rewrite closuresRichard Henderson2014-11-121-8/+5
| | | | | | | | | Move everything into sysv.S, removing win32.S and freebsd.S. Handle all abis with a single ffi_closure_inner function. Move complexity of the raw THISCALL trampoline into assembly instead of the trampoline itself. Only push the context for the REGISTER abi; let the rest receive it in a register.
* win64: RewriteRichard Henderson2014-11-121-2/+2
| | | | | It's way too different from the 32-bit ABIs with which it is currently associated. As seen from all of the existing XFAILs.
* Add OpenRISC supportSebastian Macke2014-09-271-0/+4
| | | | | | | | | | | | | | | | | | | This patch adds support for the OpenRISC architecture. (http://opencores.org/or1k/Main_Page) This patch has been tested under Linux with QEMU-user emulation support. - 32 Bit - big endian - delayed instructions This is the only available configuration under Linux. The description of the ABI can be found on the official website. Is passes the testsuite except of the unwindtest_ffi_call.cc testcase, which seems to be a problem of gcc and not libffi. Some testcases of the gcc testsuite still fail. Signed-off-by: Sebastian Macke <sebastian@macke.de>
* Support versions of git older than 1.8.5Anthony Green2014-05-111-1/+1
|
* Compile win32.S on FreeBSDJosh Triplett2014-03-251-1/+1
|
* Compile win32.S on 32-bit Darwin as wellJosh Triplett2014-03-241-0/+3
|
* Change double quotes in Makefile.am to single quotes.Ryan VanderMeulen2014-03-161-33/+33
| | | | This was originally done in PR #84, except the change was made to Makefile.in instead of Makefile.am and was therefore reverted the next time the files were regenerated.
* Merge pull request #98 from joshtriplett/unconfigure.hostAnthony Green2014-03-161-1/+1
|\ | | | | Merge configure.host into configure.ac
| * Merge configure.host into configure.acJosh Triplett2014-03-161-1/+1
| | | | | | | | | | configure.host only has a single entry, and shows no signs of needing more added.
* | Generate ChangeLog from git in make distJosh Triplett2014-03-161-1/+3
|/ | | | Archive the existing ChangeLog to ChangeLog.libffi-3.1
* Add support for stdcall, thiscall, and fastcall on non-Windows x86-32Josh Triplett2014-03-161-1/+1
| | | | | | | | | Linux supports the stdcall calling convention, either via functions explicitly declared with the stdcall attribute, or via code compiled with -mrtd which effectively makes stdcall the default. This introduces FFI_STDCALL, FFI_THISCALL, and FFI_FASTCALL on non-Windows x86-32 platforms, as non-default calling conventions.
* Update Makefile for new darwin scriptsAnthony Green2014-03-011-2/+1
|
* Add missing -DFFI_DEBUG flagAnthony Green2014-02-281-0/+7
|