[PATCH] [lld][ELF][Writer] Add a PHDR program table entry for dynamic files.
Michael Spencer
bigcheesegs at gmail.com
Fri Feb 22 18:28:59 PST 2013
Hi shankarke,
This adds a PT_PHDR entry for dynamic files.
http://llvm-reviews.chandlerc.com/D454
Files:
lib/ReaderWriter/ELF/DefaultLayout.h
lib/ReaderWriter/ELF/HeaderChunks.h
test/elf/dynamic-phdr.test
Index: lib/ReaderWriter/ELF/DefaultLayout.h
===================================================================
--- lib/ReaderWriter/ELF/DefaultLayout.h
+++ lib/ReaderWriter/ELF/DefaultLayout.h
@@ -593,6 +593,8 @@
for (auto si : _segments) {
newSegmentHeaderAdded = _programHeader->addSegment(si);
}
+ if (_targetInfo.isDynamic() && _programHeader->addPHDR())
+ newSegmentHeaderAdded = true;
if (!newSegmentHeaderAdded)
break;
uint64_t fileoffset = 0;
Index: lib/ReaderWriter/ELF/HeaderChunks.h
===================================================================
--- lib/ReaderWriter/ELF/HeaderChunks.h
+++ lib/ReaderWriter/ELF/HeaderChunks.h
@@ -119,6 +119,27 @@
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();
}
Index: test/elf/dynamic-phdr.test
===================================================================
--- /dev/null
+++ test/elf/dynamic-phdr.test
@@ -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--
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D454.1.patch
Type: text/x-patch
Size: 1826 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130222/33044b59/attachment.bin>
More information about the llvm-commits
mailing list