[InstrProfiling] Support relative CountersPtr for PlatformOther
authorJinsong Ji <jji@us.ibm.com>
Wed, 18 Aug 2021 17:20:18 +0000 (17:20 +0000)
committerJinsong Ji <jji@us.ibm.com>
Wed, 18 Aug 2021 17:45:39 +0000 (17:45 +0000)
D104556 change the CountersPtr to be relative, however, it did not
update the pointer initialization in  __llvm_profile_register_function,
so the platform (eg:AIX) that use __llvm_profile_register_function is now totaly
broken, any PGO code will SEGV.

This patch update the code to reflect that the Data->CountersPtr is now
relative.

Reviewed By: MaskRay, davidxl

Differential Revision: https://reviews.llvm.org/D108304

compiler-rt/lib/profile/InstrProfilingPlatformOther.c

index 0e59148..48946ce 100644 (file)
@@ -46,17 +46,19 @@ void __llvm_profile_register_function(void *Data_) {
   if (!DataFirst) {
     DataFirst = Data;
     DataLast = Data + 1;
-    CountersFirst = Data->CounterPtr;
-    CountersLast = (uint64_t *)Data->CounterPtr + Data->NumCounters;
+    CountersFirst = (uint64_t *)((uintptr_t)Data_ + Data->CounterPtr);
+    CountersLast = CountersFirst + Data->NumCounters;
     return;
   }
 
   DataFirst = (const __llvm_profile_data *)getMinAddr(DataFirst, Data);
-  CountersFirst = (uint64_t *)getMinAddr(CountersFirst, Data->CounterPtr);
+  CountersFirst = (uint64_t *)getMinAddr(
+      CountersFirst, (uint64_t *)((uintptr_t)Data_ + Data->CounterPtr));
 
   DataLast = (const __llvm_profile_data *)getMaxAddr(DataLast, Data + 1);
   CountersLast = (uint64_t *)getMaxAddr(
-      CountersLast, (uint64_t *)Data->CounterPtr + Data->NumCounters);
+      CountersLast,
+      (uint64_t *)((uintptr_t)Data_ + Data->CounterPtr) + Data->NumCounters);
 }
 
 COMPILER_RT_VISIBILITY