mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +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];
|
char relocationSectionName[128];
|
||||||
int x = ksprintf(relocationSectionName, ".rel%s", name());
|
int x = ksprintf(relocationSectionName, ".rel%s", name());
|
||||||
|
|
||||||
|
#ifdef ELFIMAGE_DEBUG
|
||||||
kprintf("looking for '%s'\n", relocationSectionName);
|
kprintf("looking for '%s'\n", relocationSectionName);
|
||||||
|
#endif
|
||||||
auto relocationSection = m_image.lookupSection(relocationSectionName);
|
auto relocationSection = m_image.lookupSection(relocationSectionName);
|
||||||
if (relocationSection.type() != SHT_REL)
|
if (relocationSection.type() != SHT_REL)
|
||||||
return static_cast<const RelocationSection>(m_image.section(0));
|
return static_cast<const RelocationSection>(m_image.section(0));
|
||||||
|
|
||||||
|
#ifdef ELFIMAGE_DEBUG
|
||||||
kprintf("Found relocations for %s in %s\n", name(), relocationSection.name());
|
kprintf("Found relocations for %s in %s\n", name(), relocationSection.name());
|
||||||
|
#endif
|
||||||
return static_cast<const RelocationSection>(relocationSection);
|
return static_cast<const RelocationSection>(relocationSection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "ELFLoader.h"
|
#include "ELFLoader.h"
|
||||||
#include <AK/kstdio.h>
|
#include <AK/kstdio.h>
|
||||||
|
|
||||||
|
//#define ELFLOADER_DEBUG
|
||||||
|
|
||||||
#ifdef SERENITY
|
#ifdef SERENITY
|
||||||
ELFLoader::ELFLoader(ExecSpace& execSpace, ByteBuffer&& file)
|
ELFLoader::ELFLoader(ExecSpace& execSpace, ByteBuffer&& file)
|
||||||
#else
|
#else
|
||||||
|
@ -17,7 +19,9 @@ ELFLoader::~ELFLoader()
|
||||||
|
|
||||||
bool ELFLoader::load()
|
bool ELFLoader::load()
|
||||||
{
|
{
|
||||||
|
#ifdef ELFLOADER_DEBUG
|
||||||
m_image->dump();
|
m_image->dump();
|
||||||
|
#endif
|
||||||
if (!m_image->isValid())
|
if (!m_image->isValid())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -30,9 +34,13 @@ bool ELFLoader::load()
|
||||||
|
|
||||||
void ELFLoader::layout()
|
void ELFLoader::layout()
|
||||||
{
|
{
|
||||||
|
#ifdef ELFLOADER_DEBUG
|
||||||
kprintf("[ELFLoader] Layout\n");
|
kprintf("[ELFLoader] Layout\n");
|
||||||
|
#endif
|
||||||
m_image->forEachSectionOfType(SHT_PROGBITS, [this] (const ELFImage::Section& section) {
|
m_image->forEachSectionOfType(SHT_PROGBITS, [this] (const ELFImage::Section& section) {
|
||||||
|
#ifdef ELFLOADER_DEBUG
|
||||||
kprintf("[ELFLoader] Allocating progbits section: %s\n", section.name());
|
kprintf("[ELFLoader] Allocating progbits section: %s\n", section.name());
|
||||||
|
#endif
|
||||||
char* ptr = m_execSpace.allocateArea(section.name(), section.size());
|
char* ptr = m_execSpace.allocateArea(section.name(), section.size());
|
||||||
memcpy(ptr, section.rawData(), section.size());
|
memcpy(ptr, section.rawData(), section.size());
|
||||||
m_sections.set(section.name(), move(ptr));
|
m_sections.set(section.name(), move(ptr));
|
||||||
|
@ -61,7 +69,9 @@ char* ELFLoader::areaForSectionName(const char* name)
|
||||||
|
|
||||||
void ELFLoader::performRelocations()
|
void ELFLoader::performRelocations()
|
||||||
{
|
{
|
||||||
|
#ifdef ELFLOADER_DEBUG
|
||||||
kprintf("[ELFLoader] Performing relocations\n");
|
kprintf("[ELFLoader] Performing relocations\n");
|
||||||
|
#endif
|
||||||
|
|
||||||
m_image->forEachSectionOfType(SHT_PROGBITS, [this] (const ELFImage::Section& section) {
|
m_image->forEachSectionOfType(SHT_PROGBITS, [this] (const ELFImage::Section& section) {
|
||||||
auto& relocations = section.relocations();
|
auto& relocations = section.relocations();
|
||||||
|
@ -75,6 +85,7 @@ void ELFLoader::performRelocations()
|
||||||
case R_386_PC32: {
|
case R_386_PC32: {
|
||||||
char* targetPtr = (char*)lookup(symbol);
|
char* targetPtr = (char*)lookup(symbol);
|
||||||
ptrdiff_t relativeOffset = (char*)targetPtr - ((char*)&patchPtr + 4);
|
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",
|
kprintf("[ELFLoader] Relocate PC32: offset=%x, symbol=%u(%s) value=%x target=%p, offset=%d\n",
|
||||||
relocation.offset(),
|
relocation.offset(),
|
||||||
symbol.index(),
|
symbol.index(),
|
||||||
|
@ -83,16 +94,19 @@ void ELFLoader::performRelocations()
|
||||||
targetPtr,
|
targetPtr,
|
||||||
relativeOffset
|
relativeOffset
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
patchPtr = relativeOffset;
|
patchPtr = relativeOffset;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case R_386_32: {
|
case R_386_32: {
|
||||||
|
#ifdef ELFLOADER_DEBUG
|
||||||
kprintf("[ELFLoader] Relocate Abs32: symbol=%u(%s), value=%x, section=%s\n",
|
kprintf("[ELFLoader] Relocate Abs32: symbol=%u(%s), value=%x, section=%s\n",
|
||||||
symbol.index(),
|
symbol.index(),
|
||||||
symbol.name(),
|
symbol.name(),
|
||||||
symbol.value(),
|
symbol.value(),
|
||||||
symbol.section().name()
|
symbol.section().name()
|
||||||
);
|
);
|
||||||
|
#endif
|
||||||
char* targetPtr = areaForSection(symbol.section()) + symbol.value();
|
char* targetPtr = areaForSection(symbol.section()) + symbol.value();
|
||||||
patchPtr += (ptrdiff_t)targetPtr;
|
patchPtr += (ptrdiff_t)targetPtr;
|
||||||
break;
|
break;
|
||||||
|
@ -108,7 +122,9 @@ void ELFLoader::performRelocations()
|
||||||
void ELFLoader::exportSymbols()
|
void ELFLoader::exportSymbols()
|
||||||
{
|
{
|
||||||
m_image->forEachSymbol([&] (const ELFImage::Symbol symbol) {
|
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());
|
kprintf("symbol: %u, type=%u, name=%s, section=%u\n", symbol.index(), symbol.type(), symbol.name(), symbol.sectionIndex());
|
||||||
|
#endif
|
||||||
if (symbol.type() == STT_FUNC)
|
if (symbol.type() == STT_FUNC)
|
||||||
m_execSpace.addSymbol(symbol.name(), areaForSection(symbol.section()) + symbol.value(), symbol.size());
|
m_execSpace.addSymbol(symbol.name(), areaForSection(symbol.section()) + symbol.value(), symbol.size());
|
||||||
// FIXME: What about other symbol types?
|
// FIXME: What about other symbol types?
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include <AK/TemporaryFile.h>
|
#include <AK/TemporaryFile.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
|
|
||||||
|
//#define EXECSPACE_DEBUG
|
||||||
|
|
||||||
ExecSpace::ExecSpace()
|
ExecSpace::ExecSpace()
|
||||||
{
|
{
|
||||||
initializeBuiltins();
|
initializeBuiltins();
|
||||||
|
@ -36,6 +38,7 @@ bool ExecSpace::loadELF(MappedFile&& file)
|
||||||
ELFLoader loader(*this, move(file));
|
ELFLoader loader(*this, move(file));
|
||||||
if (!loader.load())
|
if (!loader.load())
|
||||||
return false;
|
return false;
|
||||||
|
#ifdef EXECSPACE_DEBUG
|
||||||
kprintf("[ExecSpace] ELF loaded, symbol map now:\n");
|
kprintf("[ExecSpace] ELF loaded, symbol map now:\n");
|
||||||
for (auto& s : m_symbols) {
|
for (auto& s : m_symbols) {
|
||||||
kprintf("> %p: %s (%u)\n",
|
kprintf("> %p: %s (%u)\n",
|
||||||
|
@ -43,9 +46,11 @@ bool ExecSpace::loadELF(MappedFile&& file)
|
||||||
s.key.characters(),
|
s.key.characters(),
|
||||||
s.value.size);
|
s.value.size);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef EXECSPACE_DEBUG
|
||||||
static void disassemble(const char* data, size_t length)
|
static void disassemble(const char* data, size_t length)
|
||||||
{
|
{
|
||||||
if (!length)
|
if (!length)
|
||||||
|
@ -74,13 +79,16 @@ static void disassemble(const char* data, size_t length)
|
||||||
system(cmdbuf);
|
system(cmdbuf);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
char* ExecSpace::symbolPtr(const char* name)
|
char* ExecSpace::symbolPtr(const char* name)
|
||||||
{
|
{
|
||||||
if (auto it = m_symbols.find(name); it != m_symbols.end()) {
|
if (auto it = m_symbols.find(name); it != m_symbols.end()) {
|
||||||
kprintf("[ELFLoader] symbolPtr(%s) dump:\n", name);
|
|
||||||
auto& symbol = (*it).value;
|
auto& symbol = (*it).value;
|
||||||
|
#ifdef EXECSPACE_DEBUG
|
||||||
|
kprintf("[ELFLoader] symbolPtr(%s) dump:\n", name);
|
||||||
disassemble(symbol.ptr, symbol.size);
|
disassemble(symbol.ptr, symbol.size);
|
||||||
|
#endif
|
||||||
return symbol.ptr;
|
return symbol.ptr;
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
Loading…
Reference in a new issue