<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/57618>57618</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            lld produces non-runnable ELF if common-page-size and max-page-size options are used
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          vient
      </td>
    </tr>
</table>

<pre>
    Hi,

Linking ELF file with lld and `-Wl,-zcommon-page-size=2097152 -Wl,-zmax-page-size=2097152` produces ELF which crashes on start with error:
```
/opt/php/bin/php: error while loading shared libraries: cannot apply additional memory protection after relocation: Cannot allocate memory
```

Linking with `-Wl,-zmax-page-size=2097152` only produces ELF which has align 0x200000 in readelf's output but no sections are actually aligned to this value. ld works fine in both cases.

I've encountered this error in a private codebase but since producing minimal testcase is not trivial and there was [exact same issue in PHP](https://bugs.php.net/bug.php?id=79092&edit=3), I decided to refresh their reproducer:

```dockerfile
FROM ubuntu:22.04

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 15

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

# uncomment to set common-page-size and produce invalid ELF
#RUN sed -i 's/EXTRA_LDFLAGS_PROGRAM -Wl,-zmax-page-size=2097152/EXTRA_LDFLAGS_PROGRAM -Wl,-zcommon-page-size=2097152 -Wl,-zmax-page-size=2097152/g' ./configure.ac && ./buildconf --force

ARG CFLAGS="-Oz"
ARG LDFLAGS="-fuse-ld=lld-15"
RUN CC="clang-15" 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 ; readelf -WlS /opt/php/bin/php
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJylVk1z4jgQ_TXm0mWXER-GA4ckhJnsZiYpsruzt5Qsy1gTIbkkGUh-_XbbTgIpMnNYCgiW1K3Xr193J7fF8-KrithVlC6j9KL7vlXmSZkNXN-uoFRawl6FCrQugJsComka_9BoEr8Iu91aE9d8I2OvXmQ0WrJ0ng0nDF6PbPnh3D46gdrZohHSt_fsKyUqEI77ClesAR-4C93N0jnrolGPDk37d_fIVrYO-F1XNX7nyvS_RxedIbnGGLTlBQXlK-5kAVrljjslPZ0T3BgbgNe1fgZeFCooa7iGrdxa90xAgxS0BrwM0oGT2gpOC2R91VvrdlH2VufBnvDbBndE5y-4skY_nyOs4h4vVhsD6YGl9AJlEB8vpC4jliGVTaibADl-jAXfxYFGTgIXoUHUz50HJCVYCJXysOO6kQlgwvfWPXkUgZHkN7cIWHAvfXIczw1etJMgjbCNQX7IE7np6Ec7jtDVjrgRtpA5OmjxeGWE7KMiPrbKqC3SHqQPdAugD2I2oLHCdVJfqNA_7DHsaHIpDxgCeL6lo75pMd5_vY8my4jNqhBqyi7KgXTRbHyCskiMDN1j0opkpQpkOpuncxaxqcTU4-MoYnPMCNxAIYUqOmacLJ30FSFQJIE-G0fCPM14YcWTdFQ_3cZqffcNmhwZatCEsSQdH9ut__6OAgzxRgZo6oLIQkD4xkD76gR8vR5RBgtEa4ifP-w3wQprShCN07AxTb1hoH0eo2YlcbrlT_LUxNsy7FEPMUZUSxewKOKusmGPVx2D_HG3_nN5s0ZkK2dteEdOB-GUcUSaaL3bJtZt8LH9ifSdC0pUW4uNhV0e4FfHkiM3w8kxrov1F0r84z_X64ebu--YwogxzG88S4YJppK9I215if3tB7T7_f5IHoXyKDrUKNVKe2AcZZfHN2TLBBtUcniBKLsC_AmHP3bnSTpvfqIZNoLGEOfSBNKaRzY_NtdW_r3oMP1Y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