Files
MSYS2-packages/ninja/0005-Use-64-bit-alignment-safe-timestamp-reading.patch
2018-10-31 10:10:11 +03:00

60 lines
2.4 KiB
Diff

From bf4fb03e4b266e7f75f88664b6a941d20650046b Mon Sep 17 00:00:00 2001
From: Elliott Sales de Andrade <quantum.analyst@gmail.com>
Date: Thu, 20 Apr 2017 23:10:56 -0400
Subject: [PATCH 5/9] Use 64-bit-alignment-safe timestamp reading.
Read and write the timestamp as two separate 32-bit integers in a fixed
order to prevent any issues with alignment or byte order.
---
src/deps_log.cc | 10 ++++++++--
src/deps_log.h | 5 +++--
2 files changed, 11 insertions(+), 4 deletions(-)
diff --git a/src/deps_log.cc b/src/deps_log.cc
index d7f0b26..4239426 100644
--- a/src/deps_log.cc
+++ b/src/deps_log.cc
@@ -135,7 +135,11 @@ bool DepsLog::RecordDeps(Node* node, TimeStamp mtime,
int id = node->id();
if (fwrite(&id, 4, 1, file_) < 1)
return false;
- if (fwrite(&mtime, 8, 1, file_) < 1)
+ uint32_t mtime_part = static_cast<uint32_t>(mtime & 0xffffffff);
+ if (fwrite(&mtime_part, 4, 1, file_) < 1)
+ return false;
+ mtime_part = static_cast<uint32_t>((mtime >> 32) & 0xffffffff);
+ if (fwrite(&mtime_part, 4, 1, file_) < 1)
return false;
for (int i = 0; i < node_count; ++i) {
id = nodes[i]->id();
@@ -217,7 +221,9 @@ bool DepsLog::Load(const string& path, State* state, string* err) {
assert(size % 4 == 0);
int* deps_data = reinterpret_cast<int*>(buf);
int out_id = deps_data[0];
- TimeStamp mtime = reinterpret_cast<TimeStamp*>(&deps_data[1])[0];
+ TimeStamp mtime;
+ mtime = (TimeStamp)(((uint64_t)(unsigned int)deps_data[2] << 32) |
+ (uint64_t)(unsigned int)deps_data[1]);
deps_data += 3;
int deps_count = (size / 4) - 3;
diff --git a/src/deps_log.h b/src/deps_log.h
index 793af07..b1aa361 100644
--- a/src/deps_log.h
+++ b/src/deps_log.h
@@ -57,8 +57,9 @@ struct State;
/// one's complement of the expected index of the record (to detect
/// concurrent writes of multiple ninja processes to the log).
/// dependency records are an array of 4-byte integers
-/// [output path id, output path mtime (8-byte int), input path id,
-/// input path id...]
+/// [output path id,
+/// output path mtime (lower 4 bytes), output path mtime (upper 8 bytes),
+/// input path id, input path id...]
/// (The mtime is compared against the on-disk output path mtime
/// to verify the stored data is up-to-date.)
/// If two records reference the same output the latter one in the file
--
2.14.1