[cfe-dev] Linking ProfileRT when using -nodefaultlibs

Alexey Samsonov vonosmas at gmail.com
Mon Nov 10 18:14:30 PST 2014

On Mon, Nov 10, 2014 at 5:49 PM, Justin Bogner <mail at justinbogner.com>

> Alexey Samsonov <vonosmas at gmail.com> writes:
> > On Mon, Nov 10, 2014 at 3:12 PM, Eric Fiselier <eric at efcs.ca> wrote:
> >
> >     >Interesting. This issue doesn't arise with sanitizers, because we
> put
> >     sanitizer runtimes *before* the user inputs, and force it into the
> >     executable by wrapping it in "-whole-archive". I wonder if
> >     >we can do the same trick for profile runtime. I don't really know
> that,
> >     but it seems we have both GCDA profiling and new InstrProfiling stuff
> >     there, so pulling all of them into the executable
> >     >is not desirable, is it?
> >
> >     I can't answer if we *should* do it put the profile runtime first,
> but I
> >     tested doing so and the change worked for me.
> >
> > What do you mean? We can't put it first, because user libraries depend
> on it.
> > We fail when we put it last either, because
> > of this specific case, where user provides "-lc" + "-nostdlib".
> >
> > We can workaround this by forcing to link in libprofile deps even if
> -nostdlib
> > is specified (assuming the user passing
> > this weird combination knows what (s)he is doing).
> >
> > Or we can design a magic flag "--profile-lib", or smth. like this, which
> > would be matched and replaced by the path to actual static profile
> runtime in
> > the driver. Then you'd be able
> > to write ("clang++ -nostdlib a.o b.o --profile-lib -lc -lpthread").
> Can we just teach clang where to find compiler-rt libraries and spell
> this like so?
>     clang++ -nostdlib a.o b.o -lclang_rt.profile -lc -lpthread
> I don't think I'd mind that so much, as it makes sense for clang to know
> where to find it's own runtime libraries.

All compiler-rt libs are target-specific, so that would have to be
Forcing user to write triple-dependent linker invocation is not nice...
what we *might* do, is to restructure the way we layout resource directory,
make triple-specific folders. That is, replace this:
with this:
... and then setup correct -L flag depending on the target triple. FWIW, I
do something
similar in the internal compiler setup.
This is a rather intrusive change, though.

Also, this can work for profile or builtins runtimes, but won't work for
as they require complex changes to the linker invocation.

Alexey Samsonov
vonosmas at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20141110/ff7125bb/attachment.html>

More information about the cfe-dev mailing list