PackVmlinuxBase::canPack bug for AMD64 with holes between PT_LOAD

This commit is contained in:
John Reiser
2006-12-19 18:18:47 -08:00
parent cd6a318903
commit 1d39796e3f
+17 -12
View File
@@ -137,8 +137,9 @@ bool PackVmlinuxBase<T>::canPack()
|| ehdri.e_machine != my_e_machine || ehdri.e_machine != my_e_machine
|| ehdri.e_version != 1 // version || ehdri.e_version != 1 // version
|| ehdri.e_ehsize != sizeof(ehdri) // different <elf.h> ? || ehdri.e_ehsize != sizeof(ehdri) // different <elf.h> ?
) ) {
return false; return false;
}
// additional requirements for vmlinux // additional requirements for vmlinux
if (ehdri.e_type != Ehdr::ET_EXEC if (ehdri.e_type != Ehdr::ET_EXEC
@@ -155,15 +156,16 @@ bool PackVmlinuxBase<T>::canPack()
return false; return false;
} }
{ {
int j; int j;
for (p = shdri, j= ehdri.e_shnum; --j>=0; ++p) { for (p = shdri, j= ehdri.e_shnum; --j>=0; ++p) {
if (Shdr::SHT_PROGBITS==p->sh_type if (Shdr::SHT_PROGBITS==p->sh_type
&& 0==strcmp("__ksymtab", p->sh_name + shstrtab)) { && 0==strcmp("__ksymtab", p->sh_name + shstrtab)) {
break; break;
}
}
if (j < 0) {
return false;
} }
}
if (j < 0)
return false;
} }
phdri = new Phdr[(unsigned) ehdri.e_phnum]; phdri = new Phdr[(unsigned) ehdri.e_phnum];
@@ -181,9 +183,12 @@ bool PackVmlinuxBase<T>::canPack()
return false; return false;
} }
if (0 < j) { if (0 < j) {
unsigned const sz = (0u - phdri[j-1].p_align) unsigned const org = (0u - phdri[j].p_align) &
& (phdri[j-1].p_align -1 + phdri[j-1].p_filesz); (-1 + phdri[j].p_align +
if ((sz + phdri[j-1].p_offset)!=phdri[j].p_offset) { phdri[j-1].p_filesz + phdri[j-1].p_offset);
unsigned const loc = (0u - phdri[j].p_align) &
(-1 + phdri[j].p_align + phdri[j].p_offset);
if (org!=loc) {
return false; return false;
} }
} }