New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
linker script: implement SIZEOF_HEADERS #29062
Comments
Take. |
Also used in the main FreeBSD kernel link script. |
So, I'm taking a shot at implementing this but I'd like to discuss the implementation a little bit before digging into code. |
SIZEOF_HEADERS seems pretty tricky to me and doesn't seem to be recommended to use without PHDRS command. I think it's a reasonable stance. https://sourceware.org/binutils/docs/ld/Builtin-Functions.html#Builtin-Functions I'm wondering what the FreeBSD's linker script is doing with SIZEOF_HEADERS. I don't understand why it is needed for Xen. Could you give me an insight? |
It's not for just for Xen; SIZEOF_HEADERS has been there since the beginning of the FreeBSD/amd64 project. For reference the default (built-in) userland linker script in GNU ld uses it like so: SECTIONS and the kernel use is equivalent: SECTIONS Xen support added the "AT (kernphys + SIZEOF_HEADERS)" but that use is no different really. I don't really have an objection to the binutils restrictions: To avoid this error, you must avoid using the SIZEOF_HEADERS function, or you must rework your linker script to avoid forcing the linker to use additional program headers, or you must define the program headers yourself using the PHDRS command (see PHDRS). except that I think "additional program headers" in the GNU ld case is based on the default layout it assumes, which we don't really want to do. For the FreeBSD kernel we could certainly add PHDRS if that's the best way forward. |
I'm inclined to allow SIZEOF_HEADER only when PHDRS commands are used to give us a full definition of the program headers. It is simple and easy to understand. Otherwise, we could either (1) assume some PHDRS and report an error if the program needs more PHDRS or (2) walk over all the SECTIONS command twice as Davide said. I think both are a bit too much for this variable. |
At fact we are already walk over SECTIONS twice. First pass is createSections(), the second is assignAddresses(). Can't we use that ? I would try to estimate segments amount during the first pass. |
Review: https://reviews.llvm.org/D23165 |
Extended Description
SIZEOF_HEADERS is used by the linker script in FreeBSD's linux emulation layer:
SECTIONS
{
. = . + SIZEOF_HEADERS;
...
SIZEOF_HEADERS'
sizeof_headers'Return the size in bytes of the output file's headers. You can
use this number as the start address of the first section, if you
choose, to facilitate paging.
The text was updated successfully, but these errors were encountered: