mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Move ELFLoader debug output behind flags.
The logging spam was out of control.
This commit is contained in:
parent
fe237ee215
commit
56ed448424
Notes:
sideshowbarker
2024-07-19 18:44:55 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/56ed448424b
3 changed files with 29 additions and 1 deletions
|
@ -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<const RelocationSection>(m_image.section(0));
|
||||
|
||||
#ifdef ELFIMAGE_DEBUG
|
||||
kprintf("Found relocations for %s in %s\n", name(), relocationSection.name());
|
||||
#endif
|
||||
return static_cast<const RelocationSection>(relocationSection);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#include "ELFLoader.h"
|
||||
#include <AK/kstdio.h>
|
||||
|
||||
//#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?
|
||||
|
|
|
@ -3,6 +3,8 @@
|
|||
#include <AK/TemporaryFile.h>
|
||||
#include <AK/Types.h>
|
||||
|
||||
//#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;
|
||||
|
|
Loading…
Reference in a new issue