Bug 1423821 - Add a consistency check for section offsets to elfhack. r=froydnj

lld is being too smart for its own good, and places non-relocatable data
right after the program headers, which prevents the program headers from
growing. But elfhack wasn't checking for that, so happily placed the
non-relocatable data at its non-relocated location, overwriting the last
item of the program headers.

--HG--
extra : rebase_source : 6f26d475f0a19d88ddf21399dbce8ceac62b492d
This commit is contained in:
Mike Hommey 2017-12-07 15:34:58 +09:00
Родитель b248919e81
Коммит 8bb6a1a03e
1 изменённых файлов: 12 добавлений и 0 удалений

Просмотреть файл

@ -420,6 +420,18 @@ void Elf::normalize()
ehdr->e_shoff = shdr_section->getOffset();
ehdr->e_entry = eh_entry.getValue();
ehdr->e_shstrndx = eh_shstrndx->getIndex();
// Check sections consistency
unsigned int minOffset = 0;
for (ElfSection *section = ehdr; section != nullptr; section = section->getNext()) {
unsigned int offset = section->getOffset();
if (offset < minOffset) {
throw std::runtime_error("Sections overlap");
}
if (section->getType() != SHT_NOBITS) {
minOffset = offset + section->getSize();
}
}
}
void Elf::write(std::ofstream &file)