public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Fangrui Song <i@maskray.me>
To: Matheus Afonso Martins Moreira <matheus.a.m.moreira@gmail.com>
Cc: binutils@sourceware.org, Nick Clifton <nickc@redhat.com>
Subject: Re: Appending program headers to existing ELFs?
Date: Fri, 17 Nov 2023 00:05:33 -0800	[thread overview]
Message-ID: <DS7PR12MB5765E334735D24F7EEE02373CBB7A@DS7PR12MB5765.namprd12.prod.outlook.com> (raw)
In-Reply-To: <e0b6078a-5e79-4b4e-a424-24cba5d8892d@redhat.com>

I think "error: could not allocate headers" means that you need to set
the location counter to an appropriate address.
In the internal linker script, it's something like   . =
SEGMENT_START("text-segment", 0) + SIZEOF_HEADERS;

For your original feature request, I wonder whether it should be the
responsibility of the post-link tool.
For example, patchelf supports adding a new program header. This is
done by appending the program headers to the end of the object file,
then changing e_phoff in the ELF header.
The original program headers immediately after the ELF header (added
by the linker) are then unused, but that is a small amount of waste.

On Thu, Nov 16, 2023 at 12:51 AM Nick Clifton <nickc@redhat.com> wrote:
>
> Hi Matheus,
>
> > In concrete terms:
> >
> > I'm building a small programming language interpreter
> > and would like to add support for embedding programs
> > into the executable. My intention is to treat the
> > embedded programs section as an additional load path
> > for libraries and modules as well as the main function.
>
> Couldn't your interpreter be a library (shared or static)
> and then all that a programmer would need to do is to
> include your library along with their code when they perform
> a link of their own ?
>
> Cheers
>    Nick
>
>

      reply	other threads:[~2023-11-17  8:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-13 14:19 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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=DS7PR12MB5765E334735D24F7EEE02373CBB7A@DS7PR12MB5765.namprd12.prod.outlook.com \
    --to=i@maskray.me \
    --cc=binutils@sourceware.org \
    --cc=matheus.a.m.moreira@gmail.com \
    --cc=nickc@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).