Index: lib/profile/CMakeLists.txt =================================================================== --- lib/profile/CMakeLists.txt +++ lib/profile/CMakeLists.txt @@ -1,16 +1,18 @@ add_custom_target(profile) -set(PROFILE_SOURCES +set(COMMON_SOURCES GCDAProfiling.c InstrProfiling.c InstrProfilingBuffer.c InstrProfilingFile.c - InstrProfilingPlatformDarwin.c - InstrProfilingPlatformOther.c InstrProfilingRuntime.cc InstrProfilingUtil.c) if(APPLE) + set(PROFILE_SOURCES + ${COMMON_SOURCES} + InstrProfilingPlatformDarwin.c) + add_compiler_rt_runtime(clang_rt.profile STATIC OS osx @@ -18,6 +20,18 @@ SOURCES ${PROFILE_SOURCES} PARENT_TARGET profile) else() + if(UNIX) + # Assume Linux + set(PROFILE_SOURCES + ${COMMON_SOURCES} + InstrProfilingPlatformLinux.c) + add_compiler_rt_resource_file(profile_x prf_data.x) + add_dependencies(profile profile_x) + else() + set(PROFILE_SOURCES + ${COMMON_SOURCES} + InstrProfilingPlatformOther.c) + endif() add_compiler_rt_runtime(clang_rt.profile STATIC ARCHS ${PROFILE_SUPPORTED_ARCH} Index: lib/profile/InstrProfilingPlatformLinux.c =================================================================== --- /dev/null +++ lib/profile/InstrProfilingPlatformLinux.c @@ -0,0 +1,48 @@ +/*===- InstrProfilingPlatformLinux.c - Profile data Linux platform ------===*\ +|* +|* The LLVM Compiler Infrastructure +|* +|* This file is distributed under the University of Illinois Open Source +|* License. See LICENSE.TXT for details. +|* +\*===----------------------------------------------------------------------===*/ + +#include "InstrProfiling.h" + +#if !defined(__APPLE__) +#include + +extern __llvm_profile_data __llvm_prf_data_start + __attribute__((visibility("hidden"))); +extern __llvm_profile_data __llvm_prf_data_end + __attribute__((visibility("hidden"))); +extern uint64_t __llvm_prf_cnts_start __attribute__((visibility("hidden"))); +extern uint64_t __llvm_prf_cnts_end __attribute__((visibility("hidden"))); +extern char __llvm_prf_names_start __attribute__((visibility("hidden"))); +extern char __llvm_prf_names_end __attribute__((visibility("hidden"))); + +__attribute__((visibility("hidden"))) const __llvm_profile_data * +__llvm_profile_begin_data(void) { + return &__llvm_prf_data_start; +} +__attribute__((visibility("hidden"))) const __llvm_profile_data * +__llvm_profile_end_data(void) { + return &__llvm_prf_data_end; +} +__attribute__((visibility("hidden"))) const char *__llvm_profile_begin_names( + void) { + return &__llvm_prf_names_start; +} +__attribute__((visibility("hidden"))) const char *__llvm_profile_end_names( + void) { + return &__llvm_prf_names_end; +} +__attribute__((visibility("hidden"))) uint64_t *__llvm_profile_begin_counters( + void) { + return &__llvm_prf_cnts_start; +} +__attribute__((visibility("hidden"))) uint64_t *__llvm_profile_end_counters( + void) { + return &__llvm_prf_cnts_end; +} +#endif Index: lib/profile/prf_data.x =================================================================== --- /dev/null +++ lib/profile/prf_data.x @@ -0,0 +1,8 @@ +SECTIONS { + PROVIDE(__llvm_prf_data_start = ADDR(__llvm_prf_data)); + PROVIDE(__llvm_prf_data_end = ADDR(__llvm_prf_data) + SIZEOF(__llvm_prf_data)); + PROVIDE(__llvm_prf_cnts_start = ADDR(__llvm_prf_cnts)); + PROVIDE(__llvm_prf_cnts_end = ADDR(__llvm_prf_cnts) + SIZEOF(__llvm_prf_cnts)); + PROVIDE(__llvm_prf_names_start = ADDR(__llvm_prf_names)); + PROVIDE(__llvm_prf_names_end = ADDR(__llvm_prf_names) + SIZEOF(__llvm_prf_names)); +};