[lld] a5249c2 - [ELF] Change gnuHashTab/hashTab to unique_ptr. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 12 13:04:37 PST 2022


Author: Fangrui Song
Date: 2022-01-12T13:04:32-08:00
New Revision: a5249c2dd2bb306e442ce795930e71d8e819a0c6

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

LOG: [ELF] Change gnuHashTab/hashTab to unique_ptr. NFC

and remove associated make<XXX> calls.

My x86-64 `lld` is ~5KiB smaller.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/lld/ELF/SyntheticSections.h b/lld/ELF/SyntheticSections.h
index 6a6a2dd136a1..3090cf1aae14 100644
--- a/lld/ELF/SyntheticSections.h
+++ b/lld/ELF/SyntheticSections.h
@@ -1216,8 +1216,8 @@ struct Partition {
   std::unique_ptr<SymbolTableBaseSection> dynSymTab;
   std::unique_ptr<EhFrameHeader> ehFrameHdr;
   std::unique_ptr<EhFrameSection> ehFrame;
-  GnuHashTableSection *gnuHashTab;
-  HashTableSection *hashTab;
+  std::unique_ptr<GnuHashTableSection> gnuHashTab;
+  std::unique_ptr<HashTableSection> hashTab;
   std::unique_ptr<RelocationBaseSection> relaDyn;
   std::unique_ptr<RelrBaseSection> relrDyn;
   std::unique_ptr<VersionDefinitionSection> verDef;

diff  --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp
index e51e1c432722..7249368fe912 100644
--- a/lld/ELF/Writer.cpp
+++ b/lld/ELF/Writer.cpp
@@ -385,12 +385,12 @@ template <class ELFT> void elf::createSyntheticSections() {
       add(*part.verNeed);
 
       if (config->gnuHash) {
-        part.gnuHashTab = make<GnuHashTableSection>();
+        part.gnuHashTab = std::make_unique<GnuHashTableSection>();
         add(*part.gnuHashTab);
       }
 
       if (config->sysvHash) {
-        part.hashTab = make<HashTableSection>();
+        part.hashTab = std::make_unique<HashTableSection>();
         add(*part.hashTab);
       }
 
@@ -2091,8 +2091,8 @@ template <class ELFT> void Writer<ELFT>::finalizeSections() {
     // symbol table section (dynSymTab) must be the first one.
     for (Partition &part : partitions) {
       finalizeSynthetic(part.dynSymTab.get());
-      finalizeSynthetic(part.gnuHashTab);
-      finalizeSynthetic(part.hashTab);
+      finalizeSynthetic(part.gnuHashTab.get());
+      finalizeSynthetic(part.hashTab.get());
       finalizeSynthetic(part.verDef.get());
       finalizeSynthetic(part.relaDyn.get());
       finalizeSynthetic(part.relrDyn.get());


        


More information about the llvm-commits mailing list