Index: compiler-rt/include/profile/InstrProfData.inc =================================================================== --- compiler-rt/include/profile/InstrProfData.inc +++ compiler-rt/include/profile/InstrProfData.inc @@ -327,7 +327,7 @@ InstrProfValueData ValueData[]; */ -#ifdef __cplusplus +#if defined(__cplusplus) && !defined(COMPILER_RT) /*! * Return the number of value sites. */ @@ -374,7 +374,7 @@ * ValueProfRecord Record_N; */ -#if __cplusplus +#if __cplusplus && !defined(COMPILER_RT) /*! * Return the total size in bytes of the on-disk value profile data * given the data stored in Record. Index: compiler-rt/lib/profile/CMakeLists.txt =================================================================== --- compiler-rt/lib/profile/CMakeLists.txt +++ compiler-rt/lib/profile/CMakeLists.txt @@ -49,24 +49,24 @@ add_compiler_rt_component(profile) set(PROFILE_SOURCES - GCDAProfiling.c - InstrProfiling.c - InstrProfilingInternal.c - InstrProfilingValue.c - InstrProfilingBuffer.c - InstrProfilingFile.c - InstrProfilingMerge.c - InstrProfilingMergeFile.c - InstrProfilingNameVar.c - InstrProfilingVersionVar.c - InstrProfilingWriter.c - InstrProfilingPlatformDarwin.c - InstrProfilingPlatformFuchsia.c - InstrProfilingPlatformLinux.c - InstrProfilingPlatformOther.c - InstrProfilingPlatformWindows.c + GCDAProfiling.cpp + InstrProfiling.cpp + InstrProfilingInternal.cpp + InstrProfilingValue.cpp + InstrProfilingBuffer.cpp + InstrProfilingFile.cpp + InstrProfilingMerge.cpp + InstrProfilingMergeFile.cpp + InstrProfilingNameVar.cpp + InstrProfilingVersionVar.cpp + InstrProfilingWriter.cpp + InstrProfilingPlatformDarwin.cpp + InstrProfilingPlatformFuchsia.cpp + InstrProfilingPlatformLinux.cpp + InstrProfilingPlatformOther.cpp + InstrProfilingPlatformWindows.cpp InstrProfilingRuntime.cpp - InstrProfilingUtil.c + InstrProfilingUtil.cpp ) set(PROFILE_HEADERS @@ -110,6 +110,8 @@ -DCOMPILER_RT_HAS_UNAME=1) endif() +set(EXTRA_FLAGS ${EXTRA_FLAGS} -DCOMPILER_RT=1) + # We don't use the C++ Standard Library here, so avoid including it by mistake. append_list_if(COMPILER_RT_HAS_NOSTDINCXX_FLAG -nostdinc++ EXTRA_FLAGS) # XRay uses C++ standard library headers. Index: compiler-rt/lib/profile/GCDAProfiling.cpp =================================================================== --- compiler-rt/lib/profile/GCDAProfiling.cpp +++ compiler-rt/lib/profile/GCDAProfiling.cpp @@ -42,6 +42,8 @@ #include "InstrProfiling.h" #include "InstrProfilingUtil.h" +extern "C" { + /* #define DEBUG_GCDAPROFILING */ enum { @@ -111,7 +113,7 @@ struct fn_list reset_fn_list; static void fn_list_insert(struct fn_list* list, fn_ptr fn) { - struct fn_node* new_node = malloc(sizeof(struct fn_node)); + struct fn_node* new_node = static_cast(malloc(sizeof(struct fn_node))); new_node->fn = fn; new_node->next = NULL; new_node->id = CURRENT_ID; @@ -160,7 +162,7 @@ if (size <= cur_buffer_size) return; size = (size - 1) / WRITE_BUFFER_SIZE + 1; size *= WRITE_BUFFER_SIZE; - write_buffer = realloc(write_buffer, size); + write_buffer = static_cast(realloc(write_buffer, size)); cur_buffer_size = size; } @@ -211,7 +213,7 @@ if (prefix == NULL) return strdup(orig_filename); - new_filename = malloc(prefix_len + 1 + strlen(orig_filename) + 1); + new_filename = static_cast(malloc(prefix_len + 1 + strlen(orig_filename) + 1)); lprofApplyPathPrefix(new_filename, orig_filename, prefix, prefix_len, prefix_strip); @@ -249,8 +251,8 @@ return -1; } #else - write_buffer = mmap(0, file_size, PROT_READ | PROT_WRITE, - MAP_FILE | MAP_SHARED, fd, 0); + write_buffer = static_cast(mmap(0, file_size, PROT_READ | PROT_WRITE, + MAP_FILE | MAP_SHARED, fd, 0)); if (write_buffer == (void *)-1) { int errnum = errno; fprintf(stderr, "profiling: %s: cannot map: %s\n", filename, @@ -424,7 +426,7 @@ return; } - old_ctrs = malloc(sizeof(uint64_t) * num_counters); + old_ctrs = static_cast(malloc(sizeof(uint64_t) * num_counters)); for (i = 0; i < num_counters; ++i) old_ctrs[i] = read_64bit_value(); } @@ -639,4 +641,6 @@ f->fn(); } +} // extern "C" + #endif Index: compiler-rt/lib/profile/InstrProfiling.h =================================================================== --- compiler-rt/lib/profile/InstrProfiling.h +++ compiler-rt/lib/profile/InstrProfiling.h @@ -12,6 +12,10 @@ #include "InstrProfilingPort.h" #include +#ifdef __cplusplus +extern "C" { +#endif + #define INSTR_PROF_VISIBILITY COMPILER_RT_VISIBILITY #include "profile/InstrProfData.inc" @@ -32,7 +36,7 @@ #include "profile/InstrProfData.inc" } __llvm_profile_header; -typedef struct ValueProfNode * PtrToNodeT; +typedef struct ValueProfNode *PtrToNodeT; typedef struct ValueProfNode { #define INSTR_PROF_VALUE_NODE(Type, LLVMType, Name, Initializer) Type Name; #include "profile/InstrProfData.inc" @@ -116,8 +120,7 @@ * structurally the in-process counters. If the profile data in buffer is * not compatible, the interface returns 1 (failure). */ -int __llvm_profile_check_compatibility(const char *Profile, - uint64_t Size); +int __llvm_profile_check_compatibility(const char *Profile, uint64_t Size); /*! * \brief Counts the number of times a target value is seen. @@ -130,7 +133,7 @@ void INSTR_PROF_VALUE_PROF_FUNC( #define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType) ArgType ArgName #include "profile/InstrProfData.inc" - ); +); void __llvm_profile_instrument_target_value(uint64_t TargetValue, void *Data, uint32_t CounterIndex, @@ -307,7 +310,7 @@ * definition of this variable in an instrumented shared library won't * affect runtime initialization decision of the main program. * __llvm_profile_profile_runtime. */ -COMPILER_RT_VISIBILITY extern int INSTR_PROF_PROFILE_RUNTIME_VAR; +__attribute__((visibility("hidden"))) extern int INSTR_PROF_PROFILE_RUNTIME_VAR; /*! * This variable is defined in InstrProfilingVersionVar.c as a hidden symbol @@ -326,4 +329,8 @@ */ extern char INSTR_PROF_PROFILE_NAME_VAR[1]; /* __llvm_profile_filename. */ +#ifdef __cplusplus +} // extern "C" +#endif + #endif /* PROFILE_INSTRPROFILING_H_ */ Index: compiler-rt/lib/profile/InstrProfiling.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfiling.cpp +++ compiler-rt/lib/profile/InstrProfiling.cpp @@ -20,6 +20,8 @@ #define INSTR_PROF_VALUE_PROF_DATA #include "profile/InstrProfData.inc" +extern "C" { + COMPILER_RT_VISIBILITY uint64_t __llvm_profile_get_magic(void) { return sizeof(void *) == sizeof(uint64_t) ? (INSTR_PROF_RAW_MAGIC_64) : (INSTR_PROF_RAW_MAGIC_32); @@ -72,3 +74,5 @@ } lprofSetProfileDumped(0); } + +} // extern "C" Index: compiler-rt/lib/profile/InstrProfilingBuffer.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfilingBuffer.cpp +++ compiler-rt/lib/profile/InstrProfilingBuffer.cpp @@ -13,6 +13,8 @@ #include "InstrProfilingInternal.h" #include "InstrProfilingPort.h" +extern "C" { + /* When continuous mode is enabled (%c), this parameter is set to 1. * * This parameter is defined here in InstrProfilingBuffer.o, instead of in @@ -163,3 +165,5 @@ return lprofWriteDataImpl(&BufferWriter, DataBegin, DataEnd, CountersBegin, CountersEnd, 0, NamesBegin, NamesEnd, 0); } + +} // extern "C" Index: compiler-rt/lib/profile/InstrProfilingFile.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfilingFile.cpp +++ compiler-rt/lib/profile/InstrProfilingFile.cpp @@ -36,6 +36,8 @@ #include "InstrProfilingPort.h" #include "InstrProfilingUtil.h" +extern "C" { + /* From where is profile name specified. * The order the enumerators define their * precedence. Re-order them may lead to @@ -297,7 +299,7 @@ VPBufferSize = BufferSz; ProfDataWriter *fileWriter = (ProfDataWriter *)calloc(sizeof(ProfDataWriter), 1); - initFileWriter(fileWriter, File); + initFileWriter(fileWriter, static_cast(File)); ProfBufferIO *IO = lprofCreateBufferIO(fileWriter); IO->OwnFileWriter = 1; return IO; @@ -348,8 +350,8 @@ * responsible for unmapping the mmap'd buffer in \p ProfileBuffer. */ static int mmapProfileForMerging(FILE *ProfileFile, uint64_t ProfileFileSize, char **ProfileBuffer) { - *ProfileBuffer = mmap(NULL, ProfileFileSize, PROT_READ, MAP_SHARED | MAP_FILE, - fileno(ProfileFile), 0); + *ProfileBuffer = static_cast(mmap(NULL, ProfileFileSize, PROT_READ, + MAP_SHARED | MAP_FILE, fileno(ProfileFile), 0)); if (*ProfileBuffer == MAP_FAILED) { PROF_ERR("Unable to merge profile data, mmap failed: %s\n", strerror(errno)); @@ -655,7 +657,7 @@ static const char *DefaultProfileName = "default.profraw"; static void resetFilenameToDefault(void) { if (lprofCurFilename.FilenamePat && lprofCurFilename.OwnsFilenamePat) { - free((void *)lprofCurFilename.FilenamePat); + free(const_cast(lprofCurFilename.FilenamePat)); } memset(&lprofCurFilename, 0, sizeof(lprofCurFilename)); lprofCurFilename.FilenamePat = DefaultProfileName; @@ -699,10 +701,10 @@ /* Clean up cached prefix and filename. */ if (lprofCurFilename.ProfilePathPrefix) - free((void *)lprofCurFilename.ProfilePathPrefix); + free(const_cast(lprofCurFilename.ProfilePathPrefix)); if (lprofCurFilename.FilenamePat && lprofCurFilename.OwnsFilenamePat) { - free((void *)lprofCurFilename.FilenamePat); + free(const_cast(lprofCurFilename.FilenamePat)); } memset(&lprofCurFilename, 0, sizeof(lprofCurFilename)); @@ -1191,4 +1193,6 @@ return 0; } +} + #endif Index: compiler-rt/lib/profile/InstrProfilingInternal.h =================================================================== --- compiler-rt/lib/profile/InstrProfilingInternal.h +++ compiler-rt/lib/profile/InstrProfilingInternal.h @@ -13,6 +13,10 @@ #include "InstrProfiling.h" +#ifdef __cplusplus +extern "C" { +#endif + /*! * \brief Write instrumentation data to the given buffer, given explicit * pointers to the live data in memory. This function is probably not what you @@ -125,14 +129,14 @@ uint8_t *SiteCountArray[]); /* Function pointer to getValueProfRecordHeader method. */ uint32_t (*GetValueProfRecordHeaderSize)(uint32_t NumSites); - /* Function pointer to getFristValueProfRecord method. */ + /* Function pointer to getFristValueProfRecord method. */ struct ValueProfRecord *(*GetFirstValueProfRecord)(struct ValueProfData *); /* Return the number of value data for site \p Site. */ uint32_t (*GetNumValueDataForSite)(uint32_t VK, uint32_t Site); - /* Return the total size of the value profile data of the + /* Return the total size of the value profile data of the * current function. */ uint32_t (*GetValueProfDataSize)(void); - /*! + /*! * Read the next \p N value data for site \p Site and store the data * in \p Dst. \p StartNode is the first value node to start with if * it is not null. The function returns the pointer to the value @@ -163,7 +167,7 @@ VPDataReaderType *lprofGetVPDataReader(); -/* Internal interface used by test to reset the max number of +/* Internal interface used by test to reset the max number of * tracked values per value site to be \p MaxVals. */ void lprofSetMaxValsPerSite(uint32_t MaxVals); @@ -176,7 +180,7 @@ * to dump merged profile data into its own profile file. */ uint64_t lprofGetLoadModuleSignature(); -/* +/* * Return non zero value if the profile data has already been * dumped to the file. */ @@ -198,4 +202,8 @@ */ int __llvm_write_binary_ids(ProfDataWriter *Writer); +#ifdef __cplusplus +} // extern "C" +#endif + #endif Index: compiler-rt/lib/profile/InstrProfilingInternal.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfilingInternal.cpp +++ compiler-rt/lib/profile/InstrProfilingInternal.cpp @@ -13,6 +13,8 @@ #include "InstrProfilingInternal.h" +extern "C" { + static unsigned ProfileDumped = 0; COMPILER_RT_VISIBILITY unsigned lprofProfileDumped() { @@ -23,4 +25,6 @@ ProfileDumped = Value; } +} // extern "C" + #endif Index: compiler-rt/lib/profile/InstrProfilingMerge.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfilingMerge.cpp +++ compiler-rt/lib/profile/InstrProfilingMerge.cpp @@ -16,6 +16,8 @@ #define INSTR_PROF_VALUE_PROF_DATA #include "profile/InstrProfData.inc" +extern "C" { + COMPILER_RT_VISIBILITY void (*VPMergeHook)(ValueProfData *, __llvm_profile_data *); @@ -43,10 +45,10 @@ int __llvm_profile_check_compatibility(const char *ProfileData, uint64_t ProfileSize) { /* Check profile header only for now */ - __llvm_profile_header *Header = (__llvm_profile_header *)ProfileData; - __llvm_profile_data *SrcDataStart, *SrcDataEnd, *SrcData, *DstData; + const __llvm_profile_header *Header = (const __llvm_profile_header *)ProfileData; + const __llvm_profile_data *SrcDataStart, *SrcDataEnd, *SrcData, *DstData; SrcDataStart = - (__llvm_profile_data *)(ProfileData + sizeof(__llvm_profile_header) + + (const __llvm_profile_data *)(ProfileData + sizeof(__llvm_profile_header) + Header->BinaryIdsSize); SrcDataEnd = SrcDataStart + Header->DataSize; @@ -74,7 +76,7 @@ return 1; for (SrcData = SrcDataStart, - DstData = (__llvm_profile_data *)__llvm_profile_begin_data(); + DstData = (const __llvm_profile_data *)__llvm_profile_begin_data(); SrcData < SrcDataEnd; ++SrcData, ++DstData) { if (SrcData->NameRef != DstData->NameRef || SrcData->FuncHash != DstData->FuncHash || @@ -105,18 +107,18 @@ return 1; } - __llvm_profile_data *SrcDataStart, *SrcDataEnd, *SrcData, *DstData; - __llvm_profile_header *Header = (__llvm_profile_header *)ProfileData; - char *SrcCountersStart; - const char *SrcNameStart; - const char *SrcValueProfDataStart, *SrcValueProfData; + const __llvm_profile_data *SrcDataStart, *SrcDataEnd, *SrcData, *DstData; + const __llvm_profile_header *Header = (const __llvm_profile_header *)ProfileData; + uintptr_t SrcCountersStart; + uintptr_t SrcNameStart; + uintptr_t SrcValueProfDataStart, SrcValueProfData; uintptr_t CountersDelta = Header->CountersDelta; SrcDataStart = - (__llvm_profile_data *)(ProfileData + sizeof(__llvm_profile_header) + + (const __llvm_profile_data *)(ProfileData + sizeof(__llvm_profile_header) + Header->BinaryIdsSize); SrcDataEnd = SrcDataStart + Header->DataSize; - SrcCountersStart = (char *)SrcDataEnd; + SrcCountersStart = (uintptr_t)SrcDataEnd; SrcNameStart = SrcCountersStart + Header->CountersSize * __llvm_profile_counter_entry_size(); SrcValueProfDataStart = @@ -126,7 +128,7 @@ return 1; for (SrcData = SrcDataStart, - DstData = (__llvm_profile_data *)__llvm_profile_begin_data(), + DstData = (const __llvm_profile_data *)__llvm_profile_begin_data(), SrcValueProfData = SrcValueProfDataStart; SrcData < SrcDataEnd; ++SrcData, ++DstData) { // For the in-memory destination, CounterPtr is the distance from the start @@ -144,7 +146,7 @@ // CountersDelta computes the offset into the in-buffer counter section. // // On WIN64, CountersDelta is truncated as well, so no need for signext. - char *SrcCounters = + uintptr_t SrcCounters = SrcCountersStart + ((uintptr_t)SrcData->CounterPtr - CountersDelta); // CountersDelta needs to be decreased as we advance to the next data // record. @@ -168,12 +170,14 @@ if (!NVK) continue; - if (SrcValueProfData >= ProfileData + ProfileSize) + if (SrcValueProfData >= (uintptr_t)ProfileData + ProfileSize) return 1; - VPMergeHook((ValueProfData *)SrcValueProfData, DstData); + VPMergeHook((ValueProfData *)SrcValueProfData, const_cast<__llvm_profile_data *>(DstData)); SrcValueProfData = SrcValueProfData + ((ValueProfData *)SrcValueProfData)->TotalSize; } return 0; } + +} // extern "C" Index: compiler-rt/lib/profile/InstrProfilingMergeFile.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfilingMergeFile.cpp +++ compiler-rt/lib/profile/InstrProfilingMergeFile.cpp @@ -18,6 +18,8 @@ #define INSTR_PROF_VALUE_PROF_DATA #include "profile/InstrProfData.inc" +extern "C" { + /* Merge value profile data pointed to by SrcValueProfData into * in-memory profile counters pointed by to DstData. */ COMPILER_RT_VISIBILITY @@ -42,4 +44,6 @@ } } +} // extern "C" + #endif Index: compiler-rt/lib/profile/InstrProfilingNameVar.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfilingNameVar.cpp +++ compiler-rt/lib/profile/InstrProfilingNameVar.cpp @@ -8,6 +8,8 @@ #include "InstrProfiling.h" +extern "C" { + /* char __llvm_profile_filename[1] * * The runtime should only provide its own definition of this symbol when the @@ -15,3 +17,5 @@ * symbol to an object file within the archive. */ COMPILER_RT_WEAK char INSTR_PROF_PROFILE_NAME_VAR[1] = {0}; + +} // extern "C" Index: compiler-rt/lib/profile/InstrProfilingPlatformDarwin.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfilingPlatformDarwin.cpp +++ compiler-rt/lib/profile/InstrProfilingPlatformDarwin.cpp @@ -12,6 +12,8 @@ #include "InstrProfiling.h" #include "InstrProfilingInternal.h" +extern "C" { + #if defined(__APPLE__) /* Use linker magic to find the bounds of the Data section. */ COMPILER_RT_VISIBILITY @@ -73,3 +75,5 @@ } #endif + +} // extern "C" Index: compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.cpp +++ compiler-rt/lib/profile/InstrProfilingPlatformFuchsia.cpp @@ -34,6 +34,8 @@ #include "InstrProfilingInternal.h" #include "InstrProfilingUtil.h" +extern "C" { + /* This variable is an external reference to symbol defined by the compiler. */ COMPILER_RT_VISIBILITY extern intptr_t INSTR_PROF_PROFILE_COUNTER_BIAS_VAR; @@ -187,4 +189,6 @@ lprofReleaseMemoryPagesToOS((uintptr_t)CountersBegin, (uintptr_t)CountersEnd); } +} // extern "C" + #endif Index: compiler-rt/lib/profile/InstrProfilingPlatformLinux.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfilingPlatformLinux.cpp +++ compiler-rt/lib/profile/InstrProfilingPlatformLinux.cpp @@ -17,6 +17,8 @@ #include "InstrProfiling.h" #include "InstrProfilingInternal.h" +extern "C" { + #if defined(__FreeBSD__) && !defined(ElfW) /* * FreeBSD's elf.h and link.h headers do not define the ElfW(type) macro yet. @@ -99,8 +101,8 @@ uint64_t BinaryIdPadding) { ProfDataIOVec BinaryIdIOVec[] = { {&BinaryIdLen, sizeof(uint64_t), 1, 0}, - {BinaryIdData, sizeof(uint8_t), BinaryIdLen, 0}, - {NULL, sizeof(uint8_t), BinaryIdPadding, 1}, + {BinaryIdData, sizeof(uint8_t), static_cast(BinaryIdLen), 0}, + {NULL, sizeof(uint8_t), static_cast(BinaryIdPadding), 1}, }; if (Writer->Write(Writer, BinaryIdIOVec, sizeof(BinaryIdIOVec) / sizeof(*BinaryIdIOVec))) @@ -227,4 +229,6 @@ } #endif +} // extern "C" + #endif Index: compiler-rt/lib/profile/InstrProfilingPlatformOther.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfilingPlatformOther.cpp +++ compiler-rt/lib/profile/InstrProfilingPlatformOther.cpp @@ -16,6 +16,8 @@ #include "InstrProfiling.h" #include "InstrProfilingInternal.h" +extern "C" { + static const __llvm_profile_data *DataFirst = NULL; static const __llvm_profile_data *DataLast = NULL; static const char *NamesFirst = NULL; @@ -106,4 +108,6 @@ return 0; } +} // extern "C" + #endif Index: compiler-rt/lib/profile/InstrProfilingPlatformWindows.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfilingPlatformWindows.cpp +++ compiler-rt/lib/profile/InstrProfilingPlatformWindows.cpp @@ -11,6 +11,8 @@ #if defined(_WIN32) +extern "C" { + #if defined(_MSC_VER) /* Merge read-write sections into .data. */ #pragma comment(linker, "/MERGE:.lprfc=.data") @@ -70,4 +72,6 @@ return 0; } +} // extern "C" + #endif Index: compiler-rt/lib/profile/InstrProfilingUtil.h =================================================================== --- compiler-rt/lib/profile/InstrProfilingUtil.h +++ compiler-rt/lib/profile/InstrProfilingUtil.h @@ -13,6 +13,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /*! \brief Create a directory tree. */ void __llvm_profile_recursive_mkdir(char *Pathname); @@ -35,8 +39,9 @@ #if __ORBIS__ #include static inline char *getenv(const char *name) { return NULL; } -static inline int setenv(const char *name, const char *value, int overwrite) -{ return 0; } +static inline int setenv(const char *name, const char *value, int overwrite) { + return 0; +} static pid_t fork() { return -1; } #endif /* #if __ORBIS__ */ @@ -84,4 +89,8 @@ int lprofReleaseMemoryPagesToOS(uintptr_t Begin, uintptr_t End); +#ifdef __cplusplus +} // extern "C" +#endif + #endif /* PROFILE_INSTRPROFILINGUTIL_H */ Index: compiler-rt/lib/profile/InstrProfilingUtil.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfilingUtil.cpp +++ compiler-rt/lib/profile/InstrProfilingUtil.cpp @@ -46,6 +46,8 @@ #include "InstrProfiling.h" #include "InstrProfilingUtil.h" +extern "C" { + COMPILER_RT_WEAK unsigned lprofDirMode = 0755; COMPILER_RT_VISIBILITY @@ -373,3 +375,5 @@ return 0; #endif } + +} // extern "C" Index: compiler-rt/lib/profile/InstrProfilingValue.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfilingValue.cpp +++ compiler-rt/lib/profile/InstrProfilingValue.cpp @@ -21,6 +21,8 @@ #define INSTR_PROF_VALUE_PROF_MEMOP_API #include "profile/InstrProfData.inc" +extern "C" { + static int hasStaticCounters = 1; static int OutOfNodesWarnings = 0; static int hasNonDefaultValsPerSite = 0; @@ -59,7 +61,7 @@ COMPILER_RT_VISIBILITY void __llvm_profile_set_num_value_sites(__llvm_profile_data *Data, uint32_t ValueKind, uint16_t NumValueSites) { - *((uint16_t *)&Data->NumValueSites[ValueKind]) = NumValueSites; + *(const_cast(Data->NumValueSites + ValueKind)) = NumValueSites; } /* This method is only used in value profiler mock testing. */ @@ -356,3 +358,5 @@ COMPILER_RT_VISIBILITY VPDataReaderType *lprofGetVPDataReader() { return &TheVPDataReader; } + +} // extern "C" Index: compiler-rt/lib/profile/InstrProfilingVersionVar.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfilingVersionVar.cpp +++ compiler-rt/lib/profile/InstrProfilingVersionVar.cpp @@ -8,6 +8,8 @@ #include "InstrProfiling.h" +extern "C" { + /* uint64 __llvm_profile_raw_version * * The runtime should only provide its own definition of this symbol when the @@ -24,3 +26,5 @@ #endif VERSION_VAR_VISIBILITY COMPILER_RT_WEAK uint64_t INSTR_PROF_RAW_VERSION_VAR = INSTR_PROF_RAW_VERSION; + +} // extern "C" Index: compiler-rt/lib/profile/InstrProfilingWriter.cpp =================================================================== --- compiler-rt/lib/profile/InstrProfilingWriter.cpp +++ compiler-rt/lib/profile/InstrProfilingWriter.cpp @@ -22,6 +22,8 @@ #define INSTR_PROF_VALUE_PROF_DATA #include "profile/InstrProfData.inc" +extern "C" { + COMPILER_RT_VISIBILITY void (*FreeHook)(void *) = NULL; static ProfBufferIO TheBufferIO; #define VP_BUFFER_SIZE 8 * 1024 @@ -321,13 +323,13 @@ /* Write the profile data. */ ProfDataIOVec IOVecData[] = { - {DebugInfoCorrelate ? NULL : DataBegin, sizeof(uint8_t), DataSize, 0}, - {NULL, sizeof(uint8_t), PaddingBytesBeforeCounters, 1}, - {CountersBegin, sizeof(uint8_t), CountersSize, 0}, - {NULL, sizeof(uint8_t), PaddingBytesAfterCounters, 1}, + {DebugInfoCorrelate ? NULL : DataBegin, sizeof(uint8_t), static_cast(DataSize), 0}, + {NULL, sizeof(uint8_t), static_cast(PaddingBytesBeforeCounters), 1}, + {CountersBegin, sizeof(uint8_t), static_cast(CountersSize), 0}, + {NULL, sizeof(uint8_t), static_cast(PaddingBytesAfterCounters), 1}, {(SkipNameDataWrite || DebugInfoCorrelate) ? NULL : NamesBegin, - sizeof(uint8_t), NamesSize, 0}, - {NULL, sizeof(uint8_t), PaddingBytesAfterNames, 1}}; + sizeof(uint8_t), static_cast(NamesSize), 0}, + {NULL, sizeof(uint8_t), static_cast(PaddingBytesAfterNames), 1}}; if (Writer->Write(Writer, IOVecData, sizeof(IOVecData) / sizeof(*IOVecData))) return -1; @@ -337,3 +339,5 @@ return writeValueProfData(Writer, VPDataReader, DataBegin, DataEnd); } + +} // extern "C"