From 34e9c41164335d7797bd20a8a9f989e5b2ef29df Mon Sep 17 00:00:00 2001 From: Reid Kleckner Date: Tue, 7 May 2019 20:30:41 +0000 Subject: [PATCH] [COFF] Store Chunk RVAs and section offsets as uint32_t Saves 8 bytes on SectionChunk, one of the most commonly allocated data structures. llvm-svn: 360188 --- lld/COFF/Chunks.cpp | 2 +- lld/COFF/Chunks.h | 22 ++++++++++++++-------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp index d2007ea..1669124 100644 --- a/lld/COFF/Chunks.cpp +++ b/lld/COFF/Chunks.cpp @@ -53,7 +53,7 @@ SectionChunk::SectionChunk(ObjFile *F, const coff_section *H) // SectionChunk is one of the most frequently allocated classes, so it is // important to keep it as compact as possible. As of this writing, the number // below is the size of this class on x64 platforms. -static_assert(sizeof(SectionChunk) <= 120, "SectionChunk grew unexpectedly"); +static_assert(sizeof(SectionChunk) <= 112, "SectionChunk grew unexpectedly"); static void add16(uint8_t *P, int16_t V) { write16le(P, read16le(P) + V); } static void add32(uint8_t *P, int32_t V) { write32le(P, read32le(P) + V); } diff --git a/lld/COFF/Chunks.h b/lld/COFF/Chunks.h index f3ea540..223141b 100644 --- a/lld/COFF/Chunks.h +++ b/lld/COFF/Chunks.h @@ -67,9 +67,14 @@ public: // getSize(). virtual void finalizeContents() {} - // The writer sets and uses the addresses. - uint64_t getRVA() const { return RVA; } - void setRVA(uint64_t V) { RVA = V; } + // The writer sets and uses the addresses. In practice, PE images cannot be + // larger than 2GB. Chunks are always laid as part of the image, so Chunk RVAs + // can be stored with 32 bits. + uint32_t getRVA() const { return RVA; } + void setRVA(uint64_t V) { + RVA = (uint32_t)V; + assert(RVA == V && "RVA truncated"); + } // Returns true if this has non-zero data. BSS chunks return // false. If false is returned, the space occupied by this chunk @@ -114,14 +119,15 @@ public: protected: // The RVA of this chunk in the output. The writer sets a value. - uint64_t RVA = 0; - - // The output section for this chunk. - OutputSection *Out = nullptr; + uint32_t RVA = 0; public: // The offset from beginning of the output section. The writer sets a value. - uint64_t OutputSectionOff = 0; + uint32_t OutputSectionOff = 0; + +protected: + // The output section for this chunk. + OutputSection *Out = nullptr; }; // A chunk corresponding a section of an input file. -- 2.7.4