dstogov / php-ffi

PHP Foreign Function Interface
570 stars 32 forks source link

make fail, ‘FFI_FASTCALL’ undeclared #8

Open diyism opened 6 years ago

diyism commented 6 years ago

==========reproduce===========

$git clone -b PHP-7.3 --depth 1 https://github.com/php/php-src.git
$cd php-src/
$git clone -b master --depth 1 https://github.com/dstogov/php-ffi.git ext/php_ffi
$./buildconf --force

$./configure --prefix=/usr/local/php7 --disable-all --enable-cli --disable-cgi --disable-fpm --disable-phpdbg --enable-bcmath --enable-hash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --enable-sockets --enable-pdo --with-sodium --with-password-argon2 --with-sqlite3 --with-pdo-sqlite --with-pcre-regex --with-zlib --with-openssl-dir --enable-openssl --with-ffi
$time make -j `cat /proc/cpuinfo | grep processor | wc -l`
......
libtool --silent --preserve-dup-deps --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Iext/reflection/ -I/home/malcolm/WorkSpace/php-src/ext/reflection/ -DPHP_ATOM_INC -I/home/malcolm/WorkSpace/php-src/include -I/home/malcolm/WorkSpace/php-src/main -I/home/malcolm/WorkSpace/php-src -I/home/malcolm/WorkSpace/php-src/ext/date/lib -I/home/malcolm/WorkSpace/php-src/ext/mbstring/oniguruma -I/home/malcolm/WorkSpace/php-src/ext/mbstring/libmbfl -I/home/malcolm/WorkSpace/php-src/ext/mbstring/libmbfl/mbfl -I/home/malcolm/WorkSpace/php-src/ext/sqlite3/libsqlite -I/usr/local/include -I/home/malcolm/WorkSpace/php-src/TSRM -I/home/malcolm/WorkSpace/php-src/Zend    -g -O2 -fvisibility=hidden -DZEND_SIGNALS   -c /home/malcolm/WorkSpace/php-src/ext/reflection/php_reflection.c -o ext/reflection/php_reflection.lo 
php-src/ext/php_ffi/ffi.c: In function ‘zend_ffi_make_func_type’:
php-src/ext/php_ffi/ffi.c:4957:21: error: ‘FFI_FASTCALL’ undeclared (first use in this function); did you mean ‘FFI_LAST_ABI’?

$ ll /usr/local/include/ffi*
-rw-r--r-- 1 root staff 13702 Aug  9 19:29 /usr/local/include/ffi.h
-rw-r--r-- 1 root staff  4343 Aug  9 19:29 /usr/local/include/ffitarget.h

$ sudo apt-get install libffi-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libffi-dev is already the newest version (3.2.1-8).
0 upgraded, 0 newly installed, 0 to remove and 964 not upgraded.

@dstogov any hint?

dstogov commented 6 years ago

I'm on vacation and will able to check this only on next week. I tested ext/ffi only as a shared extension (built separately from php with phpize; configure, make install).

do you use x86(_64) Linux?

dstogov commented 6 years ago

@diyism may be you have different libffi versions installed in /usr and /usr/local (the size of your /usr/local/include/ffi.h is very different from mine).

diyism commented 6 years ago

in my ubuntu 14.04, the libffi-dev version is 3.1~rc1+r3.0.13-12ubuntu0.2, the make error is: ‘FFI_FASTCALL’ undeclared

