[PATCH] D91018: [ELF] Make InputSection smaller

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Nov 7 16:33:03 PST 2020


MaskRay created this revision.
MaskRay added reviewers: grimar, psmith.
Herald added subscribers: llvm-commits, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
MaskRay requested review of this revision.

On LP64/LLP64 platforms, this decreases sizeof(InputSection) from 208 to 184.

For a large executable (7.6GiB, inputSections.size()=5105122,
make<InputSection> called 4835760 times), this decreases cgroup
memory.max_usage_in_bytes by 0.6%


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91018

Files:
  lld/ELF/InputSection.h


Index: lld/ELF/InputSection.h
===================================================================
--- lld/ELF/InputSection.h
+++ lld/ELF/InputSection.h
@@ -134,6 +134,10 @@
   // and shrinking a section.
   unsigned bytesDropped = 0;
 
+  // Indicates that this section needs to be padded with a NOP filler if set to
+  // true.
+  bool nopFiller = false;
+
   void drop_back(uint64_t num) { bytesDropped += num; }
 
   void push_back(uint64_t num) {
@@ -210,17 +214,13 @@
   // The native ELF reloc data type is not very convenient to handle.
   // So we convert ELF reloc records to our own records in Relocations.cpp.
   // This vector contains such "cooked" relocations.
-  std::vector<Relocation> relocations;
-
-  // Indicates that this section needs to be padded with a NOP filler if set to
-  // true.
-  bool nopFiller = false;
+  SmallVector<Relocation, 0> relocations;
 
   // These are modifiers to jump instructions that are necessary when basic
   // block sections are enabled.  Basic block sections creates opportunities to
   // relax jump instructions at basic block boundaries after reordering the
   // basic blocks.
-  std::vector<JumpInstrMod> jumpInstrMods;
+  SmallVector<JumpInstrMod, 0> jumpInstrMods;
 
   // A function compiled with -fsplit-stack calling a function
   // compiled without -fsplit-stack needs its prologue adjusted. Find
@@ -390,6 +390,8 @@
   template <class ELFT> void copyShtGroup(uint8_t *buf);
 };
 
+static_assert(sizeof(InputSection) <= 184, "InputSection is too big");
+
 inline bool isDebugSection(const InputSectionBase &sec) {
   return sec.name.startswith(".debug") || sec.name.startswith(".zdebug");
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91018.303681.patch
Type: text/x-patch
Size: 1660 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201108/7a9eb02a/attachment.bin>


More information about the llvm-commits mailing list