diff --git a/Core/ELF/ElfReader.cpp b/Core/ELF/ElfReader.cpp index 1542e65dfc..2df7fa01eb 100644 --- a/Core/ELF/ElfReader.cpp +++ b/Core/ELF/ElfReader.cpp @@ -28,8 +28,7 @@ using std::strnlen; #endif -const char *ElfReader::GetSectionName(int section) -{ +const char *ElfReader::GetSectionName(int section) const { if (sections[section].sh_type == SHT_NULL) return 0; @@ -615,6 +614,17 @@ u32 ElfReader::GetTotalDataSize() const { return total; } +u32 ElfReader::GetTotalSectionSizeByPrefix(const std::string &prefix) const { + u32 total = 0; + for (int i = 0; i < GetNumSections(); ++i) { + const char *secname = GetSectionName(i); + if (secname && !strncmp(secname, prefix.c_str(), prefix.length())) { + total += sections[i].sh_size; + } + } + return total; +} + bool ElfReader::LoadSymbols() { bool hasSymbols = false; diff --git a/Core/ELF/ElfReader.h b/Core/ELF/ElfReader.h index 78b99ebf86..62417a7db8 100644 --- a/Core/ELF/ElfReader.h +++ b/Core/ELF/ElfReader.h @@ -79,7 +79,7 @@ public: int GetNumSegments() const { return (int)(header->e_phnum); } int GetNumSections() const { return (int)(header->e_shnum); } - const char *GetSectionName(int section); + const char *GetSectionName(int section) const; u8 *GetPtr(u32 offset) const { return (u8*)base + offset; } @@ -132,6 +132,7 @@ public: u32 GetTotalTextSize() const; u32 GetTotalDataSize() const; + u32 GetTotalSectionSizeByPrefix(const std::string &prefix) const; // More indepth stuff:) int LoadInto(u32 vaddr, bool fromTop); diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 827b3b8100..79f719945c 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -994,12 +994,7 @@ Module *__KernelLoadELFFromPtr(const u8 *ptr, u32 loadAddress, bool fromTop, std module->nm.text_size = 0; } - SectionID bssSection = reader.GetSectionByName(".bss"); - if (bssSection != -1) { - module->nm.bss_size = reader.GetSectionSize(bssSection); - } else { - module->nm.bss_size = 0; - } + module->nm.bss_size = reader.GetTotalSectionSizeByPrefix(".bss"); module->nm.data_size = reader.GetTotalDataSize() - module->nm.bss_size; INFO_LOG(LOADER, "Module %s: %08x %08x %08x", modinfo->name, modinfo->gp, modinfo->libent, modinfo->libstub);