Skip to content

Commit

Permalink
COFF: Don't use COFFHeader->NumberOfRelocations.
Browse files Browse the repository at this point in the history
The size of the field is 16 bit, so it's inaccurate if the
number of relocations in a section is more than 65535.

llvm-svn: 240661
  • Loading branch information
rui314 committed Jun 25, 2015
1 parent 05f75e9 commit 02c3027
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lld/COFF/Chunks.cpp
Expand Up @@ -29,7 +29,8 @@ namespace coff {

SectionChunk::SectionChunk(ObjectFile *F, const coff_section *H)
: File(F), Ptr(this), Header(H),
Relocs(File->getCOFFObj()->getRelocations(Header)) {
Relocs(File->getCOFFObj()->getRelocations(Header)),
NumRelocs(std::distance(Relocs.begin(), Relocs.end())) {
// Initialize SectionName.
File->getCOFFObj()->getSectionName(Header, SectionName);

Expand Down Expand Up @@ -156,9 +157,11 @@ StringRef SectionChunk::getDebugName() {
uint64_t SectionChunk::getHash() const {
ArrayRef<uint8_t> A;
File->getCOFFObj()->getSectionContents(Header, A);
return hash_combine(getPermissions(), llvm::hash_value(SectionName),
return hash_combine(getPermissions(),
llvm::hash_value(SectionName),
NumRelocs,
uint32_t(Header->SizeOfRawData),
uint32_t(Header->NumberOfRelocations),
std::distance(Relocs.end(), Relocs.begin()),
hash_combine_range(A.data(), A.data() + A.size()));
}

Expand All @@ -171,7 +174,7 @@ bool SectionChunk::equals(const SectionChunk *X) const {
return false;
if (Header->SizeOfRawData != X->Header->SizeOfRawData)
return false;
if (Header->NumberOfRelocations != X->Header->NumberOfRelocations)
if (NumRelocs != X->NumRelocs)
return false;

// Compare data
Expand Down
1 change: 1 addition & 0 deletions lld/COFF/Chunks.h
Expand Up @@ -164,6 +164,7 @@ class SectionChunk : public Chunk {
StringRef SectionName;
std::vector<Chunk *> AssocChildren;
llvm::iterator_range<const coff_relocation *> Relocs;
size_t NumRelocs;

// Chunks are basically unnamed chunks of bytes.
// Symbols are associated for debugging and logging purposs only.
Expand Down

0 comments on commit 02c3027

Please sign in to comment.