Skip to content

Commit 120f630

Browse files
committed
[profile] Fix iteration over profile data entries
Fix a crash when gathering value profile data on i386 Darwin. The Darwin linker shrinks sections containing aligned structures when padding is not explicitly added to the end of the structure. When iterating over these structures, be sure to not walk past the end of the section. No tests added, since running `ninja check-profile` on i386 Darwin is enough to reproduce the original crash. llvm-svn: 261683
1 parent d5b688c commit 120f630

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

compiler-rt/lib/profile/InstrProfiling.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ COMPILER_RT_VISIBILITY void __llvm_profile_reset_counters(void) {
4646
const __llvm_profile_data *DataBegin = __llvm_profile_begin_data();
4747
const __llvm_profile_data *DataEnd = __llvm_profile_end_data();
4848
const __llvm_profile_data *DI;
49-
for (DI = DataBegin; DI != DataEnd; ++DI) {
49+
for (DI = DataBegin; DI < DataEnd; ++DI) {
5050
uint64_t CurrentVSiteCount = 0;
5151
uint32_t VKI, i;
5252
if (!DI->Values)

compiler-rt/lib/profile/InstrProfilingValue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ __llvm_profile_gather_value_data(uint64_t *ValueDataSize) {
151151
* Compute the total Size of the buffer to hold ValueProfData
152152
* structures for functions with value profile data.
153153
*/
154-
for (I = (__llvm_profile_data *)DataBegin; I != DataEnd; ++I) {
154+
for (I = (__llvm_profile_data *)DataBegin; I < DataEnd; ++I) {
155155
ValueProfRuntimeRecord R;
156156
if (initializeValueProfRuntimeRecord(&R, I->NumValueSites, I->Values))
157157
PROF_OOM_RETURN("Failed to write value profile data ");

0 commit comments

Comments
 (0)