diff options
author | Andre Heider | 2010-09-05 22:00:19 +0000 |
---|---|---|
committer | Andre Heider | 2010-09-05 22:00:19 +0000 |
commit | 364acaae455b465201f4467809edb7384a6c2bda (patch) | |
tree | 14dac920f22e6059ca11903b07fef9337fabf6be /backends | |
parent | 4c7f5084c2e5e10942d2f5d8dfffb4a7f3258ad5 (diff) | |
download | scummvm-rg350-364acaae455b465201f4467809edb7384a6c2bda.tar.gz scummvm-rg350-364acaae455b465201f4467809edb7384a6c2bda.tar.bz2 scummvm-rg350-364acaae455b465201f4467809edb7384a6c2bda.zip |
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
Diffstat (limited to 'backends')
-rw-r--r-- | backends/plugins/elf/elf-loader.cpp | 10 | ||||
-rw-r--r-- | backends/plugins/elf/mips-loader.cpp | 17 |
2 files changed, 13 insertions, 14 deletions
diff --git a/backends/plugins/elf/elf-loader.cpp b/backends/plugins/elf/elf-loader.cpp index 7bdec22508..a6e20a7f6d 100644 --- a/backends/plugins/elf/elf-loader.cpp +++ b/backends/plugins/elf/elf-loader.cpp @@ -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); diff --git a/backends/plugins/elf/mips-loader.cpp b/backends/plugins/elf/mips-loader.cpp index 6ad608556e..0fc1ca8728 100644 --- a/backends/plugins/elf/mips-loader.cpp +++ b/backends/plugins/elf/mips-loader.cpp @@ -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); |