so i tried building it again in my ubuntu 18.04: $sudo apt-get install libffi6 libffi-dev $apt-cache policy libffi-dev libffi-dev: Installed: 3.2.1-4 Candidate: 3.2.1-4 $ln -s /usr/include/x86_64-linux-gnu/ffi.h /usr/include/ffi.h $ln -s /usr/include/x86_64-linux-gnu/ffitarget.h /usr/include/ffitarget.h $git clone -b PHP-7.3 --depth 1 https://github.com/php/php-src.git $cd php-src/ $git clone -b master --depth 1 https://github.com/dstogov/php-ffi.git ext/php_ffi $./buildconf --force $./configure --prefix=/usr/local/php7 --disable-all --enable-cli --disable-cgi --disable-fpm --disable-phpdbg --enable-bcmath --enable-hash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --enable-sockets --enable-pdo --with-sodium --with-password-argon2 --with-sqlite3 --with-pdo-sqlite --with-pcre-regex --with-zlib --with-openssl-dir --enable-openssl --with-ffi $time make -j cat /proc/cpuinfo | grep processor | wc -l ...... /bin/bash /root/php-src/libtool --silent --preserve-dup-deps --mode=compile cc -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 -Imain/ -I/root/php-src/main/ -DPHP_ATOM_INC -I/root/php-src/include -I/root/php-src/main -I/root/php-src -I/root/php-src/ext/date/lib -I/root/php-src/ext/mbstring/oniguruma -I/root/php-src/ext/mbstring/libmbfl -I/root/php-src/ext/mbstring/libmbfl/mbfl -I/root/php-src/ext/sqlite3/libsqlite -I/root/php-src/TSRM -I/root/php-src/Zend -g -O2 -fvisibility=hidden -DZEND_SIGNALS -c main/internal_functions_cli.c -o main/internal_functions_cli.lo main/internal_functions_cli.c:57:2: error: ‘phpext_ffi_ptr’ undeclared here (not in a function) phpext_ffi_ptr, ^ Makefile:1130: recipe for target 'main/internal_functions_cli.lo' failed make: *** [main/internal_functions_cli.lo] Error 1

dstogov commented 6 years ago

@diyism You have different problems on different systems.

1) ‘FFI_FASTCALL’ undeclared error may be because of old libffi (libffi-3.1-16.fc28 works fine for me) or non x86 host.

2) You shouldn't embed ext/ffi into PHP binary, but build it separately (as shared extension), using phpize, configure, make and then load through extension directive in php.ini

yaroslavche commented 4 years ago

Hi. I got similar issue. openSUSE Leap 15.1, libffi-devel 3.2.1.git259-lp151.19.1 x86_64

