From 66e2772e4285588ccc3bcdb5f392c8326debbd7d Mon Sep 17 00:00:00 2001 From: Jinsong Ji Date: Wed, 18 Aug 2021 17:20:18 +0000 Subject: [PATCH] [InstrProfiling] Support relative CountersPtr for PlatformOther 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 | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformOther.c b/compiler-rt/lib/profile/InstrProfilingPlatformOther.c index 0e59148e2044..48946ce94253 100644 --- a/compiler-rt/lib/profile/InstrProfilingPlatformOther.c +++ b/compiler-rt/lib/profile/InstrProfilingPlatformOther.c @@ -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