php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79092 Building with clang+lld-9 results in a broken PHP binary
Submitted: 2020-01-10 04:47 UTC Modified: 2020-01-28 15:54 UTC
From: mike at tedder dot cc Assigned: dmitry (profile)
Status: Closed Package: *Compile Issues
PHP Version: 7.4.1 OS: Ubuntu 19.10
Private report: No CVE-ID: None
 [2020-01-10 04:47 UTC] mike at tedder dot cc
Description:
------------
When building PHP 7.4.1 with clang/llvm-9 and using the lld linker, executing the built php binary results in the following error:

/opt/php/bin/php: error while loading shared libraries: cannot apply additional memory protection after relocation: Cannot allocate memory

I've traced the cause of this to be due to added support for alignment of segments on huge page boundaries, which passes two extra page-size flags to the linker.  This was added to configure.ac in git commit 62ded6e here ( https://github.com/php/php-src/commit/62ded6efbcb41e24a505117f8de5b70d56a98f57 ):

    EXTRA_LDFLAGS_PROGRAM="$EXTRA_LDFLAGS_PROGRAM -Wl,-zcommon-page-size=2097152 -Wl,-zmax-page-size=2097152"

If both of these page-size flags are removed, the resulting PHP binary successfully executes as expected.

At this time, I don't know if this is a bug in lld, or if these values are incorrect in some form (possibly GNU ld specific?) and shouldn't be passed by PHP.

Below is a Dockerfile to reproduce this issue:
=======================================================
FROM ubuntu:19.10

RUN apt-get update && \
	apt-get install -y \
		autoconf curl gnupg2 lsb-release make \
		software-properties-common wget

WORKDIR /root
RUN wget https://apt.llvm.org/llvm.sh && \
	chmod +x llvm.sh && \
	./llvm.sh 9

ARG PHP_VERSION="php-7.4.1"
RUN curl -sL https://www.php.net/distributions/${PHP_VERSION}.tar.xz | tar xJv
WORKDIR /root/${PHP_VERSION}

# uncomment to disable alignment of segments on huge page boundaries in configure.ac to work with clang/lld-9
#RUN sed -i 's/-Wl,-zcommon-page-size=2097152 -Wl,-zmax-page-size=2097152//g' ./configure.ac && ./buildconf --force

ARG CFLAGS="-Oz"
ARG LDFLAGS="-fuse-ld=lld-9"
RUN CC="clang-9" CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" ./configure --prefix=/opt/php --disable-cgi --disable-all && \
	make -j $(nproc) && \
	make install

RUN echo "<?php phpinfo();" | /opt/php/bin/php
=======================================================



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-10 09:19 UTC] nikic@php.net
-Assigned To: +Assigned To: dmitry
 [2020-01-28 11:59 UTC] dmitry@php.net
The proposed patch https://github.com/php/php-src/pull/5123
It would be great to test it with lld-9.
 [2020-01-28 15:54 UTC] mike at tedder dot cc
Thanks!  I've tested the new proposed patch, but there's two issues:

1. Running configure with the new configure.ac results in the following error:

=======================================
Configuring TSRM
checking linker support for -zcommon-page-size=2097152... ./configure: line 83375: = -Wl,-zcommon-page-size=2097152 -Wl,-zmax-page-size=2097152: command not found
yes
=======================================

This appears to be due to use of $LDFLAGS to set variables instead of LDFLAGS (without the $ sign).

2. Even with the above fix, lld-9 generates valid executables for the page size detection during the configure process.  This results in no change to the php link phase, and still ends up with a broken binary.

I've added a related comment to the pull request: https://github.com/php/php-src/pull/5123
 [2020-01-29 09:15 UTC] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=ce44cd3b3c32a1ef400065468df94efa6a9624dd
Log: Fixed bug #79092 (Building with clang+lld-9 results in a broken PHP binary)
 [2020-01-29 09:15 UTC] dmitry@php.net
-Status: Assigned +Status: Closed
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Feb 24 21:01:26 2020 UTC