➜ phpize ``` Configuring for: PHP Api Version: 20190902 Zend Module Api No: 20190902 Zend Extension Api No: 320190902 ```
➜ ./configure --with-ffi ``` configure: loading site script /usr/share/site/x86_64-unknown-linux-gnu checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking for a sed that does not truncate output... /usr/bin/sed checking for pkg-config... /usr/bin/pkg-config checking pkg-config is at least version 0.9.0... yes checking for cc... cc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether cc accepts -g... yes checking for cc option to accept ISO C89... none needed checking how to run the C preprocessor... cc -E checking for icc... no checking for suncc... no checking for system library directory... lib checking if compiler supports -R... no checking if compiler supports -Wl,-rpath,... yes checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking target system type... x86_64-pc-linux-gnu checking for PHP prefix... /usr checking for PHP includes... -I/usr/include/php7 -I/usr/include/php7/main -I/usr/include/php7/TSRM -I/usr/include/php7/Zend -I/usr/include/php7/ext -I/usr/include/php7/ext/date/lib checking for PHP extension directory... /usr/lib64/php7/extensions checking for PHP installed headers prefix... /usr/include/php7 checking if debug is enabled... no checking if zts is enabled... no checking for gawk... gawk checking for FFI support... yes, shared checking for libffi... found version 3.3 checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking for long double... yes checking for ffi_call in -lffi... yes checking how to print strings... printf checking for a sed that does not truncate output... (cached) /usr/bin/sed checking for fgrep... /usr/bin/grep -F checking for ld used by cc... /usr/x86_64-suse-linux/bin/ld checking if the linker (/usr/x86_64-suse-linux/bin/ld) is GNU ld... yes checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B checking the name lister (/usr/bin/nm -B) interface... BSD nm checking whether ln -s works... yes checking the maximum length of command line arguments... 1572864 checking how to convert x86_64-pc-linux-gnu file names to x86_64-pc-linux-gnu format... func_convert_file_noop checking how to convert x86_64-pc-linux-gnu file names to toolchain format... func_convert_file_noop checking for /usr/x86_64-suse-linux/bin/ld option to reload object files... -r checking for objdump... objdump checking how to recognize dependent libraries... pass_all checking for dlltool... no checking how to associate runtime and link libraries... printf %s\n checking for ar... ar checking for archiver @FILE support... @ checking for strip... strip checking for ranlib... ranlib checking for gawk... (cached) gawk checking command to parse /usr/bin/nm -B output from cc object... ok checking for sysroot... no checking for a working dd... /usr/bin/dd checking how to truncate binary pipes... /usr/bin/dd bs=4096 count=1 checking for mt... mt checking if mt is a manifest tool... no checking for dlfcn.h... yes checking for objdir... .libs checking if cc supports -fno-rtti -fno-exceptions... no checking for cc option to produce PIC... -fPIC -DPIC checking if cc PIC flag -fPIC -DPIC works... yes checking if cc static flag -static works... no checking if cc supports -c -o file.o... yes checking if cc supports -c -o file.o... (cached) yes checking whether the cc linker (/usr/x86_64-suse-linux/bin/ld -m elf_x86_64) supports shared libraries... yes checking whether -lc should be explicitly linked in... no checking dynamic linker characteristics... GNU/Linux ld.so checking how to hardcode library paths into programs... immediate checking whether stripping libraries is possible... yes checking if libtool supports shared libraries... yes checking whether to build shared libraries... yes checking whether to build static libraries... no configure: patching config.h.in configure: creating ./config.status config.status: creating config.h config.status: config.h is unchanged config.status: executing libtool commands ```
➜ make ``` /bin/sh /home/yaroslav/projects/OSS/php/php-ffi/libtool --mode=compile cc -I. -I/home/yaroslav/projects/OSS/php/php-ffi -DPHP_ATOM_INC -I/home/yaroslav/projects/OSS/php/php-ffi/include -I/home/yaroslav/projects/OSS/php/php-ffi/main -I/home/yaroslav/projects/OSS/php/php-ffi -I/usr/include/php7 -I/usr/include/php7/main -I/usr/include/php7/TSRM -I/usr/include/php7/Zend -I/usr/include/php7/ext -I/usr/include/php7/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /home/yaroslav/projects/OSS/php/php-ffi/ffi.c -o ffi.lo libtool: compile: cc -I. -I/home/yaroslav/projects/OSS/php/php-ffi -DPHP_ATOM_INC -I/home/yaroslav/projects/OSS/php/php-ffi/include -I/home/yaroslav/projects/OSS/php/php-ffi/main -I/home/yaroslav/projects/OSS/php/php-ffi -I/usr/include/php7 -I/usr/include/php7/main -I/usr/include/php7/TSRM -I/usr/include/php7/Zend -I/usr/include/php7/ext -I/usr/include/php7/ext/date/lib -I/usr/local/include -DHAVE_CONFIG_H -g -O2 -c /home/yaroslav/projects/OSS/php/php-ffi/ffi.c -fPIC -DPIC -o .libs/ffi.o /home/yaroslav/projects/OSS/php/php-ffi/ffi.c: In function ‘zend_ffi_make_func_type’: /home/yaroslav/projects/OSS/php/php-ffi/ffi.c:5545:21: error: ‘FFI_FASTCALL’ undeclared (first use in this function); did you mean ‘FFI_LAST_ABI’? type->func.abi = FFI_FASTCALL; ^~~~~~~~~~~~ FFI_LAST_ABI /home/yaroslav/projects/OSS/php/php-ffi/ffi.c:5545:21: note: each undeclared identifier is reported only once for each function it appears in /home/yaroslav/projects/OSS/php/php-ffi/ffi.c:5548:21: error: ‘FFI_THISCALL’ undeclared (first use in this function); did you mean ‘FFI_FASTCALL’? type->func.abi = FFI_THISCALL; ^~~~~~~~~~~~ FFI_FASTCALL /home/yaroslav/projects/OSS/php/php-ffi/ffi.c:5551:21: error: ‘FFI_STDCALL’ undeclared (first use in this function); did you mean ‘FFI_FASTCALL’? type->func.abi = FFI_STDCALL; ^~~~~~~~~~~ FFI_FASTCALL /home/yaroslav/projects/OSS/php/php-ffi/ffi.c:5571:21: error: ‘FFI_SYSV’ undeclared (first use in this function); did you mean ‘FFI_OK’? type->func.abi = FFI_SYSV; ^~~~~~~~ FFI_OK make: *** [Makefile:192: ffi.lo] Error 1 ```
dstogov commented 4 years ago

ext/ffi has been merged into main PHP source tree since PHP-7.4. This repository is not supported any more.

This issue is already fixed there. See https://github.com/php/php-src/tree/master/ext/ffi