[PATCH] D61688: [LLD][ELF] Full support for -n (--nmagic) and -N (--omagic) via -zcommon-page-size
Peter Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 9 05:42:09 PDT 2019
peter.smith added a comment.
In D61688#1496262 <https://reviews.llvm.org/D61688#1496262>, @ruiu wrote:
> Sorry for my ignorance, but I don't think I fully understand the difference of "page size" and "common page size". In what situation you want to set different values to these variables? Is there any constraint between them, such as one value is always greater than the other, etc.?
"page size" as in Target->PageSize and "common page size" as in Config->CommonPageSize that I renamed it to from this patch are synonymous. From memory I think ld.bfd uses page_size for common-page and abi_page_size for "max page size", I preferred to make the CommonPageSize more explicit.
There is a difference between "max page size" and "common page size". The best explanation I've seen is in the review comment https://reviews.llvm.org/D33630#767301 in the patch that introduced it's only use in LLD outside of the linker script CONSTANT(COMMONPAGESIZE). A quick summary is:
- max-page-size or abi-page-size is the largest page size that might be encountered at run-time. For example some AArch64 platforms such as Fedora use 64k page size, others such as Ubuntu use 4k page size. If an executable is to be portable it sets max-page-size to 64k. All significant layout decisions have to use the max-page-size.
- common-page-size or sometimes just page-size is the "most common" page-size that might be encountered at run-time. There are some optimisations that can be done that use this. The best explanation that I've seen is the description DATA_SEGMENT_ALIGN at https://sourceware.org/binutils/docs-2.30/ld/Builtin-Functions.html#Builtin-Functions. As I understand it, LLD only uses common-page-size for D33630 <https://reviews.llvm.org/D33630> "Fill the empty space in executable segments with instruction padding" and in the linker script CONSTANT(COMMONPAGESIZE).
There is a constraint (enforced by Gold and this patch) that "common page size" can't be greater than "max page size". This constraint is the only requirement for -n and -N, if we lower -zmax-page-size to 1 the Target->PageSize remains at 4k and this produces an incorrect output. It just so happens that implementing that requires implementing all of -zcommon-page-size apart for the command-line option -zcommon-page-size.
Why would anyone want to change the common-page-size with -zcommon-page-size. Good question; the strongest reason I can come up with is backwards compatibility with the small number programs that use it (for example D56205 <https://reviews.llvm.org/D56205>). I don't think that there is a strong enough reason to implement it on its own, but it is just adding a command line option and a test.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D61688/new/
https://reviews.llvm.org/D61688
More information about the llvm-commits
mailing list