From: Rui Ueyama Date: Mon, 2 May 2016 23:35:59 +0000 (+0000) Subject: Pass all buffers to BuildId hash function at once. NFC. X-Git-Tag: llvmorg-3.9.0-rc1~7181 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=dd368fcb05ef5c7187c8d94f84aa8703a234a6d0;p=platform%2Fupstream%2Fllvm.git Pass all buffers to BuildId hash function at once. NFC. This change simplifies the BuildId classes by removing a few member functions and variables from them. It should also make it easy to parallelize hash computation in future because now each BuildId object see all inputs rather than one at a time. llvm-svn: 268333 --- diff --git a/lld/ELF/OutputSections.cpp b/lld/ELF/OutputSections.cpp index 13d5805..922de77 100644 --- a/lld/ELF/OutputSections.cpp +++ b/lld/ELF/OutputSections.cpp @@ -1636,35 +1636,36 @@ template void BuildIdSection::writeTo(uint8_t *Buf) { HashBuf = Buf + 16; } -template void BuildIdFnv1::update(ArrayRef Buf) { +template +void BuildIdFnv1::writeBuildId(ArrayRef> Bufs) { + const endianness E = ELFT::TargetEndianness; + // 64-bit FNV-1 hash - const uint64_t Prime = 0x100000001b3; - for (uint8_t B : Buf) { - Hash *= Prime; - Hash ^= B; + uint64_t Hash = 0xcbf29ce484222325; + for (ArrayRef Buf : Bufs) { + for (uint8_t B : Buf) { + Hash *= 0x100000001b3; + Hash ^= B; + } } -} - -template void BuildIdFnv1::writeBuildId() { - const endianness E = ELFT::TargetEndianness; write64(this->HashBuf, Hash); } -template void BuildIdMd5::update(ArrayRef Buf) { - Hash.update(Buf); -} - -template void BuildIdMd5::writeBuildId() { +template +void BuildIdMd5::writeBuildId(ArrayRef> Bufs) { + llvm::MD5 Hash; + for (ArrayRef Buf : Bufs) + Hash.update(Buf); MD5::MD5Result Res; Hash.final(Res); memcpy(this->HashBuf, Res, 16); } -template void BuildIdSha1::update(ArrayRef Buf) { - Hash.update(Buf); -} - -template void BuildIdSha1::writeBuildId() { +template +void BuildIdSha1::writeBuildId(ArrayRef> Bufs) { + llvm::SHA1 Hash; + for (ArrayRef Buf : Bufs) + Hash.update(Buf); memcpy(this->HashBuf, Hash.final().data(), 20); } diff --git a/lld/ELF/OutputSections.h b/lld/ELF/OutputSections.h index f9c4b6e..64ed3d7 100644 --- a/lld/ELF/OutputSections.h +++ b/lld/ELF/OutputSections.h @@ -541,8 +541,7 @@ private: template class BuildIdSection : public OutputSectionBase { public: void writeTo(uint8_t *Buf) override; - virtual void update(ArrayRef Buf) = 0; - virtual void writeBuildId() = 0; + virtual void writeBuildId(ArrayRef> Bufs) = 0; protected: BuildIdSection(size_t HashSize); @@ -553,32 +552,19 @@ protected: template class BuildIdFnv1 final : public BuildIdSection { public: BuildIdFnv1() : BuildIdSection(8) {} - void update(ArrayRef Buf) override; - void writeBuildId() override; - -private: - // 64-bit FNV-1 initial value - uint64_t Hash = 0xcbf29ce484222325; + void writeBuildId(ArrayRef> Bufs) override; }; template class BuildIdMd5 final : public BuildIdSection { public: BuildIdMd5() : BuildIdSection(16) {} - void update(ArrayRef Buf) override; - void writeBuildId() override; - -private: - llvm::MD5 Hash; + void writeBuildId(ArrayRef> Bufs) override; }; template class BuildIdSha1 final : public BuildIdSection { public: BuildIdSha1() : BuildIdSection(20) {} - void update(ArrayRef Buf) override; - void writeBuildId() override; - -private: - llvm::SHA1 Hash; + void writeBuildId(ArrayRef> Bufs) override; }; // All output sections that are hadnled by the linker specially are diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 98ad727..00004e7 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -1907,16 +1907,15 @@ template void Writer::writeBuildId() { // other sections are the same. uint8_t *Start = Buffer->getBufferStart(); uint8_t *Last = Start; + std::vector> Regions; for (OutputSectionBase *Sec : OutputSections) { uint8_t *End = Start + Sec->getFileOff(); if (!Sec->getName().startswith(".debug_")) - S->update({Last, End}); + Regions.push_back({Last, End}); Last = End; } - S->update({Last, Start + FileSize}); - - // Fill the hash value field in the .note.gnu.build-id section. - S->writeBuildId(); + Regions.push_back({Last, Start + FileSize}); + S->writeBuildId(Regions); } template void elf::writeResult(SymbolTable *Symtab);