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

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 (arm64) Chromium Framework with ld64.lld 17% faster.
See also PR56121.

No behavior change.

Differential Revision: https://reviews.llvm.org/D128290
This commit is contained in:
Nico Weber 2022-06-21 13:49:26 -04:00
parent 27e4afcea7
commit 858e8b17f7
1 changed files with 11 additions and 1 deletions

View File

@ -23,10 +23,14 @@
#include "llvm/Support/FileSystem.h" #include "llvm/Support/FileSystem.h"
#include "llvm/Support/LEB128.h" #include "llvm/Support/LEB128.h"
#include "llvm/Support/Path.h" #include "llvm/Support/Path.h"
#include "llvm/Support/SHA256.h"
#if defined(__APPLE__) #if defined(__APPLE__)
#include <sys/mman.h> #include <sys/mman.h>
#define COMMON_DIGEST_FOR_OPENSSL
#include <CommonCrypto/CommonDigest.h>
#else
#include "llvm/Support/SHA256.h"
#endif #endif
#ifdef LLVM_HAVE_LIBXAR #ifdef LLVM_HAVE_LIBXAR
@ -45,10 +49,16 @@ using namespace lld::macho;
// Reads `len` bytes at data and writes the 32-byte SHA256 checksum to `output`. // 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) { 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); ArrayRef<uint8_t> block(data, len);
std::array<uint8_t, 32> hash = SHA256::hash(block); std::array<uint8_t, 32> hash = SHA256::hash(block);
assert(hash.size() == CodeSignatureSection::hashSize); assert(hash.size() == CodeSignatureSection::hashSize);
memcpy(output, hash.data(), hash.size()); memcpy(output, hash.data(), hash.size());
#endif
} }
InStruct macho::in; InStruct macho::in;