[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[llvm coverage] Update LLVM profile raw format from v4 to v10



This patch updates the LLVM profile raw format in
`xen/common/coverage/llvm.c` from version 4 to version 10,
enabling compatibility with LLVM versions 19 and 20.
While the patch supports only one version:
1. It seems better to support one version than no version --
   the current profile version 4 is not compatible with
   LLVM version 11 or later
2. The patch could be extended to support multiple
   LLVM profile versions, e.g., from 5 to 10

The llvm-cov toolchain, with its Source-based Code Coverage,
offers two substantial advantages over gcov:
  - More accurate coverage reporting when compiler optimizations
    are enabled, ensuring better analysis of optimized code.
  - Better tracking of coverage across inlined function boundaries,
    critical for complex control flows in Xen.

Overall, this change would enhance Xen's code coverage analysis
capabilities by leveraging the latest LLVM toolchain improvements,
particularly for safety-critical hypervisor code.

The patch modifies only `xen/common/coverage/llvm.c`,
maintaining API compatibility while enabling modern toolchain support.
Testing was performed with LLVM 19 and 20 to confirm functionality.

---
 xen/common/coverage/llvm.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/xen/common/coverage/llvm.c b/xen/common/coverage/llvm.c
index 517b2aa8c2..3da82c6cda 100644
--- a/xen/common/coverage/llvm.c
+++ b/xen/common/coverage/llvm.c
@@ -44,27 +44,37 @@
     ((uint64_t)'f' << 16) | ((uint64_t)'R' << 8)  | ((uint64_t)129)
 #endif
 
-#define LLVM_PROFILE_VERSION    4
-#define LLVM_PROFILE_NUM_KINDS  2
+#define LLVM_PROFILE_VERSION    10
+#define LLVM_PROFILE_NUM_KINDS  3
 
 struct llvm_profile_data {
     uint64_t name_ref;
     uint64_t function_hash;
-    void *counter;
+    void *relative_counter;
+    void *relative_bitmap;
     void *function;
     void *values;
     uint32_t nr_counters;
     uint16_t nr_value_sites[LLVM_PROFILE_NUM_KINDS];
+    uint32_t numbitmap_bytes;
 };
 
 struct llvm_profile_header {
     uint64_t magic;
     uint64_t version;
-    uint64_t data_size;
-    uint64_t counters_size;
+    uint64_t binary_ids_size;
+    uint64_t num_data;
+    uint64_t padding_bytes_before_counters;
+    uint64_t num_counters;
+    uint64_t padding_bytes_after_counters;
+    uint64_t num_bitmap_bytes;    
+    uint64_t padding_bytes_after_bitmap_bytes;
     uint64_t names_size;
     uint64_t counters_delta;
+    uint64_t bitmap_delta;
     uint64_t names_delta;
+    uint64_t num_vtables;
+    uint64_t vnames_size;
     uint64_t value_kind_last;
 };
 
@@ -110,7 +120,7 @@ static int cf_check dump(
         .data_size = (END_DATA - START_DATA) / sizeof(struct 
llvm_profile_data),
         .counters_size = (END_COUNTERS - START_COUNTERS) / sizeof(uint64_t),
         .names_size = END_NAMES - START_NAMES,
-        .counters_delta = (uintptr_t)START_COUNTERS,
+        .counters_delta = (uintptr_t)(START_COUNTERS - START_DATA),
         .names_delta = (uintptr_t)START_NAMES,
         .value_kind_last = LLVM_PROFILE_NUM_KINDS - 1,
     };
-- 
2.49.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.