public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: Nick Clifton <nickc@redhat.com>
Cc: hjl.tools@gmail.com, binutils@sourceware.org, siddhesh@redhat.com
Subject: Re: RFC: ld: Add --text-section-ordering-file (version 2)
Date: Fri, 26 Apr 2024 13:47:51 +0930	[thread overview]
Message-ID: <Zisq7xDI0IK27Nf3@squeak.grove.modra.org> (raw)
In-Reply-To: <87edat7g1e.fsf@redhat.com>

On Thu, Apr 25, 2024 at 02:01:01PM +0100, Nick Clifton wrote:
> Hi Guys,
> 
>   Attached is a patch to add a --section-ordering-file option to the BFD
>   linker.  It is based upon H.J.'s original patch, but extended so that
>   it will work with multiple output sections.
> 
>   There are a couple of points that I feel I should highlight:
> 
>   * The option only works in conjunction with a modified linker script.
>   
>     In particular the script must have: "INCLUDE section-ordering-file"
>     statements in it, wherever it wants section ordering to be allowed.
>     This statement can appear multiple times in a linker script,
>     although it would not make sense to have it appear more than once in
>     any given output section.  Here is an example:
>     
>       SECTIONS
>       {
>         .text : {
>           INCLUDE section-ordering-file
>           *(.text)
>         }
>         .data : {
>           INCLUDE section-ordering-file
>           *(.data)
>         }
>       }
>     
>   * H.J's original version allowed for linker script like
>     "filename(section)" syntax to be used to name sections, eg:
>     "*(.text.*)", as well as a simpler "section name regexp", eg
>     ".text.*", to be used.  This version only supports the latter
>     format.
> 
>     In addition H.J.'s syntax allowed for abbreviated section names to
>     match.  So ".t*t" would match any section starting with ".t" and
>     ending with "t" and would put it into the .text section.  In this
>     version however the output section is selected based upon matching
>     the fixed part at the start of the pattern with the output section.
>     So ".t*t" would only work if the output section was called ".t".
> 
>     To help compensate for this, and to allow arbitrary input sections
>     to be mapped to specific output sections, the output section name
>     can be provided as if it were a filename.  So .foo(.bar) would map
>     all sections called .bar to the output section .foo, but only if the
>     linker script has an output section called .foo, and only if that
>     output section declaration includes a INCLUDE section-ordering-file
>     statement.
>     
>     Perhaps an example will make things clearer.  If the above linker
>     script is used and the section ordering file contains:
> 
>       # A comment - this will be ignored.
>       .text.hot .text.cold .text.warm
>       .data.big
>       .data(.bar)
>       .text.foo*
>       .ignore(.me)
> 
>     This is roughly equivalent to a linker script that looks like this:
> 
>       SECTIONS
>       {
>         .text : {
>           *(.text.hot)
>           *(.text.cold)
>           *(.text.warm)
>           *(.text.foo*)
>           *(.text)
>         }
>         .data : {
>           *(.data.big)
>           *(.bar)
>           *(.data)
>         }
>       }
> 
>     Note - the linker will not warn about entries in the section
>     ordering file that do not match an output section name.  So in the
>     above example the ".ignore(.me)" entry will not generate a warning
>     about it not being used.
> 
>   Thoughts, comments, etc ?

This seems really clunky to me.  How about a script that augments
the default script, but looks very similar to other scripts, ie. with
a SECTIONS clause?  To take your example, use a script like:

  SECTIONS
  {
    .text : {
      *(.text.hot)
      *(.text.cold)
      *(.text.warm)
      *(.text.foo*)
    }
    .data : {
      *(.data.big)
      *(.bar)
    }
  }

Then arrange to insert the contents of each output section statement
in this script at the start of corresponding output section statement
in the default script.

-- 
Alan Modra
Australia Development Lab, IBM

  parent reply	other threads:[~2024-04-26  4:17 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-25 13:01 Nick Clifton
2024-04-25 15:32 ` H.J. Lu
2024-04-26  9:38   ` Nick Clifton
2024-04-26  1:46 ` Hans-Peter Nilsson
2024-04-26  9:46   ` Nick Clifton
2024-04-27  0:46     ` Hans-Peter Nilsson
2024-04-26  4:17 ` Alan Modra [this message]
2024-04-26  9:59   ` Nick Clifton
2024-04-26 12:43     ` Alan Modra
2024-04-29  0:12       ` Alan Modra
2024-05-02 15:16         ` Nick Clifton
2024-05-06 18:27         ` H.J. Lu
2024-05-07 16:39         ` RFC: ld: Add --text-section-ordering-file (version 4) Nick Clifton

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=Zisq7xDI0IK27Nf3@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    --cc=hjl.tools@gmail.com \
    --cc=nickc@redhat.com \
    --cc=siddhesh@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).