[cfe-dev] Linking ProfileRT when using -nodefaultlibs

Alexey Samsonov vonosmas at gmail.com
Mon Nov 10 17:09:35 PST 2014


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

I like neither of this :(


>
> >I believe -whole-archive will cause issues for the profile_rt library.
> >We really do only want particular symbols pulled in.
>
> How would I go about looking into this?
>
> /Eric
>
> On Mon, Nov 10, 2014 at 4:10 PM, Justin Bogner <mail at justinbogner.com>
> wrote:
>
>> Alexey Samsonov <vonosmas at gmail.com> writes:
>> > Ah, I see the problem here.
>> >
>> > 1) We add profile runtime library after the linker inputs (in
>> particular,
>> > after "-lc" provided by the user), because user-provided libraries can
>> have
>> > references to libclang_rt.profile.a, and therefore should precede it.
>> > 2) If -nodefautlibs is there, we never add "-lc" and friends at the
>> very end,
>> > so some symbols in profile runtime may be left unresolved.
>> >
>> > 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 believe -whole-archive will cause issues for the profile_rt library.
>> We really do only want particular symbols pulled in.
>>
>
>


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


More information about the cfe-dev mailing list