[PATCH] D92736: [lld/mac] Use xxhash instead of MD5 for computing the UUID

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 6 11:15:12 PST 2020


thakis created this revision.
thakis added a reviewer: lld-macho.
thakis requested review of this revision.

15% faster for linking Chromium's base_unittests.txt, according to ministat:

      N           Min           Max        Median           Avg        Stddev
  x  10      0.650213    0.69287586    0.65793395    0.66127126   0.012365407
  +  10    0.54993701    0.59006906    0.55885506    0.56146643   0.013215349
  Difference at 95.0% confidence
          -0.0998048 +/- 0.0120244
          -15.0929% +/- 1.81838%
          (Student's t, pooled s = 0.0127974)

And matches what we do on the other ports.


https://reviews.llvm.org/D92736

Files:
  lld/MachO/Writer.cpp


Index: lld/MachO/Writer.cpp
===================================================================
--- lld/MachO/Writer.cpp
+++ lld/MachO/Writer.cpp
@@ -24,9 +24,9 @@
 #include "llvm/BinaryFormat/MachO.h"
 #include "llvm/Config/llvm-config.h"
 #include "llvm/Support/LEB128.h"
-#include "llvm/Support/MD5.h"
 #include "llvm/Support/MathExtras.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/xxhash.h"
 
 #include <algorithm>
 
@@ -369,8 +369,10 @@
     uuidBuf = c->uuid;
   }
 
-  void writeUuid(const std::array<uint8_t, 16> &uuid) const {
-    memcpy(uuidBuf, uuid.data(), uuid.size());
+  void writeUuid(uint64_t digest) const {
+    memcpy(uuidBuf, &digest, 8);
+    // xxhash only gives us 8 bytes, so put some fixed data in the other half.
+    memcpy(uuidBuf, "LLD UUID", 8);
   }
 
   mutable uint8_t *uuidBuf;
@@ -663,18 +665,9 @@
 }
 
 void Writer::writeUuid() {
-  MD5 hash;
-  const auto *bufStart = reinterpret_cast<char *>(buffer->getBufferStart());
-  const auto *bufEnd = reinterpret_cast<char *>(buffer->getBufferEnd());
-  hash.update(StringRef(bufStart, bufEnd - bufStart));
-  MD5::MD5Result result;
-  hash.final(result);
-  // Conform to UUID version 4 & 5 as specified in RFC 4122:
-  // 1. Set the version field to indicate that this is an MD5-based UUID.
-  result.Bytes[6] = (result.Bytes[6] & 0xf) | 0x30;
-  // 2. Set the two MSBs of uuid_t::clock_seq_hi_and_reserved to zero and one.
-  result.Bytes[8] = (result.Bytes[8] & 0x3f) | 0x80;
-  uuidCommand->writeUuid(result.Bytes);
+  uint64_t digest =
+      xxHash64({buffer->getBufferStart(), buffer->getBufferEnd()});
+  uuidCommand->writeUuid(digest);
 }
 
 void Writer::run() {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92736.309782.patch
Type: text/x-patch
Size: 1669 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201206/67b2a2e7/attachment.bin>


More information about the llvm-commits mailing list