Bug 628618 part 6 - Delay refreshing of ElfSection addresses and offsets. r=tglek,a=sdwilsh

This commit is contained in:
Mike Hommey 2011-01-28 09:22:58 +01:00
parent cc0eedf4c6
commit 3a16edea86
3 changed files with 13 additions and 12 deletions

View File

@ -234,19 +234,19 @@ Elf::Elf(std::ifstream &file)
s.sh_size = s.sh_entsize * ehdr->e_phnum;
phdr_section = new ElfSection(s, NULL, NULL);
phdr_section->insertAfter(ehdr);
phdr_section->insertAfter(ehdr, false);
sections[1]->insertAfter(phdr_section);
sections[1]->insertAfter(phdr_section, false);
for (int i = 2; i < ehdr->e_shnum; i++) {
// TODO: this should be done in a better way
if ((shdr_section->getPrevious() == NULL) && (shdr[i]->sh_offset > ehdr->e_shoff)) {
shdr_section->insertAfter(sections[i - 1]);
sections[i]->insertAfter(shdr_section);
shdr_section->insertAfter(sections[i - 1], false);
sections[i]->insertAfter(shdr_section, false);
} else
sections[i]->insertAfter(sections[i - 1]);
sections[i]->insertAfter(sections[i - 1], false);
}
if (shdr_section->getPrevious() == NULL)
shdr_section->insertAfter(sections[ehdr->e_shnum - 1]);
shdr_section->insertAfter(sections[ehdr->e_shnum - 1], false);
tmp_file = NULL;
tmp_shdr = NULL;
@ -273,7 +273,6 @@ Elf::Elf(std::ifstream &file)
phdr_section->getShdr().sh_addr += phdr.p_vaddr;
segment->addSection(ehdr);
segment->addSection(phdr_section);
ehdr->markDirty();
}
if (phdr.p_type == PT_PHDR)
segment->addSection(phdr_section);
@ -381,7 +380,7 @@ void Elf::write(std::ofstream &file)
ehdr->e_shnum = section->getIndex() + 1;
section->getShdr().sh_name = eh_shstrndx->getStrIndex(section->getName());
}
phdr_section->getNext()->markDirty();
ehdr->markDirty();
// Adjust PT_LOAD segments
int i = 0;
for (std::vector<ElfSegment *>::iterator seg = segments.begin(); seg != segments.end(); seg++, i++) {

View File

@ -316,8 +316,6 @@ int do_relocation_section(Elf *elf, unsigned int rel_type)
Elf_Shdr relhackcode_section(relhackcode32_section);
ElfRelHack_Section *relhack = new ElfRelHack_Section(relhack_section);
ElfRelHackCode_Section *relhackcode = new ElfRelHackCode_Section(relhackcode_section, *elf);
relhackcode->insertAfter(section);
relhack->insertAfter(relhackcode);
std::vector<Rel_Type> new_rels;
Elf_RelHack relhack_entry;
@ -350,6 +348,9 @@ int do_relocation_section(Elf *elf, unsigned int rel_type)
relhack_entry.r_offset = relhack_entry.r_info = 0;
relhack->push_back(relhack_entry);
relhackcode->insertAfter(section);
relhack->insertAfter(relhackcode);
section->rels.assign(new_rels.begin(), new_rels.end());
section->shrink(new_rels.size() * section->getEntSize());
ElfLocation *init = new ElfLocation(relhackcode, 0);

View File

@ -334,7 +334,7 @@ public:
(getFlags() & SHF_ALLOC));
}
void insertAfter(ElfSection *section) {
void insertAfter(ElfSection *section, bool dirty = true) {
if (previous != NULL)
previous->next = next;
if (next != NULL)
@ -347,7 +347,8 @@ public:
next = NULL;
if (next != NULL)
next->previous = this;
markDirty();
if (dirty)
markDirty();
}
void markDirty() {