title: Cross compile PHP
body: <p>I have downloaded the PHP 5.4.0 source, extracted it and moved into the source folder.</p>
  
  <p>I do a configure with:</p>
  
  <pre><code>./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/
  </code></pre>
  
  <p>Followed by </p>
  
  <pre><code>make
  </code></pre>
  
  <p>no errors, everything runs fine.
  Next i do a make install. </p>
  
  <pre><code>make install
  </code></pre>
  
  <p>Again everything runs fine.
  i move it to the target platform and run</p>
  
  <pre><code>/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
  </code></pre>
  
  <p>I test a simple home page with my webserver and directly with php. </p>
  
  <pre><code>&lt;?php echo "hello" ?&gt;
  # php index.php
  hello
  </code></pre>
  
  <p>it works as expected.
  next i test:</p>
  
  <pre><code>&lt;?php
  $output = shell_exec('ls -lart');
  echo "&lt;pre&gt;$output&lt;/pre&gt;";
  ?&gt;
  </code></pre>
  
  <p>oh noes~</p>
  
  <pre><code># php shell.php 
  
  Segmentation fault
  </code></pre>
  
  <p>I teset another script:</p>
  
  <pre><code>#!/bin/php
  &lt;?php
  
  echo "hello";
  $handle = fopen("info.txt", "r");
  echo $handle;
  ?&gt;
  </code></pre>
  
  <p>Same result:</p>
  
  <pre><code># php index.php 
  helloSegmentation fault
  </code></pre>
  
  <p>do i have a php.ini?</p>
  
  <pre><code># /usr/arm/www/bin/php --ini
  Configuration File (php.ini) Path: /etc/
  Loaded Configuration File:         /etc/php.ini
  </code></pre>
  
  <p>yes, and no disabled functions. 
  testing strace /usr/arm/www/bin/php index.php</p>
  
  <pre><code>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 +++
  </code></pre>
  
  <p>the file info.txt exists and it got premission to read/write to it.</p>
  
  <p>Testing strace /usr/arm/www/bin/php shell.php</p>
  
  <pre><code>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) &amp;&amp; WEXITSTATUS(s) == 0}], 0, NULL) = 3324
  --- SIGSEGV (Segmentation fault) @ 0 (0) ---
  +++ killed by SIGSEGV +++
  </code></pre>
  
  <p>if i run the index.php through gdb it gives me:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>gdb gives me this from shell.php
  Starting program: /usr/arm/www/bin/php shell.php</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>
  
  <p>Thanks for any help!</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <pre><code># 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
  </code></pre>
  
  <p><strong>Update2</strong></p>
  
  <p>re-run valgrind with memcheck, got about the same output as before but this was new:</p>
  
  <pre><code>php: can't resolve symbol '__libc_freeres'
  </code></pre>
  
  <p><strong>Update3</strong></p>
  
  <p>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:</p>
  
  <pre><code>(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-&gt;refcount__gc;
  </code></pre>
  
  <p>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.</p>
  
  <p>This topic have been CLOSED! :(
  Continued on: <a href="https://serverfault.com/questions/418521/cross-compile-php">https://serverfault.com/questions/418521/cross-compile-php</a> [CLOSED]
  and now on: <a href="https://stackoverflow.com/questions/12004567/cross-compile-php-with-uclibc">Cross compile PHP with UCLIBC</a></p>