Skip to content

Commit

Permalink
Bug 1378986 - Adjust the fake phdr section properly. r=froydnj
Browse files Browse the repository at this point in the history
The PT_PHDR segment is optional, but the Android toolchain decides to
create one in some cases, and places it first. When that happens, the
work around for bug 1233963 fails, because the fake phdr section has not
been adjusted yet (it only happens when we see a PT_LOAD).

So we adjust the fake phdr section when we see a PT_PHDR segment (and
avoid re-updating it when we see a subsequent PT_LOAD).
  • Loading branch information
glandium committed Jul 7, 2017
1 parent 011746a commit 08138cf
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions build/unix/elfhack/elf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ Elf::Elf(std::ifstream &file)
if (ehdr->e_phnum == 0)
return;

bool adjusted_phdr_section = false;
// Read program headers
file.seekg(ehdr->e_phoff);
for (int i = 0; i < ehdr->e_phnum; i++) {
Expand All @@ -247,12 +248,20 @@ Elf::Elf(std::ifstream &file)
if ((phdr.p_type == PT_LOAD) && (phdr.p_offset == 0)) {
// Use a fake section for ehdr and phdr
ehdr->getShdr().sh_addr = phdr.p_vaddr;
phdr_section->getShdr().sh_addr += phdr.p_vaddr;
if (!adjusted_phdr_section) {
phdr_section->getShdr().sh_addr += phdr.p_vaddr;
adjusted_phdr_section = true;
}
segment->addSection(ehdr);
segment->addSection(phdr_section);
}
if (phdr.p_type == PT_PHDR)
if (phdr.p_type == PT_PHDR) {
if (!adjusted_phdr_section) {
phdr_section->getShdr().sh_addr = phdr.p_vaddr;
adjusted_phdr_section = true;
}
segment->addSection(phdr_section);
}
for (int j = 1; j < ehdr->e_shnum; j++)
if (phdr.contains(sections[j]))
segment->addSection(sections[j]);
Expand Down

0 comments on commit 08138cf

Please sign in to comment.