Description
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 a PT_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 a PHDRS
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
issue