[lld] r175951 - [ELF][Writer] Add a PHDR program table entry for dynamic files.
Michael J. Spencer
bigcheesegs at gmail.com
Fri Feb 22 19:58:06 PST 2013
Author: mspencer
Date: Fri Feb 22 21:58:06 2013
New Revision: 175951
URL: http://llvm.org/viewvc/llvm-project?rev=175951&view=rev
Log:
[ELF][Writer] Add a PHDR program table entry for dynamic files.
Added:
lld/trunk/test/elf/dynamic-phdr.test
Modified:
lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h
Modified: lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h?rev=175951&r1=175950&r2=175951&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/DefaultLayout.h Fri Feb 22 21:58:06 2013
@@ -593,6 +593,8 @@ DefaultLayout<ELFT>::assignVirtualAddres
for (auto si : _segments) {
newSegmentHeaderAdded = _programHeader->addSegment(si);
}
+ if (_targetInfo.isDynamic() && _programHeader->addPHDR())
+ newSegmentHeaderAdded = true;
if (!newSegmentHeaderAdded)
break;
uint64_t fileoffset = 0;
Modified: lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h?rev=175951&r1=175950&r2=175951&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h (original)
+++ lld/trunk/lib/ReaderWriter/ELF/HeaderChunks.h Fri Feb 22 21:58:06 2013
@@ -119,6 +119,27 @@ public:
bool addSegment(Segment<ELFT> *segment);
+ bool addPHDR() {
+ bool allocatedNew = false;
+ auto phdr = allocateProgramHeader();
+ if (phdr.second)
+ allocatedNew = true;
+
+ this->_fsize = fileSize();
+ this->_msize = this->_fsize;
+
+ phdr.first->p_type = llvm::ELF::PT_PHDR;
+ phdr.first->p_offset = this->fileOffset();
+ phdr.first->p_vaddr = this->virtualAddr();
+ phdr.first->p_paddr = this->virtualAddr();
+ phdr.first->p_filesz = this->fileSize();
+ phdr.first->p_memsz = this->memSize();
+ phdr.first->p_flags = llvm::ELF::PF_R;
+ phdr.first->p_align = 8;
+
+ return allocatedNew;
+ }
+
void resetProgramHeaders() {
_phi = _ph.begin();
}
Added: lld/trunk/test/elf/dynamic-phdr.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/elf/dynamic-phdr.test?rev=175951&view=auto
==============================================================================
--- lld/trunk/test/elf/dynamic-phdr.test (added)
+++ lld/trunk/test/elf/dynamic-phdr.test Fri Feb 22 21:58:06 2013
@@ -0,0 +1,7 @@
+RUN: lld -core -target x86_64-linux %p/Inputs/use-shared.x86-64 \
+RUN: %p/Inputs/shared.so-x86-64 -output=%t -entry=main \
+RUN: -output-type=dynamic
+RUN: llvm-objdump -p %t | FileCheck %s
+
+CHECK: PHDR off 0x{{0+}}40
+CHECK: flags r--
More information about the llvm-commits
mailing list