|  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
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 in git commit 62ded6e here ( ):

    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

RUN wget && \
	chmod +x && \
	./ 9

ARG PHP_VERSION="php-7.4.1"
RUN curl -sL${PHP_VERSION}.tar.xz | tar xJv

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

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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-10 09:19 UTC]
-Assigned To: +Assigned To: dmitry
 [2020-01-28 11:59 UTC]
The proposed patch
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 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

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:
 [2020-01-29 09:15 UTC]
Automatic comment on behalf of
Log: Fixed bug #79092 (Building with clang+lld-9 results in a broken PHP binary)
 [2020-01-29 09:15 UTC]
-Status: Assigned +Status: Closed
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Tue Sep 28 21:03:37 2021 UTC