[lld] [ELF] Align the end of PT_GNU_RELRO associated PT_LOAD to a common-page-size boundary (PR #66042)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 11:37:26 PDT 2023


MaskRay wrote:

> I've not had a chance to go through the code changes in detail yet.
> 
> Can you help me out a bit with what is causing the problem? Is it just that strip is corrupting the output, or is that just one of the problems?
> 
> The description says "system-page-size < common-page-size".
> 
> What does system-page-size refer to? Do you mean max-page-size? Or is it something like the page size used by the OS? For example: AArch64 max-page-size = 64Kib common-page-size = 4 KiB. An OS may set system-page-size to 4KiB but if I link with max-page-size and common-page-size set to 64 KiB then system-page-size < common-page (and max-page-size).
> 
> I mention that because we currently don't permit common-page-size to be larger than max-page-size.
> 
> ```
> getCommonPageSize()
> ...
>   // commonPageSize can't be larger than maxPageSize.                                                                                                               if (val > config->maxPageSize)
>     val = config->maxPageSize;
> ```

Thanks for the comments. I used system-page-size to mean the OS's page-size. I have renamed it to "runtime page-size" to improve clarity.

Updated the description of the PR:

    Close #57618: currently we align the end of PT_GNU_RELRO to a common-page-size
    boundary, but do not align the end of the associated PT_LOAD, i.e.
    when runtime_page_size < common-page-size, it is possible that `alignUp(end(PT_LOAD), page_size) > alignDown(end(PT_GNU_RELRO), page_size)`.
    rtld calling `mprotect` on unmapped regions gives an error, e.g.

    ```
    error while loading shared libraries: cannot apply additional memory protection after relocation: Cannot allocate memory
    ```

The issue was why [[ELF] Align the end of PT_GNU_RELRO to max-page-size instead of common-page-size](https://reviews.llvm.org/D125410) was incorrect.

> In the description
> 
> > in the absence of PHDRS/SECTIONS: ensure the end of PT_GNU_RELRO associated PT_LOAD to a common-page-size boundary
> 
> Looks like the sentence is missing a few words on alignment. Perhaps:
> 
> > ensure the end of the PT_LOAD program loader associated with the PT_GNU_RELRO segment is aligned to a common-page-size boundary.

Updated. Thanks for the suggestion.


https://github.com/llvm/llvm-project/pull/66042


More information about the llvm-commits mailing list