交叉编译PHP uClibc的 [英] Cross compile PHP with UCLIBC

查看:464
本文介绍了交叉编译PHP uClibc的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个重新发布,preVIOUS POST GOT关闭,转移到SERVERFAULT,然后关闭。我觉得这个职位是一个有效的计算器问题,因为我认为它引起的一些automake的/编译/链接错误。这是一个规划问题不是一个服务器管理员的问题。

THIS IS A REPOST, PREVIOUS POST GOT CLOSED, MOVED TO SERVERFAULT AND CLOSED AGAIN. I think this post is a valid stackoverflow problem because i think its caused by some automake/compile/linking error. This is a programming problem not a server admin problem.

交叉编译PHP

<一个href=\"http://serverfault.com/questions/418521/cross-compile-php\">http://serverfault.com/questions/418521/cross-compile-php

后开始

我已经下载了PHP 5.4.0源,提取它,并移动到源文件夹中。

I have downloaded the PHP 5.4.0 source, extracted it and moved into the source folder.

我做一个配置:

./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 install的。

no errors, everything runs fine. Next i do a make install.

make install

再次一切都正常运行。
我将它移动到目标平台和运行

Again everything runs fine. i move it to the target platform and run

/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

我测试一个简单的主页我的网络服务器,并直接与PHP。

I test a simple home page with my webserver and directly with php.

<?php echo "hello" ?>
# php index.php
hello

它按预期工作。
接下来,我测试:

it works as expected. next i test:

<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>

哦〜不一

# php shell.php 

Segmentation fault

我teset另一个脚本:

I teset another script:

#!/bin/php
<?php

echo "hello";
$handle = fopen("info.txt", "r");
echo $handle;
?>

同样的结果:

# php index.php 
helloSegmentation fault

我有一个php.ini?

do i have a php.ini?

# /usr/arm/www/bin/php --ini
Configuration File (php.ini) Path: /etc/
Loaded Configuration File:         /etc/php.ini

yes和no禁用功能。
测试strace的在/ usr / ARM / WWW /斌/ PHP的index.php

yes, and no disabled functions. testing strace /usr/arm/www/bin/php index.php

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 +++

在info.txt文件存在,并且它得到了premission读/写它。

the file info.txt exists and it got premission to read/write to it.

测试strace的在/ usr / ARM / WWW /斌/ PHP shell.php

Testing strace /usr/arm/www/bin/php shell.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 +++

如果我通过GDB运行的index.php它给了我:

if i run the index.php through gdb it gives me:

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

GDB给了我这个从shell.php
启动程序:在/ usr / ARM / WWW /斌/ PHP shell.php

gdb gives me this from shell.php Starting program: /usr/arm/www/bin/php shell.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

zend.h位于在/ usr / ARM / WWW /有/ PHP / Zend公司/
显然一些交叉编译过程中出了问题。我错过了什么?我没有找到任何配置标志来纠正这个并创建一个符号链接到需要的位置删除gdb的输出,但依然PHP出现segfaults。

zend.h is located in /usr/arm/www/include/php/Zend/ obviously something went wrong during cross compilation. what have i missed? i do not find any configure flag to correct this and creating a symlink to the desired location removes the gdb output but php still segfaults.

感谢您的帮助!

更新:

# 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

UPDATE2

重新运行Valgrind的与MEMCHECK,得到了大致相同的输出之前,但,这是新的:

re-run valgrind with memcheck, got about the same output as before but this was new:

php: can't resolve symbol '__libc_freeres'

UPDATE3

虽然Valgrind的都失败了,我继续用gdb,我创建的文件夹/home/maiden/..etc我的目标系统上复制我的PHP的内容/ include文件夹,然后重新运行GDB。现在我收到此错误信息:

While valgrind have failed me, i continued with gdb, i created the folder /home/maiden/..etc on my target system and copied over the content of my php/include folder and re-run gdb. now i get this error message:

(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;

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

this is very similar to what sixeightzero wrote in the comments yesterday. I have now tried PHP version 5.3.5, 5.4.0, 5.4.5 same error on all.

UPDATE4

我下载了一个新的工具链glibc的交叉编译的一个新的busybox用glibc,创建了一个chroot监牢,交叉编译PHP用glibc,而不是uClibc的和测试它在我的chroot监牢我uClibc的箱子,和它的作品!但我仍然需要为了让PHP在我uClibc的环境中工作......

I downloaded a new toolchain for glibc, cross compiled a new busybox with glibc, created a chroot jail, cross compiled php with glibc instead of uclibc and tested it inside my chroot jail on my uclibc box, and it works! But i still need to get php to work in my uclibc environment....

推荐答案

我会检查uClibc的的configure.log,看看 ARCH_USE_MMU 和叉已启用。如果没有了vfork置换叉这很可能是通过了shell_exec使用。与vfork的主要问题是,父母和孩子使用相同的内存空间而导致奇怪的崩溃。

i would check configure.log of uClibc to see if ARCH_USE_MMU and fork is enabled. if not vfork is replaced with fork which is likely to be used by shell_exec. the main problem with vfork is, parent and child uses same memory space which leads to weird crashes.

这篇关于交叉编译PHP uClibc的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