[lld] r247181 - Add the DT_NEEDED entries to the dynamic table.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 9 13:26:24 PDT 2015
Author: rafael
Date: Wed Sep 9 15:26:23 2015
New Revision: 247181
URL: http://llvm.org/viewvc/llvm-project?rev=247181&view=rev
Log:
Add the DT_NEEDED entries to the dynamic table.
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/elf2/basic.s
lld/trunk/test/elf2/basic32.s
lld/trunk/test/elf2/basic32be.s
lld/trunk/test/elf2/basic64be.s
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=247181&r1=247180&r2=247181&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Wed Sep 9 15:26:23 2015
@@ -167,10 +167,10 @@ class DynamicSection final : public Outp
typedef typename Base::Elf_Dyn Elf_Dyn;
public:
- DynamicSection(const StringTableSection<Is64Bits> &DynStrSec)
+ DynamicSection(SymbolTable &SymTab, StringTableSection<Is64Bits> &DynStrSec)
: OutputSectionBase<Is64Bits>(".dynamic", SHT_DYNAMIC,
SHF_ALLOC | SHF_WRITE),
- DynStrSec(DynStrSec) {
+ DynStrSec(DynStrSec), SymTab(SymTab) {
typename Base::HeaderT &Header = this->Header;
Header.sh_addralign = Is64Bits ? 8 : 4;
Header.sh_entsize = Is64Bits ? 16 : 8;
@@ -178,6 +178,14 @@ public:
unsigned NumEntries = 0;
++NumEntries; // DT_STRTAB
+ ++NumEntries; // DT_STRSZ
+
+ const std::vector<std::unique_ptr<SharedFileBase>> &SharedFiles =
+ SymTab.getSharedFiles();
+ for (const std::unique_ptr<SharedFileBase> &File : SharedFiles)
+ DynStrSec.add(File->getName());
+ NumEntries += SharedFiles.size();
+
++NumEntries; // DT_NULL
Header.sh_size = NumEntries * Header.sh_entsize;
@@ -194,12 +202,26 @@ public:
P->d_un.d_ptr = DynStrSec.getVA();
++P;
+ P->d_tag = DT_STRSZ;
+ P->d_un.d_val = DynStrSec.StrTabBuilder.data().size();
+ ++P;
+
+ const std::vector<std::unique_ptr<SharedFileBase>> &SharedFiles =
+ SymTab.getSharedFiles();
+ for (const std::unique_ptr<SharedFileBase> &File : SharedFiles) {
+ P->d_tag = DT_NEEDED;
+ P->d_un.d_val = DynStrSec.getFileOff(File->getName());
+ ++P;
+ }
+
P->d_tag = DT_NULL;
P->d_un.d_val = 0;
+ ++P;
}
private:
- const StringTableSection<Is64Bits> &DynStrSec;
+ StringTableSection<Is64Bits> &DynStrSec;
+ SymbolTable &SymTab;
};
// The writer writes a SymbolTable result to a file.
@@ -212,7 +234,7 @@ public:
typedef typename ELFFile<ELFT>::Elf_Sym Elf_Sym;
Writer(SymbolTable *T)
: StrTabSec(false), DynStrSec(true), SymTable(*T, StrTabSec),
- DynamicSec(DynStrSec) {}
+ DynamicSec(*T, DynStrSec) {}
void run();
private:
@@ -638,7 +660,7 @@ template <class ELFT> void Writer<ELFT>:
auto PHdrs = reinterpret_cast<Elf_Phdr *>(Buf + EHdr->e_phoff);
PHdrs->p_type = PT_LOAD;
PHdrs->p_flags = PF_R | PF_X;
- PHdrs->p_offset = 0x0000;
+ PHdrs->p_offset = 0x1000;
PHdrs->p_vaddr = 0x1000;
PHdrs->p_paddr = PHdrs->p_vaddr;
PHdrs->p_filesz = FileSize;
Modified: lld/trunk/test/elf2/basic.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic.s?rev=247181&r1=247180&r2=247181&view=diff
==============================================================================
--- lld/trunk/test/elf2/basic.s (original)
+++ lld/trunk/test/elf2/basic.s Wed Sep 9 15:26:23 2015
@@ -151,7 +151,7 @@ _start:
# CHECK-NEXT: ProgramHeaders [
# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_LOAD (0x1)
-# CHECK-NEXT: Offset: 0x0
+# CHECK-NEXT: Offset: 0x1000
# CHECK-NEXT: VirtualAddress: 0x1000
# CHECK-NEXT: PhysicalAddress: 0x1000
# CHECK-NEXT: FileSize: 4592
Modified: lld/trunk/test/elf2/basic32.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic32.s?rev=247181&r1=247180&r2=247181&view=diff
==============================================================================
--- lld/trunk/test/elf2/basic32.s (original)
+++ lld/trunk/test/elf2/basic32.s Wed Sep 9 15:26:23 2015
@@ -130,7 +130,7 @@ _start:
# CHECK-NEXT: ProgramHeaders [
# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_LOAD (0x1)
-# CHECK-NEXT: Offset: 0x0
+# CHECK-NEXT: Offset: 0x1000
# CHECK-NEXT: VirtualAddress: 0x1000
# CHECK-NEXT: PhysicalAddress: 0x1000
# CHECK-NEXT: FileSize: 4424
Modified: lld/trunk/test/elf2/basic32be.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic32be.s?rev=247181&r1=247180&r2=247181&view=diff
==============================================================================
--- lld/trunk/test/elf2/basic32be.s (original)
+++ lld/trunk/test/elf2/basic32be.s Wed Sep 9 15:26:23 2015
@@ -130,7 +130,7 @@ _start:
# CHECK-NEXT: ProgramHeaders [
# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_LOAD (0x1)
-# CHECK-NEXT: Offset: 0x0
+# CHECK-NEXT: Offset: 0x1000
# CHECK-NEXT: VirtualAddress: 0x1000
# CHECK-NEXT: PhysicalAddress: 0x1000
# CHECK-NEXT: FileSize: 4424
Modified: lld/trunk/test/elf2/basic64be.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic64be.s?rev=247181&r1=247180&r2=247181&view=diff
==============================================================================
--- lld/trunk/test/elf2/basic64be.s (original)
+++ lld/trunk/test/elf2/basic64be.s Wed Sep 9 15:26:23 2015
@@ -151,7 +151,7 @@ _start:
# CHECK-NEXT: ProgramHeaders [
# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_LOAD (0x1)
-# CHECK-NEXT: Offset: 0x0
+# CHECK-NEXT: Offset: 0x1000
# CHECK-NEXT: VirtualAddress: 0x1000
# CHECK-NEXT: PhysicalAddress: 0x1000
# CHECK-NEXT: FileSize: 4680
Modified: lld/trunk/test/elf2/shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/shared.s?rev=247181&r1=247180&r2=247181&view=diff
==============================================================================
--- lld/trunk/test/elf2/shared.s (original)
+++ lld/trunk/test/elf2/shared.s Wed Sep 9 15:26:23 2015
@@ -67,6 +67,8 @@
// CHECK: DynamicSection [
// CHECK-NEXT: Tag Type Name/Value
// CHECK-NEXT: 0x00000005 STRTAB [[DYNSTRADDR]]
+// CHECK-NEXT: 0x0000000A STRSZ
+// CHECK-NEXT: 0x00000001 NEEDED SharedLibrary ({{.*}}/Inputs/i686-simple-library.so)
// CHECK-NEXT: 0x00000000 NULL 0x0
// CHECK-NEXT: ]
More information about the llvm-commits
mailing list