[PATCH] D24987: [ELF] Use MaxPageSize for aligning PT_LOAD
Ed Maste via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 6 15:44:52 PST 2016
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?
> 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));
...
.lrodata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT
(MAXPAGESIZE) - 1)) :
{
*(.lrodata .lrodata.* .gnu.linkonce.lr.*)
}
.ldata ALIGN(CONSTANT (MAXPAGESIZE)) + (. & (CONSTANT (MAXPAGESIZE) - 1)) :
{
*(.ldata .ldata.* .gnu.linkonce.l.*)
. = ALIGN(. != 0 ? 64 / 8 : 1);
}
More information about the llvm-commits
mailing list