[ELF][Writer] Add a PHDR program table entry for dynamic files.

llvm-svn: 175951
This commit is contained in:
Michael J. Spencer 2013-02-23 03:58:06 +00:00
parent dacee2bb44
commit 13db19d64e
3 changed files with 30 additions and 0 deletions

View File

@ -593,6 +593,8 @@ DefaultLayout<ELFT>::assignVirtualAddress() {
for (auto si : _segments) {
newSegmentHeaderAdded = _programHeader->addSegment(si);
}
if (_targetInfo.isDynamic() && _programHeader->addPHDR())
newSegmentHeaderAdded = true;
if (!newSegmentHeaderAdded)
break;
uint64_t fileoffset = 0;

View File

@ -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();
}

View File

@ -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--