@@ -51,12 +51,18 @@ uint64_t __llvm_profile_get_size_for_buffer(void) {
51
51
const char * BitmapEnd = __llvm_profile_end_bitmap ();
52
52
const char * NamesBegin = __llvm_profile_begin_names ();
53
53
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 ();
54
58
55
59
return __llvm_profile_get_size_for_buffer_internal (
56
60
DataBegin , DataEnd , CountersBegin , CountersEnd , BitmapBegin , BitmapEnd ,
57
- NamesBegin , NamesEnd );
61
+ NamesBegin , NamesEnd , VTableBegin , VTableEnd , VNamesBegin , VNamesEnd );
58
62
}
59
63
64
+ // NOTE: Caller should guarantee that `Begin` and `End` specifies a half-open
65
+ // interval [Begin, End). Namely, `End` is one-byte past the end of the array.
60
66
COMPILER_RT_VISIBILITY
61
67
uint64_t __llvm_profile_get_num_data (const __llvm_profile_data * Begin ,
62
68
const __llvm_profile_data * End ) {
@@ -71,6 +77,26 @@ uint64_t __llvm_profile_get_data_size(const __llvm_profile_data *Begin,
71
77
return __llvm_profile_get_num_data (Begin , End ) * sizeof (__llvm_profile_data );
72
78
}
73
79
80
+ // Counts the number of `VTableProfData` elements within the range of [Begin,
81
+ // End). Caller should guarantee that End points to one byte past the inclusive
82
+ // range.
83
+ // FIXME: Add a compiler-rt test to make sure the number of vtables in the
84
+ // raw profile is the same as the number of vtable elements in the instrumented
85
+ // binary.
86
+ COMPILER_RT_VISIBILITY
87
+ uint64_t __llvm_profile_get_num_vtable (const VTableProfData * Begin ,
88
+ const VTableProfData * End ) {
89
+ // Convert pointers to intptr_t to use integer arithmetic.
90
+ intptr_t EndI = (intptr_t )End , BeginI = (intptr_t )Begin ;
91
+ return (EndI - BeginI ) / sizeof (VTableProfData );
92
+ }
93
+
94
+ COMPILER_RT_VISIBILITY
95
+ uint64_t __llvm_profile_get_vtable_section_size (const VTableProfData * Begin ,
96
+ const VTableProfData * End ) {
97
+ return (intptr_t )(End ) - (intptr_t )(Begin );
98
+ }
99
+
74
100
COMPILER_RT_VISIBILITY size_t __llvm_profile_counter_entry_size (void ) {
75
101
if (__llvm_profile_get_version () & VARIANT_MASK_BYTE_COVERAGE )
76
102
return sizeof (uint8_t );
@@ -119,21 +145,33 @@ static int needsCounterPadding(void) {
119
145
}
120
146
121
147
COMPILER_RT_VISIBILITY
122
- void __llvm_profile_get_padding_sizes_for_counters (
148
+ int __llvm_profile_get_padding_sizes_for_counters (
123
149
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 ) {
150
+ uint64_t NamesSize , uint64_t VTableSize , uint64_t VNameSize ,
151
+ uint64_t * PaddingBytesBeforeCounters , uint64_t * PaddingBytesAfterCounters ,
152
+ uint64_t * PaddingBytesAfterBitmapBytes , uint64_t * PaddingBytesAfterNames ,
153
+ uint64_t * PaddingBytesAfterVTable , uint64_t * PaddingBytesAfterVName ) {
154
+ // Counter padding is needed only if continuous mode is enabled.
127
155
if (!needsCounterPadding ()) {
128
156
* PaddingBytesBeforeCounters = 0 ;
129
157
* PaddingBytesAfterCounters =
130
158
__llvm_profile_get_num_padding_bytes (CountersSize );
131
159
* PaddingBytesAfterBitmapBytes =
132
160
__llvm_profile_get_num_padding_bytes (NumBitmapBytes );
133
161
* PaddingBytesAfterNames = __llvm_profile_get_num_padding_bytes (NamesSize );
134
- return ;
162
+ if (PaddingBytesAfterVTable != NULL )
163
+ * PaddingBytesAfterVTable =
164
+ __llvm_profile_get_num_padding_bytes (VTableSize );
165
+ if (PaddingBytesAfterVName != NULL )
166
+ * PaddingBytesAfterVName = __llvm_profile_get_num_padding_bytes (VNameSize );
167
+ return 0 ;
135
168
}
136
169
170
+ // Value profiling not supported in continuous mode at profile-write time.
171
+ // Return -1 to alert the incompatibility.
172
+ if (VTableSize != 0 || VNameSize != 0 )
173
+ return -1 ;
174
+
137
175
// In continuous mode, the file offsets for headers and for the start of
138
176
// counter sections need to be page-aligned.
139
177
* PaddingBytesBeforeCounters =
@@ -142,34 +180,52 @@ void __llvm_profile_get_padding_sizes_for_counters(
142
180
* PaddingBytesAfterBitmapBytes =
143
181
calculateBytesNeededToPageAlign (NumBitmapBytes );
144
182
* PaddingBytesAfterNames = calculateBytesNeededToPageAlign (NamesSize );
183
+ // Set these two variables to zero to avoid uninitialized variables
184
+ // even if VTableSize and VNameSize are known to be zero.
185
+ if (PaddingBytesAfterVTable != NULL )
186
+ * PaddingBytesAfterVTable = 0 ;
187
+ if (PaddingBytesAfterVName != NULL )
188
+ * PaddingBytesAfterVName = 0 ;
189
+ return 0 ;
145
190
}
146
191
147
192
COMPILER_RT_VISIBILITY
148
193
uint64_t __llvm_profile_get_size_for_buffer_internal (
149
194
const __llvm_profile_data * DataBegin , const __llvm_profile_data * DataEnd ,
150
195
const char * CountersBegin , const char * CountersEnd , const char * BitmapBegin ,
151
- const char * BitmapEnd , const char * NamesBegin , const char * NamesEnd ) {
196
+ const char * BitmapEnd , const char * NamesBegin , const char * NamesEnd ,
197
+ const VTableProfData * VTableBegin , const VTableProfData * VTableEnd ,
198
+ const char * VNamesBegin , const char * VNamesEnd ) {
152
199
/* Match logic in __llvm_profile_write_buffer(). */
153
200
const uint64_t NamesSize = (NamesEnd - NamesBegin ) * sizeof (char );
154
201
uint64_t DataSize = __llvm_profile_get_data_size (DataBegin , DataEnd );
155
202
uint64_t CountersSize =
156
203
__llvm_profile_get_counters_size (CountersBegin , CountersEnd );
157
204
const uint64_t NumBitmapBytes =
158
205
__llvm_profile_get_num_bitmap_bytes (BitmapBegin , BitmapEnd );
206
+ const uint64_t VTableSize =
207
+ __llvm_profile_get_vtable_section_size (VTableBegin , VTableEnd );
208
+ const uint64_t VNameSize =
209
+ __llvm_profile_get_name_size (VNamesBegin , VNamesEnd );
159
210
160
211
/* Determine how much padding is needed before/after the counters and after
161
212
* the names. */
162
213
uint64_t PaddingBytesBeforeCounters , PaddingBytesAfterCounters ,
163
- PaddingBytesAfterNames , PaddingBytesAfterBitmapBytes ;
214
+ PaddingBytesAfterNames , PaddingBytesAfterBitmapBytes ,
215
+ PaddingBytesAfterVTable , PaddingBytesAfterVNames ;
164
216
__llvm_profile_get_padding_sizes_for_counters (
165
- DataSize , CountersSize , NumBitmapBytes , NamesSize ,
166
- & PaddingBytesBeforeCounters , & PaddingBytesAfterCounters ,
167
- & PaddingBytesAfterBitmapBytes , & PaddingBytesAfterNames );
217
+ DataSize , CountersSize , NumBitmapBytes , NamesSize , 0 /* VTableSize */ ,
218
+ 0 /* VNameSize */ , & PaddingBytesBeforeCounters ,
219
+ & PaddingBytesAfterCounters , & PaddingBytesAfterBitmapBytes ,
220
+ & PaddingBytesAfterNames , & PaddingBytesAfterVTable ,
221
+ & PaddingBytesAfterVNames );
168
222
169
223
return sizeof (__llvm_profile_header ) + __llvm_write_binary_ids (NULL ) +
170
224
DataSize + PaddingBytesBeforeCounters + CountersSize +
171
225
PaddingBytesAfterCounters + NumBitmapBytes +
172
- PaddingBytesAfterBitmapBytes + NamesSize + PaddingBytesAfterNames ;
226
+ PaddingBytesAfterBitmapBytes + NamesSize + PaddingBytesAfterNames +
227
+ VTableSize + PaddingBytesAfterVTable + VNameSize +
228
+ PaddingBytesAfterVNames ;
173
229
}
174
230
175
231
COMPILER_RT_VISIBILITY
@@ -191,7 +247,10 @@ COMPILER_RT_VISIBILITY int __llvm_profile_write_buffer_internal(
191
247
const char * NamesBegin , const char * NamesEnd ) {
192
248
ProfDataWriter BufferWriter ;
193
249
initBufferWriter (& BufferWriter , Buffer );
194
- return lprofWriteDataImpl (& BufferWriter , DataBegin , DataEnd , CountersBegin ,
195
- CountersEnd , BitmapBegin , BitmapEnd , 0 , NamesBegin ,
196
- NamesEnd , 0 );
250
+ // Set virtual table arguments to NULL since they are not supported yet.
251
+ return lprofWriteDataImpl (
252
+ & BufferWriter , DataBegin , DataEnd , CountersBegin , CountersEnd ,
253
+ BitmapBegin , BitmapEnd , /*VPDataReader=*/ 0 , NamesBegin , NamesEnd ,
254
+ /*VTableBegin=*/ NULL , /*VTableEnd=*/ NULL , /*VNamesBegin=*/ NULL ,
255
+ /*VNamesEnd=*/ NULL , /*SkipNameDataWrite=*/ 0 );
197
256
}
0 commit comments