From 56ed448424b7b4a9fb724b9c5e7a23c2586232a0 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 23 Oct 2018 11:03:26 +0200 Subject: [PATCH] Move ELFLoader debug output behind flags. The logging spam was out of control. --- ELFLoader/ELFImage.cpp | 4 ++++ ELFLoader/ELFLoader.cpp | 16 ++++++++++++++++ ELFLoader/ExecSpace.cpp | 10 +++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ELFLoader/ELFImage.cpp b/ELFLoader/ELFImage.cpp index a4dbdc26c3..7d2d1426a5 100644 --- a/ELFLoader/ELFImage.cpp +++ b/ELFLoader/ELFImage.cpp @@ -180,12 +180,16 @@ const ELFImage::RelocationSection ELFImage::Section::relocations() const char relocationSectionName[128]; int x = ksprintf(relocationSectionName, ".rel%s", name()); +#ifdef ELFIMAGE_DEBUG kprintf("looking for '%s'\n", relocationSectionName); +#endif auto relocationSection = m_image.lookupSection(relocationSectionName); if (relocationSection.type() != SHT_REL) return static_cast(m_image.section(0)); +#ifdef ELFIMAGE_DEBUG kprintf("Found relocations for %s in %s\n", name(), relocationSection.name()); +#endif return static_cast(relocationSection); } diff --git a/ELFLoader/ELFLoader.cpp b/ELFLoader/ELFLoader.cpp index 40df901f37..3b3bf4845e 100644 --- a/ELFLoader/ELFLoader.cpp +++ b/ELFLoader/ELFLoader.cpp @@ -1,6 +1,8 @@ #include "ELFLoader.h" #include +//#define ELFLOADER_DEBUG + #ifdef SERENITY ELFLoader::ELFLoader(ExecSpace& execSpace, ByteBuffer&& file) #else @@ -17,7 +19,9 @@ ELFLoader::~ELFLoader() bool ELFLoader::load() { +#ifdef ELFLOADER_DEBUG m_image->dump(); +#endif if (!m_image->isValid()) return false; @@ -30,9 +34,13 @@ bool ELFLoader::load() void ELFLoader::layout() { +#ifdef ELFLOADER_DEBUG kprintf("[ELFLoader] Layout\n"); +#endif m_image->forEachSectionOfType(SHT_PROGBITS, [this] (const ELFImage::Section& section) { +#ifdef ELFLOADER_DEBUG kprintf("[ELFLoader] Allocating progbits section: %s\n", section.name()); +#endif char* ptr = m_execSpace.allocateArea(section.name(), section.size()); memcpy(ptr, section.rawData(), section.size()); m_sections.set(section.name(), move(ptr)); @@ -61,7 +69,9 @@ char* ELFLoader::areaForSectionName(const char* name) void ELFLoader::performRelocations() { +#ifdef ELFLOADER_DEBUG kprintf("[ELFLoader] Performing relocations\n"); +#endif m_image->forEachSectionOfType(SHT_PROGBITS, [this] (const ELFImage::Section& section) { auto& relocations = section.relocations(); @@ -75,6 +85,7 @@ void ELFLoader::performRelocations() case R_386_PC32: { char* targetPtr = (char*)lookup(symbol); ptrdiff_t relativeOffset = (char*)targetPtr - ((char*)&patchPtr + 4); +#ifdef ELFLOADER_DEBUG kprintf("[ELFLoader] Relocate PC32: offset=%x, symbol=%u(%s) value=%x target=%p, offset=%d\n", relocation.offset(), symbol.index(), @@ -83,16 +94,19 @@ void ELFLoader::performRelocations() targetPtr, relativeOffset ); +#endif patchPtr = relativeOffset; break; } case R_386_32: { +#ifdef ELFLOADER_DEBUG kprintf("[ELFLoader] Relocate Abs32: symbol=%u(%s), value=%x, section=%s\n", symbol.index(), symbol.name(), symbol.value(), symbol.section().name() ); +#endif char* targetPtr = areaForSection(symbol.section()) + symbol.value(); patchPtr += (ptrdiff_t)targetPtr; break; @@ -108,7 +122,9 @@ void ELFLoader::performRelocations() void ELFLoader::exportSymbols() { m_image->forEachSymbol([&] (const ELFImage::Symbol symbol) { +#ifdef ELFLOADER_DEBUG kprintf("symbol: %u, type=%u, name=%s, section=%u\n", symbol.index(), symbol.type(), symbol.name(), symbol.sectionIndex()); +#endif if (symbol.type() == STT_FUNC) m_execSpace.addSymbol(symbol.name(), areaForSection(symbol.section()) + symbol.value(), symbol.size()); // FIXME: What about other symbol types? diff --git a/ELFLoader/ExecSpace.cpp b/ELFLoader/ExecSpace.cpp index cbcc8568a5..33172c29d6 100644 --- a/ELFLoader/ExecSpace.cpp +++ b/ELFLoader/ExecSpace.cpp @@ -3,6 +3,8 @@ #include #include +//#define EXECSPACE_DEBUG + ExecSpace::ExecSpace() { initializeBuiltins(); @@ -36,6 +38,7 @@ bool ExecSpace::loadELF(MappedFile&& file) ELFLoader loader(*this, move(file)); if (!loader.load()) return false; +#ifdef EXECSPACE_DEBUG kprintf("[ExecSpace] ELF loaded, symbol map now:\n"); for (auto& s : m_symbols) { kprintf("> %p: %s (%u)\n", @@ -43,9 +46,11 @@ bool ExecSpace::loadELF(MappedFile&& file) s.key.characters(), s.value.size); } +#endif return true; } +#ifdef EXECSPACE_DEBUG static void disassemble(const char* data, size_t length) { if (!length) @@ -74,13 +79,16 @@ static void disassemble(const char* data, size_t length) system(cmdbuf); #endif } +#endif char* ExecSpace::symbolPtr(const char* name) { if (auto it = m_symbols.find(name); it != m_symbols.end()) { - kprintf("[ELFLoader] symbolPtr(%s) dump:\n", name); auto& symbol = (*it).value; +#ifdef EXECSPACE_DEBUG + kprintf("[ELFLoader] symbolPtr(%s) dump:\n", name); disassemble(symbol.ptr, symbol.size); +#endif return symbol.ptr; } return nullptr;