From: "Rebecca Cran" <rebecca@bsdio.com>
To: "Marvin Häuser" <mhaeuser@posteo.de>
Cc: Pedro Falcato <pedro.falcato@gmail.com>,
Liming Gao <gaoliming@byosoft.com.cn>,
Ard Biesheuvel <ardb+tianocore@kernel.org>,
devel@edk2.groups.io
Subject: Re: Linker scripts use of "-z common-page-size=0x20" etc.
Date: Mon, 3 Apr 2023 16:56:18 -0600 [thread overview]
Message-ID: <6b49d3f9-d58b-a8d4-3695-7a0c8f673d67@bsdio.com> (raw)
In-Reply-To: <668CD723-746F-4A04-B5E8-7DD55AECD55F@posteo.de>
On 4/3/23 2:58 PM, Marvin Häuser wrote:
> That last part is actually not ignoring the use-case, that *is* our use-case. The terminology again is very OS-oriented, it’s important to know that generally OSes will fail to load binaries that are aligned less than the platform page size, as they cannot apply permissions (and probably also some implementation details of mmap / VM / whatever). That’s why the maximum page size you’re realistic to encounter is exactly the image segment alignment (by hardware convention, this is a power of two, thus a strict alignment satisfies all less strict alignment constraints).
>
> The common page size on the other hand appears to be an optimization, for which you specify the most common page size (e.g., you may target AARCH64 which may require 16 KB alignment, but most of your targets will have only 4 KB pages), which the compiler will use to optimize the binary for the common targets. I have no idea why this is even used. There also were discussions on LLVM platforms that it should be avoided.
>
> The naive approach would be to just use max-page-size, drop all references to common-page-size, and align all ELF sections that will be converted to PE sections by max-page-size. But I’m sure there’s some ancient workaround / compiler bug / edge use case / portability or whatever reason why common-page-size was used. :)
> (CC Leif for related experience.)
>
> edk2 generally sets this to a low value to save SPI (and possibly RAM) space, as nothing in the stack enforces memory protection ( :( ). I’m not sure why there’s both 32 and 64 Bytes, but I could imagine it’s some GNU ABI thing where some type of some arch actually requires this alignment, or maybe there’s different rules for global variables. A text segment must at least satisfy the maximum instruction alignment constraint (this may be a thing with, e.g., normalised instruction lengths), while data segments must satisfy at least the maximum data alignment constraint (which might usually be some large float? Not sure). 4 KB is used when memory protection is needed (usually RT drivers, as they’re mapped into the OS environment), but AARCH64 may actually require 16 KB (e.g. Apple A chips didn’t even support less for a while).
Thanks.
One problem with using max page size appears to be that there are some
modules that set the common page size to 4KB in order to enable memory
protection. e.g.:
commit ddd89cd50dd3a989e58a75ed38011168e3ec0954
Author: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Date: Wed Sep 30 08:53:00 2015 +0000
OvmfPkg: set 4 KB section alignment for DXE_RUNTIME_DRIVER modules
Increase the section alignment to 4 KB for DXE_RUNTIME_DRIVER modules.
This allows the OS to map them with tightened permissions (i.e.,
R-X for
.text and RW- for .data). This is a prerequisite for enabling the
EFI_PROPERTIES_RUNTIME_MEMORY_PROTECTION_NON_EXECUTABLE_PE_DATA (sic)
feature that was introduced in UEFIv2.5.
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Tested-by: Laszlo Ersek <lersek@redhat.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18564
6f19259b-4bc3-4df7-8a09-765794883524
next prev parent reply other threads:[~2023-04-03 22:56 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-03 20:33 Linker scripts use of "-z common-page-size=0x20" etc Rebecca Cran
2023-04-03 20:58 ` Marvin Häuser
2023-04-03 22:56 ` Rebecca Cran [this message]
2023-04-04 7:22 ` Ard Biesheuvel
2023-04-04 7:43 ` Marvin Häuser
2023-04-04 11:10 ` Rebecca Cran
2023-04-04 14:03 ` Ard Biesheuvel
2023-04-04 14:10 ` Marvin Häuser
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6b49d3f9-d58b-a8d4-3695-7a0c8f673d67@bsdio.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox