用UCLIBC交叉编译PHP

用UCLIBC交叉编译PHP,php,linux,arm,glibc,uclibc,Php,Linux,Arm,Glibc,Uclibc,这是一个重新发布,前一篇文章被关闭,移动到SERVERFAULT并再次关闭。我认为这篇文章是一个有效的堆栈溢出问题,因为我认为它是由一些自动生成/编译/链接错误引起的。这是一个编程问题,而不是服务器管理问题 发帖开始 我已经下载了PHP5.4.0源代码,将其解压缩并移动到source文件夹中 我执行以下配置: ./configure --build=x86_64-unknown-linux-gnu --host=arm-linux-uclibcgnueabi --prefix=/usr/ar

这是一个重新发布,前一篇文章被关闭,移动到SERVERFAULT并再次关闭。我认为这篇文章是一个有效的堆栈溢出问题,因为我认为它是由一些自动生成/编译/链接错误引起的。这是一个编程问题,而不是服务器管理问题

发帖开始

我已经下载了PHP5.4.0源代码,将其解压缩并移动到source文件夹中

我执行以下配置:

./configure --build=x86_64-unknown-linux-gnu --host=arm-linux-uclibcgnueabi --prefix=/usr/arm/www CC="arm-linux-uclibcgnueabi-gcc --sysroot=/toolchains/gnu_cortex-a9_tools/"  --disable-libxml --disable-dom  --without-iconv --without-openssl --disable-simplexml --disable-xml --disable-xmlreader --disable-xmlwriter --without-pear --without-sqlite3 --disable-pdo --without-pdo-sqlite --disable-phar  --with-config-file-path=/etc/

make
没有错误,一切正常。 接下来我做一个make安装

make install
同样,一切正常。 我将其移动到目标平台并运行

/usr/arm/www/bin/php -v
PHP 5.4.0 (cli) (built: Aug 15 2012 16:07:41) 
Copyright (c) 1997-2012 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2012 Zend Technologies
我用我的Web服务器直接用php测试一个简单的主页

<?php echo "hello" ?>
# php index.php
hello
我设置了另一个脚本:

# php index.php 
helloSegmentation fault
我有php.ini吗

lstat("/srv/www/info.txt", {st_mode=S_IFREG|0644, st_size=20, ...}) = 0
open("/srv/www/info.txt", O_RDONLY)     = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=20, ...}) = 0
lseek(3, 10, SEEK_CUR)                  = 0
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
是,并且没有禁用的功能。 测试strace/usr/arm/www/bin/php index.php

fcntl64(3, F_GETFL)                     = 0 (flags O_RDONLY)
ioctl(3, SNDCTL_TMR_TIMEBASE or TCGETS, 0x7e31fddc) = -1 EINVAL (Invalid argument)
vfork()                                 = 3324
close(4)                                = 0
fstat(3, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
read(3, "total 24\n-rw-rw-r--    1 1001    "..., 8192) = 468
read(3, ""..., 8192)                    = 0
--- SIGCHLD (Child exited) @ 0 (0) ---
close(3)                                = 0
wait4(3324, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], 0, NULL) = 3324
--- SIGSEGV (Segmentation fault) @ 0 (0) ---
+++ killed by SIGSEGV +++
info.txt文件存在,并且获得了读取/写入该文件的预授权

测试strace/usr/arm/www/bin/php shell.php

Starting program: /usr/arm/www/bin/php index.php
hello
Program received signal SIGSEGV, Segmentation fault.
zend_do_fcall_common_helper_SPEC (execute_data=0x2ac7a040) at /home/maiden/Downloads/php-5.4.0/Zend/zend.h:391
391 /home/maiden/Downloads/php-5.4.0/Zend/zend.h: No such file or directory.
    in /home/maiden/Downloads/php-5.4.0/Zend/zend.h
