Bug #65106 [NoF->ReO]: PHP fails to compile

From: Date: Mon, 23 Jan 2023 12:55:16 +0000
Subject: Bug #65106 [NoF->ReO]: PHP fails to compile
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-243545@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65106&edit=1

 ID:                 65106
 Updated by:         cmb@php.net
 Reported by:        mark at kreine dot ru
 Summary:            PHP fails to compile
-Status:             No Feedback
+Status:             Re-Opened
 Type:               Bug
 Package:            Compile Failure
 Operating System:   Ubuntu 12.04
 PHP Version:        5.5.0
 Block user comment: N
 Private report:     N



Previous Comments:
------------------------------------------------------------------------
[2023-01-23 06:17:48] guillaume-php at outters dot eu

P.R. at https://github.com/php/php-src/pull/10422

------------------------------------------------------------------------
[2023-01-23 05:15:45] guillaume-php at outters dot eu

The problem arises on a Raspberry Pi 3 Model B (1 Go of RAM) trying to compile PHP 8.1.14.
The 42 MB data_file.c triggers an (exponential?) memory consumption, with gcc at least,
while compiling a 7 MB array (with bytes expressed as "0x00, " thus the total file size).
I wonder if those 7 MB get embedded into every php binary, and are duplicated in every process
(unless fileinfo gets compiled as a shared lib) :-\

PHP 7.4.33's 34 MB data_file.c manages to compile,
using 600 to 700 MB of vsize (tested by decrementing ulimit -v from 1 GB down until crash)

Now, I "seem" (1) to have a solution:
-----------------------------------------------------------
Replace list initialization with string initialization (2).
-----------------------------------------------------------
That is:
    0x1C, 0x04, 0x1E, 0xF1, 0x0E, 0x00, 0x00, 0x00, 0x4F, 0x33, 0x00, 0x00, 0x78, 0x0C, 0x00, 0x00,
become:
    "\x1C\x04\x1E\xF1\x0E\x00\x00\x00\x4F\x33\x00\x00\x78\x0C\x00\x00"

Although a modest gain on the .c size (33 %), gcc requires 75 % less memory to compile. This would
allow us years of fileinfo growing.
Of course a non-regression needs to be done to avoid breaking under compilers who, on the contrary,
worked better with lists; but (1) makes me optimistic.

Notes
-----

(1) "seem" because after crashing my RPi (3), I continued my tests on a totally unrelated
machine (FreeBSD in an amd64 VBox), using PHP 7.4.33 source to test gcc behaviour.
So it lacks a test in real conditions, but I hope the transposition could reveal successful.
Here I needed (ulimit -v dichotomy to determine the necessary vsize for a successful compilation):
* 655 MB (gcc 11.2 with list initialization)
* 179 MB (gcc 11.2 with string initialization)
* 898 MB (clang 13.0.0 with list initialization)
* 210 MB (clang 13.0.0 with string initialization)

(2) Converting the .c:
sed -e 's#^0x#"\\x#' -e 's#, 0x#\\x#g' -e 's#, *$#"#' -e
's#{ *$##' -e 's#}##'
Maybe I could provide a patch for create_data_file.php.

(3) My attempt at fine-graining mem consumption:
# procpath from https:
//unix.stackexchange.com/a/414770/452410
rm -f /tmp/procpath.sqlite3 ; ~/.local/bin/procpath record -i 0.3 -d /tmp/procpath.sqlite3 -r 600
'$..children[?("apprentice" in @.cmdline)]' &
(
    ulimit -v 524288 # Letting 1048576 was a mistake… The RPi crashed.
    cd ~/tmp/php-8.1.14/
    time _here the crashing "/bin/bash …/libtool … …/apprentice.lo" command
line from a ps auxww_
)
killall procpath
sqlite3 /tmp/procpath.sqlite3 "select max(stat_vsize) / 1048576, cmdline from record group by
stat_pid order by max(record_id)" | sed -e 's# -[IW].[^ ]*##g'

------------------------------------------------------------------------
[2020-11-13 09:49:00] remy dot issard at cnrs dot fr

Same problem, Ubuntu 20.04 on VirtualBox VM with Vagrant, PHP7.3.
VM with 1024MB of memory -> not enought !
Solved by setting, in VagrantFile, 2048MB of memory for VM and... It works !

------------------------------------------------------------------------
[2016-03-25 11:19:22] slier81 at gmail dot com

Run to this same issue when try to compile php7.0.4

After some research, i figure this error occurred when im compiling on machine with only 512mb of
memory..

Should have stated system requirement clearly

------------------------------------------------------------------------
[2015-12-22 14:46:30] noreplythanks at example dot fake dot com

I had this issue too, on Raspbian (Linux) on a Raspberry Pi.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=65106


--
Edit this bug report at https://bugs.php.net/bug.php?id=65106&edit=1


Thread (12 messages)

« previous php.bugs (#243545) next »