RFC: ld: Add --text-section-ordering-file (version 2)

Nick Clifton nickc@redhat.com
Fri Apr 26 09:59:00 GMT 2024


Hi Alan,

> 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.

Well I had several reasons:

   1. I wanted the feature to be compatible with the gold linker, which
      just uses the plain section name format, not the linker script format.

   2. I wanted users who are not familiar with linker scripts to be able
      to use the feature.  In particular I am hoping that package maintainers
      that profile their programs can use this feature to experiment with
      different section orderings without having to learn how to create
      their own scripts.

   3. I want the linker script to be able to define where, within an output
      section, the ordering should take place.  That way, if there are things
      that must appear at the start of the section, before any ordering, the
      script can make sure that this happens.  eg:

      .init : {
          LONG (0)
          INCLUDE section-ordering-file
          (*.init)
          LONG (0)
       }

      I just made that example up, but I am sure that you get the idea.

The other thing is practicality.  With the current method the contents of
the section ordering file can be parsed as they appear during the normal
linker script processing.  If on the other hand the ordering file was to
be processed first and then parts of it inserted ad hoc into the output
section statements, that would require a lot more hacking on the parser.
It could be done, but I like keeping things simple.

Cheers
   Nick





More information about the Binutils mailing list