src


Log

Author Commit Date CI Message
Anthony Green 074c423f 2025-06-08T07:30:54 feat: Add ffi_get_default_abi and ffi_get_closure_size functions
Anthony Green c9a3a06f 2025-05-26T08:18:13 feat(libffi): upgrade to version 3.5.0 and add version API
Peter Bergner aea22de2 2025-04-18T10:09:45 powerpc: Fix closures on powerpc64-linux when statically linking (#900) (#902) Closures on powerpc64-linux using static trampolines do not work when statically linking libffi. The problem is the usage of tramp_globals.text in libffi assumes it contains the entry point address of the first trampoline. Powerpc's ffi_tramp_arch code returns &trampoline_code_table which for ABIs that use function descriptors, ends up returning trampoline_code_table's function descriptor address instead of its entry point address. Update the code to always return the entry point address for all ABIs.
Sam James a431b478 2025-04-15T10:30:27 pa: add .note.GNU-stack marker to linux.S (#899) Similarly to f515eac04cf8e5f594d5d9dee5fb7dfc3a186a4c, add a .note.GNU-stack marker to pa/linux.S as it doesn't need an executable stack. Absence of the note means that GNU Binutils will consider it as needing an executable stack and mark it as such automatically. When building libffi on HPPA with `-Wl,--warn-warn-execstack`, we get: ``` ld: warning: src/pa/.libs/linux.o: missing .note.GNU-stack section implies executable stack ld: NOTE: This behaviour is deprecated and will be removed in a future version of the linker ``` That becomes more problematic with glibc-2.41 which forbids dlopen() of a library with an executable stack, and libffi is commonly dlopen()'d, especially by Python. I suspect the reason it didn't show up on Debian is that since February, Debian has been building Binutils with --disable-default-execstack. Bug: https://bugs.gentoo.org/953805 Bug: https://github.com/libffi/libffi/issues/898
Peter Bergner 3429ed6b 2025-04-08T05:52:37 powerpc: Add static trampoline support (#894) (#895) Add static trampoline support to all three powerpc Linux ABIs, specifically powerpc-linux (32-bit SYSV BE), powerpc64-linux (64-bit ELFv1 BE) and powerpc64le-linux (64-bit ELFv2 LE). This follows the s390x implementation and does not introduce a ffi_closure_*_alt function, but rather jumps directly to the ffi_closure_* function itself. If compiling with --with-gcc-arch=power10 and pc-relative is enabled, we use a simpler and smaller trampoline that utilizes Power10's new pc-relative load instructions.
mikulas-patocka fe203ffb 2025-03-27T01:31:49 Fix bugs in the x86-64 and x32 target (#887) (#889) This commit fixes two bugs in ffi in the x86-64 target. The bugs were introduced by the commit d21881f55ed4a44d464c9091871e69b0bb47611a ("Fix x86/ffi64 calls with 6 gp and some sse registers"). The first bug is that when we pass an argument with less than 8 bytes, ffi will read memory beyond argument end, causing a crash if the argument is located just before the end of the mapped region. The second bug is in the x32 ABI - pointers in x32 are 4-byte, but GCC assumes that the pointer values in the registers are zero-extended. ffi doesn't respect this assumption, causing crashes in the called library. For example, when we compile this function for x32: int fn(int *a) { if (a) return *a; return -1; } we get this code: fn: testq %rdi, %rdi je .L3 movl (%edi), %eax ret .L3: movl $-1, %eax ret When we call this function using ffi with the argument NULL, the function crashes because top 4 bytes of the RDI register are not cleared. Fixes: d21881f55ed4 ("Fix x86/ffi64 calls with 6 gp and some sse registers (#848)") Signed-off-by: Mikulas Patocka <mikulas@twibright.com>
fossdd 89c99d73 2025-02-28T22:10:10 MIPS: Dont import asm/sgidefs.h on linux (#885) Removed from Linux since Linux 3.7 Ref: https://web.git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=61730c538f8281efa7ac12596da9f3f9a31b9272
Bill Roberts 5ceddf40 2025-02-20T04:25:21 aarch64: add PAC to GNU Notes (#882) While PAC was enabled, the bit to indicate support in the GNU Notes section of the ELF was missing. Before: readelf -n ./aarch64-unknown-linux-gnu/.libs/libffi.so Displaying notes found in: .note.gnu.property Owner Data size Description GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0 Properties: AArch64 feature: BTI This was caused by this file not having PAC indicated in GNU Notes and the linker discarding it: File: ./aarch64-unknown-linux-gnu/src/aarch64/sysv.o Displaying notes found in: .note.gnu.property Owner Data size Description GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0 Properties: AArch64 feature: BTI Now it has it: File: ./aarch64-unknown-linux-gnu/src/aarch64/sysv.o Displaying notes found in: .note.gnu.property Owner Data size Description GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0 Properties: AArch64 feature: BTI, PAC As well as the output shared object: readelf -n ./aarch64-unknown-linux-gnu/.libs/libffi.so Displaying notes found in: .note.gnu.property Owner Data size Description GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0 Properties: AArch64 feature: BTI, PAC Fixes: #881 Signed-off-by: Bill Roberts <bill.roberts@arm.com>
Anthony Green 1716f81e 2025-02-08T11:32:05 feat: remove nios2 support Acked-by: Anthony Green <green@moxielogic.com>
Kleis Auke Wolthuizen adfe4489 2025-01-31T21:41:56 Emscripten: remove support for `-sWASM_BIGINT=0` (#874) * Emscripten: cleanup * Emscripten: remove support for `-sWASM_BIGINT=0` * Emscripten: remove redundant CircleCI config * Emscripten: modernize CI * Ensure test helper methods are static Similar to #644. * Fix test failures in `cls_multi_{s,u}shortchar`
Matthew Flatt 2f34cf63 2025-01-31T13:40:40 x86 Darwin returns structs of size 1, 2, 4, and 8 in registers (#876)
zye2-sc a0d8074a 2025-01-31T21:40:00 Disable go closures on Android (#877) * x18 register shouldn't be used on Android due to the shadow call stack feature in llvm * https://source.android.com/docs/security/test/shadow-call-stack
Icenowy Zheng f515eac0 2024-12-13T18:36:02 MIPS: add .note.GNU-stack section to assembly sources (#872) To build ELF shared libraries that do not require executable stack on MIPS, every object file linked should have a .note.GNU-stack section, otherwise the linker defaults to executable stack. As libffi shouldn't require executable stack, add the .note.GNU-stack section to the assembly source files under src/mips, like other architectures. Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
Eddy S. 458b2ae2 2024-11-16T13:03:24 Add static trampoline support for s390 (#862) * added static trampoline support for s390 * enable static tramp only for s390x 64bit
Ivan Tadeu Ferreira Antunes Filho 8308bed5 2024-09-20T06:01:23 Move cfi_startproc after CNAME(label) (#857) This is a fix for https://github.com/libffi/libffi/issues/852: error: invalid CFI advance_loc expression on apple targets. The CFI for darwin arm64 was broken because the CNAME macro was being used after the cfi_startproc macro.
KJ Tsanaktsidis 01db744b 2024-09-20T20:00:49 Disable ASAN in ffi_call_int functions (#858) The pattern for several of the architectures is for ffi_call_int to stack-allocate some arguments + the registers, and then ffi_call_$ARCH will pop the top of that structure into registers, and then adjust the stack pointer such that the alloca'd buffer _becomes_ the stack-passed arguments for the function being called. If libffi is compiled with ASAN, then there will be a redzone inserted after the alloca'd buffer which is marked as poisoned. This redzone appears beyond the end of $sp upon entry to the called function. If the called function does anything to use this stack memory, ASAN will notice that it's poisoned and report an error. This commit fixes the situation (on the architectures that I have access to) disabling instrumentation for ffi_call_int; that means there will be no alloca redzone left on the shadow-stack.
Richard Barnes 348e70ef 2024-09-15T07:39:51 Suppress unused variable warning in dlmalloc.c (#843) Allows `-Wunused-but-set-variable` to pass
Yuriy Kolerov 30e887f8 2024-09-15T14:39:01 A series of fixes for ARC port (#844) * arc: Fix warnings These warnings are fixed: 1. A series of "unused variables". 2. Implicit conversion from a pointer to uint32_t. Signed-off-by: Yuriy Kolerov <ykolerov@synopsys.com> * arc: Do not use mov_s and movl_s instructions mov_s and movl_s instructions use a restricted set of registers. However, a list of available registers for such instructions for one ARC target may not match a list for another ARC targets. For example, it is applicable to ARC700 and ARC HS3x/4x - build fails because mov_s formats may be incompatible in some cases. The easiest and the most straightforward way to fix this issue is to use mov and movl instead of mov_s and movl_s. Signed-off-by: Yuriy Kolerov <ykolerov@synopsys.com> --------- Signed-off-by: Yuriy Kolerov <ykolerov@synopsys.com>
kellda d21881f5 2024-09-15T13:29:42 Fix x86/ffi64 calls with 6 gp and some sse registers (#848) * Fix x86/ffi64 calls with 6 gp and some sse registers * Add test demonstating issue when mixing gp and sse registers
Thomas Petazzoni 8a0d0292 2024-09-15T13:22:36 OpenRISC/or1k build fixes (#854) * src/or1k/ffi.c: fix prototype of ffi_call_SYSV() The current code base of libffi on OpenRISC (or1k) fails to build with GCC 14.x with the following error: ../src/or1k/ffi.c: In function 'ffi_call': ../src/or1k/ffi.c:167:34: error: passing argument 3 of 'ffi_call_SYSV' from incompatible pointer type [-Wincompatible-pointer-types] 167 | ffi_call_SYSV(size, &ecif, ffi_prep_args, rvalue, fn, cif->flags); | ^~~~~~~~~~~~~ | | | void * (*)(char *, extended_cif *) ../src/or1k/ffi.c:113:27: note: expected 'void * (*)(int *, extended_cif *)' but argument is of type 'void * (*)(char *, extended_cif *)' 113 | void *(*)(int *, extended_cif *), | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ This is due to the fact that ffi_prep_args() is in fact defined as: void* ffi_prep_args(char *stack, extended_cif *ecif) so, let's fix the prototype of the function pointer, which anyway gets passed to assembly code, so the typing gets lost. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> * src/or1k/ffi.c: fix incompatible pointer type The current code base of libffi on OpenRISC (or1k) fails to build with GCC 14.x with the following error: ../src/or1k/ffi.c: In function 'ffi_closure_SYSV': ../src/or1k/ffi.c:183:22: error: initialization of 'char *' from incompatible pointer type 'int *' [-Wincompatible-pointer-types] 183 | char *stack_args = sp; | ^~ Indeed: register int *sp __asm__ ("r17"); [..] char *stack_args = sp; Adopt the same logic used for: char *ptr = (char *) register_args; which consists in casting to the desired pointer type. Indeed, later in the code stack_args is assigned to ptr (so they need to be the same pointer type), and some arithmetic is done on ptr, so changing its pointer type would change the behavior. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> --------- Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Anthony Green 8e3ef965 2024-06-28T04:07:09 Fix struct args (Rainer Orth)
Martin Storsjö 9c9e8368 2024-06-04T14:13:08 aarch64: Add a missing no-op define of SIGN_LR_LINUX_ONLY (#838) This is needed at least if building for Linux, with a toolchain that doesn't default to having PAC enabled, fixing build errors since 45d284f2d066cc3a080c5be88e51b4d934349797.
Bill Roberts 45d284f2 2024-06-01T12:34:53 aarch64: support pointer authentication (#834) * aarch64: fix callstack in ffi_call_SYSV The debug stack gets corrupted between the frame and stack pivots, update the CFI directives so the call stack stays correct in the debugger. str x9, [x1, #32] // stack is ffi_call_SYSV() -> ffi_call_int() -> ffi_call_int() -> main() (good) mov x29, x1 // stack is ffi_call_SYSV() -> ffi_call_int() -> ffi_call_int() -> ffi_call() -> main() (bad) mov sp, x0 // stack is ffi_call_SYSV() -> ffi_call_int() -> ffi_call_int() -> main() (good) The CFA data needs to be updated around the pivots, after this patch the callstack stays correct. Signed-off-by: Bill Roberts <bill.roberts@arm.com> * aarch64: remove uneeded CFI directive This directive doesn't actually set the CFA to anything valid, and during unwinding this isn't even used. Note that the PAC/Darwin usage is quite suspect as well, as the CFA is either x1 or x29 after the frame pivot, and the CFA address is what's used as the modifier when verifying the PAC. At least this is the behavior on Linux with PAC, I need to verify ARME ABI unwinding. So for now leave Darwin as is. Signed-off-by: Bill Roberts <bill.roberts@arm.com> * ptrauth: rename define for clarity Rename the HAVE_PTRAUTH define for clarity that its associated with the ARM64E ABI and not the ARM64 ABI that can be supported on Linux and enabled with -mbranch-protection=standard. Signed-off-by: Bill Roberts <bill.roberts@arm.com> * aarch64: add PAC support to ffi_call_SYSV Support AARCH64 Pointer Authentication Codes (PAC) within ffi_call_SYSV and support exception unwinding. The Linux ABI for PAC is to use paciasp/autiasp instructions which also have hint space equivelent instructions. They sign the LR (x30) with the A key and the current stack pointer as the salt. Note that this can also be configured to use the B key and will use pacibsp/autibsp hint instructions. The Linux ABI for exception frame data when PAC is enabled assumes that the Connonical Frame Address, or CFA is equal to the stack pointer. I.E sp is equal to x29 (fp). When the unwinder is invoked the cfa will point to the frame which will include the *signed* return address from the LR. This will then be passed to __builtin_aarch64_autia1716 where the CFA will be used as the salt and stored to register x16 and register x17 will contain the signed address to demangle. This can be noted in: - https://github.com/gcc-mirror/gcc/blob/d6d7afcdbc04adb0ec42a44b2d7e05600945af42/libgcc/config/aarch64/aarch64-unwind.h#L56 The other required portion of this is to indicate to the unwinder that this is a signed address that needs to go the special demangle route in the unwinder. This is accomplished by using CFI directive "cfi_window_save" which marks that frame as being signed. Putting all of this together is a bit tricky, as the internals of ffi_call_SYSV the callee allocates its stack and frame and passes it in arg1 (x0) and arg2 (x1) to the called function, where that function pivots its stack, so care must be taken to get the sp == fp before paciasp is called and also restore that state before autiasp is called. Signed-off-by: Bill Roberts <bill.roberts@arm.com> --------- Signed-off-by: Bill Roberts <bill.roberts@arm.com>
Bill Roberts 38732240 2024-06-01T12:33:28 ffi: fix spelling mistake (#833) Signed-off-by: Bill Roberts <bill.roberts@arm.com>
Bill Roberts f64141ee 2024-03-19T11:44:55 Fix bti support (#830) * bti: add identifier to ffi_closure_SYSV_V_alt This was missing BTI_C identifier. Old Code: ffi_closure_SYSV_V_alt: 0000fffff7f70500: ldr x17, [sp, #8] Signed-off-by: Bill Roberts <bill.roberts@arm.com> * testsuite: fix whitespace in Makefile.am Signed-off-by: Bill Roberts <bill.roberts@arm.com> * aarch64: correct comment describing BTI The comment is incorrect, BTI is enabled per mapping via mprotect with PROT_BTI flag set, not per-process. When the loader loads the library, if the GNU Notes section is missing this, PROT_BTI will not be enabled for that mapping, but is independent of other mappings. Signed-off-by: Bill Roberts <bill.roberts@arm.com> --------- Signed-off-by: Bill Roberts <bill.roberts@arm.com>
Anthony Green cd78b539 2024-02-18T07:48:51 Always define long double types.
Xi Ruoyao 04f6fa31 2024-02-15T20:52:13 mips: Fix N32 ABI return value handling (#813) In N32 ABI, 8-bit or 16-bit integers should be extended following the signedness of the integer, but 32-bit integers should always be sign-extended to 64-bit (note that N32 ABI only works on 64-bit CPUs). So handling this in everything using libffi would be nasty. And the libffi code for architectures with a similar rule (LoongArch & RISC-V) also properly handle this. Let's do this work in libffi for MIPS N32 too. This fixes two failures in Python 3.12.1 ctypes test.
杨屿杰 00c0c877 2024-02-15T20:51:40 Fix loongarch64 soft-float build (#816) (#817)
Hood Chatham b3091029 2024-02-15T04:51:12 Emscripten: Don't unbox single element structs if they are larger than 16 bytes (#818) This arguably is a compensation for a Python ctypes bug / strange behavior described here: https://github.com/python/cpython/blob/a16a9f978f42b8a09297c1efbf33877f6388c403/Modules/_ctypes/stgdict.c#L718-L779 If a struct is larger than 16 bytes, Python does not bother to accurately report its contents figuring that we don't need to know.
Bill Roberts 98881ecb 2024-02-15T06:50:40 aarch64: add BTI flag to ELF notes (#822) When a program is loaded and linked, the first ELF file that doesn't declare that BTI is supported in the GNU NOTES section disables BTI support. Example: readelf -n ./aarch64-unknown-linux-gnu/.libs/libffi.so Displaying notes found in: .note.gnu.property Owner Data size Description GNU 0x00000010 NT_GNU_PROPERTY_TYPE_0 Properties: AArch64 feature: BTI Fixes: #823 Signed-off-by: Bill Roberts <bill.roberts@arm.com>
Xi Ruoyao f8ed78f1 2024-02-15T20:49:27 LoongArch: Fix a build error with GCC 14 (#825) Fix the build error with GCC 14: ../src/loongarch64/ffi.c: In function 'ffi_prep_closure_loc': ../src/loongarch64/ffi.c:525:7: error: implicit declaration of function 'ffi_tramp_set_parms' [-Wimplicit-function-declaration]
Виктор Чернякин a1c391bd 2023-12-22T03:30:50 Fix a variety of warnings (#811)
Martin Storsjö 5b1944b4 2023-11-29T00:38:13 aarch64: Write the BTI instructions as "hint" instructions (#810) GNU binutils refuses to assemble the direct BTI instructions unless the target architecture explicitly supports BTI, ending up with errors such as ../src/aarch64/sysv.S: Assembler messages: ../src/aarch64/sysv.S:87: Error: selected processor does not support `bti c' ../src/aarch64/sysv.S:156: Error: selected processor does not support `bti j' Building with -march=armv8.5-a fixes building this. However, the BTI instructions assemble into hint instructions, that are ignored by processors that don't implement them. Therefore it is possible to assemble them for the baseline armv8.0-a target as well, by replacing "bti j" with "hint #36", "bti c" with "hint #34" and "bti jc" with "hint #38"; this assembles into the same instruction bits.
David Tenty 7f960d9a 2023-11-23T09:16:35 [powerpc][AIX] fix layout issues for nested struct types (#805) * [powerpc][AIX] fix layout issues for nested struct types On AIX under the default power alignment rules, the layout of struct types which are nested inside other structs may be different than the layout of those types on their own. Specifically the first member double rules which would apply an eight byte alignment if that type appears in the first position of a struct: 1) apply recursively if the struct appear in the first member of another struct 2) do not apply if that struct is itself a member of another struct and not the first member. The current implementation of the rules in libffi doesn't handle these cases, causing a mismatch with the compiler and causing some crashes we see when OpenJ9 is used with libffi on AIX. This PR corrects this and adds some representative test cases. * Fix code style * Add a size check * Add additional test * Fix padding in internal structs * Flip condition back to original form * Add a comment
Tobias Heider d93c0be8 2023-11-23T15:15:29 Add bti intructions to aarch64 assembly to work with strict (#808) BTI enforcement on OpenBSD.
Petr Sumbera dd907495 2023-10-21T13:42:11 Fix passing floating point arguments on 64bits SPARC (libffi#778) (#802)
Michael Osipov 5c6e53db 2023-09-04T13:27:01 Fix build failures on HP-UX (#792) This fixes #328 Co-authored-by: Chris Hunt <chrahunt@gmail.com>
Ivan Tadeu Ferreira Antunes Filho 1d0a28ab 2023-08-12T09:02:39 Make label private on apple (#788) Private labels on apple must start with L prefix, while on ELF they start with .L prefix. This makes the label start with L on apple instead of .L.
Claudiu Zissulescu c4df19c9 2023-02-18T03:33:47 Update ARC's libffi port (#771) * Add support for ARC and ARC64 Add support for ARC/ARC32/ARC64 * Implementation of GO Closure for ARC/ARC32/ARC64 Architectures --------- Co-authored-by: Nuno Cardoso <cardoso@synopsys.com> Co-authored-by: Luis Silva <luiss@synopsys.com>
Hood Chatham 2687cfc5 2023-02-02T09:10:00 Add wasm32 emscripten support (#763) * added build script * Apply libffi-emscripten patch * Some changes to wasm32/ffi.c * Remove exit(0); from test suites * Fix LONGDOUBLE argument type * Use more macros in ffi.c * Use switch statements instead of if chains * Implemented struct args * Finish struct implementation * Partially working closures * Got closures working (most of closures test suite passes) * Revert changes to test suite * Update .gitignore * Apply code formatter * Use stackSave and stackRestore rather than directly adjusting stack pointer * Add missing break * Fix visibility of ffi_closure_alloc and ffi_closure_free * Fix FFI_TYPE_STRUCT and FFI_TYPE_LONGDOUBLE when WASM_BIGINT is not used sig needs to be vi here for FFI_TYPE_STRUCT and FFI_TYPE_LONGDOUBLE, noticed this while running the test suite without WASM_BIGINT support. * Always use dynCall rather than direct wasmTable lookup (function pointer cast emulation changes dynCall) * Prevent closures.c from duplicating symbols * Try to set up CI * Add test with bigint * Make test methods static * Remove BigInt shorthand because it messes up terser * Add selenium tests * Update tests a bit to try to make CI work * WASM_BIGINT is a linker flag not a compile flag * Finish getting CI working (#1) * update gitignore * Avoid adding "use strict;" to generated JS This should be controlled by -s STRICT_JS in Emscripten. * Make JavaScript ES5 compliant * Remove redundant EXPORTED_RUNTIME_METHODS settings * Fix definition of DEREF_I16 * Avoid marshalling FFI_TYPE_LONGDOUBLE when WASM_BIGINT is not used * Add missing FFI_TYPE_STRUCT signature * Improve test scripts * Remove redundant EXPORTED_RUNTIME_METHODS settings * Add missing EOL * Add struct unpacking tests * Update ci config to try to actually use WASM_BIGINT * Revert "Avoid marshalling FFI_TYPE_LONGDOUBLE when WASM_BIGINT is not used" This reverts commit 61bd5a3e20891623715604581b6e872ab3dfab80. * Fix single_entry_structs tests * Fix return from closure call * Fix 64 bit return from closures * only allocate as much space on stack for return pointer as needed * Revert "only allocate as much space on stack for return pointer as needed" This reverts commit e54a30faea3803e7ac33eed191bde9e573850fc1. * xfail two tests * Fix err_bad_abi test * Remove test logging junk * Try to set up long double marshalling for closures * xfail err_bad_abi * Fix reference errors in previous commit * Add missing argument pointer assignment * Fix signature of function pointer in cls_dbls_struct * Fix longdouble argument * Try some changes to bigint handling * Fix BigInt handling * Fix cls_longdouble test * Fix long double closure arg with no WASM_BIGINT * Use EM_JS to factor out js helpers * Support for varargs closure calls * Fix varargs calls * Fix err_bad_abi test * Fix typo in previous commit * Add more assertions to closures test suite * Fix some asserts * Add assertions to a few more tests * Fix some tests * Fix more floating point assertions * Update more tests * Var args for ffi_call * Don't do node tests * Macro for allocating on stack * Add some comments, simplify struct handling * Try again to fix varargs calls, add comments * Consolidate WASM_BIGINT conditionals into LOAD_U64 and STORE_U64 macros * A bit of cleanup * Fix another typo * Some fixes to the testsuite * Another testsuite fix * Fix varags with closures? * Another attempt at getting closure varargs to work * sig is initialized later * Allow libffi.closures tests to be run * Improve build script * Remove redundant semicolons * Fix a few libffi.closures test failures * Cleanup * Legacy dynCall API is no longer used * Fix FFI_TYPE_LONGDOUBLE offset * xfail 2 tests for WASM - closure_loc_fn0; not applicable -- codeloc doesn't point to closure. - huge_struct; function signature too long. * Revert some redundant dg-output/printf statements Helps Node. * Revert "Don't do node tests" This reverts commit a341ef4b. * Fix assertions in cls_24byte * More tiny formating fixes to test suite * Revert "Revert "Don't do node tests"" This reverts commit 7722e685ea04e2420e042886816d8c4dd31f5dcb. * Fix 64 bit returns when WASM_BIGINT is absent * Fix print statement in cls_24byte * Add CALL_FUNC_PTR macro to allow pyodide to define custom calling behavior to handle fpcast * Update single_entry_structs tests * More explanations * Fix compile error in last commit * Add more support for pyodide fpcast emulation, update CI to try to test it * Clone via https * Fix path to pyodide emsdk_env * Add asserts to the rest of the test suite * Fix test compile errors * Fix some tests * Fix cls_ulonglong * Fix alignment of <4 byte args * fix cls_ulonglong again * Use snprintf instead of sprintf * Should assert than strncmp returned 0 * Fix va_struct1 and va_struct3 * Change double and long double tests These tests are failing because of a strange bug with prinft and doubles, but I am not convinced it necessarily has anything to do with libffi. This version casts the double to int before printing it and avoids the issue * Enable node tests * Revert "Change double and long double tests" This reverts commit 8f3ff89c6577dc99564181cd9974f2f1ba21f1e9. * Fix PYODIDE_FPCAST flag * add conftest.py back in * Fix emcc error: setting `EXPORTED_FUNCTIONS` expects `<class 'list'>` but got `<class 'str'>` See discussion on https://github.com/pyodide/pyodide/pull/1596 * Remove test.html * Remove duplicate test file * More changes from upstream * Fix some whitespace * Add some basic debug logging statements * Reapply libffi.exp changes * Don't build docs (#7) Works around build issue makeinfo: command not found. * Update long double alignment Emscripten 2.0.26 reduces the aligmnet of long double to 8. Quoting from `ChangeLog.md`: > The alignment of `long double`, which is a 128-bit floating-point > value implemented in software, is reduced from 16 to 8. The lower > alignment allows `max_align_t` to properly match the alignment we > use for malloc, which is 8 (raising malloc's alignment to achieve > correctness the other way would come with a performance regression). > (#10072) * Update long double alignment Emscripten 2.0.26 reduces the aligmnet of long double to 8. Quoting from `ChangeLog.md`: > The alignment of `long double`, which is a 128-bit floating-point > value implemented in software, is reduced from 16 to 8. The lower > alignment allows `max_align_t` to properly match the alignment we > use for malloc, which is 8 (raising malloc's alignment to achieve > correctness the other way would come with a performance regression). > (#10072) * Improve error handling a bit (#8) * Fix handling of signed arguments to ffi_call (#11) * Fix struct argument handling in ffi_call (#10) * Remove fpcast emulation tests * Align the stack to MAX_ALIGN before making call (#12) * Increase MAX_ARGS * Cleanup (#14) * Fix Closure compiler error with -sASSERTIONS=1 (#15) * Remove function pointer cast emulation (#13) This reverts commit 593b402 and cbc54da, as it's no longer needed after PR pyodide/pyodide#2019. * Prefer the `__EMSCRIPTEN__` definition over `EMSCRIPTEN` (#18) "The preprocessor define EMSCRIPTEN is deprecated. Don't pass it to code in strict mode. Code should use the define __EMSCRIPTEN__ instead." https://github.com/emscripten-core/emscripten/blob/84a634167a1cd9e8c47d37a559688153a4ceace6/emcc.py#L887-L890 * Install autoconf 2.71 * Try again with installing autoconf 2.71 * Fix compatibility with Emscripten 3.1.28 * CI: remove use of `EM_CONFIG` env See commit: https://github.com/emscripten-core/emsdk/commit/3d87d5ea8143b3636f872fb05b896eb4a19a070b * Fix cls_multi_schar: cast rest_call to signed char * Remove test xfails (#17) * Fix long double when used as a varargs argument * Enable unwindtest and fix it * Add EM_JS_DEPS * Also require convertJsFunctionToWasm * Run tests very very verbose * Echo the .emscripten file * Remove --experimental-wasm-bigint insertion * Build with assertions * Move verbosity flags back out of LDFLAGS * Remove debug print statement * Use up to date pyodide docker image * Explicitly cast res_call to fix test failure * Put back name of main function in cls_longdouble_va.c * Fix alignment The stack pointer apparently needs to be aligned to 16. There were some terrible subtle bugs caused by not respecting this. stackAlloc knows that the stack should be 16 aligned, so we can use stackAlloc(0) to enforce this. This way if alignment requirements change, as long as Emscripten updates stackAlloc to continue to enforce them we should be okay. * Fix handling of systems with no Js bigint integration When we run the node tests we use node v14 tests (since node v14 is vendored with Emscripten). Node v14 has no Js bigint integration unless the --experimental-wasm-bigint flag is passed. So only the node tests really notice if we get this right. Turns out, it didn't work. We can't call a JavaScript function with 64 bit integer arguments without bigint integration. In ffi_call, we are trying to call a wasm function that takes 64 bit integer arguments. dynCall is designed to do this. We need to go back to tracking the signature when we don't have WASM_BIGINT, and then use dynCall. This works better now that emscripten can dynamically fill in extra dynCall wrappers: https://github.com/emscripten-core/emscripten/pull/17328 On the other hand, for the closures we are not getting a function pointer as a first argument. We need to make our own wasm legalizer adaptor that splits 64 bit integer arguments and then calls the JavaScript trampoline, then the JavaScript trampoline reassembles them, calls the closure, then splits the result (if it's a 64 bit integer) and the adaptor puts it back together. * Improvements to emscripten test shell scripts (#21) This fixes the C++ unwinding tests and makes other minor improvements to the Emscripten test shell scripts. * Rename the test folder and move test files into emscripten test folder * Use docker image that has autoconf-2.71 * Cleanup * Pin emscripten 3.1.30 * Fix build.sh path * Rearrange ci pipeline * Fix bpo_38748 test * Cleanup * Improvements to comments, add static asserts, and update copyright * Use `*_js` instead of `*_helper` for EM_JS functions (#22) * Minor code simplification * Xfail first dejagnu test to work around emscripten cache messages See https://github.com/emscripten-core/emscripten/issues/18607 * Remove unneeded xfails * Shorten conftest.py by using pytest-pyodide * Apply formatters and linters to emscripten directory * Fix Emscripten xfail hack * Fix build-tests script * Patch emscripten to quiet info messages * Clean up compiler flags in scripts and remove some settings from circleci config * Rename emscripten quiet script * Add missing export * Don't remove go.exp * Add reference to emscripten logging issue --------- Co-authored-by: Kleis Auke Wolthuizen <info@kleisauke.nl> Co-authored-by: Kleis Auke Wolthuizen <github@kleisauke.nl> Co-authored-by: Christian Heimes <christian@python.org>
serge-sans-paille ce077e55 2023-02-02T14:46:29 Forward declare open_temp_exec_file (#764) It's defined in closures.c and used in tramp.c. Also declare it as an hidden symbol, as it should be. Co-authored-by: serge-sans-paille <sguelton@mozilla.com>
Anthony Green 222abd0c 2023-02-02T07:04:55 From Dave Anglin: This patch is derived from the work done in implementing libffi for 64-bit hppa64-hpux target. Currently, the 32-bit hppa targets do a linear search for the return type of an ffi_call. This is slow and inefficient. A jump table can used to jump directly to the code used to process the return value. In most common cases, the return value can be processed in the jump table itself. The patch also fixes return handling for FFI_TYPE_UINT8, FFI_TYPE_SINT8, FFI_TYPE_UINT16 and FFI_TYPE_SINT16.
Anthony Green e58e22b2 2023-02-02T07:02:53 From Dave Anglin: A couple of years ago the 32-bit hppa targets were converted from using a trampoline executed on the stack to the function descriptor technique used by ia64. This is more efficient and avoids having to have an executable stack. However, function pointers on 32-bit need the PLABEL bit set in the pointer. It distinguishes between pointers that point directly to the executable code and pointer that point to a function descriptor. We need the later for libffi. But as a result, it is not possible to convert using casts data pointers to function pointers. The solution at the time was to set the PLABEL bit in hppa closure pointers using FFI_CLOSURE_PTR. However, I realized recently that this was a bad choice. Packages like python-cffi allocate their own closure pointers, so this isn't going to work well there. A better solution is to leave closure pointers unchanged and only set the PLABEL bit in pointers used to point to executable code. The attached patch drops the FFI_CLOSURE_PTR and FFI_RESTORE_PTR defines. This allows some cleanup in the hppa closure routines. The FFI_FN define is now used to set the PLABEL bit on hppa. ffi_closure_alloc is modified to set the PLABEL bit in the value set in *code. I also added a FFI_CL define to convert a function pointer to a closure pointer. It is only used in one test case.
Anthony Green baa6bbbc 2023-02-02T06:59:46 Add HPPA64 support
Iain Sandoe e70dd1aa 2023-02-02T11:44:13 libffi: Fix X86 32b Darwin build and EH frames. (#757) This addresses a number of issues in the X86 Darwin 32b port for libffi. 1. The pic symbol stubs are weak definitions; the correct section placement for these depends on the linker version in use. We do not have access to that information, but we can use the target OS version (assumes that the user has installed the latest version of xcode available). When a coalesced section is in use (OS versions earlier than Darwin12 / OSX 10.8), its name must differ from __TEXT,__text since otherwise that would correspond to altering the attributes of the .text section (which produces a diagnostic from the assembler). Here we use __TEXT, __textcoal_nt for this which is what GCC emits for these stubs. For later versions than Darwin 12 (OS X 10.8) we can place the stubs in the .text section (if we do not we get a diagnostic from clang -cc1as saying that the use of coalesced sections for this is deprecated). 2. The EH frame is specified manually, since there is no support for .cfi_ directives in 'cctools' assemblers. The implementation needs to provide offsets for CFA advance, code size and to the CIE as signed values rather than relocations. However the cctools assembler will produce a relocation for expressions like ' .long Lxx-Lyy' which then leads to a link-time error. We correct this by forming the offset values using ' .set' directives and then assigning the results of them. 3. The register numbering used by m32 X86 Darwin EH frames is not the same as the DWARF debug numbering (the Frame and Stack pointer numbers are swapped). 4. The FDE address encoding used by the system tools is '0x10' (PCrel + abs) where the value provided was PCrel + sdata4. 5. GCC does not use compact unwind at present, and it was not implemented until Darwin10 / OSX 10.6. There were some issues with function location in 10.6 so that the solution here suppresses emitting the compact unwind section until Darwin11 / OSX 10.7.
serge-sans-paille ebbc5e14 2023-02-02T11:40:17 Fix signed vs unsigned comparison (#765) As reported by -Wsign-compare. In the case of getting the result of comparing the result of sysconf (_SC_PAGESIZE) to other value, this also correctly handles edge cases where the above fails and returns -1. Co-authored-by: serge-sans-paille <sguelton@mozilla.com>
Alexander Kanavin 00116b6d 2022-12-05T03:20:09 arm/sysv: reverted clang VFP mitigation (#747) Since commit e3d2812ce43940aacae5bab2d0e965278cb1e7ea, seperate instructions were used when compiling under clang, as clang didn't allow the directives at the time. This mitigation now causes compilation to fail under clang 10, as described by https://github.com/libffi/libffi/issues/607. Now that clang supports the LDC and SDC instructions, this mitigation has been reverted. Co-authored-by: Brett Warren <brett.warren@arm.com>
Anthony Green c50c16d0 2022-11-20T12:20:40 Fix large struct passing on PA-RISC
Icecream95 af0f14cd 2022-10-24T04:08:10 Fix types of temporary variables in aarch64 extend_integer_type (#745) Fixes truncated values in weston-info output.
Anthony Green 93cfb655 2022-10-10T14:32:35 Correction for older compilers
Andreas Schwab 3874fd98 2022-10-10T17:58:48 Fix strict aliasing problem in aarch64 ffi_call (#739) The assignment a = &dest in ffi_call_int may be moved after the call to extend_integer_type because that function accesses the assigned value with a different type. Co-authored-by: Andreas Schwab <schwab@suse.de>
Andreas Schwab 4b0c358e 2022-10-10T17:57:47 riscv: make copies of structs passed by reference (#738) Co-authored-by: Andreas Schwab <schwab@suse.de>
Anthony Green 963c4a96 2022-09-27T22:05:42 Remove nested comments
Anthony Green a2473cde 2022-09-24T21:41:02 or1k: All struct args are passed in memory
Anthony Green f93224d3 2022-09-24T21:38:57 moxie: All struct args are passed in memory
Anthony Green ff34df23 2022-09-19T06:45:19 Update comment about platform support
Anthony Green fc6b9390 2022-09-19T06:42:29 Standardize temp exec file creation
Anthony Green 4c2984c4 2022-09-18T15:06:57 Handle win32 ABIs for struct return
Anthony Green b05dc51b 2022-09-18T13:03:10 Debug x86
Anthony Green cafdb837 2022-09-18T12:05:12 Revert
Anthony Green 735e7be4 2022-09-18T08:21:34 X86 is never defined.
Hans ee22ecbd 2022-09-18T01:56:25 Add MSYS configuration files (#728) * Add MSYS configuration files MSYS behaves very similiar to Cygwin, e.g. also __CYGWIN__ is defined. Now 'make check' passes on MSYS without extra patches. * Fix warning extra tokens at end of #endif in closures.c Extra tokens converted into a comment. Also nearby indentations corrected. * Fix missing prototype warning mkostemp() on Cygwin Cygwin requires also _GNU_SOURCE to be defined to enable mkostemp() prototype. * Fix warning label ‘out’ defined but not used in ffi functions Define same preprocessor conditions for goto and label visibility. * Fix warning label ‘out’ defined but not used and related indentations. Define same preprocessor conditions for goto and label visibility. Correct also related indentations. Co-authored-by: Hannes Müller <>
Anthony Green 05785caf 2022-09-15T15:18:09 Fix arg alignment for STDCALL
Anthony Green 4b54a647 2022-09-12T09:02:08 Fix limits.h inclusion for cygwin
Anthony Green a1130f37 2022-09-12T08:53:06 Add static trampoline support for Cygwin
Anthony Green da905276 2022-09-06T21:15:58 dlmmap fix and always check for PaX MPROTECT on linux Also make EMUTRAMP experimental From Stefan Bühler https://github.com/libffi/libffi/pull/282
Anthony Green e4c5d46b 2022-09-05T12:19:57 Pass large structs by value
Clément Chigot 80912f2f 2022-09-01T14:47:16 Makefile: enable target overridings. (#661) 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>
Anthony Green 0eb91425 2022-08-31T20:46:24 Change comment style
Xi Ruoyao 5a4774cd 2022-07-22T05:56:30 static trampoline for LoongArch (#723) For the benefit and technical details of static trampoline, see https://github.com/libffi/libffi/pull/624. As a new architecture, let's be "safer" from the start. The change survived libffi testsuite on loongarch64-linux-gnu.
Anthony Green fc8c8c1e 2022-06-25T11:06:00 Fix ILP32 for aarch64
Russell Keith-Magee 1f14b3fa 2022-06-03T02:46:35 Ensure that VM_PROT_EXECUTE is set on the trampoline page. (#718)
Sergei Trofimovich 000ecd01 2022-06-02T18:43:53 powerpc64: fix build on gcc-12 (assembly requires AltiVec) (#719) Without the change build fails on powerpc64-gcc-12 as: src/powerpc/linux64_closure.S: Assembler messages: src/powerpc/linux64_closure.S:363: Error: unrecognized opcode: `lvx' It's a 90205f67 "rs6000: Fix bootstrap (libffi)" patch by Segher Boessenkool from gcc upstream repository. It's enough to get libffi build on powerpc64.
Anthony Green c528d5b4 2022-05-29T11:22:38 Fix windows arg passing
Anthony Green aa2c4141 2022-05-29T10:28:10 64-bit cygwin: fix struct args. Document change.
Anthony Green 36b265ae 2022-05-29T10:12:30 m32r: pass copies of large structs
Martin Storsjö fd1fe195 2022-05-29T14:16:49 Fix building on aarch64 after e409225b41b60c490a094bb068e639a2364202fd (#716) The ALIGN_DOWN macro was renamed in 2018 in e6eac7863e2bf1a009ea863041b354bdb4af6b67.
Anthony Green c1e237b2 2022-05-28T20:46:14 Pass large structs by value on the stack
Anthony Green 769b7366 2022-05-28T19:59:35 Fix for MS x64 ABI
Anthony Green faafcb9d 2022-05-28T17:24:43 Fix moxie struct passing
Anthony Green f55d7ff1 2022-05-28T14:30:13 moxie: structs > 8 go on stack
Anthony Green 72c31927 2022-05-28T13:53:26 Pass copies of large structs on the stack
Anthony Green e409225b 2022-05-28T09:42:13 Pass large structs by value for Linux x86_64 and Aarch64. Aarch patch by Andreas Schwab. https://github.com/libffi/libffi/commit/482b37f00467325e3389bab322525099860dd9aa
zhangwenlong f259a6f6 2022-05-25T09:31:08 Support loongarch64 (#678) * 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>
Anthony Green 7e93ded9 2022-05-23T21:42:52 Revert "Don't dereference beyond the last array entry. (#667)" (#715) This reverts commit 92d77d0e87a5f2a8c9c9b2431ffd264cb664e17a.
Kevin Bowling 9af445fd 2022-05-23T18:05:01 Upstream FreeBSD riscv patch (#708) Like 8276f812a99b10d1f2c387dbd6ef2ca4f597c733 commit message: > devel/libffi: Fix abort() on ARM related to __clear_cache() > > The current FreeBSD __clear_cache() implementation does nothing #if > __i386__ || __x86_64__ #else abort(); > > cognet@ advises this is an issue for anything !Apple that is using the > libcompiler_rt provided by Clang on ARM, and requires upstreaming. Co-authored-by: Kristof Provost <kp@FreeBSD.org>
Roland Schatz de95947a 2022-05-24T03:04:43 Fix check for invalid varargs arguments. (#707)
Anthony Green 92d77d0e 2022-05-23T21:03:00 Don't dereference beyond the last array entry. (#667)
YunQiang Su 2e825e21 2022-05-16T09:47:11 MIPS: fix some N32 test failure (#701) Some go closure and pointer testcase fails. These failures is not introduced by the complex support code.
YunQiang Su 1f1c3375 2022-05-16T09:45:27 MIPS: fix O32 softfloat support (#702)
hjl-tools 3ac265d5 2022-05-15T18:43:56 x86-64: Always double jump table slot size for CET (#710) (#711) When CET is enabled, double jump table slot size to add 4 bytes of ENDBR64 for CET. Since CET enabled clang doesn't have the LLVM assembler bug: https://bugs.llvm.org/show_bug.cgi?id=21501 fixed by commit 04d39260d64e08b8bfb3844109ad43d4055b2e8d Author: Rafael Espindola <rafael.espindola@gmail.com> Date: Wed Nov 4 23:50:29 2015 +0000 Simplify .org processing and make it a bit more powerful. we can use .org to allocate jump table slot size to 16 bytes.
YunQiang Su e67697c3 2022-03-31T20:44:49 MIPS: add Complex support (#698)
Ole André Vadla Ravnås e3cf8b80 2022-03-31T14:42:03 Allow system to have overlapping mallopt defines (#700) Which is the case on some OSes, such as QNX.
Ole André Vadla Ravnås c086cacb 2022-03-31T14:40:59 Clean up the QNX ARM bits (#699) - Add missing include. - Use constants instead of magic values.
Max Filippov ab167710 2022-02-20T16:01:38 Xtensa cleanups and XEA3 support (#677) * xtensa: clean up stack usage in ffi_trampoline call Space for outgoing call arguments reserved in the stack frame of the function ffi_trampoline overlaps register spill overflow area at the top of the frame. In xtensa XEA2 exception architecture the layout of overlapping areas is identical so that even if the ffi_trampoline registers frame gets spilled the memory contents doesn't change. This is not so with the xtensa XEA3 exception architecture, where registers a0 - a7 of a different function are spilled in that location. Reserve spill area for 8 registers to avoid overlapping of the spill area with the outgoing call arguments area in the ffi_trampoline. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com> * xtensa: support xtensa XEA3 exception architecture XEA3 requires that 32 bytes of register spill area is reserved in all functions. Fix ffi_cacheflush entry instruction to satisfy this requirement. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com> * xtensa: maintain stack alignment xtensa ABI requires stack alignment on 16 byte boundary and passing up to 6 arguments in registers. To simplify stack alignment maintenance fixed amount of stack space is reserved for arguments passed in registers and variable but correctly aligned amount is reserved for the remaining arguments. After copying arguments to the stack and loading registers the fixed part of the stack reservation is freed. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com> * xtensa: fix err_bad_abi tests Check ffi_cif::abi value in the ffi_prep_closure_loc and return FFI_BAD_ABI error if it's not one of the supported values. Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Andreas Schwab aa3fce08 2022-02-13T21:04:33 riscv: extend return types smaller than ffi_arg (#680) Co-authored-by: Andreas Schwab <schwab@suse.de>
Dan Horák 464b4b66 2022-01-31T14:08:09 powerpc64: fix handling of homogeneous float128 structs (#689) If there is a homogeneous struct with float128 members, they should be copied to vector register save area. The current code incorrectly copies only the value of the first member, not increasing the pointer with each iteration. Fix this.
rorth b60d4fc7 2021-12-23T14:32:46 src/x86/win64.S: Use #define instead of .macro (#665) (#669) The Solaris/x86 assembler doesn't support .macro/.endm, so use #define since win64.S is passed through cpp anyway.
Anthony Green ee1263f7 2021-07-29T17:46:17 Fix 'type'-o
Anthony Green 86d5ecc5 2021-07-29T16:58:32 Fix struct arg passing