forked from OSchip/llvm-project
[ELF][Writer] Add a PHDR program table entry for dynamic files.
llvm-svn: 175951
This commit is contained in:
parent
dacee2bb44
commit
13db19d64e
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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--
|
Loading…
Reference in New Issue