[llvm-commits] [llvm] r157852 - /llvm/trunk/lib/Transforms/Instrumentation/GCOVProfiling.cpp

Bill Wendling isanbard at gmail.com
Sat Jun 2 02:50:05 PDT 2012


On Jun 1, 2012, at 9:34 PM, Nick Lewycky <nicholas at mxc.ca> wrote:

> Bill Wendling wrote:
>> Author: void
>> Date: Fri Jun  1 18:14:32 2012
>> New Revision: 157852
>> 
>> URL: http://llvm.org/viewvc/llvm-project?rev=157852&view=rev
>> Log:
>> Register the gcov "writeout" at init time. Don't list this as a d'tor. Instead,
>> inject some code in that will run via the "__mod_init_func" method that
>> registers the gcov "writeout" function to execute at exit time.
>> 
>> The problem is that the "__mod_term_func" method of specifying d'tors is
>> deprecated on Darwin. And it can lead to some ambiguities when dealing with
>> multiple libraries.
> 
> Why isn't @llvm.global_dtors doing what you want? Is it broken on Darwin? Is the bug that it was getting called when the .dylib is unloaded as opposed to at program exit?
> 
> The LangRef description of @llvm.global_dtors is wrong, it says "The functions referenced by this array will be called in descending order of priority (i.e. highest first) when the module is loaded." which is clearly copy+paste from the @llvm.global_ctors case; either it should be s/loaded/unloaded/ or s/module is loaded/program exits/ and that changes where the bug is. :)


It was placing them into the __mod_term_func section just fine. But in a simulated environment (e.g., using the iPhone simulator), two copies of system libraries are involved, as are two copies of libdyld. The libdyld long ago replaced using __mod_term_func with atexit() calls. It did this because of badness due to the ordering of d'tor executions. Anyway, because there are two libdylds here, there are two __mod_term_func sections to deal with. But only one of them is executed correctly in the simulated environment when the process exits. In particular, the gcov files won't be emitted because those mod_term_funcs aren't seen by the simulator.

-bw





More information about the llvm-commits mailing list