src


Log

Author Commit Date CI Message
Jakub Jelinek 5651bea2 2021-06-15T15:19:26 2021-06-15 Jakub Jelinek <jakub@redhat.com> * src/x86/ffi64.c (classify_argument): For FFI_TYPE_STRUCT set words to number of words needed for type->size + byte_offset bytes rather than just type->size bytes. Compute pos before the loop and check total size of the structure. * testsuite/libffi.call/nested_struct12.c: New test.
vhankala ff059dd9 2021-06-10T18:41:02 Fix build on OpenBSD/mips64 (#638) The build fails on OpenBSD/mips64 because clang 11's integrated assembler expects read-only .eh_frame: ../src/mips/n32.S:585:9: error: changed section flags for .eh_frame, expected: 0x2 .section .eh_frame,"aw",@progbits ^ Use EH_FRAME_FLAGS to get matching flags for the section.
Martin Storsjö dd5bd030 2021-04-07T05:42:10 Fix building for arm windows with mingw toolchains (#631) * arm: Check _WIN32 instead of _M_ARM or _MSC_VER for detecting windows This matches what was done for ARM64 in c06468fa6674d3783a0edb1d0fae9afc8bc28513. * arm: Only use armasm source when building with MSVC When building for windows/arm with clang, the normal gas style .S source works fine (if fixed up to support thumb and other windows specifics). This matches what was done for ARM64 in c06468fa6674d3783a0edb1d0fae9afc8bc28513. * arm: Fix sysv.S to work in thumb mode Align cases in jump tables (adding nop padding to make sure each case starts where expected). Rewrite instructions that add directly to the pc register. For ffi_closure_ret, factor out a call_epilogue subroutine that restores both sp and pc from the stack; the thumb version of ldm can't load into the sp register. To avoid excessive ifdeffing, keep using call_epilogue in arm mode, but keep the shorter "ldm sp, {sp, pc}" epilogue in that case. * arm: Add win32 version of trampoline to sysv.S This matches the version of it in sysv_msvc_arm32.S. The calling C code expects a specific form of the trampoline on windows; make sure these work the same on windows regardless of the form of assembly used. * arm: Avoid optimizing out clearing the thumb bit of ffi_arm_trampoline We clear the thumb bit of ffi_arm_trampoline with a bitmask before memcpying its instructions into closure->tramp. If the bit isn't cleared, the memcpy of the trampoline function copies the wrong instructions. If the ffi_arm_trampoline symbol is declared as an array of int, the compiler can assume that it is aligned to a 4 byte boundary and the bitmask operation is a no-op, and optimize it out. See https://godbolt.org/z/dE3jE1WTz; both Clang and GCC optimize out the bitmask as it is, while MSVC doesn't. By declaring the trampoline as an array of unsigned char, the bitmask works as intended.
Jeremy Huddleston Sequoia eafab235 2021-03-24T11:38:36 arm64e: Pull in pointer authentication code from Apple's arm64e libffi port (#565) NOTES: This changes the ptrauth support from #548 to match what Apple is shipping in its libffi-27 tag. Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Ole André Vadla Ravnås 1aeb2671 2021-03-24T12:16:12 x86: Fix thiscall and fastcall stack cleanup behavior (#611) These are meant to use callee clean-up.
Ole André Vadla Ravnås f88add14 2021-03-24T12:04:51 x86: Fix MSVC runtime checks interop (#612) MSVC can add runtime code that checks if a stack frame is mismanaged, however our custom assembly deliberately accesses and modifies the parent stack frame. Fortunately we can disable that specific check for the function call so do that. Co-authored-by: Matthew Waters <matthew@centricular.com>
DJ Delorie 70ea259c 2021-03-23T19:03:45 Search $LIBFFI_TMPDIR also (#605) Most temp file directories need to be hardened against execution, but libffi needs execute privileges. Add a libffi-specific temp directory that can be set up by sysadmins as needed with suitable permissions. This both ensures that libffi will have a valid temp directory to use as well as preventing attempts to access other directories.
AndreRH f58e5ee6 2021-03-23T23:54:00 aarch64: Fix closures for win64 (#606)
Anthony Green 205cf01b 2021-03-23T11:31:08 Bug #680. Don't accept floats or small ints as var args. (#628) * Bug #680. Don't accept floats or small ints as var args. * Bug #680. Don't accept floats or small ints as var args. * Bug #680. Don't accept floats or small ints as var args.
Jeremy Huddleston Sequoia d271dbe0 2021-03-20T06:06:28 Add some missing #if conditionals from Apple's code drop (#620) * arm/aarch64: Add FFI_CLOSURES conditionals where appropriate Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com> * aarch64: Don't emit the do_closure label when building without FFI_GO_CLOSURES Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Madhavan T. Venkataraman 9ba55921 2021-03-05T10:07:30 Static tramp v5 (#624) * 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>
DJ Delorie 5c63b463 2020-12-02T16:14:27 Use memfd_create() (#604) memfd_create creates a file in a memory-only filesystem that may bypass strict security protocols in filesystem-based temporary files.
Mike Hommey 8cc8f446 2020-11-10T20:41:33 Allow to build with mingw-clang (#579) For some reason, compiling sysv.S with mingw-clang fails with: ``` error: invalid variant 'ffi_closure_inner@8' ``` This can be fixed (worked around?) by quoting the symbol. This works fine with mingw-gcc too.
Mike Hommey d817d0da 2020-11-10T20:39:25 Don't use FFI_TYPE_LONGDOUBLE in the jump table in win64*.S (#580) It may have the same value as FFI_TYPE_DOUBLE per ffi.h, which possibly can make things go wrong with .org/ORG. For instance, GCC complains about "Error: attempt to move .org backwards"
AndreRH 56f7df71 2020-11-10T12:27:59 aarch64: Allow FFI_WIN64 for winelib (#593)
Ken 484c1a0d 2020-10-27T07:07:07 darwin powerpc: use go closures only if enabled (#583) SHA: 0ff9419f2e75652426469e256cb7d0748064ad58 added go closures for darwin powerpc AIX, but these have not yet been implemented for non-AIX systems use the go closures only if enabled
Jeremy Huddleston Sequoia 032b3cd6 2020-10-27T07:06:21 Support building x86 and arm64 without FFI_GO_CLOSURES (#586) * x86: Support building without FFI_GO_CLOSURES Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com> * arm: Support building without FFI_GO_CLOSURES Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
petersn c78fcf88 2020-10-27T07:02:36 Removing unnecessary instruction from ffi_call_unix64 (#588) unix64.S's `ffi_call_unix64` looks like it used to take six parameters, where the sixth said the number of SSE register arguments. However, currently the function only takes five parameters, and the number of SSE register arguments is encoded in the `struct register_args *` passed as the first parameter to `ffi_call_unix64`. This change removes an instruction that tries to use this missing sixth parameter as the number of SSE arguments. This fix should not change any behavior, nor fix any bugs, because a few instructions later the value moved from %r9d into %eax is overwritten by the correct value anyway. This change merely makes the code a tad less confusing, because currently the assembly moves from a register (r9) whose value is never set.
Alan Modra f4435980 2020-10-27T23:36:21 Power10 libffi fixes (#585) Power10 pc-relative code doesn't use or preserve r2 as a TOC pointer. That means calling between pc-relative and TOC using code can't be done without intervening linker stubs, and a call from TOC code to pc-relative code must have a nop after the bl in order to restore r2. Now the PowerPC libffi assembly code doesn't use r2 except for the implicit use when making calls back to C, ffi_closure_helper_LINUX64 and ffi_prep_args64. So changing the assembly to interoperate with pc-relative code without stubs is easily done. * src/powerpc/linux64.S (ffi_call_LINUX64): Don't emit global entry when __PCREL__. Call using @notoc. Add nops. * src/powerpc/linux64_closure.S (ffi_closure_LINUX64): Likewise. (ffi_go_closure_linux64): Likewise.
Tim Gates 407394c0 2020-10-11T15:07:40 docs: fix simple typo, paramters -> parameters (#589) There is a small typo in src/x86/ffi.c. Should read `parameters` rather than `paramters`.
Niclas Zeising 8276f812 2020-08-07T21:05:23 Upstream local FreeBSD patches (#567) * Add support for FreeBSD mips Add support for FreeBSD mips, this has been a local patch in the FreeBSD ports tree for quite some time. Originally submitted by sson, and committed by sbruno AT FreeBSD DOT org See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=191909 for background details. Signed-off-by: Niclas Zeising <zeising@daemonic.se> * Add support for FreeBSD powerpcspe Add support for powerpcspe on FreeBSD This has been in the FreeBSD ports tree for some time. Originally submitted by jhibbits AT FreeBSD DOT org. Signed-off-by: Niclas Zeising <zeising@daemonic.se> * Fix abort() on FreeBSD arm related to __clear_cache() This patch has been in the FreeBSD ports tree for a number of years. Original commit by koobs AT FreeBSD DOT org Original commit message: > devel/libffi: Fix abort() on ARM related to __clear_cache() > > The current FreeBSD/ARM __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. See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=149167 for some background details. Signed-off-by: Niclas Zeising <zeising@daemonic.se>
Jakub Wilk 8e58f88d 2020-06-30T22:59:28 aarch64: Fix typo
Ma Jun fbd1de85 2020-06-29T08:02:20 Add support for csky
Yann Sionneau 5e6ca054 2020-05-01T13:59:11 Add support for Kalray KVX architecture (#559)
Andrew Geissler 4f9e20ac 2020-05-01T06:58:30 ffi_powerpc.h: fix build failure with powerpc7 (#561) This is a patch pulled down from the following: https://github.com/buildroot/buildroot/blob/78926f610b1411b03464152472fd430012deb9ac/package/libffi/0004-ffi_powerpc.h-fix-build-failure-with-powerpc7.patch This issue is being hit on OpenBMC code when pulling the latest libffi tag and building on a P8 ppc64le machine. I verified this patch fixes the issue we are seeing. Below is the original commit message: Sicne commit 73dd43afc8a447ba98ea02e9aad4c6898dc77fb0, build on powerpc7 fails on: In file included from ../src/powerpc/ffi.c:33:0: ../src/powerpc/ffi_powerpc.h:61:9: error: '_Float128' is not supported on this target typedef _Float128 float128; ^~~~~~~~~ Fix this build failure by checking for __HAVE_FLOAT128 before using _Float128, as _Float128 is enabled only on specific conditions, see output/host/powerpc64-buildroot-linux-gnu/sysroot/usr/include/bits/floatn.h: /* Defined to 1 if the current compiler invocation provides a floating-point type with the IEEE 754 binary128 format, and this glibc includes corresponding *f128 interfaces for it. */ #if defined _ARCH_PWR8 && defined __LITTLE_ENDIAN__ && (_CALL_ELF == 2) \ && defined __FLOAT128__ && !defined __NO_LONG_DOUBLE_MATH # define __HAVE_FLOAT128 1 #else # define __HAVE_FLOAT128 0 #endif Fixes: - http://autobuild.buildroot.org/results/5c9dd8fb3b6a128882b6250f197c80232d8a3b53 Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> Signed-off-by: Andrew Geissler <geissonator@yahoo.com> Co-authored-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Martin Storsjö 053b04c5 2020-04-26T05:02:14 arm: Fix the clang specific version of the assembly (#556) Also fix the same error in the comment for the non-clang case. That typo there seems to have existed since the code was written in that form, in e7f15f60e86 - and when the clang specific codepath was added in e3d2812ce43, the typo in the comment made it into the actual code.
Martin Storsjö c543849c 2020-04-26T05:01:03 win64_armasm: Fix the spelling of ALIGN (#553)
Martin Storsjö 15d3ea31 2020-04-26T04:59:35 Use __builtin_ffs instead of ffs (#554) USE_BUILTIN_FFS is defined to 1 within __GNUC__, and the __builtin_ffs function is available since GCC 3.x at least, while the ffs function only exists on some OSes. This fixes compilation for non-x86 mingw platforms. For x86, USE_BUILTIN_FFS is explicitly disabled for windows targets - but if USE_BUILTIN_FFS is enabled based on __GNUC__, it should also use the builtin which actually is available correspondingly, not dependent on the target OS.
Martin Storsjö c06468fa 2020-04-26T04:58:33 Fix building for aarch64 windows with mingw toolchains (#555) * aarch64: Check _WIN32 instead of _M_ARM64 for detecting windows This fixes building for aarch64 with mingw toolchains. _M_ARM64 is predefined by MSVC, while mingw compilers predefine __aarch64__. In aarch64 specific code, change checks for _M_ARM64 into checks for _WIN32. In arch independent code, check for (defined(_M_ARM64) || defined(__aarch64__)) && defined(_WIN32) instead of just _M_ARM64. In src/closures.c, coalesce checks like defined(X86_WIN32) || defined(X86_WIN64) || defined(_M_ARM64) into plain defined(_WIN32). Technically, this enables code for ARM32 windows where it wasn't, but as far as I can see it, those codepaths should be fine for that architecture variant as well. * aarch64: Only use armasm source when building with MSVC When building for windows/arm64 with clang, the normal gas style .S source works fine. sysv.S and win64_armasm.S seem to be functionally equivalent, with only differences being due to assembler syntax.
Ole André Vadla Ravnås 4c7bde32 2020-03-10T02:05:42 Port to iOS/arm64e (#548)
Moxie Bot 8eb2d2b0 2020-02-24T10:29:20 Revamp PA_LINUX and PA_HPUX target closures to use function descriptors. 2020-02-23 John David Anglin <danglin@gcc.gnu.org> * include/ffi.h.in (FFI_CLOSURE_PTR, FFI_RESTORE_PTR): Define. * src/closures.c (ffi_closure_alloc): Convert closure pointer return by malloc to function pointer. (ffi_closure_free): Convert function pointer back to malloc pointer. * src/pa/ffi.c (ffi_closure_inner_pa32): Use union to double word align return address on stack. Adjust statements referencing return address. Convert closure argument from function pointer to standard closure pointer. (ffi_prep_closure_loc): Likewise convert closure argument back to closure pointer. Remove assembler trampolines. Setup simulated function descriptor as on ia64. src/pa/ffitarget.h (FFI_TRAMPOLINE_SIZE): Reduce to 12. src/pa/hpux32.S (ffi_closure_pa32): Retrieve closure pointer and real gp from fake gp value in register %r19. src/pa/linux.S (ffi_closure_pa32): Likewise.
hjl-tools d9abffea 2020-02-22T06:32:22 x86: Fix ffi_prep_closure_loc (#542) Since FFI_TRAMPOLINE_SIZE is increased by 4 bytes to add ENDBR32, adjust jump displacement by 4 bytes.
hjl-tools 78556561 2020-02-21T19:08:06 x86: Add indirect branch tracking support (#540) 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.
Samuel Holland 4d6d2866 2020-02-21T21:06:15 Update powerpc sysv assembly for ffi_powerpc.h changes (#541) Some of the flag bits were moved when adding powerpc64 vector support. Fixes #536
Khem Raj e50b9ef8 2019-12-07T02:34:14 powerpc64: Use memcpy to help platforms with no __int128. (#534) Signed-off-by: Khem Raj <raj.khem@gmail.com>
Carl Hurd 76c0cfea 2019-11-29T14:46:11 Fixed missed #ifndef for __mips_soft_float (#442) Thank you!
Anthony Green 6663047f 2019-11-29T07:00:35 Address platforms with no __int128.
Sergei Trofimovich 01a75ed7 2019-11-28T12:42:41 powerpc: fix build failure on power7 and older (#532) Build failure looks as: ``` libtool: compile: powerpc-unknown-linux-gnu-gcc \ -O2 -mcpu=powerpc -mtune=powerpc -pipe ... -c src/powerpc/ffi.c ... In file included from src/powerpc/ffi.c:33: src/powerpc/ffi_powerpc.h:65:9: error: '__int128' is not supported on this target 65 | typedef __int128 float128; | ^~~~~~~~ ``` The fix avoids using __int128 in favour of aligned char[16]. Closes: https://github.com/libffi/libffi/issues/531 Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Anthony Green 31543c79 2019-11-20T06:15:55 Add work-around for users who manage their own closure memory As suggested by DJ
Samuel Holland 73dd43af 2019-11-17T07:22:25 IEEE754 binary128 long double support for PowerPC64 (#526) * powerpc: Adjust flags to make room for vector types * powerpc64 ELFv2 IEEE128 long double support
Andreas Schwab a8efc2f7 2019-10-26T14:57:05 Fix FFI_STDCALL ABI (#514) Even for a stdcall function, the stack alignment is still the responsibility of the caller. Remember the original, not stack-aligned argument size, but align when setting up a stack frame. In ffi_closure_inner, return the true argument size, so that ffi_[go_]closure_STDCALL doesn't adjust too much.
zhanhb c4f61240 2019-10-09T18:59:32 Add long double test (#492) Required to fix build error on macos with gcc-9
pnallan 55c22092 2019-10-08T18:46:47 handle compilation warnings with ftruncate API (#508) * fix me: avoid warning while handle ftruncate API Signed-off-by: Prasad Nallani <prasad.nallani@intel.com> * Update closures.c
John Ericson e5f0eb15 2019-10-08T06:58:52 Clean up line endings (#509) The CLRF visual studio files can be kept that way, but recognized as text. The assembly file can be converted to LF.
Samuel Holland ea9b6639 2019-10-08T05:57:28 PowerPC bugfixes (#520) * powerpc: Silence warnings about unused labels * powerpc: Fix a couple of comments * powerpc: Fix alignment after float structs * powerpc: Don't pad rvalues copied from FP regs * powerpc: Add missing check in struct alignment * powerpc: Support homogeneous long double structs
Paul Monson c2a68590 2019-08-07T11:57:45 fix mingw build and crashing bugs for Python Windows ARM64 (#496) * fix mingw build and crashing bugs for Python Windows ARM64 * Fix issues found in PR review
ossdev07 d856743e 2019-06-26T07:31:22 libffi: added ARM64 support for Windows (#486) * libffi: added ARM64 support for Windows 1. ported sysv.S to win64_armasm.S for armasm64 assembler 2. added msvc_build folder for visual studio solution 3. updated README.md for the same 4. MSVC solution created with the changes, and below test suites are tested with test script written in python. libffi.bhaible libffi.call 5. Basic functionality of above test suites are getting passed Signed-off-by: ossdev07 <ossdev@puresoftware.com> * Update README.md
Sergei Trofimovich fadf1eb5 2019-04-27T20:53:29 hppa: avoid TEXTREL in .eh_frame section (#447) Before the change hand-crafted .eh_frame section contained ABS relocation and caused TEXTREL tag to be emitted: ``` $ ./configure --host=hppa2.0-unknown-linux-gnu LDFLAGS=-Wl,-z,text $ make ... /usr/libexec/gcc/hppa2.0-unknown-linux-gnu/ld: read-only segment has dynamic relocations. ``` Link failure is caused by absolute address of FDEs encoded into .eh_frame entries. Fixed TEXTREL by using pcrel (instead of ABS) encoding for absolute addresses (__PIC__ code) by adding augmentation information ("zR" CIE type). All tests still pass on hppa2.0. The specific tests that still pass and exercise this code path: testsuite/libffi.call/unwindtest.cc testsuite/libffi.call/unwindtest_ffi_call.cc Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
driver1998 06bf1a9d 2019-04-28T03:21:44 fix x86/x64 MSVC build (#487)
Paul Monson db5706ff 2019-04-26T04:58:58 add support for 32-bit ARM on Windows (#477) * 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
Dan Horák a7d6396f 2019-03-29T14:19:20 fix check for Linux/aarch64 fixes #473
Jeremy Huddleston Sequoia 05a17964 2019-02-19T04:11:28 Cleanup symbol exports on darwin and add architecture preprocessor checks to assist in building fat binaries (eg: i386+x86_64 on macOS or arm+aarch64 on iOS) (#450) * x86: Ensure _efi64 suffixed symbols are not exported * x86: Ensure we do not export ffi_prep_cif_machdep Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com> * x86: Ensure we don't export ffi_call_win64, ffi_closure_win64, or ffi_go_closure_win64 Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com> * closures: Silence a semantic warning libffi/src/closures.c:175:23: This function declaration is not a prototype Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com> * aarch64: Ensure we don't export ffi_prep_cif_machdep Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com> * arm: Ensure we don't export ffi_prep_cif_machdep Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com> * aarch64, arm, x86: Add architecture preprocessor checks to support easier fat builds (eg: iOS) Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com> * x86: Silence some static analysis warnings libffi/src/x86/ffi64.c:286:21: The left operand of '!=' is a garbage value due to array index out of bounds libffi/src/x86/ffi64.c:297:22: The left operand of '!=' is a garbage value due to array index out of bounds Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com> * aarch: Use FFI_HIDDEN rather than .hidden Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com> * ffi.h: Don't advertise ffi_java_rvalue_to_raw, ffi_prep_java_raw_closure, and ffi_prep_java_raw_closure_loc when FFI_NATIVE_RAW_API is 0 Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Paul Monson e1118af5 2019-02-19T03:58:25 changes for win32 on windows (#468)
Florian Weimer 44a6c285 2019-02-19T12:55:11 aarch64: Flush code mapping in addition to data mapping (#471) This needs a new function, ffi_data_to_code_pointer, to translate from data pointers to code pointers. Fixes issue #470.
Martin Bektchiev 4a84df4a 2018-10-31T15:53:54 Fix Q registers parameter passing on ARM64 The second two quads are located at offset 32 not 16
Tom Tromey a5ea7527 2018-09-19T07:29:36 Merge pull request #443 from jeremyhu/master Update FFI_HIDDEN() to use .private_extern on Apple platforms and use the macro where appropriate
Gregory Pakosz e6eac786 2018-09-18T15:19:53 Prefix ALIGN_DOWN macro with FFI_
Andreas Schwab 4cb776bc 2018-08-09T12:12:29 RISC-V go closures This implements go closures for RISC-V. It has been tested on riscv64-suse-linux and against the libgo testsuite.
Jeremy Huddleston Sequoia ba73a671 2018-07-20T09:37:43 Update FFI_HIDDEN() to use .private_extern on Apple platforms and use the macro where appropriate Fix issue #439 Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@macports.org>
Jeremy Huddleston Sequoia 65da63ab 2018-06-25T04:38:58 Add compact unwind for darwin/i386 (#440) * x86: Add implementation of compact unwind for ffi_call_i386, et al. Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@macports.org> * x86: Use __text as the section name to avoid deprecated section name warnings. Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@macports.org> * darwin: Add missing regular,debug attributes for compact unwind sections Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@macports.org>
Shoaib Meenai 2309b584 2018-06-17T17:04:24 Mark sysv.S as SafeSEH compatible (#438) It contains no exception handler, so we can just emit the special @feat.00 symbol to indicate that it's trivially SafeSEH compatible. SafeSEH only applies to x86 and not x86-64, hence its inclusion in the x86-specific block. See [1] for details. [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms680547(v=vs.85).aspx#the_.sxdata_section_
Jeremy Huddleston Sequoia 1d704051 2018-06-17T17:01:50 i386: Fix missing break; in case statement leading to incorrectly returned FFI_BAD_ABI (#437) * i386: Add missing break triggering dead store static analyzer checks. Register calling sequence is being reported as bad ABI instead of working as intended. Found-by: Clang Static Analysis Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@macports.org> * Mark ffi arm sysv entry points as private_extern. Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@macports.org> * x86_64: Add implementation of compact unwind for ffi_call_unix64. Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@apple.com>
Anthony Green b55baf0b 2018-05-09T13:21:02 Handle FFI_GNUW64 on non-Windows systems (EFI)
Anthony Green b5ee3957 2018-05-05T07:41:53 Revert "Remove some symbol exports and cleanup newline warnings (#433)" This reverts commit a5a0f3cf36dfb4d64316414a872288c3170e6c1d.
Jeremy Huddleston Sequoia a5a0f3cf 2018-05-05T03:44:33 Remove some symbol exports and cleanup newline warnings (#433) * build: Ensure darwin generated sources end with a new line Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@macports.org> * build: Use .private_extern where missing to prevent exporting symbols that are not API Signed-off-by: Jeremy Huddleston Sequoia <jeremyhu@macports.org>
hjl-tools d3c54cf3 2018-05-02T06:19:58 Re-enable msabi testing (#436) * Revert "disable msabi testing for now" This reverts commit 7b7638eb0eac2adfa72f7ec9f254ba287c9947e2. * x86: Correct testing for 64-bit x86-64 Since passing -m32 to x86-64 compiler will generate i386 code, we need to check both __ILP32__ and __i386__ for 64-bit x86-64. * x86: Check __i386__ instead of i?86-*-* targets Since passing -m32 to x86-64 compiler will generate i386 code, we need to check __i386__ instead of i?86-*-* targets for i386 targets. * i386: Properly passing integer parameters in registers For thiscall and fastcall, if the paramter passed as 64-bit integer or struct, all following integer paramters will be passed on stack. * test: Add ABI_ATTR to callback_code Add ABI_ATTR to callback_code to properly test different ABIs.
Alan Modra ebf24166 2018-05-02T13:55:29 PowerPC64 ELFv1 fp arg fixes The ELFv1 ABI says: "Single precision floating point values are mapped to the second word in a single doubleword" and also "Floating point registers f1 through f13 are used consecutively to pass up to 13 floating point values, one member aggregates passed by value containing a floating point value, and to pass complex floating point values". libffi wasn't expecting float args in the second word, and wasn't passing one member aggregates in fp registers. This patch fixes those problems, making use of the existing ELFv2 homogeneous aggregate support since a one element fp struct is a special case of an homogeneous aggregate. I've also set a flag when returning pointers that might be used one day. This is just a tidy since the ppc64 assembly support code currently doesn't test FLAG_RETURNS_64BITS for integer types.. * src/powerpc/ffi_linux64.c (discover_homogeneous_aggregate): Compile for ELFv1 too, handling single element aggregates. (ffi_prep_cif_linux64_core): Call discover_homogeneous_aggregate for ELFv1. Set FLAG_RETURNS_64BITS for FFI_TYPE_POINTER return. (ffi_prep_args64): Call discover_homogeneous_aggregate for ELFv1, and handle single element structs containing float or double as if the element wasn't wrapped in a struct. Store floats in second word of doubleword slot when big-endian. (ffi_closure_helper_LINUX64): Similarly.
Tom Tromey 4c2206ac 2018-04-28T04:46:10 Fix two "return" issues in x86/ffi64.c (#431) Issue #70 pointed out that at least one compiler didn't like: return ffi_call_efi64(cif, fn, rvalue, avalue); ... where the return type is "void". This patch splits the statement into two. I also noticed that ffi_call_go here seems to do a double call. I suspect a "return" is missing here, so this patch adds it as well.
Lucas Pluvinage 7d3cab79 2018-04-21T00:24:50 xtensa-linux: use cache flush instruction only if it is available (#426)
James Cowgill 159b94e5 2018-04-19T01:28:23 Various MIPS Fixes (#425) * mips: simplify closure #defines This commit should have no visible effect. * mips: add special handling of variadic functions MIPS requires special handling of variadic functions which pass floating point arguments: * In the o32 ABI, all float arguments are passed in integer registers. * In the n32/n64 ABIs, float arguments after the ellipsis are passed in integer registers. Implement this in libffi. To support this in n32/n64 closures, we need to add a new mips_nfixedargs field to ffi_cif which will break the libffi ABI. This fixes the libffi.call/cls_longdouble_va.c test which was failing on 64-bit MIPS. * mips: align argn for all 64-bit types in o32 closure handler Ensure that argn is pre-aligned for all 64-bit argument types (including doubles) and not just integer types. This fixes closures of the form "f(float, double, <some integer args>)". Previously the first integer argument would be read from a2 which is garbage at this point (the float arguments have already "consumed" a0-a3). After this commit, argn is correctly padded between the "float" and "double" arguments so that the first integer argument is read from the stack. Fixes "double f(float,double,int)" test in #371 * mips: do not read from floating point register if returning a struct In the o32 ABI, the pointer passed in a0 used to return structures indirectly is treated as the first argument for argument allocation purposes. This means that it should inhibit floating point registers the same way that other integer arguments do. Fixes "Double f(float,Double,double)" test in #371 * mips: fix pointer cast warnings Fix two pointer cast warnings when compiled on 64-bit mips by casting through uintptr_t. Fixes mips64el part of #404
Anthony Green e27f70b8 2018-04-08T18:25:34 Fix case where callback arg value is split across regs and stack
fwg af6773d6 2018-04-02T13:55:31 Fix appveyor windows build (#420) * Fix msvcc dll build by adding dllexport decorations to all API declarations * Fix appveyor build for VS 2013 Use the new -DFFI_BUILDING_DLL for producing a working DLL. Update the msvcc.sh wrapper script to successfully compile the testsuite files. * MSVC build: suppress warnings in testsuite * fix testsuite on appveyor
Anthony Green 369ef49f 2018-03-18T12:53:42 Add missing FFI_GNUW64 enum
Anthony Green 43980dd1 2018-03-18T12:32:10 Add FFI_GNUW64 ABI for GNU 80-bit long double support
Anthony Green 9bc40d87 2018-03-18T12:32:10 Add FFI_GWIN64 ABI for GNU 80-bit long double support
Ryan C. Underwood d4640608 2018-03-18T07:00:42 Fully allocate file backing writable maps (#389) When ftruncate() is used on a filesystem supporting sparse files, space in the file is not actually allocated. Then, when the file is mmap'd and libffi writes to the mapping, SIGBUS is thrown to the calling application. Instead, always fully allocate the file that will back writable maps.
Anthony Green 6a801d04 2018-03-16T17:53:33 Fix closure case where 8-byte value is partially passed in register. Fixes cls_many_mixed_float_double test case.
Anthony Green 01db31d9 2018-03-13T20:41:55 Update moxie sub opcode
Stef O'Rear 3840d49a 2018-03-11T05:55:15 New RISC-V port (#281) * 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
Anthony Green dca52b55 2018-03-11T08:50:01 Merge pull request #406 from trofi/master ia64: fix variadic function closures with FP arguments
Anthony Green 83d9aba3 2018-03-11T08:48:42 Merge pull request #407 from trofi/ia64-small-struct ia64: fix small struct return
Andreas Schwab e66fd678 2018-02-20T10:47:09 Revert "Fix passing struct by value on aarch64" This reverts commit 482b37f00467325e3389bab322525099860dd9aa. That was actually a bug in python, see <https://bugs.python.org/issue30353>.
Sergei Trofimovich b58caef7 2018-02-17T19:00:40 ia64: fix small struct return This change fixes libffi.call/struct10.c failure on ia64: FAIL: libffi.call/struct10.c -W -Wall -Wno-psabi -O0 execution test .Lst_small_struct handles returns for structs less than 32 bytes (following ia64 return value ABI [1]). Subroutine does roughly the following: ``` mov [sp+0] = r8 mov [sp+8] = r9 mov [sp+16] = r10 mov [sp+24] = r11 memcpy(destination, source=sp, 12); ``` The problem: ia64 ABI guarantees that top 16 bytes of stack are scratch space for callee function. Thus it can clobber it. [1] says (7.1 Procedure Frames): """ * Scratch area. This 16-byte region is provided as scratch storage for procedures that are called by the current procedure. Leaf procedures do not need to allocate this region. A procedure may use the 16 bytes at the top of its own frame as scratch memory, but the contents of this area are not preserved by a procedure call. """ In our case 16 top bytes are clobbered by a PLT resolver when memcpy() is called for the first time. As a result memcpy implementation reads already clobbered data frop top of stack. The fix is simple: allocate 16 bytes of scrats space prior to memcpy() call. [1]: https://www.intel.com/content/dam/www/public/us/en/documents/guides/itanium-software-runtime-architecture-guide.pdf Bug: https://bugs.gentoo.org/634190 Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Sergei Trofimovich 11de69dd 2018-02-11T11:29:39 ia64: fix variadic function closures with FP arguments libffi test framework already flagged failures as: ``` FAIL: libffi.call/cls_double_va.c -W -Wall -Wno-psabi -O0 output pattern test, is 7.0 res: 4 0.0 res: 4 ? should match 7.0 ?es: 4 ?.0 res: 4 ``` Failure happens here at ```c // testsuite/libffi.call/cls_double_va.c ... char* format = "%.1f\n"; double doubleArg = 7; ... CHECK(ffi_prep_closure_loc(pcl, &cif, cls_double_va_fn, NULL, code) == FFI_OK); res = ((int(*)(char*, ...))(code))(format, doubleArg); ``` libffi expects 'doubleArg' to be located in 'f9' (second FP argument) but gcc placed it to 'r33' (second GR). ia64 software [1] manual described argument passing ABI in "8.5.2 Register Parameters" as: """ If an actual parameter is known to correspond to a floating-point formal parameter, the following rules apply: a) The actual parameter is passed in the next available floating-point parameter register, if one is available. Floating-point parameter registers are allocated as needed from the range f8-f15, starting with f8. b) If all available floating-point parameter registers have been used, the actual parameter is passed in the appropriate general register(s). (This case can occur only as a result of homogeneous floating-point aggregates, described below.) If a floating-point actual parameter is known to correspond to a variable-argument specification in the formal parameter list, the following rule applies: c) The actual parameter is passed in the appropriate general register(s). If the compiler cannot determine, at the point of call, whether the corresponding formal parameter is a varargs parameter, it must generate code that satisfies both of the above conditions. (The compiler’s determination may be based on prototype declarations, language standard assumptions, analysis, or other user options or information.) """ We have [c] case here and gcc uses only GR for parameter passing. The change binds known variadic arguments ro GRs instead of FPs as those are always expected to be initialized for all variadic call types. This fixes all 10 failures on ia64-unknown-linux-gnu: ``` === libffi Summary === -# of expected passes 1945 -# of unexpected failures 10 + +# of expected passes 1955 ``` [1]: https://www.intel.com/content/dam/www/public/us/en/documents/guides/itanium-software-runtime-architecture-guide.pdf Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Anthony Green 9429968b 2018-02-10T23:23:33 Merge pull request #403 from frida/fix/x86-sysv-pic-closure-regression Fix x86 SysV closure in PIC mode
Andreas Schwab 482b37f0 2017-09-18T12:44:08 Fix passing struct by value on aarch64 This fixes the ctypes test in the python testsuite.
Ole André Vadla Ravnås 28d3b61b 2018-01-20T23:56:17 Fix x86 SysV closure in PIC mode The assembly single-line comments swallowed up the remaining assembly code of the macros due to lack of line-endings. This is a regression introduced in b7f6d7a.
Anthony Green bec6135d 2018-01-10T07:20:04 Merge pull request #393 from thejunkjon/master Linker error "recompile with -fPIC" for x86_64
YunQiang Su 746dbe3a 2018-01-03T10:07:41 mips/ffi.c: fix encoding for jr on r6 mips/ffi.c: instruction jr has a different encoding for r6
YunQiang Su 94c102aa 2017-12-10T14:25:01 Not set mips on mips r6 MIPS release changed encodes of some instructions, include ll/sc etc. if .set mips4 on mips r6, as will generate some wrong encode of some instructions.
jon d15581c6 2017-12-01T00:34:30 Updating calls to ffi_closure_unix64_inner and ffi_closure_win64_inner to use PLT. Without this fix, statically linking libffi causes the linker error i.e. 'requires dynamic R_X86_64_PC32 reloc against ffi_closure_unix64_inner which may overflow at runtime; recompile with -fPIC)'
Anthony Green 4fdbb057 2017-11-03T07:05:31 Merge pull request #320 from 0-wiz-0/master Support NetBSD with mprotect.
Anthony Green b302bc3d 2017-11-03T07:03:55 Merge pull request #322 from compnerd/aarch64-base aarch64: fix index base register for AArch64
Yen Chi Hsuan 9fc9dc53 2017-10-27T16:12:56 Fix linux detection (closes #303)
Saleem Abdulrasool 1fb788ac 2017-10-10T11:37:00 aarch64: fix index base register for AArch64 The base is passed in `x3`, not in `x2`. This fixes the indexing base so that the right value is used.
Anthony Green dc2ff5ba 2017-10-25T13:11:40 Merge pull request #323 from compnerd/x86-alloca-alignment x86: align alloca to 16-byte boundary
Anthony Green 927da716 2017-10-25T13:05:53 Merge pull request #379 from jlj/master Xcode build improvements
Anthony Green a0455c03 2017-10-25T13:04:23 Merge pull request #383 from hjl-tools/hjl/master Hjl/master
H.J. Lu 9d9d92b4 2017-10-25T04:59:31 Skip WIN64/EFI64 support for x32 Since x32 doesn't support WIN64/EFI64, skip it if __ILP32__ is defined.
Saleem Abdulrasool 3c372c38 2017-10-24T13:53:56 arm: fix a level of indirection issue Rather than relying on the stack being 0'ed out always, do it manually. The stack generally happened to be zero, and because the compiler realizes that the tests are dealing with chars truncates the read value. However, the top 3 nibbles of the value are undefined and may be non-zero. The indirection level caused a null-pointer dereference. Explicitly scribbling on the stack during the allocation causes test failures without the original zexting behaviour.