diff options
| author | Hans Wennborg <hans@hanshq.net> | 2019-10-09 09:06:30 +0000 |
|---|---|---|
| committer | Hans Wennborg <hans@hanshq.net> | 2019-10-09 09:06:30 +0000 |
| commit | 1e1e3ba2526ecab1ad3c18c97abef36df00b3813 (patch) | |
| tree | 58e8e645b1d85f51ab432d8ab7e279df0b3caf17 /llvm/tools | |
| parent | f8d482c07be46b2ed0c280dfda1bb86cab5de386 (diff) | |
| download | bcm5719-llvm-1e1e3ba2526ecab1ad3c18c97abef36df00b3813.tar.gz bcm5719-llvm-1e1e3ba2526ecab1ad3c18c97abef36df00b3813.zip | |
Unify the two CRC implementations
David added the JamCRC implementation in r246590. More recently, Eugene
added a CRC-32 implementation in r357901, which falls back to zlib's
crc32 function if present.
These checksums are essentially the same, so having multiple
implementations seems unnecessary. This replaces the CRC-32
implementation with the simpler one from JamCRC, and implements the
JamCRC interface in terms of CRC-32 since this means it can use zlib's
implementation when available, saving a few bytes and potentially making
it faster.
JamCRC took an ArrayRef<char> argument, and CRC-32 took a StringRef.
This patch changes it to ArrayRef<uint8_t> which I think is the best
choice, and simplifies a few of the callers nicely.
Differential revision: https://reviews.llvm.org/D68570
llvm-svn: 374148
Diffstat (limited to 'llvm/tools')
| -rw-r--r-- | llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp | 13 | ||||
| -rw-r--r-- | llvm/tools/llvm-objcopy/CopyConfig.cpp | 10 |
2 files changed, 5 insertions, 18 deletions
diff --git a/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp b/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp index 60f70d71349..2a8d816e6f3 100644 --- a/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp +++ b/llvm/tools/llvm-objcopy/COFF/COFFObjcopy.cpp @@ -16,8 +16,8 @@ #include "llvm/Object/Binary.h" #include "llvm/Object/COFF.h" +#include "llvm/Support/CRC.h" #include "llvm/Support/Errc.h" -#include "llvm/Support/JamCRC.h" #include "llvm/Support/Path.h" #include <cassert> @@ -40,22 +40,13 @@ static uint64_t getNextRVA(const Object &Obj) { Obj.IsPE ? Obj.PeHeader.SectionAlignment : 1); } -static uint32_t getCRC32(StringRef Data) { - JamCRC CRC; - CRC.update(ArrayRef<char>(Data.data(), Data.size())); - // The CRC32 value needs to be complemented because the JamCRC dosn't - // finalize the CRC32 value. It also dosn't negate the initial CRC32 value - // but it starts by default at 0xFFFFFFFF which is the complement of zero. - return ~CRC.getCRC(); -} - static std::vector<uint8_t> createGnuDebugLinkSectionContents(StringRef File) { ErrorOr<std::unique_ptr<MemoryBuffer>> LinkTargetOrErr = MemoryBuffer::getFile(File); if (!LinkTargetOrErr) error("'" + File + "': " + LinkTargetOrErr.getError().message()); auto LinkTarget = std::move(*LinkTargetOrErr); - uint32_t CRC32 = getCRC32(LinkTarget->getBuffer()); + uint32_t CRC32 = llvm::crc32(arrayRefFromStringRef(LinkTarget->getBuffer())); StringRef FileName = sys::path::filename(File); size_t CRCPos = alignTo(FileName.size() + 1, 4); diff --git a/llvm/tools/llvm-objcopy/CopyConfig.cpp b/llvm/tools/llvm-objcopy/CopyConfig.cpp index 9b51b745d50..952b3a71796 100644 --- a/llvm/tools/llvm-objcopy/CopyConfig.cpp +++ b/llvm/tools/llvm-objcopy/CopyConfig.cpp @@ -14,10 +14,10 @@ #include "llvm/ADT/StringSet.h" #include "llvm/Option/Arg.h" #include "llvm/Option/ArgList.h" +#include "llvm/Support/CRC.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compression.h" #include "llvm/Support/Errc.h" -#include "llvm/Support/JamCRC.h" #include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/StringSaver.h" #include <memory> @@ -461,12 +461,8 @@ Expected<DriverConfig> parseObjcopyOptions(ArrayRef<const char *> ArgsArr) { if (!DebugOrErr) return createFileError(Config.AddGnuDebugLink, DebugOrErr.getError()); auto Debug = std::move(*DebugOrErr); - JamCRC CRC; - CRC.update( - ArrayRef<char>(Debug->getBuffer().data(), Debug->getBuffer().size())); - // The CRC32 value needs to be complemented because the JamCRC doesn't - // finalize the CRC32 value. - Config.GnuDebugLinkCRC32 = ~CRC.getCRC(); + Config.GnuDebugLinkCRC32 = + llvm::crc32(arrayRefFromStringRef(Debug->getBuffer())); } Config.BuildIdLinkDir = InputArgs.getLastArgValue(OBJCOPY_build_id_link_dir); if (InputArgs.hasArg(OBJCOPY_build_id_link_input)) |

