From a7b75d643fb851f6efdb9e66fb6957a8d1bce3eb Mon Sep 17 00:00:00 2001 From: Niyas Sait Date: Thu, 28 Oct 2021 10:47:34 +0100 Subject: update libffi for arm64 to release 3.4.2 and add scripts to generate static libffi static library --- c/libffi_arm64/README | 6 ++-- c/libffi_arm64/build_libffi.bat | 70 +++++++++++++++++++++++++++++++++++++ c/libffi_arm64/ffi.lib | Bin 7872 -> 66014 bytes c/libffi_arm64/include/ffi.h | 53 +++++++++++++++++----------- c/libffi_arm64/include/fficonfig.h | 21 +++++++++-- c/libffi_arm64/include/ffitarget.h | 15 +++++--- 6 files changed, 134 insertions(+), 31 deletions(-) create mode 100644 c/libffi_arm64/build_libffi.bat (limited to 'c') diff --git a/c/libffi_arm64/README b/c/libffi_arm64/README index 3b8f133..f531e5f 100644 --- a/c/libffi_arm64/README +++ b/c/libffi_arm64/README @@ -1,5 +1,5 @@ -Libffi package for ARM64 is copied from cpython binary dependencies +Please run build_libffi.bat to generate the libffi static library and header files -https://github.com/python/cpython-bin-deps/archive/libffi.zip +Environment variable LIBFFI_SOURCE needs to be set to libffi source before invoking the script. -The library file has been renamed from libffi-7.lib to ffi.lib to avoid special casing \ No newline at end of file +Libffi source can be downloaded from https://github.com/libffi/libffi \ No newline at end of file diff --git a/c/libffi_arm64/build_libffi.bat b/c/libffi_arm64/build_libffi.bat new file mode 100644 index 0000000..1fc85a2 --- /dev/null +++ b/c/libffi_arm64/build_libffi.bat @@ -0,0 +1,70 @@ +@echo off +goto :Run + +:Usage +echo. +echo Before running prepare_libffi.bat +echo . +echo LIBFFI_SOURCE environment variable must be set to the location of libffi source +echo Source can be checked out from https://github.com/libffi/libffi +echo. +echo Cygwin needs to be installed (Invoke with --install-cygwin to install) +echo. +echo. Visual Studio 2017 or newer with ARM64 toolchain needs to be installed +:Run +set INSTALL_CYGWIN= + +:CheckOpts +if "%1"=="" goto :CheckOptsDone +if /I "%1"=="-?" goto :Usage +if /I "%1"=="--install-cygwin" (set INSTALL_CYGWIN=1) & shift & goto :CheckOpts +goto :Usage + +:CheckOptsDone + +if "%INSTALL_CYGWIN%"=="1" call :InstallCygwin + +REM Set build variables + +set BUILD=i686-pc-cygwin +set HOST=aarch64-w64-cygwin +if NOT DEFINED SH if exist c:\cygwin\bin\sh.exe set SH=c:\cygwin\bin\sh.exe + +REM Initialise ARM64 build environment + +if NOT DEFINED VCVARSALL ( + for /F "tokens=*" %%i in ('"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -property installationPath -latest -prerelease -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64') DO @(set VCVARSALL="%%i\VC\Auxiliary\Build\vcvarsall.bat") +) +if ^%VCVARSALL:~0,1% NEQ ^" SET VCVARSALL="%VCVARSALL%" +call %VCVARSALL% x86_arm64 +pushd %LIBFFI_SOURCE% +%SH% --login -lc "cygcheck -dc cygwin" +set GET_MSVCC=%SH% -lc "cd $LIBFFI_SOURCE; export MSVCC=`/usr/bin/find $PWD -name msvcc.sh`; echo ${MSVCC};" +FOR /F "usebackq delims==" %%i IN (`%GET_MSVCC%`) do @set MSVCC=%%i +set MSVCC=%MSVCC% -marm64 + +echo Configuring and building libffi for ARM64 + +%SH% -lc "(cd $LIBFFI_SOURCE; ./autogen.sh)" +%SH% -lc "(cd $LIBFFI_SOURCE; ./configure CC='%MSVCC%' CXX='%MSVCC%' LD='link' CPP='cl -nologo -EP' CXXCPP='cl -nologo -EP' CPPFLAGS='-DFFI_BUILDING_DLL' NM='dumpbin -symbols' STRIP=':' --build=$BUILD --host=$HOST --enable-static --disable-shared)" +%SH% -lc "(cd $LIBFFI_SOURCE; cp src/aarch64/ffitarget.h include)" +%SH% -lc "(cd $LIBFFI_SOURCE; make)" + +set LIBFFI_OUT=%~dp0 + +echo copying files to %LIBFFI_OUT% +if not exist %LIBFFI_OUT%\include (md %LIBFFI_OUT%\include) +copy %LIBFFI_SOURCE%\%HOST%\.libs\libffi.lib C:\Users\niysai01\Workspace\cffi\c\libffi_arm64\ffi.lib || exit /B 1 +copy %LIBFFI_SOURCE%\%HOST%\fficonfig.h %LIBFFI_OUT%\include || exit /B 1 +copy %LIBFFI_SOURCE%\%HOST%\include\*.h %LIBFFI_OUT%\include || exit /B 1 +exit /B + +:InstallCygwin +setlocal +set CYG_ROOT=C:/cygwin +set CYG_CACHE=C:/cygwin/var/cache/setup +set CYG_MIRROR=http://mirrors.kernel.org/sourceware/cygwin/ +powershell -c "Invoke-WebRequest https://cygwin.com/setup-x86.exe -OutFile setup.exe" +setup.exe -qgnNdO -R "%CYG_ROOT%" -s "%CYG_MIRROR%" -l "%CYG_CACHE%" -P dejagnu -P autoconf -P automake -P libtool -P make +endlocal +exit /B diff --git a/c/libffi_arm64/ffi.lib b/c/libffi_arm64/ffi.lib index 4a8b84b..b3f79e1 100644 Binary files a/c/libffi_arm64/ffi.lib and b/c/libffi_arm64/ffi.lib differ diff --git a/c/libffi_arm64/include/ffi.h b/c/libffi_arm64/include/ffi.h index d91c3e1..87eb14b 100644 --- a/c/libffi_arm64/include/ffi.h +++ b/c/libffi_arm64/include/ffi.h @@ -1,6 +1,7 @@ /* -----------------------------------------------------------------*-C-*- - libffi 3.3-rc0 - Copyright (c) 2011, 2014 Anthony Green - - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc. + libffi 3.4.2 + - Copyright (c) 2011, 2014, 2019, 2021 Anthony Green + - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation @@ -217,7 +218,8 @@ FFI_EXTERN ffi_type ffi_type_complex_longdouble; typedef enum { FFI_OK = 0, FFI_BAD_TYPEDEF, - FFI_BAD_ABI + FFI_BAD_ABI, + FFI_BAD_ARGTYPE } ffi_status; typedef struct { @@ -269,7 +271,7 @@ typedef ffi_raw ffi_java_raw; #endif -FFI_API +FFI_API void ffi_raw_call (ffi_cif *cif, void (*fn)(void), void *rvalue, @@ -288,15 +290,15 @@ FFI_API void ffi_java_raw_call (ffi_cif *cif, void (*fn)(void), void *rvalue, - ffi_java_raw *avalue); + ffi_java_raw *avalue) __attribute__((deprecated)); #endif FFI_API -void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw); +void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_java_raw *raw) __attribute__((deprecated)); FFI_API -void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args); +void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_java_raw *raw, void **args) __attribute__((deprecated)); FFI_API -size_t ffi_java_raw_size (ffi_cif *cif); +size_t ffi_java_raw_size (ffi_cif *cif) __attribute__((deprecated)); /* ---- Definitions for closures ----------------------------------------- */ @@ -310,7 +312,10 @@ typedef struct { void *trampoline_table; void *trampoline_table_entry; #else - char tramp[FFI_TRAMPOLINE_SIZE]; + union { + char tramp[FFI_TRAMPOLINE_SIZE]; + void *ftramp; + }; #endif ffi_cif *cif; void (*fun)(ffi_cif*,void*,void**,void*); @@ -330,6 +335,14 @@ typedef struct { FFI_API void *ffi_closure_alloc (size_t size, void **code); FFI_API void ffi_closure_free (void *); +#if defined(PA_LINUX) || defined(PA_HPUX) +#define FFI_CLOSURE_PTR(X) ((void *)((unsigned int)(X) | 2)) +#define FFI_RESTORE_PTR(X) ((void *)((unsigned int)(X) & ~3)) +#else +#define FFI_CLOSURE_PTR(X) (X) +#define FFI_RESTORE_PTR(X) (X) +#endif + FFI_API ffi_status ffi_prep_closure (ffi_closure*, ffi_cif *, @@ -363,8 +376,8 @@ typedef struct { #if !FFI_NATIVE_RAW_API - /* If this is enabled, then a raw closure has the same layout - as a regular closure. We use this to install an intermediate + /* If this is enabled, then a raw closure has the same layout + as a regular closure. We use this to install an intermediate handler to do the transaltion, void** -> ffi_raw*. */ void (*translate_args)(ffi_cif*,void*,void**,void*); @@ -389,8 +402,8 @@ typedef struct { #if !FFI_NATIVE_RAW_API - /* If this is enabled, then a raw closure has the same layout - as a regular closure. We use this to install an intermediate + /* If this is enabled, then a raw closure has the same layout + as a regular closure. We use this to install an intermediate handler to do the translation, void** -> ffi_raw*. */ void (*translate_args)(ffi_cif*,void*,void**,void*); @@ -421,14 +434,14 @@ FFI_API ffi_status ffi_prep_java_raw_closure (ffi_java_raw_closure*, ffi_cif *cif, void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*), - void *user_data); + void *user_data) __attribute__((deprecated)); FFI_API ffi_status ffi_prep_java_raw_closure_loc (ffi_java_raw_closure*, ffi_cif *cif, void (*fun)(ffi_cif*,void*,ffi_java_raw*,void*), void *user_data, - void *codeloc); + void *codeloc) __attribute__((deprecated)); #endif #endif /* FFI_CLOSURES */ @@ -451,7 +464,7 @@ FFI_API void ffi_call_go (ffi_cif *cif, void (*fn)(void), void *rvalue, /* ---- Public interface definition -------------------------------------- */ -FFI_API +FFI_API ffi_status ffi_prep_cif(ffi_cif *cif, ffi_abi abi, unsigned int nargs, @@ -484,18 +497,18 @@ ffi_status ffi_get_struct_offsets (ffi_abi abi, ffi_type *struct_type, #endif /* If these change, update src/mips/ffitarget.h. */ -#define FFI_TYPE_VOID 0 +#define FFI_TYPE_VOID 0 #define FFI_TYPE_INT 1 -#define FFI_TYPE_FLOAT 2 +#define FFI_TYPE_FLOAT 2 #define FFI_TYPE_DOUBLE 3 #if 0 #define FFI_TYPE_LONGDOUBLE 4 #else #define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE #endif -#define FFI_TYPE_UINT8 5 +#define FFI_TYPE_UINT8 5 #define FFI_TYPE_SINT8 6 -#define FFI_TYPE_UINT16 7 +#define FFI_TYPE_UINT16 7 #define FFI_TYPE_SINT16 8 #define FFI_TYPE_UINT32 9 #define FFI_TYPE_SINT32 10 diff --git a/c/libffi_arm64/include/fficonfig.h b/c/libffi_arm64/include/fficonfig.h index 5768c29..e888ff1 100644 --- a/c/libffi_arm64/include/fficonfig.h +++ b/c/libffi_arm64/include/fficonfig.h @@ -18,6 +18,9 @@ /* Define this if you want extra debugging. */ /* #undef FFI_DEBUG */ +/* Define this if you want statically defined trampolines */ +/* #undef FFI_EXEC_STATIC_TRAMP */ + /* Cannot use PROT_EXEC on this target, so, we revert to alternative means */ /* #undef FFI_EXEC_TRAMPOLINE_TABLE */ @@ -77,12 +80,18 @@ /* Define to 1 if you have the `memcpy' function. */ /* #undef HAVE_MEMCPY */ +/* Define to 1 if you have the `memfd_create' function. */ +/* #undef HAVE_MEMFD_CREATE */ + /* Define to 1 if you have the header file. */ #define HAVE_MEMORY_H 1 /* Define to 1 if you have the `mkostemp' function. */ /* #undef HAVE_MKOSTEMP */ +/* Define to 1 if you have the `mkstemp' function. */ +/* #undef HAVE_MKSTEMP */ + /* Define to 1 if you have the `mmap' function. */ /* #undef HAVE_MMAP */ @@ -95,6 +104,9 @@ /* Define if read-only mmap of a plain file works. */ /* #undef HAVE_MMAP_FILE */ +/* Define if your compiler supports pointer authentication. */ +/* #undef HAVE_PTRAUTH */ + /* Define if .eh_frame sections should be read-only. */ /* #undef HAVE_RO_EH_FRAME */ @@ -110,6 +122,9 @@ /* Define to 1 if you have the header file. */ #define HAVE_STRING_H 1 +/* Define to 1 if you have the header file. */ +/* #undef HAVE_SYS_MEMFD_H */ + /* Define to 1 if you have the header file. */ /* #undef HAVE_SYS_MMAN_H */ @@ -138,7 +153,7 @@ #define PACKAGE_NAME "libffi" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "libffi 3.3-rc0" +#define PACKAGE_STRING "libffi 3.4.2" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "libffi" @@ -147,7 +162,7 @@ #define PACKAGE_URL "" /* Define to the version of this package. */ -#define PACKAGE_VERSION "3.3-rc0" +#define PACKAGE_VERSION "3.4.2" /* The size of `double', as computed by sizeof. */ #define SIZEOF_DOUBLE 8 @@ -177,7 +192,7 @@ /* #undef USING_PURIFY */ /* Version number of package */ -#define VERSION "3.3-rc0" +#define VERSION "3.4.2" /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ diff --git a/c/libffi_arm64/include/ffitarget.h b/c/libffi_arm64/include/ffitarget.h index ecb6d2d..d5622e1 100644 --- a/c/libffi_arm64/include/ffitarget.h +++ b/c/libffi_arm64/include/ffitarget.h @@ -32,7 +32,7 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #define FFI_SIZEOF_JAVA_RAW 4 typedef unsigned long long ffi_arg; typedef signed long long ffi_sarg; -#elif defined(_M_ARM64) +#elif defined(_WIN32) #define FFI_SIZEOF_ARG 8 typedef unsigned long long ffi_arg; typedef signed long long ffi_sarg; @@ -45,8 +45,13 @@ typedef enum ffi_abi { FFI_FIRST_ABI = 0, FFI_SYSV, + FFI_WIN64, FFI_LAST_ABI, +#if defined(_WIN32) + FFI_DEFAULT_ABI = FFI_WIN64 +#else FFI_DEFAULT_ABI = FFI_SYSV +#endif } ffi_abi; #endif @@ -69,22 +74,22 @@ typedef enum ffi_abi #define FFI_TRAMPOLINE_CLOSURE_OFFSET FFI_TRAMPOLINE_SIZE #endif -#ifdef _M_ARM64 +#ifdef _WIN32 #define FFI_EXTRA_CIF_FIELDS unsigned is_variadic #endif +#define FFI_TARGET_SPECIFIC_VARIADIC /* ---- Internal ---- */ #if defined (__APPLE__) -#define FFI_TARGET_SPECIFIC_VARIADIC #define FFI_EXTRA_CIF_FIELDS unsigned aarch64_nfixedargs -#elif !defined(_M_ARM64) +#elif !defined(_WIN32) /* iOS and Windows reserve x18 for the system. Disable Go closures until a new static chain is chosen. */ #define FFI_GO_CLOSURES 1 #endif -#ifndef _M_ARM64 +#ifndef _WIN32 /* No complex type on Windows */ #define FFI_TARGET_HAS_COMPLEX_TYPE #endif -- cgit v1.2.1