[compiler-rt] f98709a - [gcov] Fix big-endian problems
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon May 11 22:38:52 PDT 2020
Author: Fangrui Song
Date: 2020-05-11T22:36:46-07:00
New Revision: f98709a982b358a2df3ee6103c8b9a81cbc81d26
URL: https://github.com/llvm/llvm-project/commit/f98709a982b358a2df3ee6103c8b9a81cbc81d26
DIFF: https://github.com/llvm/llvm-project/commit/f98709a982b358a2df3ee6103c8b9a81cbc81d26.diff
LOG: [gcov] Fix big-endian problems
In a big-endian .gcda file, the first four bytes are "gcda" instead of "adcg".
All 32-bit values are in big-endian.
With this change, libclang_rt.profile can hopefully produce gcov
compatible output.
Added:
Modified:
compiler-rt/lib/profile/GCDAProfiling.c
Removed:
################################################################################
diff --git a/compiler-rt/lib/profile/GCDAProfiling.c b/compiler-rt/lib/profile/GCDAProfiling.c
index eb23a0631832..0463e972b070 100644
--- a/compiler-rt/lib/profile/GCDAProfiling.c
+++ b/compiler-rt/lib/profile/GCDAProfiling.c
@@ -67,6 +67,8 @@ typedef unsigned long long uint64_t;
/* #define DEBUG_GCDAPROFILING */
enum {
+ GCOV_DATA_MAGIC = 0x67636461, // "gcda"
+
GCOV_TAG_FUNCTION = 0x01000000,
GCOV_TAG_COUNTER_ARCS = 0x01a10000,
// GCOV_TAG_OBJECT_SUMMARY superseded GCOV_TAG_PROGRAM_SUMMARY in GCC 9.
@@ -423,7 +425,7 @@ void llvm_gcda_start_file(const char *orig_filename, const char version[4],
: (version[0] - '0') * 10 + version[2] - '0';
#endif
- write_bytes("adcg", 4);
+ write_32bit_value(GCOV_DATA_MAGIC);
write_bytes(version, 4);
write_32bit_value(checksum);
@@ -472,7 +474,7 @@ void llvm_gcda_emit_function(uint32_t ident, uint32_t func_checksum,
if (!output_file) return;
/* function tag */
- write_bytes("\0\0\0\1", 4);
+ write_32bit_value(GCOV_TAG_FUNCTION);
write_32bit_value(len);
write_32bit_value(ident);
write_32bit_value(func_checksum);
@@ -493,7 +495,7 @@ void llvm_gcda_emit_arcs(uint32_t num_counters, uint64_t *counters) {
if (val != (uint32_t)-1) {
/* There are counters present in the file. Merge them. */
- if (val != 0x01a10000) {
+ if (val != GCOV_TAG_COUNTER_ARCS) {
fprintf(stderr, "profiling: %s: cannot merge previous GCDA file: "
"corrupt arc tag (0x%08x)\n",
filename, val);
@@ -516,7 +518,7 @@ void llvm_gcda_emit_arcs(uint32_t num_counters, uint64_t *counters) {
cur_pos = save_cur_pos;
/* Counter #1 (arcs) tag */
- write_bytes("\0\0\xa1\1", 4);
+ write_32bit_value(GCOV_TAG_COUNTER_ARCS);
write_32bit_value(num_counters * 2);
for (i = 0; i < num_counters; ++i) {
counters[i] += (old_ctrs ? old_ctrs[i] : 0);
More information about the llvm-commits
mailing list