Index: lld/MachO/SyntheticSections.cpp =================================================================== --- lld/MachO/SyntheticSections.cpp +++ lld/MachO/SyntheticSections.cpp @@ -43,6 +43,14 @@ using namespace lld; using namespace lld::macho; +// 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) { + ArrayRef block(data, len); + std::array hash = SHA256::hash(block); + assert(hash.size() == CodeSignatureSection::hashSize); + memcpy(output, hash.data(), hash.size()); +} + InStruct macho::in; std::vector macho::syntheticSections; @@ -1239,13 +1247,8 @@ uint8_t *codeEnd = buf + fileOff; uint8_t *hashes = codeEnd + allHeadersSize; while (code < codeEnd) { - StringRef block(reinterpret_cast(code), - std::min(codeEnd - code, static_cast(blockSize))); - SHA256 hasher; - hasher.update(block); - std::array hash = hasher.final(); - assert(hash.size() == hashSize); - memcpy(hashes, hash.data(), hashSize); + sha256(code, std::min(static_cast(codeEnd - code), blockSize), + hashes); code += blockSize; hashes += hashSize; }