aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2015-06-25 17:56:36 +0000
committerRui Ueyama <ruiu@google.com>2015-06-25 17:56:36 +0000
commitf34c088515a414f67e781a174a1c5fcfcd5fab1b (patch)
tree4fd5851f512695882ff226b336c9d5dcdc63a758
parentc6fcfbc98a70f40d3cef850b34f606091ee33d07 (diff)
downloadllvm-f34c088515a414f67e781a174a1c5fcfcd5fab1b.zip
llvm-f34c088515a414f67e781a174a1c5fcfcd5fab1b.tar.gz
llvm-f34c088515a414f67e781a174a1c5fcfcd5fab1b.tar.bz2
COFF: Simplify. NFC.
llvm-svn: 240666
-rw-r--r--lld/COFF/Chunks.cpp20
-rw-r--r--lld/COFF/Chunks.h1
2 files changed, 11 insertions, 10 deletions
diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp
index fde2407..2acc722 100644
--- a/lld/COFF/Chunks.cpp
+++ b/lld/COFF/Chunks.cpp
@@ -59,9 +59,8 @@ void SectionChunk::writeTo(uint8_t *Buf) {
if (!hasData())
return;
// Copy section contents from source object file to output file.
- ArrayRef<uint8_t> Data;
- File->getCOFFObj()->getSectionContents(Header, Data);
- memcpy(Buf + FileOff, Data.data(), Data.size());
+ ArrayRef<uint8_t> A = getContents();
+ memcpy(Buf + FileOff, A.data(), A.size());
// Apply relocations.
for (const coff_relocation &Rel : Relocs) {
@@ -155,8 +154,7 @@ StringRef SectionChunk::getDebugName() {
}
uint64_t SectionChunk::getHash() const {
- ArrayRef<uint8_t> A;
- File->getCOFFObj()->getSectionContents(Header, A);
+ ArrayRef<uint8_t> A = getContents();
return hash_combine(getPermissions(),
llvm::hash_value(SectionName),
NumRelocs,
@@ -178,11 +176,7 @@ bool SectionChunk::equals(const SectionChunk *X) const {
return false;
// Compare data
- ArrayRef<uint8_t> A, B;
- File->getCOFFObj()->getSectionContents(Header, A);
- X->File->getCOFFObj()->getSectionContents(X->Header, B);
- assert(A.size() == B.size());
- if (memcmp(A.data(), B.data(), A.size()))
+ if (getContents() != X->getContents())
return false;
// Compare relocations
@@ -202,6 +196,12 @@ bool SectionChunk::equals(const SectionChunk *X) const {
return std::equal(Relocs.begin(), Relocs.end(), X->Relocs.begin(), Eq);
}
+ArrayRef<uint8_t> SectionChunk::getContents() const {
+ ArrayRef<uint8_t> A;
+ File->getCOFFObj()->getSectionContents(Header, A);
+ return A;
+}
+
// Returns a pointer to this chunk or its replacement.
SectionChunk *SectionChunk::repl() {
while (Ptr != Ptr->Ptr)
diff --git a/lld/COFF/Chunks.h b/lld/COFF/Chunks.h
index 3f15c16..6522f00 100644
--- a/lld/COFF/Chunks.h
+++ b/lld/COFF/Chunks.h
@@ -150,6 +150,7 @@ public:
private:
void mark() override;
+ ArrayRef<uint8_t> getContents() const;
// A file this chunk was created from.
ObjectFile *File;