public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Nick Clifton <nickc@redhat.com>
To: Ulf Samuelsson <binutils@emagii.com>,
	binutils@sourceware.org, Jan Beulich <jbeulich@suse.com>
Subject: Re: RFC: generating a header using the linker (ASCII, ASCIZ commands)
Date: Tue, 14 Feb 2023 16:06:47 +0000	[thread overview]
Message-ID: <4937b1c3-fc16-328f-7af2-13d1c42288e1@redhat.com> (raw)
In-Reply-To: <324a63be-1403-edf1-23ad-6fd11e524529@emagii.com>

Hi Ulf,

>>> Note that if the linker can call an external tool to compute the CRC
>>> based on the extracted text segment, and insert that into the resulting ELF file.
>>> then this is superior to running a utility afterwards.
>>
>> Actually -- there might be a way to do this: A linker plugin.  The linker already
>> has the architecture to support plugins, and you could create a new one which would
>> scan the text section, compute a CRC and then insert the value into a header in the
>> linked image...
>>
> OK, tell me more!

Sure.  The linker has the ability to run plugins via the use of the "-plugin <name>"
command line option.  Currently there are two known plugins for the linker.  One is
used to process the dependencies of static archives (ld/libdep_plugin.c in the
binutils sources) and one is used to pass LTO enabled object files back to the compiler
for recompilation (lto-plugin/ in the gcc sources).

The big problem with linker plugins however is the total lack of documentation
on how to write them.  Until the day comes when somebody writes a manual the
only documentation is the source code itself.  The place to start is the
include/plugin-api.h file which defines the interface between plugins and the
linker.  Then take a look at the plugin sources mentioned above and the ld/plugin.c
source file which is the linker's side of the coin.

In essence what a plugin does is provide a selection of callback functions to
the linker.  These functions are called at various stages of the link, and can do
pretty much anything.  Since plugins are shared objects, they have full access to
the linker's run-time memory space and can muck about as they please.  Of course
plugins are expected to behave nicely.

Cheers
   Nick


  reply	other threads:[~2023-02-14 16:06 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-08 17:36 Ulf Samuelsson
2023-02-13 10:09 ` Nick Clifton
2023-02-13 11:12   ` Ulf Samuelsson
2023-02-13 12:33     ` Jan Beulich
2023-02-13 15:54       ` Ulf Samuelsson
2023-02-13 14:11     ` Nick Clifton
2023-02-13 16:04       ` Ulf Samuelsson
2023-02-14 16:06         ` Nick Clifton [this message]
2023-02-14 18:12           ` Ulf Samuelsson
2023-02-15 20:07       ` RFC: generating a header using the linker (CRC calculation) Ulf Samuelsson
2023-02-15 21:01         ` Ulf Samuelsson
2023-02-15 21:29           ` Paul Koning
2023-02-15 22:08             ` Ulf Samuelsson
2023-02-15 22:11               ` Paul Koning
2023-02-16  6:45                 ` Ulf Samuelsson

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=4937b1c3-fc16-328f-7af2-13d1c42288e1@redhat.com \
    --to=nickc@redhat.com \
    --cc=binutils@emagii.com \
    --cc=binutils@sourceware.org \
    --cc=jbeulich@suse.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).