[lld] r247609 - Start adding the .hash output section.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 14 13:20:34 PDT 2015


Author: rafael
Date: Mon Sep 14 15:20:34 2015
New Revision: 247609

URL: http://llvm.org/viewvc/llvm-project?rev=247609&view=rev
Log:
Start adding the .hash output section.

It is still empty. Content will be added in the next patch.

Modified:
    lld/trunk/ELF/Writer.cpp
    lld/trunk/test/elf2/shared.s

Modified: lld/trunk/ELF/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Writer.cpp?rev=247609&r1=247608&r2=247609&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Mon Sep 14 15:20:34 2015
@@ -200,6 +200,28 @@ private:
 };
 
 template <class ELFT>
+class HashTableSection final : public OutputSectionBase<ELFT::Is64Bits> {
+  typedef typename ELFFile<ELFT>::Elf_Word Elf_Word;
+
+public:
+  HashTableSection(const SymbolTableSection<ELFT> &DynSymSec)
+      : OutputSectionBase<ELFT::Is64Bits>(".hash", SHT_HASH, SHF_ALLOC),
+        DynSymSec(DynSymSec) {
+    this->Header.sh_entsize = sizeof(Elf_Word);
+    this->Header.sh_addralign = sizeof(Elf_Word);
+  }
+
+  void finalize() override {
+    this->Header.sh_link = DynSymSec.getSectionIndex();
+  }
+
+  void writeTo(uint8_t *Buf) override {}
+
+private:
+  const SymbolTableSection<ELFT> &DynSymSec;
+};
+
+template <class ELFT>
 class DynamicSection final : public OutputSectionBase<ELFT::Is64Bits> {
   typedef OutputSectionBase<ELFT::Is64Bits> Base;
   typedef typename Base::HeaderT HeaderT;
@@ -293,7 +315,8 @@ public:
   typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
   Writer(SymbolTable *T)
       : StrTabSec(false), DynStrSec(true), SymTabSec(*this, *T, StrTabSec),
-        DynSymSec(*this, *T, DynStrSec), DynamicSec(*T, DynSymSec) {}
+        DynSymSec(*this, *T, DynStrSec), DynamicSec(*T, DynSymSec),
+        HashSec(DynSymSec) {}
   void run();
 
   const OutputSection<ELFT> &getBSS() const {
@@ -334,6 +357,8 @@ private:
 
   DynamicSection<ELFT> DynamicSec;
 
+  HashTableSection<ELFT> HashSec;
+
   InterpSection<ELFT::Is64Bits> InterpSec;
 
   OutputSection<ELFT> *BSSSec = nullptr;
@@ -650,6 +675,7 @@ template <class ELFT> void Writer<ELFT>:
     if (needsInterpSection())
       OutputSections.push_back(&InterpSec);
     OutputSections.push_back(&DynSymSec);
+    OutputSections.push_back(&HashSec);
     OutputSections.push_back(&DynamicSec);
     OutputSections.push_back(&DynStrSec);
   }

Modified: lld/trunk/test/elf2/shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/shared.s?rev=247609&r1=247608&r2=247609&view=diff
==============================================================================
--- lld/trunk/test/elf2/shared.s (original)
+++ lld/trunk/test/elf2/shared.s Mon Sep 14 15:20:34 2015
@@ -6,6 +6,38 @@
 // RUN: llvm-readobj --program-headers --dynamic-table -t -s -dyn-symbols -section-data %t | FileCheck %s
 // REQUIRES: x86
 
+
+// test that .hash is linked to .dynsym
+// SO:        Index: 4
+// SO-NEXT:   Name: .dynsym
+// SO-NEXT:   Type: SHT_DYNSYM
+// SO-NEXT:   Flags [
+// SO-NEXT:     SHF_ALLOC
+// SO-NEXT:   ]
+// SO-NEXT:   Address:
+// SO-NEXT:   Offset:
+// SO-NEXT:   Size:
+// SO-NEXT:   Link:
+// SO-NEXT:   Info:
+// SO-NEXT:   AddressAlignment: 4
+// SO-NEXT:   EntrySize: 16
+// SO-NEXT: }
+// SO-NEXT: Section {
+// SO-NEXT:   Index: 5
+// SO-NEXT:   Name: .hash
+// SO-NEXT:   Type: SHT_HASH
+// SO-NEXT:   Flags [
+// SO-NEXT:     SHF_ALLOC
+// SO-NEXT:   ]
+// SO-NEXT:   Address:
+// SO-NEXT:   Offset:
+// SO-NEXT:   Size: 0
+// SO-NEXT:   Link: 4
+// SO-NEXT:   Info: 0
+// SO-NEXT:   AddressAlignment: 4
+// SO-NEXT:   EntrySize: 4
+// SO-NEXT: }
+
 // Make sure .symtab is properly aligned.
 // SO:      Name: .symtab
 // SO-NEXT: Type: SHT_SYMTAB




More information about the llvm-commits mailing list