This is an archive of the discontinued LLVM Phabricator instance.

Add -z common-page-size option
Changes PlannedPublic

Authored by christylee on Jan 2 2019, 10:14 AM.

Details

Summary

Some of the projects I work on use the "-z common-page-size" option in their
linkerscripts. According to https://linux.die.net/man/1/ld,
common-page-size=value "set the emulation common page size to value".

Diff Detail

Event Timeline

christylee created this revision.Jan 2 2019, 10:14 AM
christylee changed the repository for this revision from rL LLVM to rLLD LLVM Linker.Jan 2 2019, 10:15 AM
smeenai added inline comments.
lld/ELF/Driver.cpp
359

Alpha sort (so put this before the .startswith("max-page-size=")

1182

The default value *is* 4096, and put a period at the end. Also, wouldn't it be more accurate to say that the default value is the page size of the target? That might not necessarily be 4096 ... for example, Arch/SPARCV9.cpp sets it to 8192.

Super nitpicky, but I might place this function above getMaxPageSize, to maintain the rough alpha sorting.

lld/ELF/ScriptParser.cpp
1050

I'm not super familiar with the script parser ... in what situation would Config be null here?

lld/test/ELF/linkerscript/common-page-size.s
4

Wouldn't it be more interesting to have a test with some value other than 0x1000, so that you get non-default behavior?

48

Same here

ruiu added a comment.Jan 2 2019, 11:20 AM

-z common-page-size=PAGESIZE creates an executable that cannot be executed if the page size is not PAGESIZE. If you want to align all segments to some value, what you should use is -z max-page-size.

I wonder if you found a use case of -z common-page-size with a page size that is different from the ABI's default. For example, did you find a use case of the option for x86-64 with a page size larger than 4096?

christylee added a comment.EditedJan 2 2019, 11:47 AM

I wonder if you found a use case of -z common-page-size with a page size that is different from the ABI's default. For example, did you find a use case of the option for x86-64 with a page size larger than 4096?

We use -z common-page-size in conjunction with -z max-page-size for hfsort. https://research.fb.com/publications/optimizing-function-placement-for-large-scale-data-center-applications-2/

ruiu added a comment.Jan 2 2019, 1:17 PM

Do you know why that system uses not only max-page-size but also common-page-size?

Do you know why that system uses not only max-page-size but also common-page-size?

It looks like they want to align hot text on common-page-size but everything else on max-page-size. gold aligns everything to max-page-size unless common-page-size is specified, I wonder if that's true for lld?

ruiu added a comment.Jan 2 2019, 2:33 PM

Do you know why that system uses not only max-page-size but also common-page-size?

It looks like they want to align hot text on common-page-size but everything else on max-page-size. gold aligns everything to max-page-size unless common-page-size is specified, I wonder if that's true for lld?

I believe that lld basically aligns everything according to max-page-size, which I believe what people expected. Could you elaborate a bit on why hot text (is that .text.hot section?) needs to have a stricter alignment requirement than the common-page-size? I'm asking because all use cases of common-page-size I've seen so far is kind of a cargo culting that people were adding the option even though they don't actually need it.

Could you elaborate a bit on why hot text (is that .text.hot section?) needs to have a stricter alignment requirement than the common-page-size?

I'm not sure to be honest. The original author for the linker script is on vacation, let me see if someone else might know why.

I don't it is correct to use common-page-size to override the value of max-page-size. My understanding of common-page-size is that it is used to save memory in some cases when the same page in the file can be mapped at a different virtual address. At the moment I don't think LLD supports this so there isn't any benefit in having a different common-page-size.

See DATA_SEGMENT_ALIGN in https://sourceware.org/binutils/docs/ld/Builtin-Functions.html#Builtin-Functions

In the default ld.bfd linker script we have at the start of the RW:

/* Adjust the address for the data segment.  We want to adjust up to
     the same address within the page on the next page up.  */
  . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));

The DATA_SEGMENT_ALIGN requires common-page-size to be < the max-page-size and is typically related to the file-system than the memory.

Taking a look at gold it seems to do the same thing as ld.bfd for its internal linker script. I'm guessing that aligning some functions with the common-page-size might be related to the performance of the file-system rather than alignment in memory?

In any case I think we'll need to be able to state more clearly what common-page-size and max-page-size in ld.bfd and gold do before proceeding as I don't think it is as simple as just setting the alignment.

christylee planned changes to this revision.Mar 6 2019, 1:45 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 6 2019, 1:45 PM
Herald added a subscriber: MaskRay. · View Herald Transcript

D61688 implements -z common-page-size.