[lld] r360188 - [COFF] Store Chunk RVAs and section offsets as uint32_t
Reid Kleckner via llvm-commits
llvm-commits at lists.llvm.org
Tue May 7 13:30:41 PDT 2019
Author: rnk
Date: Tue May 7 13:30:41 2019
New Revision: 360188
URL: http://llvm.org/viewvc/llvm-project?rev=360188&view=rev
Log:
[COFF] Store Chunk RVAs and section offsets as uint32_t
Saves 8 bytes on SectionChunk, one of the most commonly allocated data
structures.
Modified:
lld/trunk/COFF/Chunks.cpp
lld/trunk/COFF/Chunks.h
Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=360188&r1=360187&r2=360188&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Tue May 7 13:30:41 2019
@@ -53,7 +53,7 @@ SectionChunk::SectionChunk(ObjFile *F, c
// 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); }
Modified: lld/trunk/COFF/Chunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.h?rev=360188&r1=360187&r2=360188&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.h (original)
+++ lld/trunk/COFF/Chunks.h Tue May 7 13:30:41 2019
@@ -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.
More information about the llvm-commits
mailing list