-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
lld
: append ELF program header option
#72386
Comments
@llvm/issue-subscribers-lld-elf Author: Matheus Moreira (matheusmoreira)
It would be useful to have a command line option or plugin for the linker that appends an empty `PT_LOAD` program header table entry to ELF executables. This will greatly facillitate patching executables with new data after linking.
The Linux kernel automatically loads those segments onto memory and passes a pointer to the program header table via the auxiliary vector. This would be the perfect mechanism to allow executables to easily and efficiently access data embedded into the executable itself, even data patched in after the the binary has been compiled. Current solutions are insufficient. A simple Links: Related StackOverflow question |
The |
I think Nick's reply on Binutils means some uncertainly that such a feature will be accepted in GNU ld. I share a similar thought that this perhaps should be the responsibility of the post-link tool: patchelf implements program header relocating from which you can take inspirations. As a general post-link tool, it probably should work for every link unit, not those linked with specific linker options. |
@MaskRay Yes, it certainly seems that way... I've created the relevant issue and sent a contribution to NixOS/patchelf#533 I've also written an article about the real use case this feature enables: I used the The Even in that case I think a linker implementation would be beneficial. If the linker takes care of it, there will be no need to move the table to the end of the file. The result is a smaller, more compact executable. |
This is a case whether the feature really belongs to the post-link tool. And the argument to be integrated to mold is kinda weak: it is easy and there is already a For your use case, you may control how the linker output is linked, so you are fine with a linker option. However, in a lot of cases, the user using a post-link tool has limited control to the link process, so a smart post-link tool is naturally required. |
It would be useful to have a command line option or plugin for the linker that appends an empty
PT_LOAD
program header table entry to ELF executables. This will greatly facillitate patching executables with new data after linking.The Linux kernel automatically loads those segments onto memory and passes a pointer to the program header table via the auxiliary vector. This would be the perfect mechanism to allow executables to easily and efficiently access data embedded into the executable itself, even data patched in after the the binary has been compiled.
Current solutions are insufficient.
objcopy
can add new sections but they do not get loaded by the kernel without aPT_LOAD
segment and those can only be created at link time since adding new program headers would change all offsets in the file. Linker scripts support aPHDRS
command but using that disables the linker's default behavior and forces users to specify all the segments and map all the sections to them instead of letting the linker do it.A simple
--append-program-header
that just adds an empty program header to the end of the table would be ideal. With that feature in place, custom tools can be written to copy arbitrary data into the ELF and then edit the placeholder's offset and size to match.Links:
Related StackOverflow question
Binutils mailing list discussion
Equivalent
mold
issueThe text was updated successfully, but these errors were encountered: