1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 11:13:28 +01:00

llvm-cov: Added support for function checksums.

The function checksums are hashed from the concatenation of the function
name and line number.

llvm-svn: 196358
This commit is contained in:
Yuchen Wu 2013-12-04 06:00:17 +00:00
parent 37b184215d
commit b1a23c9951
10 changed files with 29 additions and 7 deletions

View File

@ -250,6 +250,7 @@ public:
private: private:
GCOVFile &Parent; GCOVFile &Parent;
uint32_t Ident; uint32_t Ident;
uint32_t Checksum;
uint32_t LineNumber; uint32_t LineNumber;
StringRef Name; StringRef Name;
StringRef Filename; StringRef Filename;

View File

@ -125,7 +125,7 @@ bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
uint32_t Dummy; uint32_t Dummy;
if (!Buff.readInt(Dummy)) return false; // Function header length if (!Buff.readInt(Dummy)) return false; // Function header length
if (!Buff.readInt(Ident)) return false; if (!Buff.readInt(Ident)) return false;
if (!Buff.readInt(Dummy)) return false; // Checksum #1 if (!Buff.readInt(Checksum)) return false;
if (Version != GCOV::V402) { if (Version != GCOV::V402) {
uint32_t CfgChecksum; uint32_t CfgChecksum;
if (!Buff.readInt(CfgChecksum)) return false; if (!Buff.readInt(CfgChecksum)) return false;
@ -212,6 +212,7 @@ bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
bool GCOVFunction::readGCDA(GCOVBuffer &Buff, GCOV::GCOVVersion Version) { bool GCOVFunction::readGCDA(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
uint32_t Dummy; uint32_t Dummy;
if (!Buff.readInt(Dummy)) return false; // Function header length if (!Buff.readInt(Dummy)) return false; // Function header length
uint32_t GCDAIdent; uint32_t GCDAIdent;
if (!Buff.readInt(GCDAIdent)) return false; if (!Buff.readInt(GCDAIdent)) return false;
if (Ident != GCDAIdent) { if (Ident != GCDAIdent) {
@ -220,8 +221,13 @@ bool GCOVFunction::readGCDA(GCOVBuffer &Buff, GCOV::GCOVVersion Version) {
return false; return false;
} }
if (!Buff.readInt(Dummy)) return false; // Checksum #1 uint32_t GCDAChecksum;
if (!Buff.readInt(GCDAChecksum)) return false;
if (Checksum != GCDAChecksum) {
errs() << "Function checksums do not match: " << Checksum << " != "
<< GCDAChecksum << " (in " << Name << ").\n";
return false;
}
uint32_t CfgChecksum; uint32_t CfgChecksum;
if (Version != GCOV::V402) { if (Version != GCOV::V402) {

View File

@ -314,12 +314,18 @@ namespace {
this->os = os; this->os = os;
Function *F = SP.getFunction(); Function *F = SP.getFunction();
DEBUG(dbgs() << "Function: " << F->getName() << "\n"); DEBUG(dbgs() << "Function: " << getFunctionName(SP) << "\n");
uint32_t i = 0; uint32_t i = 0;
for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) { for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
Blocks[BB] = new GCOVBlock(i++, os); Blocks[BB] = new GCOVBlock(i++, os);
} }
ReturnBlock = new GCOVBlock(i++, os); ReturnBlock = new GCOVBlock(i++, os);
std::string FunctionNameAndLine;
raw_string_ostream FNLOS(FunctionNameAndLine);
FNLOS << getFunctionName(SP) << SP.getLineNumber();
FNLOS.flush();
FuncChecksum = hash_value(FunctionNameAndLine);
} }
~GCOVFunction() { ~GCOVFunction() {
@ -347,6 +353,10 @@ namespace {
return EdgeDestinations; return EdgeDestinations;
} }
uint32_t getFuncChecksum() {
return FuncChecksum;
}
void setCfgChecksum(uint32_t Checksum) { void setCfgChecksum(uint32_t Checksum) {
CfgChecksum = Checksum; CfgChecksum = Checksum;
} }
@ -359,7 +369,7 @@ namespace {
++BlockLen; ++BlockLen;
write(BlockLen); write(BlockLen);
write(Ident); write(Ident);
write(0); // lineno checksum write(FuncChecksum);
if (UseCfgChecksum) if (UseCfgChecksum)
write(CfgChecksum); write(CfgChecksum);
writeGCOVString(getFunctionName(SP)); writeGCOVString(getFunctionName(SP));
@ -401,6 +411,7 @@ namespace {
private: private:
DISubprogram SP; DISubprogram SP;
uint32_t Ident; uint32_t Ident;
uint32_t FuncChecksum;
bool UseCfgChecksum; bool UseCfgChecksum;
uint32_t CfgChecksum; uint32_t CfgChecksum;
DenseMap<BasicBlock *, GCOVBlock *> Blocks; DenseMap<BasicBlock *, GCOVBlock *> Blocks;
@ -731,6 +742,7 @@ Constant *GCOVProfiler::getEmitFunctionFunc() {
Type *Args[] = { Type *Args[] = {
Type::getInt32Ty(*Ctx), // uint32_t ident Type::getInt32Ty(*Ctx), // uint32_t ident
Type::getInt8PtrTy(*Ctx), // const char *function_name Type::getInt8PtrTy(*Ctx), // const char *function_name
Type::getInt32Ty(*Ctx), // uint32_t func_checksum
Type::getInt8Ty(*Ctx), // uint8_t use_extra_checksum Type::getInt8Ty(*Ctx), // uint8_t use_extra_checksum
Type::getInt32Ty(*Ctx), // uint32_t cfg_checksum Type::getInt32Ty(*Ctx), // uint32_t cfg_checksum
}; };
@ -813,11 +825,12 @@ Function *GCOVProfiler::insertCounterWriteout(
Builder.getInt32(CfgChecksum)); Builder.getInt32(CfgChecksum));
for (unsigned j = 0, e = CountersBySP.size(); j != e; ++j) { for (unsigned j = 0, e = CountersBySP.size(); j != e; ++j) {
DISubprogram SP(CountersBySP[j].second); DISubprogram SP(CountersBySP[j].second);
Builder.CreateCall4( Builder.CreateCall5(
EmitFunction, Builder.getInt32(j), EmitFunction, Builder.getInt32(j),
Options.FunctionNamesInData ? Options.FunctionNamesInData ?
Builder.CreateGlobalStringPtr(getFunctionName(SP)) : Builder.CreateGlobalStringPtr(getFunctionName(SP)) :
Constant::getNullValue(Builder.getInt8PtrTy()), Constant::getNullValue(Builder.getInt8PtrTy()),
Builder.getInt32(Funcs[j]->getFuncChecksum()),
Builder.getInt8(Options.UseCfgChecksum), Builder.getInt8(Options.UseCfgChecksum),
Builder.getInt32(CfgChecksum)); Builder.getInt32(CfgChecksum));

Binary file not shown.

Binary file not shown.

View File

@ -11,6 +11,8 @@ RUN: rm test.cpp.llcov
RUN: not llvm-cov -gcno=test_read_fail.gcno -gcda=test.gcda RUN: not llvm-cov -gcno=test_read_fail.gcno -gcda=test.gcda
RUN: not llvm-cov -gcno=test.gcno -gcda=test_checksum_mismatch.gcda RUN: not llvm-cov -gcno=test.gcno -gcda=test_file_checksum_fail.gcda
RUN: not llvm-cov -gcno=test.gcno -gcda=test_func_checksum_fail.gcda
XFAIL: powerpc64, s390x, mips XFAIL: powerpc64, s390x, mips