@@ -237,24 +237,46 @@ static int mmapForContinuousMode(uint64_t CurrentFileOffset, FILE *File) {
237237 const char * CountersEnd = __llvm_profile_end_counters ();
238238 const char * BitmapBegin = __llvm_profile_begin_bitmap ();
239239 const char * BitmapEnd = __llvm_profile_end_bitmap ();
240+ const char * NamesBegin = __llvm_profile_begin_names ();
241+ const char * NamesEnd = __llvm_profile_end_names ();
242+ const uint64_t NamesSize = (NamesEnd - NamesBegin ) * sizeof (char );
240243 uint64_t DataSize = __llvm_profile_get_data_size (DataBegin , DataEnd );
244+ uint64_t CountersSize =
245+ __llvm_profile_get_counters_size (CountersBegin , CountersEnd );
246+ uint64_t NumBitmapBytes =
247+ __llvm_profile_get_num_bitmap_bytes (BitmapBegin , BitmapEnd );
241248 /* Get the file size. */
242249 uint64_t FileSize = 0 ;
243250 if (getProfileFileSizeForMerging (File , & FileSize ))
244251 return 1 ;
245252
253+ int Fileno = fileno (File );
254+ /* Determine how much padding is needed before/after the counters and
255+ * after the names. */
256+ uint64_t PaddingBytesBeforeCounters , PaddingBytesAfterCounters ,
257+ PaddingBytesAfterNames , PaddingBytesAfterBitmapBytes ,
258+ PaddingBytesAfterVTable , PaddingBytesAfterVNames ;
259+ __llvm_profile_get_padding_sizes_for_counters (
260+ DataSize , CountersSize , NumBitmapBytes , NamesSize , /*VTableSize=*/ 0 ,
261+ /*VNameSize=*/ 0 , & PaddingBytesBeforeCounters , & PaddingBytesAfterCounters ,
262+ & PaddingBytesAfterBitmapBytes , & PaddingBytesAfterNames ,
263+ & PaddingBytesAfterVTable , & PaddingBytesAfterVNames );
264+
265+ CurrentFileOffset = 0 ;
266+ uint64_t FileOffsetToCounters = CurrentFileOffset +
267+ sizeof (__llvm_profile_header ) + DataSize +
268+ PaddingBytesBeforeCounters ;
269+
246270 /* Map the profile. */
247271 char * Profile = (char * )mmap (NULL , FileSize , PROT_READ | PROT_WRITE ,
248- MAP_SHARED , fileno ( File ) , 0 );
272+ MAP_SHARED , Fileno , 0 );
249273 if (Profile == MAP_FAILED ) {
250274 PROF_ERR ("Unable to mmap profile: %s\n" , strerror (errno ));
251275 return 1 ;
252276 }
253- const uint64_t CountersOffsetInBiasMode =
254- sizeof (__llvm_profile_header ) + __llvm_write_binary_ids (NULL ) + DataSize ;
255277 /* Update the profile fields based on the current mapping. */
256278 INSTR_PROF_PROFILE_COUNTER_BIAS_VAR =
257- (intptr_t )Profile - (uintptr_t )CountersBegin + CountersOffsetInBiasMode ;
279+ (intptr_t )Profile - (uintptr_t )CountersBegin + FileOffsetToCounters ;
258280
259281 /* Return the memory allocated for counters to OS. */
260282 lprofReleaseMemoryPagesToOS ((uintptr_t )CountersBegin , (uintptr_t )CountersEnd );
0 commit comments