diff options
-rw-r--r-- | llvm/include/llvm/Bitcode/BitstreamReader.h | 2 | ||||
-rw-r--r-- | llvm/include/llvm/Bitcode/LLVMBitCodes.h | 4 | ||||
-rw-r--r-- | llvm/include/llvm/Bitcode/ReaderWriter.h | 3 | ||||
-rw-r--r-- | llvm/include/llvm/IR/ModuleSummaryIndex.h | 43 | ||||
-rw-r--r-- | llvm/include/llvm/Support/SHA1.h | 73 | ||||
-rw-r--r-- | llvm/include/llvm/Support/raw_sha1_ostream.h | 46 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 54 | ||||
-rw-r--r-- | llvm/lib/Bitcode/Writer/BitcodeWriter.cpp | 74 | ||||
-rw-r--r-- | llvm/lib/IR/ModuleSummaryIndex.cpp | 8 | ||||
-rw-r--r-- | llvm/lib/Support/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/lib/Support/SHA1.cpp | 168 | ||||
-rw-r--r-- | llvm/lib/Transforms/IPO/FunctionImport.cpp | 2 | ||||
-rw-r--r-- | llvm/test/Bitcode/Inputs/module_hash.ll | 4 | ||||
-rw-r--r-- | llvm/test/Bitcode/module_hash.ll | 35 | ||||
-rw-r--r-- | llvm/tools/llvm-as/llvm-as.cpp | 5 | ||||
-rw-r--r-- | llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp | 40 | ||||
-rw-r--r-- | llvm/unittests/Support/CMakeLists.txt | 1 | ||||
-rw-r--r-- | llvm/unittests/Support/raw_sha1_ostream_test.cpp | 72 |
18 files changed, 38 insertions, 597 deletions
diff --git a/llvm/include/llvm/Bitcode/BitstreamReader.h b/llvm/include/llvm/Bitcode/BitstreamReader.h index b331ceea051..628a83cb0de 100644 --- a/llvm/include/llvm/Bitcode/BitstreamReader.h +++ b/llvm/include/llvm/Bitcode/BitstreamReader.h @@ -446,8 +446,6 @@ public: using SimpleBitstreamCursor::canSkipToPos; using SimpleBitstreamCursor::AtEndOfStream; using SimpleBitstreamCursor::GetCurrentBitNo; - using SimpleBitstreamCursor::getCurrentByteNo; - using SimpleBitstreamCursor::getPointerToByte; using SimpleBitstreamCursor::getBitStreamReader; using SimpleBitstreamCursor::JumpToBit; using SimpleBitstreamCursor::fillCurWord; diff --git a/llvm/include/llvm/Bitcode/LLVMBitCodes.h b/llvm/include/llvm/Bitcode/LLVMBitCodes.h index 0c4cc854cdc..a93ed58ebb9 100644 --- a/llvm/include/llvm/Bitcode/LLVMBitCodes.h +++ b/llvm/include/llvm/Bitcode/LLVMBitCodes.h @@ -107,9 +107,6 @@ enum ModuleCodes { // SOURCE_FILENAME: [namechar x N] MODULE_CODE_SOURCE_FILENAME = 16, - - // HASH: [5*i32] - MODULE_CODE_HASH = 17, }; /// PARAMATTR blocks have code for defining a parameter attribute set. @@ -186,7 +183,6 @@ enum ValueSymtabCodes { // The module path symbol table only has one code (MST_CODE_ENTRY). enum ModulePathSymtabCodes { MST_CODE_ENTRY = 1, // MST_ENTRY: [modid, namechar x N] - MST_CODE_HASH = 2, // MST_HASH: [5*i32] }; // The summary section uses different codes in the per-module diff --git a/llvm/include/llvm/Bitcode/ReaderWriter.h b/llvm/include/llvm/Bitcode/ReaderWriter.h index 1afffa05527..bbce15a8f93 100644 --- a/llvm/include/llvm/Bitcode/ReaderWriter.h +++ b/llvm/include/llvm/Bitcode/ReaderWriter.h @@ -107,8 +107,7 @@ namespace llvm { /// for use in ThinLTO optimization). void WriteBitcodeToFile(const Module *M, raw_ostream &Out, bool ShouldPreserveUseListOrder = false, - bool EmitSummaryIndex = false, - bool GenerateHash = false); + bool EmitSummaryIndex = false); /// Write the specified module summary index to the given raw output stream, /// where it will be written in a new bitcode block. This is used when diff --git a/llvm/include/llvm/IR/ModuleSummaryIndex.h b/llvm/include/llvm/IR/ModuleSummaryIndex.h index fe0385e76b9..30a7145cb42 100644 --- a/llvm/include/llvm/IR/ModuleSummaryIndex.h +++ b/llvm/include/llvm/IR/ModuleSummaryIndex.h @@ -25,8 +25,6 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" -#include <array> - namespace llvm { /// \brief Class to accumulate and hold information about a callee. @@ -230,9 +228,6 @@ public: void setBitcodeIndex(uint64_t Offset) { BitcodeIndex = Offset; } }; -/// 160 bits SHA1 -typedef std::array<uint32_t, 5> ModuleHash; - /// List of global value info structures for a particular value held /// in the GlobalValueMap. Requires a vector in the case of multiple /// COMDAT values of the same name. @@ -250,9 +245,9 @@ typedef GlobalValueInfoMapTy::const_iterator const_globalvalueinfo_iterator; typedef GlobalValueInfoMapTy::iterator globalvalueinfo_iterator; /// String table to hold/own module path strings, which additionally holds the -/// module ID assigned to each module during the plugin step, as well as a hash -/// of the module. The StringMap makes a copy of and owns inserted strings. -typedef StringMap<std::pair<uint64_t, ModuleHash>> ModulePathStringTableTy; +/// module ID assigned to each module during the plugin step. The StringMap +/// makes a copy of and owns inserted strings. +typedef StringMap<uint64_t> ModulePathStringTableTy; /// Class to hold module path string table and global value map, /// and encapsulate methods for operating on them. @@ -309,26 +304,17 @@ public: GlobalValueMap[ValueGUID].push_back(std::move(Info)); } - /// Table of modules, containing module hash and id. - const StringMap<std::pair<uint64_t, ModuleHash>> &modulePaths() const { + /// Table of modules, containing an id. + const StringMap<uint64_t> &modulePaths() const { return ModulePathStringTable; } - /// Table of modules, containing hash and id. - StringMap<std::pair<uint64_t, ModuleHash>> &modulePaths() { - return ModulePathStringTable; - } + /// Table of modules, containing an id. + StringMap<uint64_t> &modulePaths() { return ModulePathStringTable; } /// Get the module ID recorded for the given module path. uint64_t getModuleId(const StringRef ModPath) const { - return ModulePathStringTable.lookup(ModPath).first; - } - - /// Get the module SHA1 hash recorded for the given module path. - const ModuleHash &getModuleHash(const StringRef ModPath) const { - auto It = ModulePathStringTable.find(ModPath); - assert(It != ModulePathStringTable.end() && "Module not registered"); - return It->second.second; + return ModulePathStringTable.lookup(ModPath); } /// Add the given per-module index into this module index/summary, @@ -347,14 +333,11 @@ public: return NewName.str(); } - /// Add a new module path with the given \p Hash, mapped to the given \p - /// ModID, and return an iterator to the entry in the index. - ModulePathStringTableTy::iterator - addModulePath(StringRef ModPath, uint64_t ModId, - ModuleHash Hash = ModuleHash{{0}}) { - return ModulePathStringTable.insert(std::make_pair( - ModPath, - std::make_pair(ModId, Hash))).first; + /// Add a new module path, mapped to the given module Id, and return StringRef + /// owned by string table map. + StringRef addModulePath(StringRef ModPath, uint64_t ModId) { + return ModulePathStringTable.insert(std::make_pair(ModPath, ModId)) + .first->first(); } /// Check if the given Module has any functions available for exporting diff --git a/llvm/include/llvm/Support/SHA1.h b/llvm/include/llvm/Support/SHA1.h deleted file mode 100644 index 68365ad381d..00000000000 --- a/llvm/include/llvm/Support/SHA1.h +++ /dev/null @@ -1,73 +0,0 @@ -//==- SHA1.h - SHA1 implementation for LLVM --*- C++ -*-==// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// This code is taken from public domain -// (http://oauth.googlecode.com/svn/code/c/liboauth/src/sha1.c) -// and modified by wrapping it in a C++ interface for LLVM, -// and removing unnecessary code. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_SUPPORT_SHA1_H -#define LLVM_SUPPORT_SHA1_H - -#include "llvm/ADT/ArrayRef.h" -#include "llvm/ADT/StringRef.h" - -#include <cstdint> - -namespace llvm { - -/// A class that wrap the SHA1 algorithm. -class SHA1 { -public: - SHA1() { init(); } - - /// Reinitialize the internal state - void init(); - - /// Digest more data. - void update(ArrayRef<uint8_t> Data); - - /// Return a reference to the current raw 160-bits SHA1 for the digested data - /// since the last call to init(). This call will add data to the internal - /// state and as such is not suited for getting an intermediate result - /// (see result()). - StringRef final(); - - /// Return a reference to the current raw 160-bits SHA1 for the digested data - /// since the last call to init(). This is suitable for getting the SHA1 at - /// any time without invalidating the internal state so that more calls can be - /// made into update. - StringRef result(); - -private: - static constexpr int BLOCK_LENGTH = 64; - static constexpr int HASH_LENGTH = 20; - - // Internal State - struct { - uint32_t Buffer[BLOCK_LENGTH / 4]; - uint32_t State[HASH_LENGTH / 4]; - uint32_t ByteCount; - uint8_t BufferOffset; - } InternalState; - - // Internal copy of the hash, populated and accessed on calls to result() - uint32_t HashResult[HASH_LENGTH / 4]; - - // Helper - void writebyte(uint8_t data); - void hashBlock(); - void addUncounted(uint8_t data); - void pad(); -}; - -} // end llvm namespace - -#endif diff --git a/llvm/include/llvm/Support/raw_sha1_ostream.h b/llvm/include/llvm/Support/raw_sha1_ostream.h deleted file mode 100644 index 9f136dfa7e1..00000000000 --- a/llvm/include/llvm/Support/raw_sha1_ostream.h +++ /dev/null @@ -1,46 +0,0 @@ -//==- raw_sha1_ostream.h - raw_ostream that compute SHA1 --*- C++ -*-==// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// -// This file defines the raw_sha1_ostream class. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_SUPPORT_RAW_SHA1_OSTREAM_H -#define LLVM_SUPPORT_RAW_SHA1_OSTREAM_H - -#include "llvm/Support/raw_ostream.h" -#include "llvm/Support/SHA1.h" - -namespace llvm { - -/// A raw_ostream that hash the content using the sha1 algorithm. -class raw_sha1_ostream : public raw_ostream { - SHA1 State; - - /// See raw_ostream::write_impl. - void write_impl(const char *Ptr, size_t Size) override { - State.update(ArrayRef<uint8_t>((uint8_t *)Ptr, Size)); - } - -public: - /// Return the current SHA1 hash for the content of the stream - StringRef sha1() { - flush(); - return State.result(); - } - - /// Reset the internal state to start over from scratch. - void resetHash() { State.init(); } - - uint64_t current_pos() const override { return 0; } -}; - -} // end llvm namespace - -#endif diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 1840b60cc01..93496fe8e6f 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -5632,7 +5632,11 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseModule() { } continue; - case BitstreamEntry::Record: { + case BitstreamEntry::Record: + // Once we find the last record of interest, skip the rest. + if (VSTOffset > 0) + Stream.skipRecord(Entry.ID); + else { Record.clear(); auto BitCode = Stream.readRecord(Entry.ID, Record); switch (BitCode) { @@ -5646,25 +5650,6 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseModule() { SourceFileName = ValueName.c_str(); break; } - /// MODULE_CODE_HASH: [5*i32] - case bitc::MODULE_CODE_HASH: { - if (Record.size() != 5) - return error("Invalid hash length " + Twine(Record.size()).str()); - if (!TheIndex) - break; - if (TheIndex->modulePaths().empty()) - // Does not have any summary emitted. - break; - if (TheIndex->modulePaths().size() != 1) - return error("Don't expect multiple modules defined?"); - auto &Hash = TheIndex->modulePaths().begin()->second.second; - int Pos = 0; - for (auto &Val : Record) { - assert(!(Val >> 32) && "Unexpected high bits set"); - Hash[Pos++] = Val; - } - break; - } /// MODULE_CODE_VSTOFFSET: [offset] case bitc::MODULE_CODE_VSTOFFSET: if (Record.size() < 1) @@ -5776,7 +5761,7 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() { // module path string table entry with an empty (0) ID to take // ownership. FS->setModulePath( - TheIndex->addModulePath(Buffer->getBufferIdentifier(), 0)->first()); + TheIndex->addModulePath(Buffer->getBufferIdentifier(), 0)); static int RefListStartIndex = 4; int CallGraphEdgeStartIndex = RefListStartIndex + NumRefs; assert(Record.size() >= RefListStartIndex + NumRefs && @@ -5814,7 +5799,7 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseEntireSummary() { std::unique_ptr<GlobalVarSummary> FS = llvm::make_unique<GlobalVarSummary>(getDecodedLinkage(RawLinkage)); FS->setModulePath( - TheIndex->addModulePath(Buffer->getBufferIdentifier(), 0)->first()); + TheIndex->addModulePath(Buffer->getBufferIdentifier(), 0)); for (unsigned I = 2, E = Record.size(); I != E; ++I) { unsigned RefValueId = Record[I]; uint64_t RefGUID = getGUIDFromValueId(RefValueId); @@ -5902,7 +5887,6 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseModuleStringTable() { SmallVector<uint64_t, 64> Record; SmallString<128> ModulePath; - ModulePathStringTableTy::iterator LastSeenModulePath; while (1) { BitstreamEntry Entry = Stream.advanceSkippingSubblocks(); @@ -5923,32 +5907,14 @@ std::error_code ModuleSummaryIndexBitcodeReader::parseModuleStringTable() { break; case bitc::MST_CODE_ENTRY: { // MST_ENTRY: [modid, namechar x N] - uint64_t ModuleId = Record[0]; - if (convertToString(Record, 1, ModulePath)) return error("Invalid record"); - - LastSeenModulePath = TheIndex->addModulePath(ModulePath, ModuleId); - ModuleIdMap[ModuleId] = LastSeenModulePath->first(); - + uint64_t ModuleId = Record[0]; + StringRef ModulePathInMap = TheIndex->addModulePath(ModulePath, ModuleId); + ModuleIdMap[ModuleId] = ModulePathInMap; ModulePath.clear(); break; } - /// MST_CODE_HASH: [5*i32] - case bitc::MST_CODE_HASH: { - if (Record.size() != 5) - return error("Invalid hash length " + Twine(Record.size()).str()); - if (LastSeenModulePath == TheIndex->modulePaths().end()) - return error("Invalid hash that does not follow a module path"); - int Pos = 0; - for (auto &Val : Record) { - assert(!(Val >> 32) && "Unexpected high bits set"); - LastSeenModulePath->second.second[Pos++] = Val; - } - // Reset LastSeenModulePath to avoid overriding the hash unexpectedly. - LastSeenModulePath = TheIndex->modulePaths().end(); - break; - } } } llvm_unreachable("Exit infinite loop"); diff --git a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp index 18fb7ad8d11..c1513416817 100644 --- a/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp +++ b/llvm/lib/Bitcode/Writer/BitcodeWriter.cpp @@ -12,7 +12,6 @@ //===----------------------------------------------------------------------===// #include "ValueEnumerator.h" -#include "llvm/ADT/StringExtras.h" #include "llvm/ADT/STLExtras.h" #include "llvm/ADT/Triple.h" #include "llvm/Analysis/BlockFrequencyInfo.h" @@ -40,7 +39,6 @@ #include "llvm/Support/MathExtras.h" #include "llvm/Support/Program.h" #include "llvm/Support/raw_ostream.h" -#include "llvm/Support/SHA1.h" #include <cctype> #include <map> using namespace llvm; @@ -2854,18 +2852,8 @@ static void WriteModStrings(const ModuleSummaryIndex &I, Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Char6)); unsigned Abbrev6Bit = Stream.EmitAbbrev(Abbv); - // Module Hash, 160 bits SHA1. Optionally, emitted after each MST_CODE_ENTRY. - Abbv = new BitCodeAbbrev(); - Abbv->Add(BitCodeAbbrevOp(bitc::MST_CODE_HASH)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); - Abbv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 32)); - unsigned AbbrevHash = Stream.EmitAbbrev(Abbv); - - SmallVector<unsigned, 64> Vals; - for (const auto &MPSE : I.modulePaths()) { + SmallVector<unsigned, 64> NameVals; + for (const StringMapEntry<uint64_t> &MPSE : I.modulePaths()) { StringEncoding Bits = getStringEncoding(MPSE.getKey().data(), MPSE.getKey().size()); unsigned AbbrevToUse = Abbrev8Bit; @@ -2874,29 +2862,14 @@ static void WriteModStrings(const ModuleSummaryIndex &I, else if (Bits == SE_Fixed7) AbbrevToUse = Abbrev7Bit; - Vals.push_back(MPSE.getValue().first); + NameVals.push_back(MPSE.getValue()); for (const auto P : MPSE.getKey()) - Vals.push_back((unsigned char)P); + NameVals.push_back((unsigned char)P); // Emit the finished record. - Stream.EmitRecord(bitc::MST_CODE_ENTRY, Vals, AbbrevToUse); - - Vals.clear(); - // Emit an optional hash for the module now - auto &Hash = MPSE.getValue().second; - bool AllZero = true; // Detect if the hash is empty, and do not generate it - for (auto Val : Hash) { - if (Val) - AllZero = false; - Vals.push_back(Val); - } - if (!AllZero) { - // Emit the hash record. - Stream.EmitRecord(bitc::MST_CODE_HASH, Vals, AbbrevHash); - } - - Vals.clear(); + Stream.EmitRecord(bitc::MST_CODE_ENTRY, NameVals, AbbrevToUse); + NameVals.clear(); } Stream.ExitBlock(); } @@ -3204,36 +3177,11 @@ static void WriteIdentificationBlock(const Module *M, BitstreamWriter &Stream) { Stream.ExitBlock(); } -static void writeModuleHash(BitstreamWriter &Stream, - SmallVectorImpl<char> &Buffer, - size_t BlockStartPos) { - // Emit the module's hash. - // MODULE_CODE_HASH: [5*i32] - SHA1 Hasher; - Hasher.update(ArrayRef<uint8_t>((uint8_t *)&Buffer[BlockStartPos], - Buffer.size() - BlockStartPos)); - auto Hash = Hasher.result(); - SmallVector<uint64_t, 20> Vals; - auto LShift = [&](unsigned char Val, unsigned Amount) - -> uint64_t { return ((uint64_t)Val) << Amount; }; - for (int Pos = 0; Pos < 20; Pos += 4) { - uint32_t SubHash = LShift(Hash[Pos + 0], 24); - SubHash |= LShift(Hash[Pos + 1], 16) | LShift(Hash[Pos + 2], 8) | - (unsigned)(unsigned char)Hash[Pos + 3]; - Vals.push_back(SubHash); - } - - // Emit the finished record. - Stream.EmitRecord(bitc::MODULE_CODE_HASH, Vals); -} - /// WriteModule - Emit the specified module to the bitstream. static void WriteModule(const Module *M, BitstreamWriter &Stream, bool ShouldPreserveUseListOrder, - uint64_t BitcodeStartBit, bool EmitSummaryIndex, - bool GenerateHash, SmallVectorImpl<char> &Buffer) { + uint64_t BitcodeStartBit, bool EmitSummaryIndex) { Stream.EnterSubblock(bitc::MODULE_BLOCK_ID, 3); - size_t BlockStartPos = Buffer.size(); SmallVector<unsigned, 1> Vals; unsigned CurVersion = 1; @@ -3290,10 +3238,6 @@ static void WriteModule(const Module *M, BitstreamWriter &Stream, WriteValueSymbolTable(M->getValueSymbolTable(), VE, Stream, VSTOffsetPlaceholder, BitcodeStartBit, &FunctionIndex); - if (GenerateHash) { - writeModuleHash(Stream, Buffer, BlockStartPos); - } - Stream.ExitBlock(); } @@ -3378,7 +3322,7 @@ static void WriteBitcodeHeader(BitstreamWriter &Stream) { /// stream. void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out, bool ShouldPreserveUseListOrder, - bool EmitSummaryIndex, bool GenerateHash) { + bool EmitSummaryIndex) { SmallVector<char, 0> Buffer; Buffer.reserve(256*1024); @@ -3404,7 +3348,7 @@ void llvm::WriteBitcodeToFile(const Module *M, raw_ostream &Out, // Emit the module. WriteModule(M, Stream, ShouldPreserveUseListOrder, BitcodeStartBit, - EmitSummaryIndex, GenerateHash, Buffer); + EmitSummaryIndex); } if (TT.isOSDarwin() || TT.isOSBinFormatMachO()) diff --git a/llvm/lib/IR/ModuleSummaryIndex.cpp b/llvm/lib/IR/ModuleSummaryIndex.cpp index c23e072b48a..16b58ddbeff 100644 --- a/llvm/lib/IR/ModuleSummaryIndex.cpp +++ b/llvm/lib/IR/ModuleSummaryIndex.cpp @@ -37,11 +37,9 @@ void ModuleSummaryIndex::mergeFrom(std::unique_ptr<ModuleSummaryIndex> Other, // Add the module path string ref for this module if we haven't already // saved a reference to it. - if (ModPath.empty()) { - auto Path = Info->summary()->modulePath(); - ModPath = addModulePath(Path, NextModuleId, Other->getModuleHash(Path)) - ->first(); - } else + if (ModPath.empty()) + ModPath = addModulePath(Info->summary()->modulePath(), NextModuleId); + else assert(ModPath == Info->summary()->modulePath() && "Each module in the combined map should have a unique ID"); diff --git a/llvm/lib/Support/CMakeLists.txt b/llvm/lib/Support/CMakeLists.txt index 241f2bc338c..98108e54cf2 100644 --- a/llvm/lib/Support/CMakeLists.txt +++ b/llvm/lib/Support/CMakeLists.txt @@ -75,7 +75,6 @@ add_llvm_library(LLVMSupport RandomNumberGenerator.cpp Regex.cpp ScaledNumber.cpp - SHA1.cpp SmallPtrSet.cpp SmallVector.cpp SourceMgr.cpp diff --git a/llvm/lib/Support/SHA1.cpp b/llvm/lib/Support/SHA1.cpp deleted file mode 100644 index 50fa698a4be..00000000000 --- a/llvm/lib/Support/SHA1.cpp +++ /dev/null @@ -1,168 +0,0 @@ -//======- SHA1.h - Private copy of the SHA1 implementation ---*- C++ -* ======// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// -// This code is taken from public domain -// (http://oauth.googlecode.com/svn/code/c/liboauth/src/sha1.c) -// and modified by wrapping it in a C++ interface for LLVM, -// and removing unnecessary code. -// -//===----------------------------------------------------------------------===// - -#include "llvm/Support/SHA1.h" -using namespace llvm; - -#include <stdint.h> -#include <string.h> - -#ifdef __BIG_ENDIAN__ -#define SHA_BIG_ENDIAN -#endif - -/* code */ -#define SHA1_K0 0x5a827999 -#define SHA1_K20 0x6ed9eba1 -#define SHA1_K40 0x8f1bbcdc -#define SHA1_K60 0xca62c1d6 - -#define SEED_0 0x67452301 -#define SEED_1 0xefcdab89 -#define SEED_2 0x98badcfe -#define SEED_3 0x10325476 -#define SEED_4 0xc3d2e1f0 - -void SHA1::init() { - InternalState.State[0] = SEED_0; - InternalState.State[1] = SEED_1; - InternalState.State[2] = SEED_2; - InternalState.State[3] = SEED_3; - InternalState.State[4] = SEED_4; - InternalState.ByteCount = 0; - InternalState.BufferOffset = 0; -} - -static uint32_t rol32(uint32_t number, uint8_t bits) { - return ((number << bits) | (number >> (32 - bits))); -} - -void SHA1::hashBlock() { - uint8_t i; - uint32_t a, b, c, d, e, t; - - a = InternalState.State[0]; - b = InternalState.State[1]; - c = InternalState.State[2]; - d = InternalState.State[3]; - e = InternalState.State[4]; - for (i = 0; i < 80; i++) { - if (i >= 16) { - t = InternalState.Buffer[(i + 13) & 15] ^ - InternalState.Buffer[(i + 8) & 15] ^ - InternalState.Buffer[(i + 2) & 15] ^ InternalState.Buffer[i & 15]; - InternalState.Buffer[i & 15] = rol32(t, 1); - } - if (i < 20) { - t = (d ^ (b & (c ^ d))) + SHA1_K0; - } else if (i < 40) { - t = (b ^ c ^ d) + SHA1_K20; - } else if (i < 60) { - t = ((b & c) | (d & (b | c))) + SHA1_K40; - } else { - t = (b ^ c ^ d) + SHA1_K60; - } - t += rol32(a, 5) + e + InternalState.Buffer[i & 15]; - e = d; - d = c; - c = rol32(b, 30); - b = a; - a = t; - } - InternalState.State[0] += a; - InternalState.State[1] += b; - InternalState.State[2] += c; - InternalState.State[3] += d; - InternalState.State[4] += e; -} - -void SHA1::addUncounted(uint8_t data) { - uint8_t *const b = (uint8_t *)InternalState.Buffer; -#ifdef SHA_BIG_ENDIAN - b[InternalState.BufferOffset] = data; -#else - b[InternalState.BufferOffset ^ 3] = data; -#endif - InternalState.BufferOffset++; - if (InternalState.BufferOffset == BLOCK_LENGTH) { - hashBlock(); - InternalState.BufferOffset = 0; - } -} - -void SHA1::writebyte(uint8_t data) { - ++InternalState.ByteCount; - addUncounted(data); -} - -void SHA1::update(ArrayRef<uint8_t> Data) { - for (auto &C : Data) - writebyte(C); -} - -void SHA1::pad() { - // Implement SHA-1 padding (fips180-2 ยง5.1.1) - - // Pad with 0x80 followed by 0x00 until the end of the block - addUncounted(0x80); - while (InternalState.BufferOffset != 56) - addUncounted(0x00); - - // Append length in the last 8 bytes - addUncounted(0); // We're only using 32 bit lengths - addUncounted(0); // But SHA-1 supports 64 bit lengths - addUncounted(0); // So zero pad the top bits - addUncounted(InternalState.ByteCount >> 29); // Shifting to multiply by 8 - addUncounted(InternalState.ByteCount >> - 21); // as SHA-1 supports bitstreams as well as - addUncounted(InternalState.ByteCount >> 13); // byte. - addUncounted(InternalState.ByteCount >> 5); - addUncounted(InternalState.ByteCount << 3); -} - -StringRef SHA1::final() { - // Pad to complete the last block - pad(); - -#ifdef SHA_BIG_ENDIAN - // Just copy the current state - for (int i = 0; i < 5; i++) { - HashResult[i] = InternalState.State[i]; - } -#else - // Swap byte order back - for (int i = 0; i < 5; i++) { - HashResult[i] = (((InternalState.State[i]) << 24) & 0xff000000) | - (((InternalState.State[i]) << 8) & 0x00ff0000) | - (((InternalState.State[i]) >> 8) & 0x0000ff00) | - (((InternalState.State[i]) >> 24) & 0x000000ff); - } -#endif - - // Return pointer to hash (20 characters) - return StringRef((char *)HashResult, HASH_LENGTH); -} - -StringRef SHA1::result() { - auto StateToRestore = InternalState; - - auto Hash = final(); - - // Restore the state - InternalState = StateToRestore; - - // Return pointer to hash (20 characters) - return Hash; -} diff --git a/llvm/lib/Transforms/IPO/FunctionImport.cpp b/llvm/lib/Transforms/IPO/FunctionImport.cpp index b5f1ffb046f..255a5582745 100644 --- a/llvm/lib/Transforms/IPO/FunctionImport.cpp +++ b/llvm/lib/Transforms/IPO/FunctionImport.cpp @@ -61,7 +61,7 @@ static std::unique_ptr<Module> loadFile(const std::string &FileName, /* ShouldLazyLoadMetadata = */ true); if (!Result) { Err.print("function-import", errs()); - report_fatal_error("Abort"); + return nullptr; } return Result; diff --git a/llvm/test/Bitcode/Inputs/module_hash.ll b/llvm/test/Bitcode/Inputs/module_hash.ll deleted file mode 100644 index 1d422c6e817..00000000000 --- a/llvm/test/Bitcode/Inputs/module_hash.ll +++ /dev/null @@ -1,4 +0,0 @@ -; Needs a function for the combined index to be populated -define void @bar() { - ret void -} diff --git a/llvm/test/Bitcode/module_hash.ll b/llvm/test/Bitcode/module_hash.ll deleted file mode 100644 index 70977b104c6..00000000000 --- a/llvm/test/Bitcode/module_hash.ll +++ /dev/null @@ -1,35 +0,0 @@ -; Check per module hash. -; RUN: llvm-as -module-hash %s -o - | llvm-bcanalyzer -dump | FileCheck %s --check-prefix=MOD1 -; MOD1: <HASH op0={{[0-9]*}} op1={{[0-9]*}} op2={{[0-9]*}} op3={{[0-9]*}} op4={{[0-9]*}} (match)/> -; RUN: llvm-as -module-hash %p/Inputs/module_hash.ll -o - | llvm-bcanalyzer -dump | FileCheck %s --check-prefix=MOD2 -; MOD2: <HASH op0={{[0-9]*}} op1={{[0-9]*}} op2={{[0-9]*}} op3={{[0-9]*}} op4={{[0-9]*}} (match)/> - -; Check that the hash matches in the combined index. - -; First regenerate the modules with a summary -; RUN: llvm-as -module-hash -module-summary %s -o %t.m1.bc -; RUN: llvm-as -module-hash -module-summary %p/Inputs/module_hash.ll -o %t.m2.bc - -; Recover the hashes from the modules themselves. -; RUN: llvm-bcanalyzer -dump %t1 | grep '<HASH' > %t.hash -; RUN: llvm-bcanalyzer -dump %t2 | grep '<HASH' >> %t.hash - -; Generate the combined index and gather the hashes there. -; RUN: llvm-lto --thinlto-action=thinlink -o - %t.m1.bc %t.m2.bc | llvm-bcanalyzer -dump | grep '<HASH ' >> %t.hash - -; Validate the output now, the hahes in the individual modules and the combined index are in the same file. -; RUN: cat %t.hash | FileCheck %s --check-prefix=COMBINED - -; First capture the value of the hash for the two modules. -; COMBINED: <HASH op0=[[HASH1_1:[0-9]*]] op1=[[HASH1_2:[0-9]*]] op2=[[HASH1_3:[0-9]*]] op3=[[HASH1_4:[0-9]*]] op4=[[HASH1_5:[0-9]*]] (match)/> -; COMBINED: <HASH op0=[[HASH2_1:[0-9]*]] op1=[[HASH2_2:[0-9]*]] op2=[[HASH2_3:[0-9]*]] op3=[[HASH2_4:[0-9]*]] op4=[[HASH2_5:[0-9]*]] (match)/> - -; Validate against the value extracted from the combined index -; COMBINED-DAG: <HASH abbrevid={{[0-9]*}} op0=[[HASH1_1]] op1=[[HASH1_2]] op2=[[HASH1_3]] op3=[[HASH1_4]] op4=[[HASH1_5]]/> -; COMBINED-DAG: <HASH abbrevid={{[0-9]*}} op0=[[HASH2_1]] op1=[[HASH2_2]] op2=[[HASH2_3]] op3=[[HASH2_4]] op4=[[HASH2_5]]/> - - -; Need a function for the combined index to be populated. -define void @foo() { - ret void -} diff --git a/llvm/tools/llvm-as/llvm-as.cpp b/llvm/tools/llvm-as/llvm-as.cpp index 7e9500a6672..7318bfe341d 100644 --- a/llvm/tools/llvm-as/llvm-as.cpp +++ b/llvm/tools/llvm-as/llvm-as.cpp @@ -48,9 +48,6 @@ static cl::opt<bool> EmitSummaryIndex("module-summary", cl::desc("Emit module summary index"), cl::init(false)); -static cl::opt<bool> EmitModuleHash("module-hash", cl::desc("Emit module hash"), - cl::init(false)); - static cl::opt<bool> DumpAsm("d", cl::desc("Print assembly as parsed"), cl::Hidden); @@ -85,7 +82,7 @@ static void WriteOutputFile(const Module *M) { if (Force || !CheckBitcodeOutputToConsole(Out->os(), true)) WriteBitcodeToFile(M, Out->os(), PreserveBitcodeUseListOrder, - EmitSummaryIndex, EmitModuleHash); + EmitSummaryIndex); // Declare success. Out->keep(); diff --git a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp index 85dd5f52daa..6645045db8f 100644 --- a/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp +++ b/llvm/tools/llvm-bcanalyzer/llvm-bcanalyzer.cpp @@ -29,7 +29,6 @@ #include "llvm/Bitcode/BitstreamReader.h" #include "llvm/ADT/Optional.h" -#include "llvm/ADT/StringExtras.h" #include "llvm/Bitcode/LLVMBitCodes.h" #include "llvm/Bitcode/ReaderWriter.h" #include "llvm/IR/Verifier.h" @@ -39,10 +38,8 @@ #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/PrettyStackTrace.h" #include "llvm/Support/Signals.h" -#include "llvm/Support/SHA1.h" #include "llvm/Support/raw_ostream.h" #include <algorithm> -#include <array> #include <cctype> #include <map> #include <system_error> @@ -177,7 +174,6 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID, STRINGIFY_CODE(MODULE_CODE, VSTOFFSET) STRINGIFY_CODE(MODULE_CODE, METADATA_VALUES_UNUSED) STRINGIFY_CODE(MODULE_CODE, SOURCE_FILENAME) - STRINGIFY_CODE(MODULE_CODE, HASH) } case bitc::IDENTIFICATION_BLOCK_ID: switch (CodeID) { @@ -296,7 +292,6 @@ static const char *GetCodeName(unsigned CodeID, unsigned BlockID, default: return nullptr; STRINGIFY_CODE(MST_CODE, ENTRY) - STRINGIFY_CODE(MST_CODE, HASH) } case bitc::GLOBALVAL_SUMMARY_BLOCK_ID: switch (CodeID) { @@ -486,9 +481,6 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned BlockID, if (Stream.EnterSubBlock(BlockID, &NumWords)) return Error("Malformed block record"); - // Keep it for later, when we see a MODULE_HASH record - uint64_t BlockEntryPos = Stream.getCurrentByteNo(); - const char *BlockName = nullptr; if (DumpRecords) { outs() << Indent << "<"; @@ -560,7 +552,6 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned BlockID, ++BlockStats.NumRecords; StringRef Blob; - unsigned CurrentRecordPos = Stream.getCurrentByteNo(); unsigned Code = Stream.readRecord(Entry.ID, Record, &Blob); // Increment the # occurrences of this code. @@ -595,37 +586,6 @@ static bool ParseBlock(BitstreamCursor &Stream, unsigned BlockID, for (unsigned i = 0, e = Record.size(); i != e; ++i) outs() << " op" << i << "=" << (int64_t)Record[i]; - // If we found a module hash, let's verify that it matches! - if (BlockID == bitc::MODULE_BLOCK_ID && Code == bitc::MODULE_CODE_HASH) { - if (Record.size() != 5) - outs() << " (invalid)"; - else { - // Recompute the hash and compare it to the one in the bitcode - SHA1 Hasher; - StringRef Hash; - { - int BlockSize = CurrentRecordPos - BlockEntryPos; - auto Ptr = Stream.getPointerToByte(BlockEntryPos, BlockSize); - Hasher.update(ArrayRef<uint8_t>(Ptr, BlockSize)); - Hash = Hasher.result(); - } - SmallString<20> RecordedHash; - RecordedHash.resize(20); - int Pos = 0; - for (auto &Val : Record) { - assert(!(Val >> 32) && "Unexpected high bits set"); - RecordedHash[Pos++] = (Val >> 24) & 0xFF; - RecordedHash[Pos++] = (Val >> 16) & 0xFF; - RecordedHash[Pos++] = (Val >> 8) & 0xFF; - RecordedHash[Pos++] = (Val >> 0) & 0xFF; - } - if (Hash == RecordedHash) - outs() << " (match)"; - else - outs() << " (!mismatch!)"; - } - } - outs() << "/>"; if (Abbv) { diff --git a/llvm/unittests/Support/CMakeLists.txt b/llvm/unittests/Support/CMakeLists.txt index 9a4a1445091..f02d501538b 100644 --- a/llvm/unittests/Support/CMakeLists.txt +++ b/llvm/unittests/Support/CMakeLists.txt @@ -52,7 +52,6 @@ add_llvm_unittest(SupportTests formatted_raw_ostream_test.cpp raw_ostream_test.cpp raw_pwrite_stream_test.cpp - raw_sha1_ostream_test.cpp ) # ManagedStatic.cpp uses <pthread>. diff --git a/llvm/unittests/Support/raw_sha1_ostream_test.cpp b/llvm/unittests/Support/raw_sha1_ostream_test.cpp deleted file mode 100644 index ca80cdac49e..00000000000 --- a/llvm/unittests/Support/raw_sha1_ostream_test.cpp +++ /dev/null @@ -1,72 +0,0 @@ -//===- llvm/unittest/Support/raw_ostream_test.cpp - raw_ostream tests -----===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "gtest/gtest.h" -#include "llvm/ADT/SmallString.h" -#include "llvm/Support/Format.h" -#include "llvm/Support/raw_sha1_ostream.h" - -#include <string> - -using namespace llvm; - -static std::string toHex(StringRef Input) { - static const char *const LUT = "0123456789ABCDEF"; - size_t Length = Input.size(); - - std::string Output; - Output.reserve(2 * Length); - for (size_t i = 0; i < Length; ++i) { - const unsigned char c = Input[i]; - Output.push_back(LUT[c >> 4]); - Output.push_back(LUT[c & 15]); - } - return Output; -} - -TEST(raw_sha1_ostreamTest, Basic) { - llvm::raw_sha1_ostream Sha1Stream; - Sha1Stream << "Hello World!"; - auto Hash = toHex(Sha1Stream.sha1()); - - ASSERT_EQ("2EF7BDE608CE5404E97D5F042F95F89F1C232871", Hash); -} - -// Check that getting the intermediate hash in the middle of the stream does -// not invalidate the final result. -TEST(raw_sha1_ostreamTest, Intermediate) { - llvm::raw_sha1_ostream Sha1Stream; - Sha1Stream << "Hello"; - auto Hash = toHex(Sha1Stream.sha1()); - - ASSERT_EQ("F7FF9E8B7BB2E09B70935A5D785E0CC5D9D0ABF0", Hash); - Sha1Stream << " World!"; - Hash = toHex(Sha1Stream.sha1()); - - // Compute the non-split hash separately as a reference. - llvm::raw_sha1_ostream NonSplitSha1Stream; - NonSplitSha1Stream << "Hello World!"; - auto NonSplitHash = toHex(NonSplitSha1Stream.sha1()); - - ASSERT_EQ(NonSplitHash, Hash); -} - -TEST(raw_sha1_ostreamTest, Reset) { - llvm::raw_sha1_ostream Sha1Stream; - Sha1Stream << "Hello"; - auto Hash = toHex(Sha1Stream.sha1()); - - ASSERT_EQ("F7FF9E8B7BB2E09B70935A5D785E0CC5D9D0ABF0", Hash); - - Sha1Stream.resetHash(); - Sha1Stream << " World!"; - Hash = toHex(Sha1Stream.sha1()); - - ASSERT_EQ("7447F2A5A42185C8CF91E632789C431830B59067", Hash); -} |