[lld] r249839 - ELF2: Emit a PT_PHDR header as the first entry of the program header.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 9 08:31:49 PDT 2015
Author: ruiu
Date: Fri Oct 9 10:31:49 2015
New Revision: 249839
URL: http://llvm.org/viewvc/llvm-project?rev=249839&view=rev
Log:
ELF2: Emit a PT_PHDR header as the first entry of the program header.
PT_PHDR entry points to the program header itself.
Modified:
lld/trunk/ELF/Writer.cpp
lld/trunk/test/elf2/basic-aarch64.s
lld/trunk/test/elf2/basic-mips.s
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/emulation.s
lld/trunk/test/elf2/program-header-layout.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=249839&r1=249838&r2=249839&view=diff
==============================================================================
--- lld/trunk/ELF/Writer.cpp (original)
+++ lld/trunk/ELF/Writer.cpp Fri Oct 9 10:31:49 2015
@@ -103,6 +103,7 @@ private:
llvm::BumpPtrAllocator PAlloc;
SymbolTable &Symtab;
std::vector<ProgramHeader<ELFT> *> PHDRs;
+ ProgramHeader<ELFT> PhdrPHDR{PT_PHDR, PF_R, 0, 0};
ProgramHeader<ELFT> FileHeaderPHDR{PT_LOAD, PF_R, 0, 0};
ProgramHeader<ELFT> InterpPHDR{PT_INTERP, 0, 0, 0};
ProgramHeader<ELFT> DynamicPHDR{PT_DYNAMIC, 0, 0, 0};
@@ -501,6 +502,13 @@ template <class ELFT> void Writer<ELFT>:
FileOff += sizeof(Elf_Ehdr);
VA += sizeof(Elf_Ehdr);
+ // The first PHDR entry is PT_PHDR which describes the program header itself.
+ PHDRs.push_back(&PhdrPHDR);
+ PhdrPHDR.Header.p_align = 8;
+ PhdrPHDR.Header.p_offset = FileOff;
+ PhdrPHDR.Header.p_vaddr = VA;
+ PhdrPHDR.Header.p_paddr = VA;
+
// Reserve space for PHDRs.
ProgramHeaderOff = FileOff;
FileOff = RoundUpToAlignment(FileOff, Target->getPageSize());
@@ -558,6 +566,10 @@ template <class ELFT> void Writer<ELFT>:
FileOff += OffsetToAlignment(FileOff, ELFT::Is64Bits ? 8 : 4);
+ // Fix up the first entry's size.
+ PhdrPHDR.Header.p_filesz = sizeof(Elf_Phdr) * PHDRs.size();
+ PhdrPHDR.Header.p_memsz = sizeof(Elf_Phdr) * PHDRs.size();
+
// Add space for section headers.
SectionHeaderOff = FileOff;
FileOff += getNumSections() * sizeof(Elf_Shdr);
Modified: lld/trunk/test/elf2/basic-aarch64.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic-aarch64.s?rev=249839&r1=249838&r2=249839&view=diff
==============================================================================
--- lld/trunk/test/elf2/basic-aarch64.s (original)
+++ lld/trunk/test/elf2/basic-aarch64.s Fri Oct 9 10:31:49 2015
@@ -31,7 +31,7 @@ _start:
# CHECK-NEXT: ]
# CHECK-NEXT: HeaderSize: 64
# CHECK-NEXT: ProgramHeaderEntrySize: 56
-# CHECK-NEXT: ProgramHeaderCount: 2
+# CHECK-NEXT: ProgramHeaderCount: 3
# CHECK-NEXT: SectionHeaderEntrySize: 64
# CHECK-NEXT: SectionHeaderCount: 6
# CHECK-NEXT: StringTableSectionIndex: 5
@@ -159,12 +159,24 @@ _start:
# CHECK-NEXT: ]
# CHECK-NEXT: ProgramHeaders [
# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_PHDR (0x6)
+# CHECK-NEXT: Offset: 0x40
+# CHECK-NEXT: VirtualAddress: 0x400040
+# CHECK-NEXT: PhysicalAddress: 0x400040
+# CHECK-NEXT: FileSize: 168
+# CHECK-NEXT: MemSize: 168
+# CHECK-NEXT: Flags [ (0x4)
+# CHECK-NEXT: PF_R (0x4)
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 8
+# CHECK-NEXT: }
+# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_LOAD (0x1)
# CHECK-NEXT: Offset: 0x0
# CHECK-NEXT: VirtualAddress: 0x400000
# CHECK-NEXT: PhysicalAddress: 0x400000
-# CHECK-NEXT: FileSize: 176
-# CHECK-NEXT: MemSize: 176
+# CHECK-NEXT: FileSize: 232
+# CHECK-NEXT: MemSize: 232
# CHECK-NEXT: Flags [
# CHECK-NEXT: PF_R
# CHECK-NEXT: ]
Modified: lld/trunk/test/elf2/basic-mips.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic-mips.s?rev=249839&r1=249838&r2=249839&view=diff
==============================================================================
--- lld/trunk/test/elf2/basic-mips.s (original)
+++ lld/trunk/test/elf2/basic-mips.s Fri Oct 9 10:31:49 2015
@@ -32,7 +32,7 @@ __start:
# CHECK-NEXT: ]
# CHECK-NEXT: HeaderSize: 52
# CHECK-NEXT: ProgramHeaderEntrySize: 32
-# CHECK-NEXT: ProgramHeaderCount: 2
+# CHECK-NEXT: ProgramHeaderCount: 3
# CHECK-NEXT: SectionHeaderEntrySize: 40
# CHECK-NEXT: SectionHeaderCount: 8
# CHECK-NEXT: StringTableSectionIndex: 7
@@ -181,6 +181,18 @@ __start:
# CHECK-NEXT: ]
# CHECK-NEXT: ProgramHeaders [
# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_PHDR (0x6)
+# CHECK-NEXT: Offset: 0x34
+# CHECK-NEXT: VirtualAddress: 0x400034
+# CHECK-NEXT: PhysicalAddress: 0x400034
+# CHECK-NEXT: FileSize: 96
+# CHECK-NEXT: MemSize: 96
+# CHECK-NEXT: Flags [ (0x4)
+# CHECK-NEXT: PF_R (0x4)
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 8
+# CHECK-NEXT: }
+# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_LOAD (0x1)
# CHECK-NEXT: Offset: 0x0
# CHECK-NEXT: VirtualAddress: 0x400000
Modified: lld/trunk/test/elf2/basic.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic.s?rev=249839&r1=249838&r2=249839&view=diff
==============================================================================
--- lld/trunk/test/elf2/basic.s (original)
+++ lld/trunk/test/elf2/basic.s Fri Oct 9 10:31:49 2015
@@ -32,7 +32,7 @@ _start:
# CHECK-NEXT: ]
# CHECK-NEXT: HeaderSize: 64
# CHECK-NEXT: ProgramHeaderEntrySize: 56
-# CHECK-NEXT: ProgramHeaderCount: 2
+# CHECK-NEXT: ProgramHeaderCount: 3
# CHECK-NEXT: SectionHeaderEntrySize: 64
# CHECK-NEXT: SectionHeaderCount: 6
# CHECK-NEXT: StringTableSectionIndex: 5
@@ -151,12 +151,24 @@ _start:
# CHECK-NEXT: ]
# CHECK-NEXT: ProgramHeaders [
# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_PHDR (0x6)
+# CHECK-NEXT: Offset: 0x40
+# CHECK-NEXT: VirtualAddress: 0x10040
+# CHECK-NEXT: PhysicalAddress: 0x10040
+# CHECK-NEXT: FileSize: 168
+# CHECK-NEXT: MemSize: 168
+# CHECK-NEXT: Flags [ (0x4)
+# CHECK-NEXT: PF_R (0x4)
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 8
+# CHECK-NEXT: }
+# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_LOAD (0x1)
# CHECK-NEXT: Offset: 0x0
# CHECK-NEXT: VirtualAddress: 0x10000
# CHECK-NEXT: PhysicalAddress: 0x10000
-# CHECK-NEXT: FileSize: 176
-# CHECK-NEXT: MemSize: 176
+# CHECK-NEXT: FileSize: 232
+# CHECK-NEXT: MemSize: 232
# CHECK-NEXT: Flags [
# CHECK-NEXT: PF_R
# CHECK-NEXT: ]
Modified: lld/trunk/test/elf2/basic32.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic32.s?rev=249839&r1=249838&r2=249839&view=diff
==============================================================================
--- lld/trunk/test/elf2/basic32.s (original)
+++ lld/trunk/test/elf2/basic32.s Fri Oct 9 10:31:49 2015
@@ -30,7 +30,7 @@ _start:
# CHECK-NEXT: ]
# CHECK-NEXT: HeaderSize: 52
# CHECK-NEXT: ProgramHeaderEntrySize: 32
-# CHECK-NEXT: ProgramHeaderCount: 2
+# CHECK-NEXT: ProgramHeaderCount: 3
# CHECK-NEXT: SectionHeaderEntrySize: 40
# CHECK-NEXT: SectionHeaderCount: 6
# CHECK-NEXT: StringTableSectionIndex: 5
@@ -129,12 +129,24 @@ _start:
# CHECK-NEXT: ]
# CHECK-NEXT: ProgramHeaders [
# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_PHDR (0x6)
+# CHECK-NEXT: Offset: 0x34
+# CHECK-NEXT: VirtualAddress: 0x10034
+# CHECK-NEXT: PhysicalAddress: 0x10034
+# CHECK-NEXT: FileSize: 96
+# CHECK-NEXT: MemSize: 96
+# CHECK-NEXT: Flags [ (0x4)
+# CHECK-NEXT: PF_R (0x4)
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 8
+# CHECK-NEXT: }
+# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_LOAD (0x1)
# CHECK-NEXT: Offset: 0x0
# CHECK-NEXT: VirtualAddress: 0x10000
# CHECK-NEXT: PhysicalAddress: 0x10000
-# CHECK-NEXT: FileSize: 116
-# CHECK-NEXT: MemSize: 116
+# CHECK-NEXT: FileSize: 148
+# CHECK-NEXT: MemSize: 148
# CHECK-NEXT: Flags [
# CHECK-NEXT: PF_R
# CHECK-NEXT: ]
Modified: lld/trunk/test/elf2/basic32be.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic32be.s?rev=249839&r1=249838&r2=249839&view=diff
==============================================================================
--- lld/trunk/test/elf2/basic32be.s (original)
+++ lld/trunk/test/elf2/basic32be.s Fri Oct 9 10:31:49 2015
@@ -30,7 +30,7 @@ _start:
# CHECK-NEXT: ]
# CHECK-NEXT: HeaderSize: 52
# CHECK-NEXT: ProgramHeaderEntrySize: 32
-# CHECK-NEXT: ProgramHeaderCount: 2
+# CHECK-NEXT: ProgramHeaderCount: 3
# CHECK-NEXT: SectionHeaderEntrySize: 40
# CHECK-NEXT: SectionHeaderCount: 6
# CHECK-NEXT: StringTableSectionIndex: 5
@@ -129,12 +129,24 @@ _start:
# CHECK-NEXT: ]
# CHECK-NEXT: ProgramHeaders [
# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_PHDR (0x6)
+# CHECK-NEXT: Offset: 0x34
+# CHECK-NEXT: VirtualAddress: 0x10000034
+# CHECK-NEXT: PhysicalAddress: 0x10000034
+# CHECK-NEXT: FileSize: 96
+# CHECK-NEXT: MemSize: 96
+# CHECK-NEXT: Flags [ (0x4)
+# CHECK-NEXT: PF_R (0x4)
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 8
+# CHECK-NEXT: }
+# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_LOAD (0x1)
# CHECK-NEXT: Offset: 0x0
# CHECK-NEXT: VirtualAddress: 0x10000000
# CHECK-NEXT: PhysicalAddress: 0x10000000
-# CHECK-NEXT: FileSize: 116
-# CHECK-NEXT: MemSize: 116
+# CHECK-NEXT: FileSize: 148
+# CHECK-NEXT: MemSize: 148
# CHECK-NEXT: Flags [
# CHECK-NEXT: PF_R
# CHECK-NEXT: ]
Modified: lld/trunk/test/elf2/basic64be.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/basic64be.s?rev=249839&r1=249838&r2=249839&view=diff
==============================================================================
--- lld/trunk/test/elf2/basic64be.s (original)
+++ lld/trunk/test/elf2/basic64be.s Fri Oct 9 10:31:49 2015
@@ -35,7 +35,7 @@ _start:
# CHECK-NEXT: ]
# CHECK-NEXT: HeaderSize: 64
# CHECK-NEXT: ProgramHeaderEntrySize: 56
-# CHECK-NEXT: ProgramHeaderCount: 3
+# CHECK-NEXT: ProgramHeaderCount: 4
# CHECK-NEXT: SectionHeaderEntrySize: 64
# CHECK-NEXT: SectionHeaderCount: 7
# CHECK-NEXT: StringTableSectionIndex: 6
@@ -163,13 +163,25 @@ _start:
# CHECK-NEXT: }
# CHECK-NEXT: ]
# CHECK-NEXT: ProgramHeaders [
+# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_PHDR (0x6)
+# CHECK-NEXT: Offset: 0x40
+# CHECK-NEXT: VirtualAddress: 0x10000040
+# CHECK-NEXT: PhysicalAddress: 0x10000040
+# CHECK-NEXT: FileSize: 224
+# CHECK-NEXT: MemSize: 224
+# CHECK-NEXT: Flags [ (0x4)
+# CHECK-NEXT: PF_R (0x4)
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 8
+# CHECK-NEXT: }
# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_LOAD (0x1)
# CHECK-NEXT: Offset: 0x0
# CHECK-NEXT: VirtualAddress: 0x10000000
# CHECK-NEXT: PhysicalAddress: 0x10000000
-# CHECK-NEXT: FileSize: 232
-# CHECK-NEXT: MemSize: 232
+# CHECK-NEXT: FileSize: 288
+# CHECK-NEXT: MemSize: 288
# CHECK-NEXT: Flags [
# CHECK-NEXT: PF_R
# CHECK-NEXT: ]
Modified: lld/trunk/test/elf2/emulation.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/emulation.s?rev=249839&r1=249838&r2=249839&view=diff
==============================================================================
--- lld/trunk/test/elf2/emulation.s (original)
+++ lld/trunk/test/elf2/emulation.s Fri Oct 9 10:31:49 2015
@@ -23,7 +23,7 @@
# X86-64-NEXT: ]
# X86-64-NEXT: HeaderSize: 64
# X86-64-NEXT: ProgramHeaderEntrySize: 56
-# X86-64-NEXT: ProgramHeaderCount: 1
+# X86-64-NEXT: ProgramHeaderCount: 2
# X86-64-NEXT: SectionHeaderEntrySize: 64
# X86-64-NEXT: SectionHeaderCount: 6
# X86-64-NEXT: StringTableSectionIndex: 5
@@ -54,7 +54,7 @@
# X86-NEXT: ]
# X86-NEXT: HeaderSize: 52
# X86-NEXT: ProgramHeaderEntrySize: 32
-# X86-NEXT: ProgramHeaderCount: 1
+# X86-NEXT: ProgramHeaderCount: 2
# X86-NEXT: SectionHeaderEntrySize: 40
# X86-NEXT: SectionHeaderCount: 6
# X86-NEXT: StringTableSectionIndex: 5
@@ -85,7 +85,7 @@
# PPC64-NEXT: ]
# PPC64-NEXT: HeaderSize: 64
# PPC64-NEXT: ProgramHeaderEntrySize: 56
-# PPC64-NEXT: ProgramHeaderCount: 1
+# PPC64-NEXT: ProgramHeaderCount: 2
# PPC64-NEXT: SectionHeaderEntrySize: 64
# PPC64-NEXT: SectionHeaderCount: 6
# PPC64-NEXT: StringTableSectionIndex: 5
@@ -116,7 +116,7 @@
# PPC-NEXT: ]
# PPC-NEXT: HeaderSize: 52
# PPC-NEXT: ProgramHeaderEntrySize: 32
-# PPC-NEXT: ProgramHeaderCount: 1
+# PPC-NEXT: ProgramHeaderCount: 2
# PPC-NEXT: SectionHeaderEntrySize: 40
# PPC-NEXT: SectionHeaderCount: 6
# PPC-NEXT: StringTableSectionIndex: 5
Modified: lld/trunk/test/elf2/program-header-layout.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/program-header-layout.s?rev=249839&r1=249838&r2=249839&view=diff
==============================================================================
--- lld/trunk/test/elf2/program-header-layout.s (original)
+++ lld/trunk/test/elf2/program-header-layout.s Fri Oct 9 10:31:49 2015
@@ -33,6 +33,18 @@ _start:
# CHECK: ProgramHeaders [
# CHECK-NEXT: ProgramHeader {
+# CHECK-NEXT: Type: PT_PHDR (0x6)
+# CHECK-NEXT: Offset: 0x40
+# CHECK-NEXT: VirtualAddress: 0x10040
+# CHECK-NEXT: PhysicalAddress: 0x10040
+# CHECK-NEXT: FileSize: 168
+# CHECK-NEXT: MemSize: 168
+# CHECK-NEXT: Flags [ (0x4)
+# CHECK-NEXT: PF_R (0x4)
+# CHECK-NEXT: ]
+# CHECK-NEXT: Alignment: 8
+# CHECK-NEXT: }
+# CHECK-NEXT: ProgramHeader {
# CHECK-NEXT: Type: PT_LOAD
# CHECK-NEXT: Offset: 0x0
# CHECK-NEXT: VirtualAddress:
Modified: lld/trunk/test/elf2/shared.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf2/shared.s?rev=249839&r1=249838&r2=249839&view=diff
==============================================================================
--- lld/trunk/test/elf2/shared.s (original)
+++ lld/trunk/test/elf2/shared.s Fri Oct 9 10:31:49 2015
@@ -256,9 +256,8 @@
// CHECK-NEXT: 0x00000000 NULL 0x0
// CHECK-NEXT: ]
-// CHECK: ProgramHeaders [
-// CHECK-NEXT: ProgramHeader {
-// CHECK-NEXT: Type: PT_INTERP
+// CHECK: ProgramHeaders [
+// CHECK: Type: PT_INTERP
// CHECK-NEXT: Offset: [[INTERPOFFSET]]
// CHECK-NEXT: VirtualAddress: [[INTERPADDR]]
// CHECK-NEXT: PhysicalAddress: [[INTERPADDR]]
More information about the llvm-commits
mailing list