public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Appending program headers to existing ELFs?
@ 2023-11-13 14:19 Matheus Afonso Martins Moreira
  2023-11-14 12:47 ` Nick Clifton
  0 siblings, 1 reply; 5+ messages in thread
From: Matheus Afonso Martins Moreira @ 2023-11-13 14:19 UTC (permalink / raw)
  To: binutils

I'd like to embed arbitrary data into existing ELF executables
in such a way that the data is automatically loaded onto memory
and is reachable by the program at runtime.

Linux passes a pointer to the program header table
of the running program via the auxiliary vector
which is how I plan on accessing the data.

With objcopy it is already possible to embed arbitrary files
to ELF files by placing them into sections:

    objcopy --add-section program.file1=file1 \
            --add-section program.file2=file2 \
            program program+files

However, those sections are unreachable when the program actually runs.
Given the address of the program header table, it is possible to obtain
a pointer to the ELF header. However, no progress can be made from
there since only the segments described by the program headers are
loaded by the kernel which excludes the sections and the data
I want to access. If I set the alloc flag on the new sections,
objcopy will even warn me about the fact they're not loaded.

So it seems to me that the solution is to add a new program header
to the ELF executable instead of a new section. How can this be done
with binutils tools?

If it's not possible to do this with objcopy, can it be done with ld?
Is it possible to add a placeholder program header table entry at link
time so that it can be adjusted later by external tools to encompass the
newly added sections without needing to relink the whole executable?

I've been experimenting with linker scripts but with no success.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-11-17  8:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-13 14:19 Appending program headers to existing ELFs? Matheus Afonso Martins Moreira
2023-11-14 12:47 ` Nick Clifton
2023-11-15  1:26   ` Matheus Afonso Martins Moreira
2023-11-16  8:51     ` Nick Clifton
2023-11-17  8:05       ` Fangrui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).