# valgrind php test.php
==2181== Memcheck, a memory error detector
==2181== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==2181== Using Valgrind-3.8.0 and LibVEX; rerun with -h for copyright info
==2181== Command: php test.php
==2181==
==2181== Conditional jump or move depends on uninitialised value(s)
==2181==    at 0x4004EC8: ??? (in /lib/ld-uClibc-0.9.30-nptl.so)
==2181==
==2181== Invalid read of size 4
==2181==    at 0x4004D48: _dl_get_ready_to_run (in /lib/ld-uClibc-0.9.30-nptl.so)
==2181==  Address 0x7d4cc304 is just below the stack ptr.  To suppress, use: --workaround-gcc296-bugs=yes
==2181==
==2181== Invalid read of size 4
==2181==    at 0x48C348C: __uClibc_main (in /lib/libuClibc-0.9.30-nptl.so)
==2181==  Address 0x7d4cc554 is just below the stack ptr.  To suppress, use: --workaround-gcc296-bugs=yes
==2181==
==2181== Invalid write of size 4
==2181==    at 0x233010: __eqdf2 (ieee754-df.S:1120)
==2181==  Address 0x7d4cb0bc is just below the stack ptr.  To suppress, use: --workaround-gcc296-bugs=yes
==2181==
Warning: shell_exec(): Unable to execute 'ls -lart' in /test.php on line 3
==2181== Invalid read of size 4
==2181==    at 0x1FF1AC: zend_do_fcall_common_helper_SPEC (zend.h:391)
==2181==    by 0x1F3D17: execute (zend_vm_execute.h:410)
==2181==    by 0x18B217: zend_execute_scripts (zend.c:1279)
==2181==    by 0x1365BB: php_execute_script (main.c:2473)
==2181==    by 0x22B52B: do_cli (php_cli.c:988)
==2181==    by 0x22BD4B: main (php_cli.c:1364)
==2181==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
==2181==
Segmentation fault
如果我通过gdb运行index.php,它会给我:

Program received signal SIGSEGV, Segmentation fault.

zend_do_fcall_common_helper_SPEC (execute_data=0x2ab76040) at /home/maiden/Downloads/php-5.4.0/Zend/zend.h:391
391 in /home/maiden/Downloads/php-5.4.0/Zend/zend.h
gdb从shell.php中给了我这个 启动程序:/usr/arm/www/bin/php shell.php

Starting program: /usr/arm/www/bin/php index.php
hello
Program received signal SIGSEGV, Segmentation fault.
zend_do_fcall_common_helper_SPEC (execute_data=0x2ac7a040) at /home/maiden/Downloads/php-5.4.0/Zend/zend.h:391
391 /home/maiden/Downloads/php-5.4.0/Zend/zend.h: No such file or directory.
    in /home/maiden/Downloads/php-5.4.0/Zend/zend.h
# valgrind php test.php
==2181== Memcheck, a memory error detector
==2181== Copyright (C) 2002-2012, and GNU GPL'd, by Julian Seward et al.
==2181== Using Valgrind-3.8.0 and LibVEX; rerun with -h for copyright info
==2181== Command: php test.php
==2181==
==2181== Conditional jump or move depends on uninitialised value(s)
==2181==    at 0x4004EC8: ??? (in /lib/ld-uClibc-0.9.30-nptl.so)
==2181==
==2181== Invalid read of size 4
==2181==    at 0x4004D48: _dl_get_ready_to_run (in /lib/ld-uClibc-0.9.30-nptl.so)
==2181==  Address 0x7d4cc304 is just below the stack ptr.  To suppress, use: --workaround-gcc296-bugs=yes
==2181==
==2181== Invalid read of size 4
==2181==    at 0x48C348C: __uClibc_main (in /lib/libuClibc-0.9.30-nptl.so)
==2181==  Address 0x7d4cc554 is just below the stack ptr.  To suppress, use: --workaround-gcc296-bugs=yes
==2181==
==2181== Invalid write of size 4
==2181==    at 0x233010: __eqdf2 (ieee754-df.S:1120)
==2181==  Address 0x7d4cb0bc is just below the stack ptr.  To suppress, use: --workaround-gcc296-bugs=yes
==2181==
Warning: shell_exec(): Unable to execute 'ls -lart' in /test.php on line 3
==2181== Invalid read of size 4
==2181==    at 0x1FF1AC: zend_do_fcall_common_helper_SPEC (zend.h:391)
==2181==    by 0x1F3D17: execute (zend_vm_execute.h:410)
==2181==    by 0x18B217: zend_execute_scripts (zend.c:1279)
==2181==    by 0x1365BB: php_execute_script (main.c:2473)
==2181==    by 0x22B52B: do_cli (php_cli.c:988)
==2181==    by 0x22BD4B: main (php_cli.c:1364)
==2181==  Address 0x8 is not stack'd, malloc'd or (recently) free'd
==2181==
Segmentation fault
h位于/usr/arm/www/include/php/zend中/ 显然,交叉编译过程中出现了一些问题。我错过了什么?我没有找到任何配置标志来纠正这一点,创建一个指向所需位置的符号链接会删除gdb输出,但php仍然存在错误

