@@ -237,24 +237,46 @@ static int mmapForContinuousMode(uint64_t CurrentFileOffset, FILE *File) {
237
237
const char * CountersEnd = __llvm_profile_end_counters ();
238
238
const char * BitmapBegin = __llvm_profile_begin_bitmap ();
239
239
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 );
240
243
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 );
241
248
/* Get the file size. */
242
249
uint64_t FileSize = 0 ;
243
250
if (getProfileFileSizeForMerging (File , & FileSize ))
244
251
return 1 ;
245
252
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
+
246
270
/* Map the profile. */
247
271
char * Profile = (char * )mmap (NULL , FileSize , PROT_READ | PROT_WRITE ,
248
- MAP_SHARED , fileno ( File ) , 0 );
272
+ MAP_SHARED , Fileno , 0 );
249
273
if (Profile == MAP_FAILED ) {
250
274
PROF_ERR ("Unable to mmap profile: %s\n" , strerror (errno ));
251
275
return 1 ;
252
276
}
253
- const uint64_t CountersOffsetInBiasMode =
254
- sizeof (__llvm_profile_header ) + __llvm_write_binary_ids (NULL ) + DataSize ;
255
277
/* Update the profile fields based on the current mapping. */
256
278
INSTR_PROF_PROFILE_COUNTER_BIAS_VAR =
257
- (intptr_t )Profile - (uintptr_t )CountersBegin + CountersOffsetInBiasMode ;
279
+ (intptr_t )Profile - (uintptr_t )CountersBegin + FileOffsetToCounters ;
258
280
259
281
/* Return the memory allocated for counters to OS. */
260
282
lprofReleaseMemoryPagesToOS ((uintptr_t )CountersBegin , (uintptr_t )CountersEnd );
0 commit comments