[PATCH] D128290: [lld/mac] On Apple systems, call CC_SHA256 from libSystem

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 21 10:53:02 PDT 2022


thakis created this revision.
thakis added a reviewer: lld-macho.
Herald added projects: lld-macho, All.
thakis requested review of this revision.

It's in libSystem, so it doesn't bring in any new deps, and it's
currently much faster than LLVM's current SHA256 implementation.

Makes linking Chromium Framework with ld64.lld 17% faster. See also PR56121.

No behavior change.


https://reviews.llvm.org/D128290

Files:
  lld/MachO/SyntheticSections.cpp


Index: lld/MachO/SyntheticSections.cpp
===================================================================
--- lld/MachO/SyntheticSections.cpp
+++ lld/MachO/SyntheticSections.cpp
@@ -23,10 +23,14 @@
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/LEB128.h"
 #include "llvm/Support/Path.h"
-#include "llvm/Support/SHA256.h"
 
 #if defined(__APPLE__)
 #include <sys/mman.h>
+
+#define COMMON_DIGEST_FOR_OPENSSL
+#include <CommonCrypto/CommonDigest.h>
+#else
+#include "llvm/Support/SHA256.h"
 #endif
 
 #ifdef LLVM_HAVE_LIBXAR
@@ -45,10 +49,16 @@
 
 // Reads `len` bytes at data and writes the 32-byte SHA256 checksum to `output`.
 static void sha256(const uint8_t *data, size_t len, uint8_t *output) {
+#if defined(__APPLE__)
+  // FIXME: Make LLVM's SHA256 faster and use it unconditionally. See PR56121
+  // for some notes on this.
+  CC_SHA256(data, len, output);
+#else
   ArrayRef<uint8_t> block(data, len);
   std::array<uint8_t, 32> hash = SHA256::hash(block);
   assert(hash.size() == CodeSignatureSection::hashSize);
   memcpy(output, hash.data(), hash.size());
+#endif
 }
 
 InStruct macho::in;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128290.438761.patch
Type: text/x-patch
Size: 1119 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220621/990344e6/attachment.bin>


More information about the llvm-commits mailing list