From f35032e03d9263b1d2a8ac2e675fc94cb43b608b Mon Sep 17 00:00:00 2001 From: Petr Hosek Date: Fri, 22 Nov 2019 12:09:15 -0800 Subject: [PATCH] Reland "[CMake] Support installation of InstrProfData.inc" This header fragment is useful on its own for any consumer that wants to use custom instruction profile runtime with the LLVM instrumentation. The concrete use case is in Fuchsia's kernel where we want to use instruction profile instrumentation, but we cannot use the compiler-rt runtime because it's not designed for use in the kernel environment. This change allows installing this header as part of compiler-rt. Differential Revision: https://reviews.llvm.org/D64532 --- compiler-rt/include/CMakeLists.txt | 14 +++++++++++++- compiler-rt/{lib => include}/profile/InstrProfData.inc | 0 compiler-rt/lib/profile/CMakeLists.txt | 4 +++- compiler-rt/lib/profile/InstrProfiling.c | 2 +- compiler-rt/lib/profile/InstrProfiling.h | 12 ++++++------ compiler-rt/lib/profile/InstrProfilingMerge.c | 2 +- compiler-rt/lib/profile/InstrProfilingMergeFile.c | 2 +- compiler-rt/lib/profile/InstrProfilingValue.c | 2 +- compiler-rt/lib/profile/InstrProfilingWriter.c | 4 ++-- llvm/utils/gn/secondary/compiler-rt/include/BUILD.gn | 1 + llvm/utils/gn/secondary/compiler-rt/lib/profile/BUILD.gn | 5 +++++ 11 files changed, 34 insertions(+), 14 deletions(-) rename compiler-rt/{lib => include}/profile/InstrProfData.inc (100%) diff --git a/compiler-rt/include/CMakeLists.txt b/compiler-rt/include/CMakeLists.txt index 403ded4..d47d7ba 100644 --- a/compiler-rt/include/CMakeLists.txt +++ b/compiler-rt/include/CMakeLists.txt @@ -28,10 +28,17 @@ if (COMPILER_RT_BUILD_XRAY) ) endif(COMPILER_RT_BUILD_XRAY) +if (COMPILER_RT_BUILD_PROFILE) + set(PROFILE_HEADERS + profile/InstrProfData.inc + ) +endif(COMPILER_RT_BUILD_PROFILE) + set(COMPILER_RT_HEADERS ${SANITIZER_HEADERS} ${FUZZER_HEADERS} - ${XRAY_HEADERS}) + ${XRAY_HEADERS} + ${PROFILE_HEADERS}) set(output_dir ${COMPILER_RT_OUTPUT_DIR}/include) @@ -66,6 +73,11 @@ install(FILES ${XRAY_HEADERS} COMPONENT compiler-rt-headers PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/xray) +# Install profile headers. +install(FILES ${PROFILE_HEADERS} + COMPONENT compiler-rt-headers + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + DESTINATION ${COMPILER_RT_INSTALL_PATH}/include/profile) if (NOT CMAKE_CONFIGURATION_TYPES) # don't add this for IDEs. add_custom_target(install-compiler-rt-headers diff --git a/compiler-rt/lib/profile/InstrProfData.inc b/compiler-rt/include/profile/InstrProfData.inc similarity index 100% rename from compiler-rt/lib/profile/InstrProfData.inc rename to compiler-rt/include/profile/InstrProfData.inc diff --git a/compiler-rt/lib/profile/CMakeLists.txt b/compiler-rt/lib/profile/CMakeLists.txt index cdd2159..955d0bf 100644 --- a/compiler-rt/lib/profile/CMakeLists.txt +++ b/compiler-rt/lib/profile/CMakeLists.txt @@ -68,7 +68,6 @@ set(PROFILE_SOURCES ) set(PROFILE_HEADERS - InstrProfData.inc InstrProfiling.h InstrProfilingInternal.h InstrProfilingPort.h @@ -82,6 +81,9 @@ if(WIN32) ) endif() +include_directories(..) +include_directories(../../include) + if(FUCHSIA OR UNIX) set(EXTRA_FLAGS -fPIC diff --git a/compiler-rt/lib/profile/InstrProfiling.c b/compiler-rt/lib/profile/InstrProfiling.c index f378771..087d1cd 100644 --- a/compiler-rt/lib/profile/InstrProfiling.c +++ b/compiler-rt/lib/profile/InstrProfiling.c @@ -15,7 +15,7 @@ #include "InstrProfilingInternal.h" #define INSTR_PROF_VALUE_PROF_DATA -#include "InstrProfData.inc" +#include "profile/InstrProfData.inc" COMPILER_RT_WEAK uint64_t INSTR_PROF_RAW_VERSION_VAR = INSTR_PROF_RAW_VERSION; diff --git a/compiler-rt/lib/profile/InstrProfiling.h b/compiler-rt/lib/profile/InstrProfiling.h index 78dfc67..3a3bab3 100644 --- a/compiler-rt/lib/profile/InstrProfiling.h +++ b/compiler-rt/lib/profile/InstrProfiling.h @@ -13,29 +13,29 @@ #include #define INSTR_PROF_VISIBILITY COMPILER_RT_VISIBILITY -#include "InstrProfData.inc" +#include "profile/InstrProfData.inc" enum ValueKind { #define VALUE_PROF_KIND(Enumerator, Value, Descr) Enumerator = Value, -#include "InstrProfData.inc" +#include "profile/InstrProfData.inc" }; typedef void *IntPtrT; typedef struct COMPILER_RT_ALIGNAS(INSTR_PROF_DATA_ALIGNMENT) __llvm_profile_data { #define INSTR_PROF_DATA(Type, LLVMType, Name, Initializer) Type Name; -#include "InstrProfData.inc" +#include "profile/InstrProfData.inc" } __llvm_profile_data; typedef struct __llvm_profile_header { #define INSTR_PROF_RAW_HEADER(Type, Name, Initializer) Type Name; -#include "InstrProfData.inc" +#include "profile/InstrProfData.inc" } __llvm_profile_header; typedef struct ValueProfNode * PtrToNodeT; typedef struct ValueProfNode { #define INSTR_PROF_VALUE_NODE(Type, LLVMType, Name, Initializer) Type Name; -#include "InstrProfData.inc" +#include "profile/InstrProfData.inc" } ValueProfNode; /*! @@ -120,7 +120,7 @@ int __llvm_profile_check_compatibility(const char *Profile, */ void INSTR_PROF_VALUE_PROF_FUNC( #define VALUE_PROF_FUNC_PARAM(ArgType, ArgName, ArgLLVMType) ArgType ArgName -#include "InstrProfData.inc" +#include "profile/InstrProfData.inc" ); void __llvm_profile_instrument_target_value(uint64_t TargetValue, void *Data, diff --git a/compiler-rt/lib/profile/InstrProfilingMerge.c b/compiler-rt/lib/profile/InstrProfilingMerge.c index 44dce7c..0fd9b2bc 100644 --- a/compiler-rt/lib/profile/InstrProfilingMerge.c +++ b/compiler-rt/lib/profile/InstrProfilingMerge.c @@ -14,7 +14,7 @@ #include "InstrProfilingUtil.h" #define INSTR_PROF_VALUE_PROF_DATA -#include "InstrProfData.inc" +#include "profile/InstrProfData.inc" COMPILER_RT_VISIBILITY void (*VPMergeHook)(ValueProfData *, __llvm_profile_data *); diff --git a/compiler-rt/lib/profile/InstrProfilingMergeFile.c b/compiler-rt/lib/profile/InstrProfilingMergeFile.c index b853f15..8923ba2 100644 --- a/compiler-rt/lib/profile/InstrProfilingMergeFile.c +++ b/compiler-rt/lib/profile/InstrProfilingMergeFile.c @@ -16,7 +16,7 @@ #include "InstrProfilingUtil.h" #define INSTR_PROF_VALUE_PROF_DATA -#include "InstrProfData.inc" +#include "profile/InstrProfData.inc" /* Merge value profile data pointed to by SrcValueProfData into * in-memory profile counters pointed by to DstData. */ diff --git a/compiler-rt/lib/profile/InstrProfilingValue.c b/compiler-rt/lib/profile/InstrProfilingValue.c index b7c7176..fd53cac 100644 --- a/compiler-rt/lib/profile/InstrProfilingValue.c +++ b/compiler-rt/lib/profile/InstrProfilingValue.c @@ -17,7 +17,7 @@ #define INSTR_PROF_VALUE_PROF_DATA #define INSTR_PROF_COMMON_API_IMPL -#include "InstrProfData.inc" +#include "profile/InstrProfData.inc" static int hasStaticCounters = 1; static int OutOfNodesWarnings = 0; diff --git a/compiler-rt/lib/profile/InstrProfilingWriter.c b/compiler-rt/lib/profile/InstrProfilingWriter.c index 0b2e176..ac8113e 100644 --- a/compiler-rt/lib/profile/InstrProfilingWriter.c +++ b/compiler-rt/lib/profile/InstrProfilingWriter.c @@ -17,7 +17,7 @@ #include "InstrProfilingPort.h" #define INSTR_PROF_VALUE_PROF_DATA -#include "InstrProfData.inc" +#include "profile/InstrProfData.inc" COMPILER_RT_VISIBILITY void (*FreeHook)(void *) = NULL; static ProfBufferIO TheBufferIO; @@ -280,7 +280,7 @@ lprofWriteDataImpl(ProfDataWriter *Writer, const __llvm_profile_data *DataBegin, /* Initialize header structure. */ #define INSTR_PROF_RAW_HEADER(Type, Name, Init) Header.Name = Init; -#include "InstrProfData.inc" +#include "profile/InstrProfData.inc" /* Write the data. */ ProfDataIOVec IOVec[] = { diff --git a/llvm/utils/gn/secondary/compiler-rt/include/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/include/BUILD.gn index 4d459b7..103865d 100644 --- a/llvm/utils/gn/secondary/compiler-rt/include/BUILD.gn +++ b/llvm/utils/gn/secondary/compiler-rt/include/BUILD.gn @@ -3,6 +3,7 @@ import("//clang/resource_dir.gni") copy("include") { sources = [ "fuzzer/FuzzedDataProvider.h", + "profile/InstrProfData.inc", "sanitizer/allocator_interface.h", "sanitizer/asan_interface.h", "sanitizer/common_interface_defs.h", diff --git a/llvm/utils/gn/secondary/compiler-rt/lib/profile/BUILD.gn b/llvm/utils/gn/secondary/compiler-rt/lib/profile/BUILD.gn index 14203de..36e8b15 100644 --- a/llvm/utils/gn/secondary/compiler-rt/lib/profile/BUILD.gn +++ b/llvm/utils/gn/secondary/compiler-rt/lib/profile/BUILD.gn @@ -25,6 +25,11 @@ static_library("profile") { cflags += [ "/wd4221" ] } + include_dirs = [ + "..", + "../../include", + ] + sources = [ "GCDAProfiling.c", "InstrProfiling.c", -- 2.7.4