Index: lib/profile/InstrProfiling.h =================================================================== --- lib/profile/InstrProfiling.h +++ lib/profile/InstrProfiling.h @@ -156,6 +156,10 @@ /*! \brief Initialize file handling. */ void __llvm_profile_initialize_file(void); +/*! \brief ??. */ +void __llvm_profile_initialize_handlers(void); + + /*! * \brief Return path prefix (excluding the base filename) of the profile data. * This is useful for users using \c -fprofile-generate=./path_prefix who do Index: lib/profile/InstrProfilingFile.c =================================================================== --- lib/profile/InstrProfilingFile.c +++ lib/profile/InstrProfilingFile.c @@ -11,6 +11,7 @@ #include "InstrProfilingInternal.h" #include "InstrProfilingUtil.h" #include +#include #include #include #include @@ -506,6 +507,18 @@ return Prefix; } +static void child() { + // uint64_t *cnt; + // for (cnt = __llvm_profile_begin_counters(); cnt < __llvm_profile_end_counters(); ++cnt) { + // *cnt = 0; + // } + __llvm_profile_reset_counters(); + memset(&lprofCurFilename, 0, sizeof(lprofCurFilename)); + __llvm_profile_register_write_file_atexit(); + __llvm_profile_initialize_file(); + printf("!!!!!!!\t\t\t\texecuted child!\n"); +} + /* This method is invoked by the runtime initialization hook * InstrProfilingRuntime.o if it is linked in. Both user specified * profile path via -fprofile-instr-generate= and LLVM_PROFILE_FILE @@ -518,6 +531,7 @@ int hasCommandLineOverrider = (INSTR_PROF_PROFILE_NAME_VAR[0] != 0); EnvFilenamePat = getFilenamePatFromEnv(); + printf("!!!!!!!!!!!\t\tEnvFilenamePat: %s\n", EnvFilenamePat); if (EnvFilenamePat) { /* Pass CopyFilenamePat = 1, to ensure that the filename would be valid at the moment when __llvm_profile_write_file() gets executed. */ @@ -534,6 +548,13 @@ parseAndSetFilename(SelectedPat, PNS, 0); } +COMPILER_RT_VISIBILITY +void __llvm_profile_initialize_handlers(void) { + int res = pthread_atfork(NULL, NULL, &child); + printf("!!!!!!\t\t\tpthread_atfork: %d\n", res); +} + + /* This API is directly called by the user application code. It has the * highest precedence compared with LLVM_PROFILE_FILE environment variable * and command line option -fprofile-instr-generate=. Index: lib/profile/InstrProfilingRuntime.cc =================================================================== --- lib/profile/InstrProfilingRuntime.cc +++ lib/profile/InstrProfilingRuntime.cc @@ -22,6 +22,7 @@ RegisterRuntime() { __llvm_profile_register_write_file_atexit(); __llvm_profile_initialize_file(); + __llvm_profile_initialize_handlers(); } };