atexit registered functions run earlier so __attribute__((destructor))
annotated functions cannot be tracked.
Set a priority of 100 (compatible with GCC 7 onwards) to track
destructors and destructors whose priorities are greater than 100.
Differential D82253
[gcov] Move llvm_writeout_files from atexit to a static destructor MaskRay on Jun 19 2020, 9:26 PM. Authored by
Details atexit registered functions run earlier so __attribute__((destructor)) Set a priority of 100 (compatible with GCC 7 onwards) to track
Diff Detail
Event TimelineComment Actions There is only a problem with the (possibly very rare) case where calling exec* fails:
For reference, we inject llvm_writeout_files before exec* here: https://github.com/llvm/llvm-project/blob/16cc759ebd56fddd2a9d2437b810ced885ebda73/llvm/lib/Transforms/Instrumentation/GCOVProfiling.cpp#L684. Comment Actions How does the patch cause a new problem? This is a pre-existing problem with the previous atexit approach. Comment Actions It's because you moved fn_list_remove(&writeout_fn_list); in llvm_writeout_files(void) Comment Actions Can you elaborate how deleting atexit(llvm_delete_writeout_function_list); can be a problem? Please also propose a solution if the very rare use case fails. You can add a test if you want to demonstrate this is a feature we want to support. I have to move it because we need to postpone llvm_writeout_files to a later stage. The function (via a static destructor) still runs if exec* fails. Comment Actions
With the atexit approach, we were not deleting the writeout function list before exec. With atexit:
With static destructor:
Aren't these usually responsibility of the author of the proposed change? :) Anyway, a couple possible solutions:
I personally prefer the second option. Comment Actions Thanks! I did not notice that llvm_writeout_files could be called by execl, so I failed to notice the issue you reported. (I thought it was an edge case, thus asked you to clarify.) Comment Actions @marco-c :) (Sorry to bother you again in less than one week. I hope this will not take up much of your time) |