diff --git a/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c b/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c --- a/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c +++ b/compiler-rt/lib/profile/InstrProfilingPlatformLinux.c @@ -51,6 +51,20 @@ extern ValueProfNode PROF_VNODES_START COMPILER_RT_VISIBILITY COMPILER_RT_WEAK; extern ValueProfNode PROF_VNODES_STOP COMPILER_RT_VISIBILITY COMPILER_RT_WEAK; +/* Add dummy data to ensure the section is always created. Add used attribute so + * that they are linker GC roots on supported ELF platforms. + */ +__llvm_profile_data __prof_data_sect_data[0] COMPILER_RT_SECTION( + INSTR_PROF_DATA_SECT_NAME) COMPILER_RT_RETAINED; +uint64_t __prof_cnts_sect_data[0] COMPILER_RT_SECTION(INSTR_PROF_CNTS_SECT_NAME) + COMPILER_RT_RETAINED; +uint32_t __prof_orderfile_sect_data[0] COMPILER_RT_SECTION( + INSTR_PROF_ORDERFILE_SECT_NAME) COMPILER_RT_RETAINED; +const char __prof_nms_sect_data[0] COMPILER_RT_SECTION( + INSTR_PROF_NAME_SECT_NAME) COMPILER_RT_RETAINED; +ValueProfNode __prof_vnodes_sect_data[0] COMPILER_RT_SECTION( + INSTR_PROF_VNODES_SECT_NAME) COMPILER_RT_RETAINED; + COMPILER_RT_VISIBILITY const __llvm_profile_data * __llvm_profile_begin_data(void) { return &PROF_DATA_START; diff --git a/compiler-rt/lib/profile/InstrProfilingPort.h b/compiler-rt/lib/profile/InstrProfilingPort.h --- a/compiler-rt/lib/profile/InstrProfilingPort.h +++ b/compiler-rt/lib/profile/InstrProfilingPort.h @@ -24,6 +24,7 @@ #define COMPILER_RT_ALWAYS_INLINE __forceinline #define COMPILER_RT_CLEANUP(x) #define COMPILER_RT_USED +#define COMPILER_RT_RETAINED #elif __GNUC__ #ifdef _WIN32 #define COMPILER_RT_FTRUNCATE(f, l) _chsize(fileno(f), l) @@ -39,6 +40,7 @@ #define COMPILER_RT_ALWAYS_INLINE inline __attribute((always_inline)) #define COMPILER_RT_CLEANUP(x) __attribute__((cleanup(x))) #define COMPILER_RT_USED __attribute__((used)) +#define COMPILER_RT_RETAINED __attribute__((retain)) #endif #if defined(__APPLE__)