Skip to content

Commit 4f9c367

Browse files
committed
Update the gcov version used slightly, to make it stop causing modern gcov's to
crash. llvm-svn: 130911
1 parent 8f7770f commit 4f9c367

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ namespace {
8787
// list.
8888
void insertCounterWriteout(DebugInfoFinder &,
8989
SmallVector<std::pair<GlobalVariable *,
90-
uint32_t>, 8> &);
90+
MDNode *>, 8> &);
9191

9292
std::string mangleName(DICompileUnit CU, std::string NewStem);
9393

@@ -261,12 +261,13 @@ namespace {
261261
ReturnBlock = new GCOVBlock(i++, os);
262262

263263
writeBytes(FunctionTag, 4);
264-
uint32_t BlockLen = 1 + 1 + 1 + lengthOfGCOVString(SP.getName()) +
264+
uint32_t BlockLen = 1 + 1 + 1 + 1 + lengthOfGCOVString(SP.getName()) +
265265
1 + lengthOfGCOVString(SP.getFilename()) + 1;
266266
write(BlockLen);
267267
uint32_t Ident = reinterpret_cast<intptr_t>((MDNode*)SP);
268268
write(Ident);
269-
write(0); // checksum
269+
write(0); // checksum #1
270+
write(0); // checksum #2
270271
writeGCOVString(SP.getName());
271272
writeGCOVString(SP.getFilename());
272273
write(SP.getLineNumber());
@@ -418,7 +419,7 @@ bool GCOVProfiler::emitProfileArcs(DebugInfoFinder &DIF) {
418419
if (DIF.subprogram_begin() == DIF.subprogram_end())
419420
return false;
420421

421-
SmallVector<std::pair<GlobalVariable *, uint32_t>, 8> CountersByIdent;
422+
SmallVector<std::pair<GlobalVariable *, MDNode *>, 8> CountersBySP;
422423
for (DebugInfoFinder::iterator SPI = DIF.subprogram_begin(),
423424
SPE = DIF.subprogram_end(); SPI != SPE; ++SPI) {
424425
DISubprogram SP(*SPI);
@@ -441,8 +442,7 @@ bool GCOVProfiler::emitProfileArcs(DebugInfoFinder &DIF) {
441442
GlobalValue::InternalLinkage,
442443
Constant::getNullValue(CounterTy),
443444
"__llvm_gcov_ctr", 0, false, 0);
444-
CountersByIdent.push_back(
445-
std::make_pair(Counters, reinterpret_cast<intptr_t>((MDNode*)SP)));
445+
CountersBySP.push_back(std::make_pair(Counters, (MDNode*)SP));
446446

447447
UniqueVector<BasicBlock *> ComplexEdgePreds;
448448
UniqueVector<BasicBlock *> ComplexEdgeSuccs;
@@ -509,7 +509,7 @@ bool GCOVProfiler::emitProfileArcs(DebugInfoFinder &DIF) {
509509
}
510510
}
511511

512-
insertCounterWriteout(DIF, CountersByIdent);
512+
insertCounterWriteout(DIF, CountersBySP);
513513

514514
return true;
515515
}
@@ -580,7 +580,10 @@ Constant *GCOVProfiler::getIncrementIndirectCounterFunc() {
580580
}
581581

582582
Constant *GCOVProfiler::getEmitFunctionFunc() {
583-
const Type *Args[] = { Type::getInt32Ty(*Ctx) };
583+
const Type *Args[2] = {
584+
Type::getInt32Ty(*Ctx), // uint32_t ident
585+
Type::getInt8PtrTy(*Ctx), // const char *function_name
586+
};
584587
const FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx),
585588
Args, false);
586589
return M->getOrInsertFunction("llvm_gcda_emit_function", FTy);
@@ -616,7 +619,7 @@ GlobalVariable *GCOVProfiler::getEdgeStateValue() {
616619

617620
void GCOVProfiler::insertCounterWriteout(
618621
DebugInfoFinder &DIF,
619-
SmallVector<std::pair<GlobalVariable *, uint32_t>, 8> &CountersByIdent) {
622+
SmallVector<std::pair<GlobalVariable *, MDNode *>, 8> &CountersBySP) {
620623
const FunctionType *WriteoutFTy =
621624
FunctionType::get(Type::getVoidTy(*Ctx), false);
622625
Function *WriteoutF = Function::Create(WriteoutFTy,
@@ -637,11 +640,15 @@ void GCOVProfiler::insertCounterWriteout(
637640
std::string FilenameGcda = mangleName(compile_unit, "gcda");
638641
Builder.CreateCall(StartFile,
639642
Builder.CreateGlobalStringPtr(FilenameGcda));
640-
for (SmallVector<std::pair<GlobalVariable *, uint32_t>, 8>::iterator
641-
I = CountersByIdent.begin(), E = CountersByIdent.end();
643+
for (SmallVector<std::pair<GlobalVariable *, MDNode *>, 8>::iterator
644+
I = CountersBySP.begin(), E = CountersBySP.end();
642645
I != E; ++I) {
643-
Builder.CreateCall(EmitFunction, ConstantInt::get(Type::getInt32Ty(*Ctx),
644-
I->second));
646+
DISubprogram SP(I->second);
647+
intptr_t ident = reinterpret_cast<intptr_t>(I->second);
648+
Builder.CreateCall2(EmitFunction,
649+
ConstantInt::get(Type::getInt32Ty(*Ctx), ident),
650+
Builder.CreateGlobalStringPtr(SP.getName()));
651+
645652
GlobalVariable *GV = I->first;
646653
unsigned Arcs =
647654
cast<ArrayType>(GV->getType()->getElementType())->getNumElements();

llvm/runtime/libprofile/GCDAProfiling.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ static void write_int64(uint64_t i) {
4848
write_int32(hi);
4949
}
5050

51+
static uint32_t length_of_string(const char *s) {
52+
return (strlen(s) + 5) / 4;
53+
}
54+
55+
static void write_string(const char *s) {
56+
uint32_t len = length_of_string(s);
57+
write_int32(len);
58+
fwrite(s, strlen(s), 1, output_file);
59+
fwrite("\0\0\0\0", 4 - (strlen(s) % 4), 1, output_file);
60+
}
61+
5162
static char *mangle_filename(const char *orig_filename) {
5263
/* TODO: handle GCOV_PREFIX_STRIP */
5364
const char *prefix;
@@ -129,16 +140,18 @@ void llvm_gcda_increment_indirect_counter(uint32_t *predecessor,
129140
#endif
130141
}
131142

132-
void llvm_gcda_emit_function(uint32_t ident) {
143+
void llvm_gcda_emit_function(uint32_t ident, const char *function_name) {
133144
#ifdef DEBUG_GCDAPROFILING
134145
printf("llvmgcda: function id=%x\n", ident);
135146
#endif
136147

137148
/* function tag */
138149
fwrite("\0\0\0\1", 4, 1, output_file);
139-
write_int32(2);
150+
write_int32(3 + 1 + length_of_string(function_name));
140151
write_int32(ident);
141152
write_int32(0);
153+
write_int32(0);
154+
write_string(function_name);
142155
}
143156

144157
void llvm_gcda_emit_arcs(uint32_t num_counters, uint64_t *counters) {

0 commit comments

Comments
 (0)