[PATCH] D49132: Fix gcov profiling on big-endian machines
Ulrich Weigand via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 10 09:13:29 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL336693: [gcov] Fix gcov profiling on big-endian machines (authored by uweigand, committed by ).
Herald added a subscriber: delcypher.
Changed prior to commit:
https://reviews.llvm.org/D49132?vs=154796&id=154827#toc
Repository:
rL LLVM
https://reviews.llvm.org/D49132
Files:
compiler-rt/trunk/lib/profile/GCDAProfiling.c
Index: compiler-rt/trunk/lib/profile/GCDAProfiling.c
===================================================================
--- compiler-rt/trunk/lib/profile/GCDAProfiling.c
+++ compiler-rt/trunk/lib/profile/GCDAProfiling.c
@@ -178,7 +178,12 @@
}
static void write_64bit_value(uint64_t i) {
- write_bytes((char*)&i, 8);
+ // GCOV uses a lo-/hi-word format even on big-endian systems.
+ // See also GCOVBuffer::readInt64 in LLVM.
+ uint32_t lo = (uint32_t) i;
+ uint32_t hi = (uint32_t) (i >> 32);
+ write_32bit_value(lo);
+ write_32bit_value(hi);
}
static uint32_t length_of_string(const char *s) {
@@ -203,17 +208,25 @@
return val;
}
-static uint64_t read_64bit_value() {
- uint64_t val;
+static uint32_t read_le_32bit_value() {
+ uint32_t val = 0;
if (new_file)
- return (uint64_t)-1;
+ return (uint32_t)-1;
- val = *(uint64_t*)&write_buffer[cur_pos];
- cur_pos += 8;
+ for (int i = 0; i < 4; i++)
+ val |= write_buffer[cur_pos++] << (8*i);
return val;
}
+static uint64_t read_64bit_value() {
+ // GCOV uses a lo-/hi-word format even on big-endian systems.
+ // See also GCOVBuffer::readInt64 in LLVM.
+ uint32_t lo = read_32bit_value();
+ uint32_t hi = read_32bit_value();
+ return ((uint64_t)hi << 32) | ((uint64_t)lo);
+}
+
static char *mangle_filename(const char *orig_filename) {
char *new_filename;
size_t prefix_len;
@@ -400,7 +413,7 @@
if (!output_file) return;
- val = read_32bit_value();
+ val = read_le_32bit_value();
if (val != (uint32_t)-1) {
/* There are counters present in the file. Merge them. */
@@ -454,7 +467,7 @@
if (!output_file) return;
- val = read_32bit_value();
+ val = read_le_32bit_value();
if (val != (uint32_t)-1) {
/* There are counters present in the file. Merge them. */
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D49132.154827.patch
Type: text/x-patch
Size: 1801 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180710/d07c0927/attachment.bin>
More information about the llvm-commits
mailing list