谢谢你的帮助

更新:

php: can't resolve symbol '__libc_freeres'
更新2

使用memcheck重新运行valgrind,获得与以前相同的输出,但这是新的:

(gdb) run index.php 
Starting program: /bin/php index.php
hello
Program received signal SIGSEGV, Segmentation fault.
zend_do_fcall_common_helper_SPEC (execute_data=0x2ab34040) at /home/maiden/Downloads/php-5.4.5/Zend/zend.h:391
warning: Source file is more recent than executable.
391     return --pz->refcount__gc;
更新3

虽然valgrind让我失望,但我继续使用gdb,我在目标系统上创建了文件夹/home/maiden/.etc,并复制了php/include文件夹的内容,然后重新运行gdb。现在,我收到以下错误消息:

这与sixeightzero昨天在评论中所写的非常相似。 我现在已经尝试了PHP版本5.3.5、5.4.0、5.4.5,但所有版本都出现了相同的错误

更新4


我为glibc下载了一个新的工具链,用glibc交叉编译了一个新的busybox,创建了一个chroot-jail,用glibc而不是uclibc交叉编译了php,并在我的chroot-jail中的uclibc-box上测试了它,它工作了!但是我仍然需要让php在我的uclibc环境中工作….

我会检查uclibc的configure.log,看看是否启用了ARCH\u USE\u MMU和fork。如果没有,vWork将替换为可能由shell_exec使用的fork。vWork的主要问题是,家长和孩子使用相同的内存空间,这会导致奇怪的崩溃。

对不起,伙计,我建议将其移动,因为我认为这会给你带来更多的答案,因为你的上一个问题在这里什么地方都没有。我的错:(GAAHWAAAH!!!RAAAGE!!距离赏金还有6小时,现在我不得不再等2天。>\u<,一点也不难过,你有一个很好的意图。我在@PHP.net上留下了一个错误报告,让我们看看它会带我去哪里。^\u^你能在任何arm仿真器上复制吗?例如,armware,qemu,ARMphethamine。如果是的话,你可以给我们关于如何复制这两个主机的详细说明和目标环境,一步一步准确地说明你在做什么,不必提供任何细节,下载链接或准确的版本号。不幸的是,这不是一个合适的渠道来解决这么多变量的问题,最好是暗箱操作。我很抱歉,你已经与此斗争了这么久,一定会让我很沮丧现在,如果我们可以用你的指令重现这个问题,我们可能真的会有所进展。我不知道这是否有帮助,但如果你想看看另一个嵌入式项目如何用uClibc编译PHP,请检查。它在MIPS上,但一些配置和工具链问题可能类似。在repo中,你还可以找到工具链makefiles和patc他是uClibc的。只是一个提示:列出文件名的gdb错误和valgrind错误没有在这些位置查找文件;这些位置是编译时在原始主机上的位置。php在运行时不需要包含文件…我也想检查一下。但我只从CPU制造商那里得到了二进制blob。但如果它被禁用,我会感到惊讶。我们有一个webkit浏览器,Qt和DirectFB使用相同的工具链。
php: can't resolve symbol '__libc_freeres'
(gdb) run index.php 
Starting program: /bin/php index.php
hello
Program received signal SIGSEGV, Segmentation fault.
zend_do_fcall_common_helper_SPEC (execute_data=0x2ab34040) at /home/maiden/Downloads/php-5.4.5/Zend/zend.h:391
warning: Source file is more recent than executable.
391     return --pz->refcount__gc;