[PATCH] D24987: [ELF] Use MaxPageSize for aligning PT_LOAD

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 10 10:33:01 PST 2016


On 6 November 2016 at 18:44, Ed Maste <emaste at freebsd.org> wrote:
> On 4 November 2016 at 21:08, Rafael EspĂ­ndola
> <rafael.espindola at gmail.com> wrote:
>>
>> I think so. The full picture is that bfd has two page sizes,
>> COMMONPAGESIZE and MAXPAGESIZE. MAXPAGESIZE is used almost everywhere.
>> To avoid ending up with a 4 MB binary, the pages overlap on disk. For
>> example, with a trivial binary with just a .quad of data and text I
>> get
>>
>>   LOAD           0x000000 0x0000000000000000 0x0000000000000000
>> 0x0001e8 0x0001e8 R E 0x200000
>>   LOAD           0x000f50 0x0000000000200f50 0x0000000000200f50
>> 0x0000b8 0x0000b8 RW  0x200000
>>
>> So at runtime the will be two mappings, one at base and one at base +
>> 0x200000, but they will point to offset 0 of the file.
>>
>> The COMMONPAGESIZE is only used by DATA_SEGMENT_ALIGN. It is the
>> actual page size that is expected at runtime and the logic in
>> DATA_SEGMENT_ALIGN is to try to save a page in memory by wasting one
>> on disk.
>
> OK. Do you know what gold does?

I think it uses 4k pages.

>> So if we can avoid changing this now and instead change the linker
>> script that would be awesome :-)
>
> I'm not sure I really like the overlap behaviour either, so perhaps
> the best option for now is to have FreeBSD pass
> -zmax-page-size=0x200000. It turns out it's not as easy as just
> changing the one constant in the linker script; there are a couple of
> other uses of MAXPAGESIZE in the linker script:
>
>   /* Adjust the address for the data segment.  We want to adjust up to
>      the same address within the page on the next page up.  */
>   . = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) &
> (CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT
> (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));

But that is an actual use of MAXPAGESIZE. Any particular reason it has
to be at the next 2M page?

Cheers,
Rafael


More information about the llvm-commits mailing list