Feature request: spare program headers

Matheus Afonso Martins Moreira matheus.a.m.moreira@gmail.com
Sat Nov 18 00:18:21 GMT 2023


> You can specify PHDRs in your linker script.

That's true but I ran into complications
when I tried to use the PHDRS directive.
I described my attempt in a previous email:

https://sourceware.org/pipermail/binutils/2023-November/130561.html

> I copied ld's internal linker script
> and customized it with a PHDRS command:
>
>     PHDRS
>     {
>         headers PT_PHDR FILEHDR PHDRS;
>         text PT_LOAD;
>         rodata PT_LOAD;
>         data PT_LOAD;
>         bss PT_LOAD;
>         extra PT_LOAD; /* meant to be empty */
>                        /* size/offset will be set later */
>     }
>
> I was not successful. I keep getting the following error:
>
>     error: could not allocate headers

Perhaps it is possible to do it via linker script
but I couldn't get it to work no matter what I tried.

It's also not possible to do *only* this.
Using PHDRS disables the linker's defaults
and forces users to specify all the segments.

https://sourceware.org/binutils/docs-2.41/ld/PHDRS.html

> The linker will create reasonable program headers by default.
> When the linker sees the PHDRS command in the linker script,
> it will not create any program headers other than the ones specified.

As a result of inhibiting those defaults, it also requires us to map
all the sections to all the custom segments we created instead of
simply letting the linker do it. The result is we have to maintain
customized copies of the linker's default scripts in our repositories.

An option that adds PT_NULL segments would be much easier to use.
Custom post processing tools can later customize those segments
with much greater flexibility after the link. I just implemented
such a tool for my project.


More information about the Binutils mailing list