PLUGINS: Remove spurious extra allocation.
Elf32_Phdr.p_align is to align the memory location of the loaded segment, not to extend its size. The size of the scratch area (like .bss and .sbss) is p_memsz-p_filesz, which has to be set to zero by the loader. svn-id: r52576
This commit is contained in:
parent
4c7f5084c2
commit
364acaae45
2 changed files with 13 additions and 14 deletions
|
@ -157,11 +157,7 @@ bool DLObject::readProgramHeaders(Elf32_Ehdr *ehdr, Elf32_Phdr *phdr, Elf32_Half
|
|||
}
|
||||
|
||||
bool DLObject::loadSegment(Elf32_Phdr *phdr) {
|
||||
// Attempt to allocate memory for segment
|
||||
uint32 extra = phdr->p_vaddr % phdr->p_align; // Get extra length TODO: check logic here
|
||||
debug(2, "elfloader: Extra mem is %x", extra);
|
||||
|
||||
_segment = (byte *)allocSegment(phdr->p_align, phdr->p_memsz + extra);
|
||||
_segment = (byte *)allocSegment(phdr->p_align, phdr->p_memsz);
|
||||
|
||||
if (!_segment) {
|
||||
warning("elfloader: Out of memory.");
|
||||
|
@ -171,10 +167,10 @@ bool DLObject::loadSegment(Elf32_Phdr *phdr) {
|
|||
debug(2, "elfloader: Allocated segment @ %p", _segment);
|
||||
|
||||
// Get offset to load segment into
|
||||
_segmentSize = phdr->p_memsz + extra;
|
||||
_segmentSize = phdr->p_memsz;
|
||||
_segmentVMA = phdr->p_vaddr;
|
||||
|
||||
// Set bss segment to 0 if necessary (assumes bss is at the end)
|
||||
// Set .bss segment to 0 if necessary
|
||||
if (phdr->p_memsz > phdr->p_filesz) {
|
||||
debug(2, "elfloader: Setting %p to %p to 0 for bss",
|
||||
_segment + phdr->p_filesz, _segment + phdr->p_memsz);
|
||||
|
|
|
@ -273,14 +273,10 @@ bool MIPSDLObject::loadSegment(Elf32_Phdr *phdr) {
|
|||
|
||||
// We need to take account of non-allocated segment for shorts
|
||||
if (phdr->p_flags & PF_X) { // This is a relocated segment
|
||||
// Attempt to allocate memory for segment
|
||||
uint32 extra = phdr->p_vaddr % phdr->p_align; // Get extra length TODO: check logic here
|
||||
debug(2, "elfloader: Extra mem is %x", extra);
|
||||
|
||||
if (phdr->p_align < 0x10000)
|
||||
phdr->p_align = 0x10000; // Fix for wrong alignment on e.g. AGI
|
||||
|
||||
_segment = (byte *)allocSegment(phdr->p_align, phdr->p_memsz + extra);
|
||||
_segment = (byte *)allocSegment(phdr->p_align, phdr->p_memsz);
|
||||
|
||||
if (!_segment) {
|
||||
warning("elfloader: Out of memory.");
|
||||
|
@ -291,7 +287,14 @@ bool MIPSDLObject::loadSegment(Elf32_Phdr *phdr) {
|
|||
|
||||
// Get offset to load segment into
|
||||
baseAddress = _segment + phdr->p_vaddr;
|
||||
_segmentSize = phdr->p_memsz + extra;
|
||||
_segmentSize = phdr->p_memsz;
|
||||
|
||||
// Set .bss segment to 0 if necessary
|
||||
if (phdr->p_memsz > phdr->p_filesz) {
|
||||
debug(2, "elfloader: Setting %p to %p to 0 for bss",
|
||||
_segment + phdr->p_filesz, _segment + phdr->p_memsz);
|
||||
memset(_segment + phdr->p_filesz, 0, phdr->p_memsz - phdr->p_filesz);
|
||||
}
|
||||
} else { // This is a shorts section.
|
||||
_shortsSegment = ShortsMan.newSegment(phdr->p_memsz, (char *)phdr->p_vaddr);
|
||||
|
||||
|
@ -301,7 +304,7 @@ bool MIPSDLObject::loadSegment(Elf32_Phdr *phdr) {
|
|||
_shortsSegment->getOffset());
|
||||
}
|
||||
|
||||
// Set bss segment to 0 if necessary (assumes bss is at the end)
|
||||
// Set .sbss segment to 0 if necessary
|
||||
if (phdr->p_memsz > phdr->p_filesz) {
|
||||
debug(2, "elfloader: Setting %p to %p to 0 for bss", baseAddress + phdr->p_filesz,
|
||||
baseAddress + phdr->p_memsz);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue