[cfe-dev] Linker selection

Justin Bogner mail at justinbogner.com
Fri Dec 14 18:55:43 PST 2012


David Chisnall <David.Chisnall at cl.cam.ac.uk> writes:
> I'd like to add some logic for selecting the linker at run time.
> Before I start, I was wondering if anyone had any suggestions as to
> the correct UI for this.  As far as I can see, there are two possible
> choices:
>
> 1) We have a flag that takes a full path to the linker to use.  This
> is somewhat problematic, because if two linkers require different
> arguments (not much of a problem for us, but imagine on Windows being
> able to switch between the MS and Binutils linkers) then you need to
> know what the linker is, as well as its name.
>
> 2) We have a flag like the libc++ / libstdc++ selection flag, which
> takes an argument like bfd, gold, mc, lld and some logic in the driver
> to work out what the paths and names of each of these should be.
>
> Is there a more sensible third option?  

The impression I get from the replies thus far is that (1) should be
sufficient given the assumption that different linkers have mostly
compatible command line interfaces. I think there's some merit to the
second approach even with this assumption though.

In the following the flag to specify the linker is --link-with, for
argument's sake. I'm not particularly attached to that name, but the
name isn't really the point here.

1. If you say --link-with=/full/path/to/ld, we use that binary.
2. If you say --link-with=foo, we first look for the name foo in the way
   it normally looks for ld. Notably, this would mean that if you're
   using a sysroot, we look for $sysroot/usr/bin/foo and friends.
3. If (2) doesn't find anything, we then look for ld.foo, behaving as in
   (2). This handles a fairly common idiom for having multiple
   alternative ld implementations installed.

We then call whatever linker we find with the flags we normally use.
As long as they tend to be compatible, this is fine. What do you guys
think?



More information about the cfe-dev mailing list