mirror of
https://github.com/xen-project/xen.git
synced 2026-10-28 18:21:39 +01:00
xen: Support LLVM raw profile versions 5, 6, 7, 8, 9, and 10
This change enables compatibility for measuring code coverage with Clang versions 11 through 20 by supporting their respective raw profile formats. 1- Added support for LLVM raw profile versions 5, 6, 7, 8, 9, and 10. 2- Initialized llvm_profile_header for all versions based on llvm source code in compiler-rt/include/profile/InstrProfData.inc for each version. 3- We tested this patch for all Clang versions from 11 through 20 on x86 platform. 4- Fixed linking warnings related to LLVM profile sections in x86. Signed-off-by: Saman Dehghan <samaan.dehghan@gmail.com> Release-Acked-By: Oleksii Kurochko <oleksii.kurochko@gmail.com> Tested-by: Wentao Zhang <wentaoz5@illinois.edu> Acked-by: Andrew Cooper <andrew.cooper3@citrix.com>
This commit is contained in:
1 parent
f7091c0e1f
commit
186c02e859
3 files changed
+67
-6
No files matched your search
@@ -186,6 +186,8 @@ SECTIONS
|
||||
} PHDR(note) PHDR(text)
|
||||
#endif
|
||||
|
||||
LLVM_COV_RO_DATA
|
||||
|
||||
_erodata = .;
|
||||
|
||||
. = ALIGN(SECTION_ALIGN);
|
||||
@@ -323,6 +325,8 @@ SECTIONS
|
||||
*(.data .data.*)
|
||||
} PHDR(text)
|
||||
|
||||
LLVM_COV_RW_DATA
|
||||
|
||||
DECL_SECTION(.bss) {
|
||||
__bss_start = .;
|
||||
*(.bss.page_aligned*)
|
||||
@@ -357,6 +361,8 @@ SECTIONS
|
||||
|
||||
DWARF2_DEBUG_SECTIONS
|
||||
|
||||
LLVM_COV_DEBUG
|
||||
|
||||
#ifdef CONFIG_HYPERV_GUEST
|
||||
hv_hcall_page = ABSOLUTE(HV_HCALL_PAGE - XEN_VIRT_START + __XEN_VIRT_START);
|
||||
#endif
|
||||
|
||||
@@ -44,27 +44,65 @@
|
||||
((uint64_t)'f' << 16) | ((uint64_t)'R' << 8) | ((uint64_t)129)
|
||||
#endif
|
||||
|
||||
#define LLVM_PROFILE_VERSION 4
|
||||
#if __clang_major__ >= 19 && __clang_major__ <= 20
|
||||
#define LLVM_PROFILE_VERSION 10
|
||||
#define LLVM_PROFILE_NUM_KINDS 3
|
||||
#elif __clang_major__ == 18
|
||||
#define LLVM_PROFILE_VERSION 9
|
||||
#define LLVM_PROFILE_NUM_KINDS 2
|
||||
#elif __clang_major__ >= 14
|
||||
#define LLVM_PROFILE_VERSION 8
|
||||
#define LLVM_PROFILE_NUM_KINDS 2
|
||||
#elif __clang_major__ == 13
|
||||
#define LLVM_PROFILE_VERSION 7
|
||||
#define LLVM_PROFILE_NUM_KINDS 2
|
||||
#elif __clang_major__ >= 11
|
||||
#define LLVM_PROFILE_VERSION 5
|
||||
#define LLVM_PROFILE_NUM_KINDS 2
|
||||
#else
|
||||
#error "LLVM coverage selected but an unsupported clang version is used"
|
||||
#endif
|
||||
|
||||
struct llvm_profile_data {
|
||||
uint64_t name_ref;
|
||||
uint64_t function_hash;
|
||||
void *counter;
|
||||
void *relative_counter;
|
||||
#if LLVM_PROFILE_VERSION >= 9
|
||||
void *relative_bitmap;
|
||||
#endif
|
||||
void *function;
|
||||
void *values;
|
||||
uint32_t nr_counters;
|
||||
uint16_t nr_value_sites[LLVM_PROFILE_NUM_KINDS];
|
||||
#if LLVM_PROFILE_VERSION >= 9
|
||||
uint32_t numbitmap_bytes;
|
||||
#endif
|
||||
};
|
||||
|
||||
struct llvm_profile_header {
|
||||
uint64_t magic;
|
||||
uint64_t version;
|
||||
uint64_t data_size;
|
||||
uint64_t counters_size;
|
||||
#if LLVM_PROFILE_VERSION >= 7
|
||||
uint64_t binary_ids_size;
|
||||
#endif
|
||||
uint64_t num_data;
|
||||
uint64_t padding_bytes_before_counters;
|
||||
uint64_t num_counters;
|
||||
uint64_t padding_bytes_after_counters;
|
||||
#if LLVM_PROFILE_VERSION >= 9
|
||||
uint64_t num_bitmap_bytes;
|
||||
uint64_t padding_bytes_after_bitmap_bytes;
|
||||
#endif
|
||||
uint64_t names_size;
|
||||
uint64_t counters_delta;
|
||||
#if LLVM_PROFILE_VERSION >= 9
|
||||
uint64_t bitmap_delta;
|
||||
#endif
|
||||
uint64_t names_delta;
|
||||
#if LLVM_PROFILE_VERSION == 10
|
||||
uint64_t num_vtables;
|
||||
uint64_t vnames_size;
|
||||
#endif
|
||||
uint64_t value_kind_last;
|
||||
};
|
||||
|
||||
@@ -107,10 +145,14 @@ static int cf_check dump(
|
||||
struct llvm_profile_header header = {
|
||||
.magic = LLVM_PROFILE_MAGIC,
|
||||
.version = LLVM_PROFILE_VERSION,
|
||||
.data_size = (END_DATA - START_DATA) / sizeof(struct llvm_profile_data),
|
||||
.counters_size = (END_COUNTERS - START_COUNTERS) / sizeof(uint64_t),
|
||||
.num_data = DIV_ROUND_UP(END_DATA - START_DATA, sizeof(struct llvm_profile_data)),
|
||||
.num_counters = DIV_ROUND_UP(END_COUNTERS - START_COUNTERS, sizeof(uint64_t)),
|
||||
.names_size = END_NAMES - START_NAMES,
|
||||
#if LLVM_PROFILE_VERSION >= 8
|
||||
.counters_delta = START_COUNTERS - START_DATA,
|
||||
#else
|
||||
.counters_delta = (uintptr_t)START_COUNTERS,
|
||||
#endif
|
||||
.names_delta = (uintptr_t)START_NAMES,
|
||||
.value_kind_last = LLVM_PROFILE_NUM_KINDS - 1,
|
||||
};
|
||||
|
||||
@@ -81,6 +81,19 @@
|
||||
.stab.index 0 : { *(.stab.index) } \
|
||||
.stab.indexstr 0 : { *(.stab.indexstr) }
|
||||
|
||||
/* Clang coverage sections. */
|
||||
#define LLVM_COV_RW_DATA \
|
||||
DECL_SECTION(__llvm_prf_cnts) { *(__llvm_prf_cnts) } \
|
||||
DECL_SECTION(__llvm_prf_data) { *(__llvm_prf_data) } \
|
||||
DECL_SECTION(__llvm_prf_bits) { *(__llvm_prf_bits) }
|
||||
|
||||
#define LLVM_COV_RO_DATA \
|
||||
DECL_SECTION(__llvm_prf_names) { *(__llvm_prf_names) }
|
||||
|
||||
#define LLVM_COV_DEBUG \
|
||||
DECL_DEBUG(__llvm_covfun, 8) \
|
||||
DECL_DEBUG(__llvm_covmap, 8)
|
||||
|
||||
/*
|
||||
* ELF sections.
|
||||
*
|
||||
|
||||