In GCC 4.7, function names are now forbidden from .gcda files. Support this by
authorNick Lewycky <nicholas@mxc.ca>
Wed, 27 Feb 2013 06:22:56 +0000 (06:22 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Wed, 27 Feb 2013 06:22:56 +0000 (06:22 +0000)
passing a null pointer to the function name in to GCDAProfiling, and add another
switch onto GCOVProfiling.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@176173 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Transforms/Instrumentation.h
lib/Transforms/Instrumentation/GCOVProfiling.cpp
runtime/libprofile/GCDAProfiling.c

index fed92c838be94f6495ed5198095947f7907c95c0..a57e0f3e8adcce17e35e1a2a2be1fa4be303ec98 100644 (file)
@@ -34,7 +34,8 @@ ModulePass *createPathProfilerPass();
 ModulePass *createGCOVProfilerPass(bool EmitNotes = true, bool EmitData = true,
                                    bool Use402Format = false,
                                    bool UseExtraChecksum = false,
-                                   bool NoRedZone = false);
+                                   bool NoRedZone = false,
+                                   bool NoFunctionNamesInData = false);
 
 // Insert AddressSanitizer (address sanity checking) instrumentation
 FunctionPass *createAddressSanitizerFunctionPass(
index 09dea48e3988629b08fa9db75b3cdb7c2df35ed7..095b852d9385b2ecb606c7a8b4d1ac3b77bd4e88 100644 (file)
@@ -45,14 +45,16 @@ namespace {
     static char ID;
     GCOVProfiler()
         : ModulePass(ID), EmitNotes(true), EmitData(true), Use402Format(false),
-          UseExtraChecksum(false), NoRedZone(false) {
+          UseExtraChecksum(false), NoRedZone(false),
+          NoFunctionNamesInData(false) {
       initializeGCOVProfilerPass(*PassRegistry::getPassRegistry());
     }
-    GCOVProfiler(bool EmitNotes, bool EmitData, bool use402Format,
-                 bool useExtraChecksum, bool NoRedZone_)
+    GCOVProfiler(bool EmitNotes, bool EmitData, bool Use402Format,
+                 bool UseExtraChecksum, bool NoRedZone,
+                 bool NoFunctionNamesInData)
         : ModulePass(ID), EmitNotes(EmitNotes), EmitData(EmitData),
-          Use402Format(use402Format), UseExtraChecksum(useExtraChecksum),
-          NoRedZone(NoRedZone_) {
+          Use402Format(Use402Format), UseExtraChecksum(UseExtraChecksum),
+          NoRedZone(NoRedZone), NoFunctionNamesInData(NoFunctionNamesInData) {
       assert((EmitNotes || EmitData) && "GCOVProfiler asked to do nothing?");
       initializeGCOVProfilerPass(*PassRegistry::getPassRegistry());
     }
@@ -100,6 +102,7 @@ namespace {
     bool Use402Format;
     bool UseExtraChecksum;
     bool NoRedZone;
+    bool NoFunctionNamesInData;
 
     Module *M;
     LLVMContext *Ctx;
@@ -113,9 +116,10 @@ INITIALIZE_PASS(GCOVProfiler, "insert-gcov-profiling",
 ModulePass *llvm::createGCOVProfilerPass(bool EmitNotes, bool EmitData,
                                          bool Use402Format,
                                          bool UseExtraChecksum,
-                                         bool NoRedZone) {
+                                         bool NoRedZone,
+                                         bool NoFunctionNamesInData) {
   return new GCOVProfiler(EmitNotes, EmitData, Use402Format, UseExtraChecksum,
-                          NoRedZone);
+                          NoRedZone, NoFunctionNamesInData);
 }
 
 namespace {
@@ -664,7 +668,9 @@ void GCOVProfiler::insertCounterWriteout(
         intptr_t ident = reinterpret_cast<intptr_t>(I->second);
         Builder.CreateCall2(EmitFunction,
                             Builder.getInt32(ident),
-                            Builder.CreateGlobalStringPtr(SP.getName()));
+                            NoFunctionNamesInData ?
+                              Constant::getNullValue(Builder.getInt8PtrTy()) :
+                              Builder.CreateGlobalStringPtr(SP.getName()));
         
         GlobalVariable *GV = I->first;
         unsigned Arcs =
index f2dc4f79881f205756f70deb4de10f4da6bdc9ec..d9f3b32638990bc35352a0ca40a8c87b3769591a 100644 (file)
@@ -162,17 +162,22 @@ void llvm_gcda_increment_indirect_counter(uint32_t *predecessor,
 
 void llvm_gcda_emit_function(uint32_t ident, const char *function_name) {
 #ifdef DEBUG_GCDAPROFILING
-  printf("llvmgcda: function id=%x\n", ident);
+  printf("llvmgcda: function id=%x name=%s\n", ident,
+         function_name ? function_name : "NULL");
 #endif
   if (!output_file) return;
 
   /* function tag */  
   fwrite("\0\0\0\1", 4, 1, output_file);
-  write_int32(3 + 1 + length_of_string(function_name));
+  uint32_t len = 3;
+  if (function_name)
+    len += 1 + length_of_string(function_name);
+  write_int32(len);
   write_int32(ident);
   write_int32(0);
   write_int32(0);
-  write_string(function_name);
+  if (function_name)
+    write_string(function_name);
 }
 
 void llvm_gcda_emit_arcs(uint32_t num_counters, uint64_t *counters) {