From 2ebea72474874e5a437eca994ca4d649d8234744 Mon Sep 17 00:00:00 2001 From: Yuchen Wu Date: Wed, 4 Dec 2013 06:00:17 +0000 Subject: [PATCH] llvm-cov: Added support for function checksums. The function checksums are hashed from the concatenation of the function name and line number. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@196358 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Support/GCOV.h | 1 + lib/IR/GCOV.cpp | 12 ++++++++--- .../Instrumentation/GCOVProfiling.cpp | 19 +++++++++++++++--- test/tools/llvm-cov/Inputs/test.gcda | Bin 824 -> 824 bytes test/tools/llvm-cov/Inputs/test.gcno | Bin 3112 -> 3112 bytes .../Inputs/test_checksum_mismatch.gcda | Bin 825 -> 0 bytes .../Inputs/test_file_checksum_fail.gcda | Bin 0 -> 825 bytes .../Inputs/test_func_checksum_fail.gcda | Bin 0 -> 825 bytes .../tools/llvm-cov/Inputs/test_read_fail.gcno | Bin 72 -> 71 bytes test/tools/llvm-cov/llvm-cov.test | 4 +++- 10 files changed, 29 insertions(+), 7 deletions(-) delete mode 100644 test/tools/llvm-cov/Inputs/test_checksum_mismatch.gcda create mode 100644 test/tools/llvm-cov/Inputs/test_file_checksum_fail.gcda create mode 100644 test/tools/llvm-cov/Inputs/test_func_checksum_fail.gcda diff --git a/include/llvm/Support/GCOV.h b/include/llvm/Support/GCOV.h index 6111d3aebec..188c4126f1f 100644 --- a/include/llvm/Support/GCOV.h +++ b/include/llvm/Support/GCOV.h @@ -250,6 +250,7 @@ public: private: GCOVFile &Parent; uint32_t Ident; + uint32_t Checksum; uint32_t LineNumber; StringRef Name; StringRef Filename; diff --git a/lib/IR/GCOV.cpp b/lib/IR/GCOV.cpp index 64d53e4251a..14eb71f0300 100644 --- a/lib/IR/GCOV.cpp +++ b/lib/IR/GCOV.cpp @@ -125,7 +125,7 @@ bool GCOVFunction::readGCNO(GCOVBuffer &Buff, GCOV::GCOVVersion Version) { uint32_t Dummy; if (!Buff.readInt(Dummy)) return false; // Function header length if (!Buff.readInt(Ident)) return false; - if (!Buff.readInt(Dummy)) return false; // Checksum #1 + if (!Buff.readInt(Checksum)) return false; if (Version != GCOV::V402) { uint32_t CfgChecksum; 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) { uint32_t Dummy; if (!Buff.readInt(Dummy)) return false; // Function header length + uint32_t GCDAIdent; if (!Buff.readInt(GCDAIdent)) return false; if (Ident != GCDAIdent) { @@ -220,8 +221,13 @@ bool GCOVFunction::readGCDA(GCOVBuffer &Buff, GCOV::GCOVVersion Version) { 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; if (Version != GCOV::V402) { diff --git a/lib/Transforms/Instrumentation/GCOVProfiling.cpp b/lib/Transforms/Instrumentation/GCOVProfiling.cpp index fb5bee2ede2..488f451944b 100644 --- a/lib/Transforms/Instrumentation/GCOVProfiling.cpp +++ b/lib/Transforms/Instrumentation/GCOVProfiling.cpp @@ -314,12 +314,18 @@ namespace { this->os = os; Function *F = SP.getFunction(); - DEBUG(dbgs() << "Function: " << F->getName() << "\n"); + DEBUG(dbgs() << "Function: " << getFunctionName(SP) << "\n"); uint32_t i = 0; for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) { Blocks[BB] = 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() { @@ -347,6 +353,10 @@ namespace { return EdgeDestinations; } + uint32_t getFuncChecksum() { + return FuncChecksum; + } + void setCfgChecksum(uint32_t Checksum) { CfgChecksum = Checksum; } @@ -359,7 +369,7 @@ namespace { ++BlockLen; write(BlockLen); write(Ident); - write(0); // lineno checksum + write(FuncChecksum); if (UseCfgChecksum) write(CfgChecksum); writeGCOVString(getFunctionName(SP)); @@ -401,6 +411,7 @@ namespace { private: DISubprogram SP; uint32_t Ident; + uint32_t FuncChecksum; bool UseCfgChecksum; uint32_t CfgChecksum; DenseMap Blocks; @@ -731,6 +742,7 @@ Constant *GCOVProfiler::getEmitFunctionFunc() { Type *Args[] = { Type::getInt32Ty(*Ctx), // uint32_t ident Type::getInt8PtrTy(*Ctx), // const char *function_name + Type::getInt32Ty(*Ctx), // uint32_t func_checksum Type::getInt8Ty(*Ctx), // uint8_t use_extra_checksum Type::getInt32Ty(*Ctx), // uint32_t cfg_checksum }; @@ -813,11 +825,12 @@ Function *GCOVProfiler::insertCounterWriteout( Builder.getInt32(CfgChecksum)); for (unsigned j = 0, e = CountersBySP.size(); j != e; ++j) { DISubprogram SP(CountersBySP[j].second); - Builder.CreateCall4( + Builder.CreateCall5( EmitFunction, Builder.getInt32(j), Options.FunctionNamesInData ? Builder.CreateGlobalStringPtr(getFunctionName(SP)) : Constant::getNullValue(Builder.getInt8PtrTy()), + Builder.getInt32(Funcs[j]->getFuncChecksum()), Builder.getInt8(Options.UseCfgChecksum), Builder.getInt32(CfgChecksum)); diff --git a/test/tools/llvm-cov/Inputs/test.gcda b/test/tools/llvm-cov/Inputs/test.gcda index a62c069c9a7b5d2c1536b09812bb7b4357d93ad8..c0c8329afb6cc5acbf1cbdfffca5dc10efa32dd6 100644 GIT binary patch delta 91 zcmV-h0Hpu82Dk>07zA8?lKYVyECfNVlcbSMECg&4^3aidGz9Nq*IbdbC$mkFd diff --git a/test/tools/llvm-cov/Inputs/test.gcno b/test/tools/llvm-cov/Inputs/test.gcno index 218398548efee0828fe4762c70776d7349277c8c..97b67bb692b103d69b6d9ca0ec4aa5f5f5cb350c 100644 GIT binary patch delta 107 zcmV-x0F?iz7^oPK7zA8?lKYVyfCNFUlcbTLfCOw3^3anc0f+?eVb@%fumOMsd52*{ zlQaT=1Pw!pYm>MFhy)=3wC=M+1H1wZv`%SH0ssI2ZDDC{k#H2VAO-{l1f_i&y^|;l NfCNj@uCJ4<3w*u|i^k1PcQYOq6MW&_?wC!WykgqW0jF&@6OJS zH*w7Rt-Y>hH%~9CRZ$e`R2E_)fv%s+yYl|=)02C36pL~9dKI~#zx{B{ws8&}qdrR1 zxdik$kyzJdwd;pQCtZj7poKqxeqGNueLtQ-Pbn#AkL3ZP_SFodHdOrT=Z78$^Dm8a zw(YDHCd`kSBh*v^ek1HM|H5|m-I}faYIHl;b@)`$dnI+wmCge%=Jd|cDuP2yaMiKM;YbE`aQMKCq77Xe5b_452mLw+W-In diff --git a/test/tools/llvm-cov/Inputs/test_file_checksum_fail.gcda b/test/tools/llvm-cov/Inputs/test_file_checksum_fail.gcda new file mode 100644 index 0000000000000000000000000000000000000000..8bfd82c7b2482ab1b941cf821793b8ec7b42b4bd GIT binary patch literal 825 zcmYdHNlw=?GBEKC^YLL|U|?he5+D#$H|aMskdBY?Gjud`axDXkE@Wf^(+mty8myiX zDCW3!@)C%8^U~tfoYdlCkPd`;s5V9pAOoZ~N9fZ9Rv;Z8WoVR}Uz8e;qzjuqkXn%W z?-Q@bfb_>l8K>pvBkX{=3n;}1Qp*CwmFkMF_P(DHs5|AEchwxicH$ezU~l z;>`5C%uJvt#Qh*QLjfZvkO2xKMTRZ!Ks3<(rkQz}C7FpinN_Lr=|!0-ke~wU6$8q{ z+y!zE2%z&}X2axRd>9QAhtV+oK%>C^WCt>~_+|Qo#B&of^MDi(EMznQl1OU7qPX}X zU|EEEbi1L_aPwek1l>(AahQIXxiA{peh?d-53&bM92`F&^On|1?}evFXG4_qh-3~} gJt&U6FRfdTP;Z1w{X&ph7(g-yCWK5cM&@t<0In%V1ONa4 literal 0 HcmV?d00001 diff --git a/test/tools/llvm-cov/Inputs/test_func_checksum_fail.gcda b/test/tools/llvm-cov/Inputs/test_func_checksum_fail.gcda new file mode 100644 index 0000000000000000000000000000000000000000..4c729a850d8644564bffb25164228d42fd669926 GIT binary patch literal 825 zcmYdHNlw=?GBBByedPrM0|O%)kN|<0x=Fv8fpmP7pP{3nlWQ4RbRi=Xm}X#r(qQ$B zKrzR)lb1l$o0k@+=A;%EgLEL&L$xt-02v^?zF|H-tUx+G%Frk`zbG{xNf$PKAhjU# z-zQ#=0qKvAGEU3SN7w;#7f^~3q?QGUE87!YplXv6ix6soQZN8^KS({Vb7wZh{bq^9 z#hK}OnVCRQi2Ffqh5|-TAOjReiVR!cfoP!nO*8W{OEMF4GOJSK(~B}wAVCGxD+ZK@ zxeMeT5J2a{%!bLs_%IqK4x?fEfkuJ-$qr;}@yqlFiRUI}<^d@nSjcDqB$3pDMRD;( zz_JMS=ypS;;pV~82)dhK;xPR%b73^H{UA0vA7l@jI5>Vl<}Iz2-V0BU&W0%I5y>2| gdQcpBUs|^wq236W`h_61Fo0wZObD4?jLhKz0K3CSg#Z8m literal 0 HcmV?d00001 diff --git a/test/tools/llvm-cov/Inputs/test_read_fail.gcno b/test/tools/llvm-cov/Inputs/test_read_fail.gcno index bcc20a65eee483a161ac140ee0aa6e4dec99dc6d..88073f15dac6010298d92fee6e4523072588b522 100644 GIT binary patch delta 14 VcmeZppCG{!Q#a}NL>VncE&wEC1cd+q delta 15 UcmZ?wm>|Kz00a|dw3ryU02OWm9{>OV diff --git a/test/tools/llvm-cov/llvm-cov.test b/test/tools/llvm-cov/llvm-cov.test index e2a21e1889e..b08b514a9f2 100644 --- a/test/tools/llvm-cov/llvm-cov.test +++ b/test/tools/llvm-cov/llvm-cov.test @@ -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.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 -- 2.34.1