Skip to content

Commit 16e74fd

Browse files
Reland "[TypeProf][InstrPGO] Introduce raw and instr profile format change for type profiling." (#82711)
New change on top of [reviewed patch](#81691) are [in commits after this one](d0757f4). Previous commits are restored from the remote branch with timestamps. 1. Fix build breakage for non-ELF platforms, by defining the missing functions {`__llvm_profile_begin_vtables`, `__llvm_profile_end_vtables`, `__llvm_profile_begin_vtabnames `, `__llvm_profile_end_vtabnames`} everywhere. * Tested on mac laptop (for darwins) and Windows. Specifically, functions in `InstrProfilingPlatformWindows.c` returns `NULL` to make it more explicit that type prof isn't supported; see comments for the reason. * For the rest (AIX, other), mostly follow existing examples (like this [one](f95b2f1)) 2. Rename `__llvm_prf_vtabnames` -> `__llvm_prf_vns` for shorter section name, and make returned pointers [const](a825d2a#diff-4de780ce726d76b7abc9d3353aef95013e7b21e7bda01be8940cc6574fb0b5ffR120-R121) **Original Description** * Raw profile format - Header: records the byte size of compressed vtable names, and the number of profiled vtable entries (call it `VTableProfData`). Header also records padded bytes of each section. - Payload: adds a section for compressed vtable names, and a section to store `VTableProfData`. Both sections are padded so the size is a multiple of 8. * Indexed profile format - Header: records the byte offset of compressed vtable names. - Payload: adds a section to store compressed vtable names. This section is used by `llvm-profdata` to show the list of vtables profiled for an instrumented site. [The originally reviewed patch](#66825) will have profile reader/write change and llvm-profdata change. - To ensure this PR has all the necessary profile format change along with profile version bump, created a copy of the originally reviewed patch in #80761. The copy doesn't have profile format change, but it has the set of tests which covers type profile generation, profile read and profile merge. Tests pass there. rfc in https://discourse.llvm.org/t/rfc-dynamic-type-profiling-and-optimizations-in-llvm/74600 --------- Co-authored-by: modiking <modiking213@gmail.com>
1 parent 8e3b605 commit 16e74fd

37 files changed

+541
-98
lines changed

compiler-rt/include/profile/InstrProfData.inc

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,25 @@ INSTR_PROF_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), NumBitmapBytes, \
9696
#undef INSTR_PROF_DATA
9797
/* INSTR_PROF_DATA end. */
9898

99+
/* For a virtual table object, record the name hash to associate profiled
100+
* addresses with global variables, and record {starting address, size in bytes}
101+
* to map the profiled virtual table (which usually have an offset from the
102+
* starting address) back to a virtual table object. */
103+
#ifndef INSTR_PROF_VTABLE_DATA
104+
#define INSTR_PROF_VTABLE_DATA(Type, LLVMType, Name, Initializer)
105+
#else
106+
#define INSTR_PROF_VTABLE_DATA_DEFINED
107+
#endif
108+
INSTR_PROF_VTABLE_DATA(const uint64_t, llvm::Type::getInt64Ty(Ctx), \
109+
VTableNameHash, ConstantInt::get(llvm::Type::getInt64Ty(Ctx), \
110+
IndexedInstrProf::ComputeHash(PGOVTableName)))
111+
INSTR_PROF_VTABLE_DATA(const IntPtrT, llvm::PointerType::getUnqual(Ctx), \
112+
VTablePointer, VTableAddr)
113+
INSTR_PROF_VTABLE_DATA(const uint32_t, llvm::Type::getInt32Ty(Ctx), VTableSize, \
114+
ConstantInt::get(llvm::Type::getInt32Ty(Ctx), \
115+
VTableSizeVal))
116+
#undef INSTR_PROF_VTABLE_DATA
117+
/* INSTR_PROF_VTABLE_DATA end. */
99118

100119
/* This is an internal data structure used by value profiler. It
101120
* is defined here to allow serialization code sharing by LLVM
@@ -147,6 +166,8 @@ INSTR_PROF_RAW_HEADER(uint64_t, CountersDelta,
147166
INSTR_PROF_RAW_HEADER(uint64_t, BitmapDelta,
148167
(uintptr_t)BitmapBegin - (uintptr_t)DataBegin)
149168
INSTR_PROF_RAW_HEADER(uint64_t, NamesDelta, (uintptr_t)NamesBegin)
169+
INSTR_PROF_RAW_HEADER(uint64_t, NumVTables, NumVTables)
170+
INSTR_PROF_RAW_HEADER(uint64_t, VNamesSize, VNamesSize)
150171
INSTR_PROF_RAW_HEADER(uint64_t, ValueKindLast, IPVK_Last)
151172
#undef INSTR_PROF_RAW_HEADER
152173
/* INSTR_PROF_RAW_HEADER end */
@@ -188,13 +209,26 @@ VALUE_PROF_FUNC_PARAM(uint32_t, CounterIndex, Type::getInt32Ty(Ctx))
188209
VALUE_PROF_KIND(IPVK_IndirectCallTarget, 0, "indirect call target")
189210
/* For memory intrinsic functions size profiling. */
190211
VALUE_PROF_KIND(IPVK_MemOPSize, 1, "memory intrinsic functions size")
212+
/* For virtual table address profiling, the address point of the virtual table
213+
* (i.e., the address contained in objects pointing to a virtual table) are
214+
* profiled. Note this may not be the address of the per C++ class virtual table
215+
* object (e.g., there might be an offset).
216+
*
217+
* The profiled addresses are stored in raw profile, together with the following
218+
* two types of information.
219+
* 1. The (starting and ending) addresses of per C++ class virtual table objects.
220+
* 2. The (compressed) virtual table object names.
221+
* RawInstrProfReader converts profiled virtual table addresses to virtual table
222+
* objects' MD5 hash.
223+
*/
224+
VALUE_PROF_KIND(IPVK_VTableTarget, 2, "The profiled address point of the vtable")
191225
/* These two kinds must be the last to be
192226
* declared. This is to make sure the string
193227
* array created with the template can be
194228
* indexed with the kind value.
195229
*/
196230
VALUE_PROF_KIND(IPVK_First, IPVK_IndirectCallTarget, "first")
197-
VALUE_PROF_KIND(IPVK_Last, IPVK_MemOPSize, "last")
231+
VALUE_PROF_KIND(IPVK_Last, IPVK_VTableTarget, "last")
198232

199233
#undef VALUE_PROF_KIND
200234
/* VALUE_PROF_KIND end */
@@ -284,12 +318,18 @@ INSTR_PROF_SECT_ENTRY(IPSK_bitmap, \
284318
INSTR_PROF_SECT_ENTRY(IPSK_name, \
285319
INSTR_PROF_QUOTE(INSTR_PROF_NAME_COMMON), \
286320
INSTR_PROF_NAME_COFF, "__DATA,")
321+
INSTR_PROF_SECT_ENTRY(IPSK_vname, \
322+
INSTR_PROF_QUOTE(INSTR_PROF_VNAME_COMMON), \
323+
INSTR_PROF_VNAME_COFF, "__DATA,")
287324
INSTR_PROF_SECT_ENTRY(IPSK_vals, \
288325
INSTR_PROF_QUOTE(INSTR_PROF_VALS_COMMON), \
289326
INSTR_PROF_VALS_COFF, "__DATA,")
290327
INSTR_PROF_SECT_ENTRY(IPSK_vnodes, \
291328
INSTR_PROF_QUOTE(INSTR_PROF_VNODES_COMMON), \
292329
INSTR_PROF_VNODES_COFF, "__DATA,")
330+
INSTR_PROF_SECT_ENTRY(IPSK_vtab, \
331+
INSTR_PROF_QUOTE(INSTR_PROF_VTAB_COMMON), \
332+
INSTR_PROF_VTAB_COFF, "__DATA,")
293333
INSTR_PROF_SECT_ENTRY(IPSK_covmap, \
294334
INSTR_PROF_QUOTE(INSTR_PROF_COVMAP_COMMON), \
295335
INSTR_PROF_COVMAP_COFF, "__LLVM_COV,")
@@ -668,9 +708,9 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
668708
(uint64_t)'f' << 16 | (uint64_t)'R' << 8 | (uint64_t)129
669709

670710
/* Raw profile format version (start from 1). */
671-
#define INSTR_PROF_RAW_VERSION 9
711+
#define INSTR_PROF_RAW_VERSION 10
672712
/* Indexed profile format version (start from 1). */
673-
#define INSTR_PROF_INDEX_VERSION 11
713+
#define INSTR_PROF_INDEX_VERSION 12
674714
/* Coverage mapping format version (start from 0). */
675715
#define INSTR_PROF_COVMAP_VERSION 6
676716

@@ -708,10 +748,12 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
708748
than WIN32 */
709749
#define INSTR_PROF_DATA_COMMON __llvm_prf_data
710750
#define INSTR_PROF_NAME_COMMON __llvm_prf_names
751+
#define INSTR_PROF_VNAME_COMMON __llvm_prf_vns
711752
#define INSTR_PROF_CNTS_COMMON __llvm_prf_cnts
712753
#define INSTR_PROF_BITS_COMMON __llvm_prf_bits
713754
#define INSTR_PROF_VALS_COMMON __llvm_prf_vals
714755
#define INSTR_PROF_VNODES_COMMON __llvm_prf_vnds
756+
#define INSTR_PROF_VTAB_COMMON __llvm_prf_vtab
715757
#define INSTR_PROF_COVMAP_COMMON __llvm_covmap
716758
#define INSTR_PROF_COVFUN_COMMON __llvm_covfun
717759
#define INSTR_PROF_COVDATA_COMMON __llvm_covdata
@@ -722,10 +764,12 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
722764
*/
723765
#define INSTR_PROF_DATA_COFF ".lprfd$M"
724766
#define INSTR_PROF_NAME_COFF ".lprfn$M"
767+
#define INSTR_PROF_VNAME_COFF ".lprfvn$M"
725768
#define INSTR_PROF_CNTS_COFF ".lprfc$M"
726769
#define INSTR_PROF_BITS_COFF ".lprfb$M"
727770
#define INSTR_PROF_VALS_COFF ".lprfv$M"
728771
#define INSTR_PROF_VNODES_COFF ".lprfnd$M"
772+
#define INSTR_PROF_VTAB_COFF ".lprfvt$M"
729773
#define INSTR_PROF_COVMAP_COFF ".lcovmap$M"
730774
#define INSTR_PROF_COVFUN_COFF ".lcovfun$M"
731775
/* Since cov data and cov names sections are not allocated, we don't need to
@@ -741,6 +785,8 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
741785
#define INSTR_PROF_NAME_SECT_NAME INSTR_PROF_NAME_COFF
742786
#define INSTR_PROF_CNTS_SECT_NAME INSTR_PROF_CNTS_COFF
743787
#define INSTR_PROF_BITS_SECT_NAME INSTR_PROF_BITS_COFF
788+
#define INSTR_PROF_VTAB_SECT_NAME INSTR_PROF_VTAB_COFF
789+
#define INSTR_PROF_VNAME_SECT_NAME INSTR_PROF_VNAME_COFF
744790
/* Array of pointers. Each pointer points to a list
745791
* of value nodes associated with one value site.
746792
*/
@@ -758,6 +804,8 @@ serializeValueProfDataFrom(ValueProfRecordClosure *Closure,
758804
#define INSTR_PROF_NAME_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_NAME_COMMON)
759805
#define INSTR_PROF_CNTS_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_CNTS_COMMON)
760806
#define INSTR_PROF_BITS_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_BITS_COMMON)
807+
#define INSTR_PROF_VTAB_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_VTAB_COMMON)
808+
#define INSTR_PROF_VNAME_SECT_NAME INSTR_PROF_QUOTE(INSTR_PROF_VNAME_COMMON)
761809
/* Array of pointers. Each pointer points to a list
762810
* of value nodes associated with one value site.
763811
*/

compiler-rt/lib/profile/InstrProfiling.h

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ typedef struct ValueProfNode {
4949
#include "profile/InstrProfData.inc"
5050
} ValueProfNode;
5151

52+
typedef void *IntPtrT;
53+
typedef struct COMPILER_RT_ALIGNAS(INSTR_PROF_DATA_ALIGNMENT) VTableProfData {
54+
#define INSTR_PROF_VTABLE_DATA(Type, LLVMType, Name, Initializer) Type Name;
55+
#include "profile/InstrProfData.inc"
56+
} VTableProfData;
57+
5258
/*!
5359
* \brief Return 1 if profile counters are continuously synced to the raw
5460
* profile via an mmap(). This is in contrast to the default mode, in which
@@ -103,12 +109,16 @@ const __llvm_profile_data *__llvm_profile_begin_data(void);
103109
const __llvm_profile_data *__llvm_profile_end_data(void);
104110
const char *__llvm_profile_begin_names(void);
105111
const char *__llvm_profile_end_names(void);
112+
const char *__llvm_profile_begin_vtabnames(void);
113+
const char *__llvm_profile_end_vtabnames(void);
106114
char *__llvm_profile_begin_counters(void);
107115
char *__llvm_profile_end_counters(void);
108116
char *__llvm_profile_begin_bitmap(void);
109117
char *__llvm_profile_end_bitmap(void);
110118
ValueProfNode *__llvm_profile_begin_vnodes();
111119
ValueProfNode *__llvm_profile_end_vnodes();
120+
const VTableProfData *__llvm_profile_begin_vtables();
121+
const VTableProfData *__llvm_profile_end_vtables();
112122
uint32_t *__llvm_profile_begin_orderfile();
113123

114124
/*!
@@ -252,20 +262,31 @@ uint64_t __llvm_profile_get_num_bitmap_bytes(const char *Begin,
252262
/*! \brief Get the size of the profile name section in bytes. */
253263
uint64_t __llvm_profile_get_name_size(const char *Begin, const char *End);
254264

255-
/* ! \brief Given the sizes of the data and counter information, return the
256-
* number of padding bytes before and after the counters, and after the names,
257-
* in the raw profile.
265+
/*! \brief Get the number of virtual table profile data entries */
266+
uint64_t __llvm_profile_get_num_vtable(const VTableProfData *Begin,
267+
const VTableProfData *End);
268+
269+
/*! \brief Get the size of virtual table profile data in bytes. */
270+
uint64_t __llvm_profile_get_vtable_section_size(const VTableProfData *Begin,
271+
const VTableProfData *End);
272+
273+
/* ! \brief Given the sizes of the data and counter information, computes the
274+
* number of padding bytes before and after the counter section, as well as the
275+
* number of padding bytes after other setions in the raw profile.
276+
* Returns -1 upon errors and 0 upon success. Output parameters should be used
277+
* iff return value is 0.
258278
*
259279
* Note: When mmap() mode is disabled, no padding bytes before/after counters
260280
* are needed. However, in mmap() mode, the counter section in the raw profile
261281
* must be page-aligned: this API computes the number of padding bytes
262282
* needed to achieve that.
263283
*/
264-
void __llvm_profile_get_padding_sizes_for_counters(
284+
int __llvm_profile_get_padding_sizes_for_counters(
265285
uint64_t DataSize, uint64_t CountersSize, uint64_t NumBitmapBytes,
266-
uint64_t NamesSize, uint64_t *PaddingBytesBeforeCounters,
267-
uint64_t *PaddingBytesAfterCounters, uint64_t *PaddingBytesAfterBitmap,
268-
uint64_t *PaddingBytesAfterNames);
286+
uint64_t NamesSize, uint64_t VTableSize, uint64_t VNameSize,
287+
uint64_t *PaddingBytesBeforeCounters, uint64_t *PaddingBytesAfterCounters,
288+
uint64_t *PaddingBytesAfterBitmap, uint64_t *PaddingBytesAfterNames,
289+
uint64_t *PaddingBytesAfterVTable, uint64_t *PaddingBytesAfterVNames);
269290

270291
/*!
271292
* \brief Set the flag that profile data has been dumped to the file.

compiler-rt/lib/profile/InstrProfilingBuffer.c

Lines changed: 81 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,29 @@ uint64_t __llvm_profile_get_size_for_buffer(void) {
5151
const char *BitmapEnd = __llvm_profile_end_bitmap();
5252
const char *NamesBegin = __llvm_profile_begin_names();
5353
const char *NamesEnd = __llvm_profile_end_names();
54+
const VTableProfData *VTableBegin = __llvm_profile_begin_vtables();
55+
const VTableProfData *VTableEnd = __llvm_profile_end_vtables();
56+
const char *VNamesBegin = __llvm_profile_begin_vtabnames();
57+
const char *VNamesEnd = __llvm_profile_end_vtabnames();
5458

5559
return __llvm_profile_get_size_for_buffer_internal(
5660
DataBegin, DataEnd, CountersBegin, CountersEnd, BitmapBegin, BitmapEnd,
57-
NamesBegin, NamesEnd);
61+
NamesBegin, NamesEnd, VTableBegin, VTableEnd, VNamesBegin, VNamesEnd);
5862
}
5963

6064
COMPILER_RT_VISIBILITY
6165
uint64_t __llvm_profile_get_num_data(const __llvm_profile_data *Begin,
6266
const __llvm_profile_data *End) {
6367
intptr_t BeginI = (intptr_t)Begin, EndI = (intptr_t)End;
68+
// `sizeof(__llvm_profile_data) - 1` is required in the numerator when
69+
// [Begin, End] represents an inclusive range.
70+
// For ELF, [Begin, End) represents the address of linker-inserted
71+
// symbols `__start__<elf-section>` and `__stop_<elf-section>`.
72+
// Thereby, `End` is one byte past the inclusive range, and
73+
// `sizeof(__llvm_profile_data) - 1` is not necessary in the numerator to get
74+
// the correct number of profile data.
75+
// FIXME: Consider removing `sizeof(__llvm_profile_data) - 1` if this is true
76+
// across platforms.
6477
return ((EndI + sizeof(__llvm_profile_data) - 1) - BeginI) /
6578
sizeof(__llvm_profile_data);
6679
}
@@ -71,6 +84,26 @@ uint64_t __llvm_profile_get_data_size(const __llvm_profile_data *Begin,
7184
return __llvm_profile_get_num_data(Begin, End) * sizeof(__llvm_profile_data);
7285
}
7386

87+
// Counts the number of `VTableProfData` elements within the range of [Begin,
88+
// End). Caller should guarantee that End points to one byte past the inclusive
89+
// range.
90+
// FIXME: Add a compiler-rt test to make sure the number of vtables in the
91+
// raw profile is the same as the number of vtable elements in the instrumented
92+
// binary.
93+
COMPILER_RT_VISIBILITY
94+
uint64_t __llvm_profile_get_num_vtable(const VTableProfData *Begin,
95+
const VTableProfData *End) {
96+
// Convert pointers to intptr_t to use integer arithmetic.
97+
intptr_t EndI = (intptr_t)End, BeginI = (intptr_t)Begin;
98+
return (EndI - BeginI) / sizeof(VTableProfData);
99+
}
100+
101+
COMPILER_RT_VISIBILITY
102+
uint64_t __llvm_profile_get_vtable_section_size(const VTableProfData *Begin,
103+
const VTableProfData *End) {
104+
return (intptr_t)(End) - (intptr_t)(Begin);
105+
}
106+
74107
COMPILER_RT_VISIBILITY size_t __llvm_profile_counter_entry_size(void) {
75108
if (__llvm_profile_get_version() & VARIANT_MASK_BYTE_COVERAGE)
76109
return sizeof(uint8_t);
@@ -119,21 +152,33 @@ static int needsCounterPadding(void) {
119152
}
120153

121154
COMPILER_RT_VISIBILITY
122-
void __llvm_profile_get_padding_sizes_for_counters(
155+
int __llvm_profile_get_padding_sizes_for_counters(
123156
uint64_t DataSize, uint64_t CountersSize, uint64_t NumBitmapBytes,
124-
uint64_t NamesSize, uint64_t *PaddingBytesBeforeCounters,
125-
uint64_t *PaddingBytesAfterCounters, uint64_t *PaddingBytesAfterBitmapBytes,
126-
uint64_t *PaddingBytesAfterNames) {
157+
uint64_t NamesSize, uint64_t VTableSize, uint64_t VNameSize,
158+
uint64_t *PaddingBytesBeforeCounters, uint64_t *PaddingBytesAfterCounters,
159+
uint64_t *PaddingBytesAfterBitmapBytes, uint64_t *PaddingBytesAfterNames,
160+
uint64_t *PaddingBytesAfterVTable, uint64_t *PaddingBytesAfterVName) {
161+
// Counter padding is needed only if continuous mode is enabled.
127162
if (!needsCounterPadding()) {
128163
*PaddingBytesBeforeCounters = 0;
129164
*PaddingBytesAfterCounters =
130165
__llvm_profile_get_num_padding_bytes(CountersSize);
131166
*PaddingBytesAfterBitmapBytes =
132167
__llvm_profile_get_num_padding_bytes(NumBitmapBytes);
133168
*PaddingBytesAfterNames = __llvm_profile_get_num_padding_bytes(NamesSize);
134-
return;
169+
if (PaddingBytesAfterVTable != NULL)
170+
*PaddingBytesAfterVTable =
171+
__llvm_profile_get_num_padding_bytes(VTableSize);
172+
if (PaddingBytesAfterVName != NULL)
173+
*PaddingBytesAfterVName = __llvm_profile_get_num_padding_bytes(VNameSize);
174+
return 0;
135175
}
136176

177+
// Value profiling not supported in continuous mode at profile-write time.
178+
// Return -1 to alert the incompatibility.
179+
if (VTableSize != 0 || VNameSize != 0)
180+
return -1;
181+
137182
// In continuous mode, the file offsets for headers and for the start of
138183
// counter sections need to be page-aligned.
139184
*PaddingBytesBeforeCounters =
@@ -142,34 +187,52 @@ void __llvm_profile_get_padding_sizes_for_counters(
142187
*PaddingBytesAfterBitmapBytes =
143188
calculateBytesNeededToPageAlign(NumBitmapBytes);
144189
*PaddingBytesAfterNames = calculateBytesNeededToPageAlign(NamesSize);
190+
// Set these two variables to zero to avoid uninitialized variables
191+
// even if VTableSize and VNameSize are known to be zero.
192+
if (PaddingBytesAfterVTable != NULL)
193+
*PaddingBytesAfterVTable = 0;
194+
if (PaddingBytesAfterVName != NULL)
195+
*PaddingBytesAfterVName = 0;
196+
return 0;
145197
}
146198

147199
COMPILER_RT_VISIBILITY
148200
uint64_t __llvm_profile_get_size_for_buffer_internal(
149201
const __llvm_profile_data *DataBegin, const __llvm_profile_data *DataEnd,
150202
const char *CountersBegin, const char *CountersEnd, const char *BitmapBegin,
151-
const char *BitmapEnd, const char *NamesBegin, const char *NamesEnd) {
203+
const char *BitmapEnd, const char *NamesBegin, const char *NamesEnd,
204+
const VTableProfData *VTableBegin, const VTableProfData *VTableEnd,
205+
const char *VNamesBegin, const char *VNamesEnd) {
152206
/* Match logic in __llvm_profile_write_buffer(). */
153207
const uint64_t NamesSize = (NamesEnd - NamesBegin) * sizeof(char);
154208
uint64_t DataSize = __llvm_profile_get_data_size(DataBegin, DataEnd);
155209
uint64_t CountersSize =
156210
__llvm_profile_get_counters_size(CountersBegin, CountersEnd);
157211
const uint64_t NumBitmapBytes =
158212
__llvm_profile_get_num_bitmap_bytes(BitmapBegin, BitmapEnd);
213+
const uint64_t VTableSize =
214+
__llvm_profile_get_vtable_section_size(VTableBegin, VTableEnd);
215+
const uint64_t VNameSize =
216+
__llvm_profile_get_name_size(VNamesBegin, VNamesEnd);
159217

160218
/* Determine how much padding is needed before/after the counters and after
161219
* the names. */
162220
uint64_t PaddingBytesBeforeCounters, PaddingBytesAfterCounters,
163-
PaddingBytesAfterNames, PaddingBytesAfterBitmapBytes;
221+
PaddingBytesAfterNames, PaddingBytesAfterBitmapBytes,
222+
PaddingBytesAfterVTable, PaddingBytesAfterVNames;
164223
__llvm_profile_get_padding_sizes_for_counters(
165-
DataSize, CountersSize, NumBitmapBytes, NamesSize,
166-
&PaddingBytesBeforeCounters, &PaddingBytesAfterCounters,
167-
&PaddingBytesAfterBitmapBytes, &PaddingBytesAfterNames);
224+
DataSize, CountersSize, NumBitmapBytes, NamesSize, 0 /* VTableSize */,
225+
0 /* VNameSize */, &PaddingBytesBeforeCounters,
226+
&PaddingBytesAfterCounters, &PaddingBytesAfterBitmapBytes,
227+
&PaddingBytesAfterNames, &PaddingBytesAfterVTable,
228+
&PaddingBytesAfterVNames);
168229

169230
return sizeof(__llvm_profile_header) + __llvm_write_binary_ids(NULL) +
170231
DataSize + PaddingBytesBeforeCounters + CountersSize +
171232
PaddingBytesAfterCounters + NumBitmapBytes +
172-
PaddingBytesAfterBitmapBytes + NamesSize + PaddingBytesAfterNames;
233+
PaddingBytesAfterBitmapBytes + NamesSize + PaddingBytesAfterNames +
234+
VTableSize + PaddingBytesAfterVTable + VNameSize +
235+
PaddingBytesAfterVNames;
173236
}
174237

175238
COMPILER_RT_VISIBILITY
@@ -191,7 +254,10 @@ COMPILER_RT_VISIBILITY int __llvm_profile_write_buffer_internal(
191254
const char *NamesBegin, const char *NamesEnd) {
192255
ProfDataWriter BufferWriter;
193256
initBufferWriter(&BufferWriter, Buffer);
194-
return lprofWriteDataImpl(&BufferWriter, DataBegin, DataEnd, CountersBegin,
195-
CountersEnd, BitmapBegin, BitmapEnd, 0, NamesBegin,
196-
NamesEnd, 0);
257+
// Set virtual table arguments to NULL since they are not supported yet.
258+
return lprofWriteDataImpl(
259+
&BufferWriter, DataBegin, DataEnd, CountersBegin, CountersEnd,
260+
BitmapBegin, BitmapEnd, /*VPDataReader=*/0, NamesBegin, NamesEnd,
261+
/*VTableBegin=*/NULL, /*VTableEnd=*/NULL, /*VNamesBegin=*/NULL,
262+
/*VNamesEnd=*/NULL, /*SkipNameDataWrite=*/0);
197263
}

compiler-rt/lib/profile/InstrProfilingFile.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,18 @@ static int mmapForContinuousMode(uint64_t CurrentFileOffset, FILE *File) {
137137
DataBegin, PageSize);
138138
return 1;
139139
}
140+
140141
int Fileno = fileno(File);
141142
/* Determine how much padding is needed before/after the counters and
142143
* after the names. */
143144
uint64_t PaddingBytesBeforeCounters, PaddingBytesAfterCounters,
144-
PaddingBytesAfterNames, PaddingBytesAfterBitmapBytes;
145+
PaddingBytesAfterNames, PaddingBytesAfterBitmapBytes,
146+
PaddingBytesAfterVTable, PaddingBytesAfterVNames;
145147
__llvm_profile_get_padding_sizes_for_counters(
146-
DataSize, CountersSize, NumBitmapBytes, NamesSize,
147-
&PaddingBytesBeforeCounters, &PaddingBytesAfterCounters,
148-
&PaddingBytesAfterBitmapBytes, &PaddingBytesAfterNames);
148+
DataSize, CountersSize, NumBitmapBytes, NamesSize, /*VTableSize=*/0,
149+
/*VNameSize=*/0, &PaddingBytesBeforeCounters, &PaddingBytesAfterCounters,
150+
&PaddingBytesAfterBitmapBytes, &PaddingBytesAfterNames,
151+
&PaddingBytesAfterVTable, &PaddingBytesAfterVNames);
149152

150153
uint64_t PageAlignedCountersLength = CountersSize + PaddingBytesAfterCounters;
151154
uint64_t FileOffsetToCounters = CurrentFileOffset +

0 commit comments

Comments
 (0)