[compiler-rt] r261683 - [profile] Fix iteration over profile data entries

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 23 12:46:15 PST 2016


Author: vedantk
Date: Tue Feb 23 14:46:14 2016
New Revision: 261683

URL: http://llvm.org/viewvc/llvm-project?rev=261683&view=rev
Log:
[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.

Modified:
    compiler-rt/trunk/lib/profile/InstrProfiling.c
    compiler-rt/trunk/lib/profile/InstrProfilingValue.c

Modified: compiler-rt/trunk/lib/profile/InstrProfiling.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfiling.c?rev=261683&r1=261682&r2=261683&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfiling.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfiling.c Tue Feb 23 14:46:14 2016
@@ -46,7 +46,7 @@ COMPILER_RT_VISIBILITY void __llvm_profi
   const __llvm_profile_data *DataBegin = __llvm_profile_begin_data();
   const __llvm_profile_data *DataEnd = __llvm_profile_end_data();
   const __llvm_profile_data *DI;
-  for (DI = DataBegin; DI != DataEnd; ++DI) {
+  for (DI = DataBegin; DI < DataEnd; ++DI) {
     uint64_t CurrentVSiteCount = 0;
     uint32_t VKI, i;
     if (!DI->Values)

Modified: compiler-rt/trunk/lib/profile/InstrProfilingValue.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/profile/InstrProfilingValue.c?rev=261683&r1=261682&r2=261683&view=diff
==============================================================================
--- compiler-rt/trunk/lib/profile/InstrProfilingValue.c (original)
+++ compiler-rt/trunk/lib/profile/InstrProfilingValue.c Tue Feb 23 14:46:14 2016
@@ -151,7 +151,7 @@ __llvm_profile_gather_value_data(uint64_
    * Compute the total Size of the buffer to hold ValueProfData
    * structures for functions with value profile data.
    */
-  for (I = (__llvm_profile_data *)DataBegin; I != DataEnd; ++I) {
+  for (I = (__llvm_profile_data *)DataBegin; I < DataEnd; ++I) {
     ValueProfRuntimeRecord R;
     if (initializeValueProfRuntimeRecord(&R, I->NumValueSites, I->Values))
       PROF_OOM_RETURN("Failed to write value profile data ");




More information about the llvm-commits mailing list