public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Georg-Johann Lay <avr@gjlay.de>
To: Nick Clifton <nickc@redhat.com>, binutils@sourceware.org
Subject: Re: Question: default linker scripts and emulations
Date: Wed, 6 Dec 2023 17:44:38 +0100	[thread overview]
Message-ID: <f3392c5c-fb6b-4856-a769-6f582330be6a@gjlay.de> (raw)
In-Reply-To: <627688a1-176c-4a8e-984e-3848c902b273@redhat.com>

Ni Nick

Am 06.12.23 um 12:21 schrieb Nick Clifton:
> Hi Johann,
> 
>> GCC could generate better code for some devices if it could use an
>> adjusted linker description file for these devices.
>>
>> Is it possible to add a new option to the linker so it picks a different
>> ld script, such that:
>>
>> o The same emulation is used.
>>
>> o All works a usual, e.g. when the user request -T myscript.ld, use
>> myscript.ld provided it is a complete ld script and not just INSERT 
>> AFTER etc.
>  >
>> In the case a new emulation is required:
>>
>> The compiler has currently around 60 multilib variants, and a new 
>> emulation
>> would add yet another 6 multilibs. Therefore, it would be desirable to
>> re-use the old multilib (which still has some devices in it).
>>
>> Say the old machine is avr:102 and the new one is avr:108, but the 
>> generated
>> code is all the same, only difference is ld script. The compiler would
>> map avr:108 to avr:102 multilibs.
>>
>> What's the best way to implement this in Binutils?
> 
> Actually it might be easier to implement this using gcc's spec file syntax
> rather than adding a new linker option.  For example
> 
>    gcc [...other gcc options...] --specs=avr108.spec
> 
> and avr108.spec could contain:
> 
>    *self_spec:
>    + %{!T{-T avr108.ld}}
> 
> The spec file syntax allows for options to be conditionally added, so in 
> this
> case a "-T avr108.ld" would be added to the linker command line only if the
> user has not already provided a -T option of their own.
> 
> [This is totally not tested by me, but I think that in theory it should 
> work].
> 
> Cheers
>    Nick

I don't see how this can work, because there is no way to inspect the
contents of the provided file:

* When the user provides a complete ld-script, then use his script instead
of avr108.ld.

* When the user provides an ld-script snipped with INSERT AFTER etc, then use
avr108.ld but with the augmentation provided by the user.

But the compiler (or specs handling) cannot tell which is which.

Then there's the technical problem that the compiler needs to know the install
path (in configure and when running) and provide the complete path to avr108.ld.

Just dropping avr108.ld in $install/avr/lib/ldscripts is not enough that the
linker can find it with -Tavr108.ld

Then the specs would need to be able to select different ld-script flavours
like *.x, *.xn, *.xr, etc depending on options like -r and whatnot.

And the default ld-scripts are contained in the ld executable, so that
changing the scripts on file won't have any effect (except you select them
explicitly with -T).

IMO specs cannot resolve that in a reasonable way, in  particular the
distinction between complete ld-scripts and snippets.

Cheers,

Johann

  reply	other threads:[~2023-12-06 16:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-06 10:30 Georg-Johann Lay
2023-12-06 11:21 ` Nick Clifton
2023-12-06 16:44   ` Georg-Johann Lay [this message]
2023-12-07 15:50     ` Nick Clifton
2023-12-07 18:29       ` Georg-Johann Lay
2023-12-08 11:29         ` Nick Clifton
2023-12-08 16:04           ` Georg-Johann Lay

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=f3392c5c-fb6b-4856-a769-6f582330be6a@gjlay.de \
    --to=avr@gjlay.de \
    --cc=binutils@sourceware.org \
    --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).