[lld] 196aedb - [ELF] Change vector<InputSection *> to SmallVector. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 1 00:14:25 PST 2022


Author: Fangrui Song
Date: 2022-02-01T00:14:21-08:00
New Revision: 196aedb8437eb0cf62cfa39581e4f8ad1e68ce43

URL: https://github.com/llvm/llvm-project/commit/196aedb8437eb0cf62cfa39581e4f8ad1e68ce43
DIFF: https://github.com/llvm/llvm-project/commit/196aedb8437eb0cf62cfa39581e4f8ad1e68ce43.diff

LOG: [ELF] Change vector<InputSection *> to SmallVector. NFC

My x86-64 lld executable is 8KiB smaller.

Added: 
    

Modified: 
    lld/ELF/ICF.cpp
    lld/ELF/SyntheticSections.cpp
    lld/ELF/SyntheticSections.h
    lld/ELF/Writer.cpp

Removed: 
    


################################################################################
diff  --git a/lld/ELF/ICF.cpp b/lld/ELF/ICF.cpp
index 3b991e8d3470..ed19bde41323 100644
--- a/lld/ELF/ICF.cpp
+++ b/lld/ELF/ICF.cpp
@@ -122,7 +122,7 @@ template <class ELFT> class ICF {
 
   void forEachClass(llvm::function_ref<void(size_t, size_t)> fn);
 
-  std::vector<InputSection *> sections;
+  SmallVector<InputSection *, 0> sections;
 
   // We repeat the main loop while `Repeat` is true.
   std::atomic<bool> repeat;

diff  --git a/lld/ELF/SyntheticSections.cpp b/lld/ELF/SyntheticSections.cpp
index 8c0c3abb9d19..36a226c20576 100644
--- a/lld/ELF/SyntheticSections.cpp
+++ b/lld/ELF/SyntheticSections.cpp
@@ -3482,7 +3482,7 @@ void ARMExidxSyntheticSection::finalizeContents() {
   sentinel = executableSections.back();
   // Optionally merge adjacent duplicate entries.
   if (config->mergeArmExidx) {
-    std::vector<InputSection *> selectedSections;
+    SmallVector<InputSection *, 0> selectedSections;
     selectedSections.reserve(executableSections.size());
     selectedSections.push_back(executableSections[0]);
     size_t prev = 0;

diff  --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 40c238207567..1b63a5d29d10 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -1086,7 +1086,7 @@ class ARMExidxSyntheticSection : public SyntheticSection {
 
   // Links to the ARMExidxSections so we can transfer the relocations once the
   // layout is known.
-  std::vector<InputSection *> exidxSections;
+  SmallVector<InputSection *, 0> exidxSections;
 
 private:
   size_t size = 0;
@@ -1095,7 +1095,7 @@ class ARMExidxSyntheticSection : public SyntheticSection {
   // InputObjects, we store pointers to the executable sections that need
   // .ARM.exidx sections. We can then use the dependentSections of these to
   // either find the .ARM.exidx section or know that we need to generate one.
-  std::vector<InputSection *> executableSections;
+  SmallVector<InputSection *, 0> executableSections;
 
   // The executable InputSection with the highest address to use for the
   // sentinel. We store separately from ExecutableSections as merging of

diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index d689db2e6dc0..a3140c98dbf7 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -1570,8 +1570,8 @@ template <class ELFT> void Writer<ELFT>::resolveShfLinkOrder() {
 
     // Link order may be distributed across several InputSectionDescriptions.
     // Sorting is performed separately.
-    std::vector<InputSection **> scriptSections;
-    std::vector<InputSection *> sections;
+    SmallVector<InputSection **, 0> scriptSections;
+    SmallVector<InputSection *, 0> sections;
     for (SectionCommand *cmd : sec->commands) {
       auto *isd = dyn_cast<InputSectionDescription>(cmd);
       if (!isd)


        


More information about the llvm-commits mailing list