r251385 - Create undef reference to profile hook symbol

Vedant Kumar via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 28 11:58:37 PDT 2015


> On Oct 28, 2015, at 11:03 AM, Justin Bogner via cfe-commits <cfe-commits at lists.llvm.org> wrote:
> 
> Xinliang David Li via cfe-commits <cfe-commits at lists.llvm.org> writes:
>> Author: davidxl
>> Date: Tue Oct 27 00:15:35 2015
>> New Revision: 251385
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=251385&view=rev
>> Log:
>> Create undef reference to profile hook symbol 
>> 
>> Create undef reference to profile hook symbol when
>> PGO instrumentation is turned on. This allows 
>> LLVM to omit emission of hook variable use method
>> for every single module instrumented.
> 
> Nick: This approach should work for ld64 as well, right?

Hm, I tried this out with a dummy file:

liba.a(a.o):
0000000000000004 C ___llvm_profile_runtime
0000000000000000 T _foo

I compiled with:

$ cc -L. -la liba.a -Wl,-u -Wl,__llvm_profile_runtime b.c -o b

The hook symbol doesn't appear in the final executable:

b:
0000000100000000 T __mh_execute_header
0000000100000f90 T _main
                 U dyld_stub_binder

If I instead link with "-force_load liba.a", I get the expected result. I could just be doing this incorrectly, so I'll defer to Nick.


> 
> David: This seems like a good idea, but it's buggy as implemented.
> Details below.
> 
>> 
>> Modified:
>>    cfe/trunk/lib/Driver/ToolChains.cpp
>>    cfe/trunk/lib/Driver/ToolChains.h
>> 
>> Modified: cfe/trunk/lib/Driver/ToolChains.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.cpp?rev=251385&r1=251384&r2=251385&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Driver/ToolChains.cpp (original)
>> +++ cfe/trunk/lib/Driver/ToolChains.cpp Tue Oct 27 00:15:35 2015
>> @@ -25,6 +25,7 @@
>> #include "llvm/Option/ArgList.h"
>> #include "llvm/Option/OptTable.h"
>> #include "llvm/Option/Option.h"
>> +#include "llvm/ProfileData/InstrProf.h"
>> #include "llvm/Support/ErrorHandling.h"
>> #include "llvm/Support/FileSystem.h"
>> #include "llvm/Support/MemoryBuffer.h"
>> @@ -3811,6 +3812,18 @@ SanitizerMask Linux::getSupportedSanitiz
>>   return Res;
>> }
>> 
>> +void Linux::addProfileRTLibs(const llvm::opt::ArgList &Args,
>> +                             llvm::opt::ArgStringList &CmdArgs) const {
>> +  if (!needsProfileRT(Args)) return;
>> +
>> +  // Add linker option -u__llvm_runtime_variable to cause runtime
>> +  // initialization module to be linked in.
>> +  if (!Args.hasArg(options::OPT_coverage))
> 
> This check isn't right. What about the other gcov-style flags like
> -fprofile-args? What if both kinds of coverage are on for some strange
> reason? It's also a maintenance burden, since the logic needs to be
> duplicated from needsProfileRT. I think we need finer grained helpers -
> maybe something like needsGCOVRT and needsInstrProfRT, either of which
> will pull in the profileRTLibs.

Sorry I missed this.

vedant

>> +    CmdArgs.push_back(Args.MakeArgString(
>> +        Twine("-u", llvm::getInstrProfRuntimeHookVarName())));
>> +  ToolChain::addProfileRTLibs(Args, CmdArgs);
>> +}
>> +
>> /// DragonFly - DragonFly tool chain which can call as(1) and ld(1) directly.
>> 
>> DragonFly::DragonFly(const Driver &D, const llvm::Triple &Triple,
>> 
>> Modified: cfe/trunk/lib/Driver/ToolChains.h
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChains.h?rev=251385&r1=251384&r2=251385&view=diff
>> ==============================================================================
>> --- cfe/trunk/lib/Driver/ToolChains.h (original)
>> +++ cfe/trunk/lib/Driver/ToolChains.h Tue Oct 27 00:15:35 2015
>> @@ -744,6 +744,8 @@ public:
>>       llvm::opt::ArgStringList &CC1Args) const override;
>>   bool isPIEDefault() const override;
>>   SanitizerMask getSupportedSanitizers() const override;
>> +  void addProfileRTLibs(const llvm::opt::ArgList &Args,
>> +                        llvm::opt::ArgStringList &CmdArgs) const override;
>> 
>>   std::string Linker;
>>   std::vector<std::string> ExtraOpts;
>> 
>> 
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits



More information about the cfe-commits mailing list