[llvm-commits] [Patch] GCDA Files for Coverage

Bob Wilson bob.wilson at apple.com
Thu Jul 28 09:01:31 PDT 2011


On Jul 28, 2011, at 1:46 AM, Bill Wendling wrote:

> Hi,
> 
> Attached is a patch that I'm concerned may cause breakage for some people. Darwin needs the "402" version of GCOV. I made this change for the .gcno file, but I failed to make it for the .gcda file. Unfortunately, it's a bit more involved than one would think. I will need to change the llvm_gcda_start_file() function in runtime/libprofile/GCDAProfiling.c, since that library gets called when running the program. But if I change the function's arguments, it would break current files that were built were built the olde waye.
> 
> So, is this a problem? If so, then would it be okay to create a new function (llvm_gcda_start_file_402format or something) and use that?
> 
> Comments?

Since we're currently setting the Use402Format option for the .gcno files based on whether the target is MacOSX, how about the following much simpler patch:

--- a/runtime/libprofile/GCDAProfiling.c
+++ b/runtime/libprofile/GCDAProfiling.c
@@ -114,7 +114,11 @@ void llvm_gcda_start_file(const char *orig_filename) {
   output_file = fopen(filename, "wb");
 
   /* gcda file, version 404*, stamp LLVM. */
+#ifdef __APPLE__
+  fwrite("adcg*204MVLL", 12, 1, output_file);
+#else
   fwrite("adcg*404MVLL", 12, 1, output_file);
+#endif
 
 #ifdef DEBUG_GCDAPROFILING
   printf("llvmgcda: [%s]\n", orig_filename);


> 
> -bw
> 
> Index: runtime/libprofile/GCDAProfiling.c
> ===================================================================
> --- runtime/libprofile/GCDAProfiling.c	(revision 136325)
> +++ runtime/libprofile/GCDAProfiling.c	(working copy)
> @@ -107,14 +107,17 @@
>  * profiling enabled will emit to a different file. Only one file may be
>  * started at a time.
>  */
> -void llvm_gcda_start_file(const char *orig_filename) {
> +void llvm_gcda_start_file(const char *orig_filename, int use_402_format) {
>   char *filename;
>   filename = mangle_filename(orig_filename);
>   recursive_mkdir(filename);
>   output_file = fopen(filename, "wb");
> 
>   /* gcda file, version 404*, stamp LLVM. */
> -  fwrite("adcg*404MVLL", 12, 1, output_file);
> +  if (!use_402_format)
> +    fwrite("adcg*404MVLL", 12, 1, output_file);
> +  else
> +    fwrite("adcg*204MVLL", 12, 1, output_file);
> 
> #ifdef DEBUG_GCDAPROFILING
>   printf("llvmgcda: [%s]\n", orig_filename);
> Index: lib/Transforms/Instrumentation/GCOVProfiling.cpp
> ===================================================================
> --- lib/Transforms/Instrumentation/GCOVProfiling.cpp	(revision 136325)
> +++ lib/Transforms/Instrumentation/GCOVProfiling.cpp	(working copy)
> @@ -571,8 +571,11 @@
> }
> 
> Constant *GCOVProfiler::getStartFileFunc() {
> +  Type *Args[] = {
> +    Type::getInt8PtrTy(*Ctx), Type::getInt32Ty(*Ctx)
> +  };
>   FunctionType *FTy = FunctionType::get(Type::getVoidTy(*Ctx),
> -                                              Type::getInt8PtrTy(*Ctx), false);
> +                                        Args, false);
>   return M->getOrInsertFunction("llvm_gcda_start_file", FTy);
> }
> 
> @@ -645,8 +648,10 @@
>            CUE = DIF.compile_unit_end(); CUI != CUE; ++CUI) {
>     DICompileUnit compile_unit(*CUI);
>     std::string FilenameGcda = mangleName(compile_unit, "gcda");
> -    Builder.CreateCall(StartFile,
> -                       Builder.CreateGlobalStringPtr(FilenameGcda));
> +    Builder.CreateCall2(StartFile,
> +                        Builder.CreateGlobalStringPtr(FilenameGcda),
> +                        ConstantInt::get(Type::getInt32Ty(*Ctx), Use402Format));
> +
>     for (SmallVector<std::pair<GlobalVariable *, MDNode *>, 8>::iterator
>              I = CountersBySP.begin(), E = CountersBySP.end();
>          I != E; ++I) {
> 
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list