Bug #79092 [Asn]: Building with clang+lld-9 results in a broken PHP binary

From: Date: Tue, 28 Jan 2020 15:54:18 +0000
Subject: Bug #79092 [Asn]: Building with clang+lld-9 results in a broken PHP binary
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225198@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79092&edit=1 ID: 79092 User updated by: mike at tedder dot cc Reported by: mike at tedder dot cc Summary: Building with clang+lld-9 results in a broken PHP binary Status: Assigned Type: Bug Package: *Compile Issues Operating System: Ubuntu 19.10 PHP Version: 7.4.1 Assigned To: dmitry Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2020-01-28 11:59:04] 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-10 04:47:15] 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 ======================================================= ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=79092&edit=1

« previous php.bugs (#225198) next »