Question: default linker scripts and emulations
Nick Clifton
nickc@redhat.com
Thu Dec 7 15:50:33 GMT 2023
Hi Georg-Johann,
>>> 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.
> 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.
OK, so it sounds to me like what is needed is an option to tell the linker
where to find its default scripts, and if used, override the use of the
built in scripts. So for example:
avr-ld foo.o
[Uses built in avr1.x script]
avr-ld -m avr2 foo.o
[Uses built in avr2.x script]
avr-ld -m avr2 -r foo.o
[Uses built in avr2.xr script]
avr-ld -m avr2 -T bar.ld foo.o
[Uses ./bar.ld unless it contains INSERT, in which case it uses the built
in avr2.x script augmented by ./bar.ld]
avr-ld --default-script-path /usr/lib/avr foo.o
[Uses /usr/lib/avr/avr1.x. Generates an error if it does not exist.
Does not use the built in avr1.x script]
avr-ld -m avr2 --default-script-path /usr/lib/avr foo.o
[Uses /usr/lib/avr/avr2.x. Generates an error if it does not exist.
Does not use the built in avr2.x script]
avr-ld -m avr2 -r --default-script-path /usr/lib/avr foo.o
[Uses /usr/lib/avr/avr2.xr. Generates an error if it does not exist.
Does not use the built in avr2.xr script]
avr-ld -m avr2 -T bar.ld --default-script-path /usr/lib/avr foo.o
[Uses ./bar.ld unless it contains INSERT, in which case it uses
/usr/lib/avr/avr2.x augmented by ./bar.ld]
And, for completeness sake, assuming that bar.ld does not exist in the
current directory:
avr-ld -m avr2 -L /usr/foo -T bar.ld --default-script-path /usr/lib/avr foo.o
[Uses /usr/foo/bar.ld unless it contains INSERT, in which case it uses
/usr/lib/avr/avr2.x augmented by /usr/foo/bar.ld]
Is this what you had in mind ?
Cheers
Nick
PS, If this is what you had in mind, then I think that it could be done,
but I am not sure that it should be done. I feel that their ought to
be an easier way to achieve the same results without adding any new
code to the linker. I am not sure - at the moment - what that easier
way might be however.
More information about the Binutils
mailing list