diff options
| author | Bill Wendling <isanbard@gmail.com> | 2012-06-01 23:14:32 +0000 |
|---|---|---|
| committer | Bill Wendling <isanbard@gmail.com> | 2012-06-01 23:14:32 +0000 |
| commit | e85f34969e93b704c3c63a2f7e2e2467e2a8cb38 (patch) | |
| tree | 1330376106e6669a81bd5a98d9b7374704aea1fc /llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp | |
| parent | 5d6e7c3351708a2131d65a52a3021a78c4eb85b6 (diff) | |
| download | bcm5719-llvm-e85f34969e93b704c3c63a2f7e2e2467e2a8cb38.tar.gz bcm5719-llvm-e85f34969e93b704c3c63a2f7e2e2467e2a8cb38.zip | |
Register the gcov "writeout" at init time. Don't list this as a d'tor. Instead,
inject some code in that will run via the "__mod_init_func" method that
registers the gcov "writeout" function to execute at exit time.
The problem is that the "__mod_term_func" method of specifying d'tors is
deprecated on Darwin. And it can lead to some ambiguities when dealing with
multiple libraries.
<rdar://problem/11110106>
llvm-svn: 157852
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp index 4cbdb9f1921..6c42137b3d5 100644 --- a/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -22,6 +22,7 @@ #include "llvm/Module.h" #include "llvm/Pass.h" #include "llvm/Instructions.h" +#include "llvm/Transforms/Utils/ModuleUtils.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Support/Debug.h" #include "llvm/Support/DebugLoc.h" @@ -57,7 +58,6 @@ namespace { virtual const char *getPassName() const { return "GCOV Profiler"; } - private: bool runOnModule(Module &M); @@ -517,6 +517,7 @@ bool GCOVProfiler::emitProfileArcs() { } } } + insertCounterWriteout(CountersBySP); } @@ -672,7 +673,26 @@ void GCOVProfiler::insertCounterWriteout( } Builder.CreateRetVoid(); - InsertProfilingShutdownCall(WriteoutF, M); + // Create a small bit of code that registers the "__llvm_gcov_writeout" + // function to be executed at exit. + FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx), false); + Function *F = Function::Create(FTy, GlobalValue::InternalLinkage, + "__llvm_gcov_init", M); + F->setUnnamedAddr(true); + F->setLinkage(GlobalValue::InternalLinkage); + F->addFnAttr(Attribute::NoInline); + + BB = BasicBlock::Create(*Ctx, "entry", F); + Builder.SetInsertPoint(BB); + + FTy = FunctionType::get(Type::getInt32Ty(*Ctx), + PointerType::get(FTy, 0), false); + Function *AtExitFn = + Function::Create(FTy, GlobalValue::ExternalLinkage, "atexit", M); + Builder.CreateCall(AtExitFn, WriteoutF); + Builder.CreateRetVoid(); + + appendToGlobalCtors(*M, F, 0); } void GCOVProfiler::insertIndirectCounterIncrement() { |

