[cfe-dev] Linker selection

Chandler Carruth chandlerc at google.com
Sat Dec 15 00:35:38 PST 2012


On Fri, Dec 14, 2012 at 6:55 PM, Justin Bogner <mail at justinbogner.com>wrote:

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

IMO, this should be sysroot-relative, not root relative. But I'm interested
if others disagree, and why. I can imagine problems with it, but not how
realistic such problems would be.


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

This seems excellent.


> We then call whatever linker we find with the flags we normally use.
>

I don't think we should go this far.

If the user gave us a '--link-with' flag, I think we should honor it or
produce an error message explaining that we were unable to honor it.


The final question in my mind is whether "--link-with" is the right name
for this flag. I would be interested if anyone has particular shades of
paint they prefer for this bikeshed. I would also be interested if someone
familiar with the GCC community could see if they want to support this
logic as well, and if so coordinate the flag name and semantics with them
so we end up with a compatible option in both GCC and Clang.

-Chandler
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121215/b192628a/attachment.html>


More information about the cfe-dev mailing list