@@ -47,13 +47,16 @@ uint64_t lprofGetLoadModuleSignature(void) {
47
47
COMPILER_RT_VISIBILITY
48
48
int __llvm_profile_check_compatibility (const char * ProfileData ,
49
49
uint64_t ProfileSize ) {
50
- /* Check profile header only for now */
51
50
__llvm_profile_header * Header = (__llvm_profile_header * )ProfileData ;
52
51
__llvm_profile_data * SrcDataStart , * SrcDataEnd , * SrcData , * DstData ;
52
+ char * SrcCountersStart , * SrcCountersEnd ;
53
53
SrcDataStart =
54
54
(__llvm_profile_data * )(ProfileData + sizeof (__llvm_profile_header ) +
55
55
Header -> BinaryIdsSize );
56
56
SrcDataEnd = SrcDataStart + Header -> DataSize ;
57
+ SrcCountersStart = (char * )SrcDataEnd ;
58
+ SrcCountersEnd = SrcCountersStart +
59
+ Header -> CountersSize * __llvm_profile_counter_entry_size ();
57
60
58
61
if (ProfileSize < sizeof (__llvm_profile_header ))
59
62
return 1 ;
@@ -72,6 +75,11 @@ int __llvm_profile_check_compatibility(const char *ProfileData,
72
75
Header -> ValueKindLast != IPVK_Last )
73
76
return 1 ;
74
77
78
+ if (SrcCountersEnd - SrcCountersStart !=
79
+ __llvm_profile_end_counters () - __llvm_profile_begin_counters ()) {
80
+ return 1 ;
81
+ }
82
+
75
83
if (ProfileSize <
76
84
sizeof (__llvm_profile_header ) + Header -> BinaryIdsSize +
77
85
Header -> DataSize * sizeof (__llvm_profile_data ) + Header -> NamesSize +
@@ -102,13 +110,6 @@ static uintptr_t signextIfWin64(void *V) {
102
110
COMPILER_RT_VISIBILITY
103
111
int __llvm_profile_merge_from_buffer (const char * ProfileData ,
104
112
uint64_t ProfileSize ) {
105
- if (__llvm_profile_get_version () & VARIANT_MASK_DBG_CORRELATE ) {
106
- PROF_ERR (
107
- "%s\n" ,
108
- "Debug info correlation does not support profile merging at runtime. "
109
- "Instead, merge raw profiles using the llvm-profdata tool." );
110
- return 1 ;
111
- }
112
113
if (__llvm_profile_get_version () & VARIANT_MASK_TEMPORAL_PROF ) {
113
114
PROF_ERR ("%s\n" ,
114
115
"Temporal profiles do not support profile merging at runtime. "
@@ -118,7 +119,8 @@ int __llvm_profile_merge_from_buffer(const char *ProfileData,
118
119
119
120
__llvm_profile_data * SrcDataStart , * SrcDataEnd , * SrcData , * DstData ;
120
121
__llvm_profile_header * Header = (__llvm_profile_header * )ProfileData ;
121
- char * SrcCountersStart ;
122
+ char * SrcCountersStart , * DstCounter ;
123
+ const char * SrcCountersEnd , * SrcCounter ;
122
124
const char * SrcNameStart ;
123
125
const char * SrcValueProfDataStart , * SrcValueProfData ;
124
126
uintptr_t CountersDelta = Header -> CountersDelta ;
@@ -128,14 +130,36 @@ int __llvm_profile_merge_from_buffer(const char *ProfileData,
128
130
Header -> BinaryIdsSize );
129
131
SrcDataEnd = SrcDataStart + Header -> DataSize ;
130
132
SrcCountersStart = (char * )SrcDataEnd ;
131
- SrcNameStart = SrcCountersStart +
132
- Header -> CountersSize * __llvm_profile_counter_entry_size ();
133
+ SrcCountersEnd = SrcCountersStart +
134
+ Header -> CountersSize * __llvm_profile_counter_entry_size ();
135
+ SrcNameStart = SrcCountersEnd ;
133
136
SrcValueProfDataStart =
134
137
SrcNameStart + Header -> NamesSize +
135
138
__llvm_profile_get_num_padding_bytes (Header -> NamesSize );
136
139
if (SrcNameStart < SrcCountersStart )
137
140
return 1 ;
138
141
142
+ // Merge counters when there is no data section and debug info correlation is
143
+ // enabled.
144
+ if (Header -> DataSize == 0 ) {
145
+ if (!(__llvm_profile_get_version () & VARIANT_MASK_DBG_CORRELATE )) {
146
+ PROF_ERR ("%s\n" , "Missing profile data section." );
147
+ return 1 ;
148
+ }
149
+ for (SrcCounter = SrcCountersStart ,
150
+ DstCounter = __llvm_profile_begin_counters ();
151
+ SrcCounter < SrcCountersEnd ;) {
152
+ if (__llvm_profile_get_version () & VARIANT_MASK_BYTE_COVERAGE ) {
153
+ * DstCounter &= * SrcCounter ;
154
+ } else {
155
+ * (uint64_t * )DstCounter += * (uint64_t * )SrcCounter ;
156
+ }
157
+ SrcCounter += __llvm_profile_counter_entry_size ();
158
+ DstCounter += __llvm_profile_counter_entry_size ();
159
+ }
160
+ return 0 ;
161
+ }
162
+
139
163
for (SrcData = SrcDataStart ,
140
164
DstData = (__llvm_profile_data * )__llvm_profile_begin_data (),
141
165
SrcValueProfData = SrcValueProfDataStart ;
0 commit comments